<template>
	<view class="content">

		<!-- <view class="flex_box">

			<view class="timeA">申请时间</view>
			<view class="timeB" @click="openDate(0)">
				{{ queryParams.startCreationTime?queryParams.startCreationTime:'开始时间' }}
			</view>
			<view class="timeA">{{'至'}}</view>
			<view class="timeB" @click="openDate(1)">
				{{ queryParams.endCreationTime?queryParams.endCreationTime:'结束时间' }}
			</view>
			<view class="seatch_r" @click="getDataList">
				<u-icon name="search" size="22" color="#fff"></u-icon>
			</view>
		</view> -->
		<template v-if="tableData.length>0">
			<view class="contentList" v-for="item,index in tableData" :key="index">
				<view class="list_flex">
					<view class="top_flex">
						<view class="zc_btn">{{item.orderTypeVal}}</view>
						<view class="code_text">{{'订单编号'}}：{{item.orderCode}}</view>
					</view>
					<view class="top_status">
						{{item.orderStatusVal}}
					</view>
				</view>
				<view class="list_flex" style="margin-top: 20rpx;" v-for="aitem,aindex in item.waresOrderList">
					<view class="center_left">
						<image class="center_img" :src="aitem.cover || aitem.cover1" mode=""></image>
						<view class="center_title">{{aitem.waresName}}</view>
					</view>
					<view class="center_right">
						<view class="center_price"><!-- ￥{{aitem.price}} --></view>
						<view class="center_num">X{{aitem.quantity}}</view>
					</view>
				</view>
				<view class="btm_time">
					{{'创建时间'}}:{{item.creationTime}}
				</view>
				<view class="list_btn">
					<view class="list_btm1">
						{{'审核状态'}}：{{item.approveStatusVal}}
					</view>
					<view class="sub_btn" v-if="item.selfCode&&item.approveStatus!=3" @click="lookCode(item)">
						{{'查看'}}
					</view>
					<view class="sub_btn" v-if="item.selfCode&&item.approveStatus==3" @click="findWhy(item)">
						{{'驳回原因'}}
					</view>
					<view v-if="!item.approveStatus" class="sub_btn" @click="goApply(item)">
						申请自提
					</view>

				</view>
			</view>
		</template>
		<template v-else>
			<u-empty mode="list">
			</u-empty>
		</template>
		<u-datetime-picker :closeOnClickOverlay="true" @close="dataShow = false" @cancel="dataShow = false"
			@confirm="getDate" :show="dataShow" v-model="value1" mode="date"></u-datetime-picker>
		<u-popup class="thePopup" :show="successShow" mode="center" @close="successShow = false">
			<view class="successPopup">

				<view class="poupTop">
					{{'查看'}}
				</view>
				<view class="poupContent">
					<!-- {{selfCode}} -->
					<text class="green">{{'自提码'}}：{{selfCode}}</text>
					<text class="copy" @click="copy(selfCode)">{{'复制'}}</text>
				</view>
				<view class="tipcontent">
					<view class="tip1">
						{{'提货地址'}}
					</view>
					<view class="tip2">
						{{'自提地址：山东省青岛市崂山区金家岭街道金岭广场1号楼13层101前台'}}</br>
						{{'提货电话'}}：400-111-2818
					</view>
				</view>
				<view class="poupBtn" @click="successShow=false">
					{{'确定'}}
				</view>
			</view>
		</u-popup>
		<u-popup :show="rejectShow" closeable mode="center" round='10' @close="rejectShow=false">\
			<view class="popview">
				<view class="email_neir " @click="clickhtml(rejectContent)" v-html="rejectContent">

				</view>
			</view>

		</u-popup>
	</view>
</template>

<script>
	import * as sel from '@/config/selfService.js'
	import * as mar from "@/config/market.js"
	import {
		formatMsToDate
	} from '@/util/index'
	export default {
		data() {
			return {
				tabList: [{
					value: 0,
					label: '可申请订单'
				}, {
					value: 1,
					label: '已申请订单'
				}],
				// isTab: 0,
				queryParams: {
					creationTimeStart: "",
					creationTimeEnd: "",
					assessType: 0,
					assessStatus: ""
				},

				tableData: [],
				dataShow: false,
				value1: '',
				timeIndex: 0,
				riqi: "",
				successShow: false,
				selfCode: "",
				rejectShow: false,
				rejectContent: ""

			}
		},
		watch: {
			// isTab(n, o) {
			// 	this.queryParams.assessType = n
			// 	this.getDataList()
			// },
		},
		onLoad() {


			this.getDataList()

		},
		methods: {
			findWhy(item) {
				this.rejectContent = item.rejectMsg
				this.rejectShow = true
			},
			clickhtml(content) {
				this.rejectShow = false
				// 在组件挂载后，调用handleImageClick方法预览第一张图片
				const parser = new DOMParser();
				const doc = parser.parseFromString(content, "text/html");
				const imgElements = doc.getElementsByTagName("img");
				if (imgElements.length > 0) {
					const firstImageUrl = imgElements[0].src;
					this.handleImageClick(firstImageUrl, content);
				}
			},
			handleImageClick(url, content) {
				uni.previewImage({
					urls: this.getUrls(content),
					current: url
				});
			},
			getUrls(content) {
				const parser = new DOMParser();
				const doc = parser.parseFromString(content, "text/html");
				const imgElements = doc.getElementsByTagName("img");
				const urls = [];
				for (let i = 0; i < imgElements.length; i++) {
					urls.push(imgElements[i].src);
				}
				return urls;
			},
			copy(code) {
				uni.setClipboardData({
					data: code,
					success() {
						uni.showToast({
							title: '复制成功',
							icon: 'success'
						});
					},
					fail() {
						uni.showToast({
							title: '复制失败',
							icon: 'none'
						});
					}
				});
			},
			lookCode(item) {
				this.selfCode = item.selfCode
				this.successShow = true

			},
			goApply(item) {
				let params = item
				let queryString = Object.keys(params).map(key =>
					`${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`).join('&')
				uni.navigateTo({
					url: '/pages/selfService/orderPick/applyPick?' + queryString,

				})
			},
			getDate(e) {
				if (this.timeIndex == 1) {
					this.queryParams.creationTimeEnd = formatMsToDate(e.value)
				} else {
					this.queryParams.creationTimeStart = formatMsToDate(e.value)
				}
				this.dataShow = false
			},
			openDate(index) {
				this.timeIndex = index
				this.dataShow = true
			},

			getDataList() {
				sel.getOrderSelfList(this.queryParams).then(res => {
					this.tableData = res.rows
				})


			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep img {
		max-width: 100%;
		height: auto;
	}
	.popview {
		padding: 24rpx;
		width: 620rpx;
		.email_neir {
			font-size: 24rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #666666;
		}
	}
	.content {
		background: #F2F2F2;
		padding-bottom: 20rpx;

		.tab {
			display: flex;
			align-items: center;
			justify-content: space-around;
			margin-bottom: 6rpx;
			background-color: #FFFFFF;

			.tab_i {
				text-align: center;
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #333333;
				white-space: nowrap;
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 24rpx 0;
				// background-color: pink;

			}

			.heng {
				border-bottom: 6rpx solid #005BAC;
				color: #005BAC;

			}

			.heng {
				color: #333333;
			}

		}

		.flex_box {
			background-color: #FFFFFF;
			padding: 30rpx 20rpx 30rpx 50rpx;
			align-items: center;
			justify-content: space-between;
			display: flex;
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #999999;

			.neibox {
				display: flex;
				align-items: center;
			}

			.seatch_r {
				background: #005BAC;
				border-radius: 50%;
				padding: 8rpx;
				margin-left: 24rpx;
			}
		}

		.contentList {
			padding: 27rpx 22rpx 22rpx 22rpx;
			background-color: #FFFFFF;
			margin-top: 21rpx;

			.list_flex {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.top_flex {
					display: flex;
					align-items: center;

					.zc_btn {
						display: flex;
						align-items: center;
						justify-content: center;
						background: #3D3D3D;
						color: #FFFFFF;
						border-radius: 30rpx;
						padding: 7rpx 23rpx;
						margin-right: 8rpx;
						font-size: 20rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
					}

					.code_text {
						font-size: 24rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #999999;
					}
				}

				.top_status {
					font-size: 24rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #69A35B;
				}

				.center_left {
					display: flex;
					align-items: center;

					.center_img {
						width: 124rpx;
						height: 124rpx;
						border-radius: 15rpx;
						margin-right: 20rpx;
					}

					.center_title {
						font-size: 28rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #333333;
					}
				}

				.center_right {
					.center_price {
						font-size: 32rpx;
						font-family: Source Han Sans CN;
						font-weight: bold;
						color: #005BAC;
					}

					.center_num {
						text-align: right;
						font-size: 22rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #666666;
					}
				}

			}

			.btm_time {
				padding: 24rpx 0;
				font-size: 24rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #999999;
				border-bottom: 1rpx solid #EEEEEE;
			}

			.list_btn {
				margin-top: 22rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.list_btm1 {
					font-size: 24rpx;
					color: #666666;
				}

				.sub_btn {
					display: flex;
					align-items: center;
					justify-content: center;
					border-radius: 30rpx;
					background: #005BAC;
					color: #ffffff;
					padding: 15rpx 28rpx;
					font-size: 24rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
				}
			}
		}

		.successPopup {
			width: 560rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 26rpx 60rpx;

			.poupTop {


				font-size: 30rpx;
				font-family: Source Han Sans CN;
				font-weight: bold;
				color: #333333;
			}

			.poupContent {
				margin-top: 50rpx;

				text-align: center;

				.green {
					font-size: 36rpx;
					font-family: Source Han Sans CN;
					font-weight: bold;
					color: #69A35B;
					margin-right: 18rpx;
				}

				.copy {
					font-size: 26rpx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #005BAC;
				}
			}

			.tipcontent {
				font-size: 26rpx;
				font-family: Source Han Sans CN;
				margin-top: 36rpx;

				.tip1 {
					color: #333333;

					font-weight: bold;
				}

				.tip2 {
					color: #666666;
					font-weight: 400;
					line-height: 42rpx;
				}

			}

			.poupBtn {
				background: #005BAC;
				border-radius: 39rpx;
				padding: 26rpx 0;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #FFFFFF;
				margin-top: 70rpx;
				margin-bottom: 40rpx;
			}
		}

	}
</style>
