<template>
	<view class="container">
		<cu-custom class="main-totextbar bg-main-oil" :isBack="true" bgColor="bg-main-oil">
			<block slot="backText">返回</block>
			<block slot="content">订单详情</block>
		</cu-custom>

		<view class="status-frame">
			<view v-if="info.orderStatus">{{statusEnum[info.orderStatus].value}}</view>
			<view>提货码: <text>{{info.takeCode}}</text></view>
			<view v-if="info.orderStatus==2">提货时间:{{info.takeTime}}</view>
		</view>


		<view class="info-frame">
			<view class="header">用户手机: {{info.customerPhone}}<text>用户名: {{info.customerName}}</text></view>
			<view class="introduce" v-for="item,index in info.mallOrderInfoDetails" :key="index">
				<image :src="item.oderDetailImg"></image>
				<view>{{item.productName}}</view>
				<view>规格:{{handler(item.attributeJson)}}</view>
				<view>¥{{item.marketPrice}} X{{item.orderNum}}</view>
			</view>
			<view class="detial">
				<view>订单编号: <text>{{info.orderCode}}</text></view>
				<view>下单时间: <text>{{info.createTime}}</text></view>
				<view>支付方式: <text>积分</text></view>
				<view>商品金额: <text>¥{{info.marketPrice}}</text></view>
				<view>支付积分: <text>{{info.integral}}</text></view>
			</view>
			<view class="footer">
				<view class="button"  v-if="info.orderStatus=='1'" @click="determine">确定提货</view>
			</view>
		</view>

		<uni-popup ref="popup">
			<view class="determine-frame">
				<view class="title">是否立即提货</view>
				<view class="buttons">
					<view @click="$refs.popup.close()">取消</view>
					<view @click="submit">确认</view>
				</view>
			</view>
		</uni-popup>

	</view>
</template>

<script>
	import serve from '@/api/packageIntegral/orderList.js'

	export default {
		options: {
			styleIsolation: 'shared'
		},
		data() {
			return {
				info: {
					mallOrderInfoDetails: []
				},
				statusEnum: {
					'-1': {
						color: 'red',
						value: "已取消"
					},
					0: {
						color: 'blue',
						value: "订单新建"
					},
					1: {
						color: 'orange',
						value: "待核销"
					},
					2: {
						color: 'blue',
						value: "已核销"
					},
				}
			}
		},

		onLoad(options) {
			this.get(options.orderId)
		},
		methods: {
			determine() {
				this.$refs.popup.open('center')
			},
			handler(json) {
				json = json.replace(/'/g, '"')
				let res = JSON.parse(json)
				let values = Object.values(res)
				let text = values.reduce((prev, item, index) => {
					let _text = `${index == 0 ? '' :','}${item}`
					return prev += _text
				}, '')
				return text
			},
			get(orderId) {
				serve.get(orderId).then(res => {
					if (res.code === 20000) {
						this.info = res.data
					}
				})
			},
			submit(){
				
				let data = {}
				data.id = this.dataList[0].orderId
				data.takeCode = this.dataList[0].takeCode
				serve.takeOrder(data).then(res => {
					if (res.code === 20000) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
						this.$refs.popup.close();
						this.get(options.orderId)
						
					}
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		background: #F1F2F7;

		>.status-frame {
			position: relative;
			margin-top: 20rpx;
			padding-top: 37rpx;
			padding-right: 30rpx;
			width: 100%;
			height: 170rpx;
			background: #fff;

			>view {
				&:nth-of-type(1) {
					position: absolute;
					top: 50%;
					transform: translateY(-50%);
					left: 34rpx;
					font-size: 40rpx;
					font-weight: 550;
					color: #333;
				}

				&:nth-of-type(2) {
					text-align: right;
					font-size: 36rpx;
					font-weight: 550;
					color: #333;

					>text {
						color: #F83D3D;
					}
				}

				&:nth-of-type(3) {
					margin-top: 12rpx;
					text-align: right;
					font-size: 28rpx;
					color: #666;
				}
			}
		}


		.determine-frame {
			padding-top: 85rpx;
			width: 681rpx;
			height: 340rpx;
			background: #FFFFFF;
			border-radius: 15rpx;

			>.title {
				text-align: center;
				font-size: 38rpx;
				color: #000;

			}

			>.buttons {

				display: flex;
				justify-content: space-evenly;
				margin-top: 80rpx;

				>view {
					width: 250rpx;
					height: 76rpx;
					text-align: center;
					line-height: 76rpx;
					border-radius: 10rpx;
					font-size: 28rpx;

					&:nth-of-type(1) {
						background: #FFFFFF;
						border: 1rpx solid #B6B6B6;
						color: #333;
					}

					&:nth-of-type(2) {
						background: #FE0505;
						color: #fff;
					}
				}
			}
		}


		.info-frame {
			margin-top: 20rpx;
			position: relative;
			background: #fff;
			border-bottom: 12rpx solid #F1F2F7;

			&:nth-last-of-type(1) {
				border-bottom: none
			}

			.header {
				padding: 35rpx 30rpx 0 34rpx;
				height: 83rpx;
				width: 100%;
				font-size: 28rpx;
				color: #666;
				border-bottom: 1rpx solid #D7D7D7;

				>text {
					float: right;
				}
			}

			.introduce {
				position: relative;
				padding: 28rpx 29rpx 0 268rpx;
				min-height: 233rpx;

				&:nth-last-of-type(1) {
					margin-bottom: 0;
				}

				>image {
					position: absolute;
					top: 13rpx;
					left: 32rpx;
					width: 220rpx;
					height: 220rpx;
					// border: 1px solid #333;
				}

				>view {
					&:nth-of-type(1) {
						font-size: 28rpx;
						color: #000;
					}

					&:nth-of-type(2),
					&:nth-of-type(3) {
						margin-top: 11rpx;
						font-size: 24rpx;
						color: #999;
					}

					&:nth-of-type(3) {
						margin-top: 18rpx;

					}
				}
			}

			>.detial {
				margin-top: 26rpx;
				padding: 0 32rpx;

				>view {

					font-size: 28rpx;

					>text {
						float: right;
					}

					&:nth-of-type(1),
					&:nth-of-type(2),
						{
						margin-bottom: 17rpx;
						color: #999;
					}

					&:nth-of-type(3) {
						color: #999;
					}

					&:nth-of-type(4) {
						margin-top: 30rpx;
						color: #000;
					}

					&:nth-of-type(5) {
						margin-top: 17rpx;
						color: #000;
					}

					&:nth-of-type(6) {
						margin-top: 17rpx;
						color: #F83D3D;
					}
				}
			}

			>.footer {
				position: relative;
				margin-top: 40rpx;

				.button {
					position: absolute;
					top: 0;
					right: 32rpx;
					width: 198rpx;
					height: 78rpx;
					line-height: 78rpx;
					text-align: center;
					font-size: 28rpx;
					color: #FFF;
					background: #FE0606;
					border-radius: 10rpx;
				}
			}
		}
	}
</style>