<template>
	<view class="content">
		<view class="top">
			<view class="hflex acenter">
				<!-- <view class="state">{{pageData.status}}</view> -->
				<view class="state" v-if="pageData.status == 0">已取消</view>
				<view class="state" v-if="pageData.status == 1">预订单</view>
				<view class="state" v-if="pageData.status == 2">等待买家付款</view>
				<view class="state" v-if="pageData.status == 3">等待买家付款</view>
				<view class="state" v-if="pageData.status == 4">买家已付款</view>
				<view class="state" v-if="pageData.status == 5">等待买家收货</view>
				<view class="state" v-if="pageData.status == 6">已完成</view>
				<view class="state" v-if="pageData.status == 7">退款中</view>
				<view class="state" v-if="pageData.status == 8">已退款</view>
				<view class="hflex acenter blue_bg2" v-if="pageData.status == 2">
					<view class="blue_bg">剩余付款时间</view>
					<view class="hflex acenter">
						<u-count-down autoStart :time="time" format="mm:ss" @change="onChange">
							<view class="time">
								<!-- <text class="time__item">{{ timeData.hours>10?timeData.hours:'0'+timeData.hours}}&nbsp;小时</text> -->
								<text class="time__item">{{ timeData.minutes>=10?timeData.minutes:'0'+timeData.minutes }}&nbsp;分钟</text>
								<text class="time__item">{{ timeData.seconds>=10?timeData.seconds:'0'+timeData.seconds }}&nbsp;秒</text>
							</view>
						</u-count-down>
					</view>
				</view>
				
			</view>
			<view class="subTitle" v-if="pageData.status == 0">{{pageData.cancel_remark}}</view>
			<view class="subTitle" v-if="pageData.status == 4">已付款，等待商家发货</view>
			<view class="subTitle" v-if="pageData.status == 5">已发货，等待买家确认收货</view>
		</view>
		<view class="center">
			<view class="box">
				<view class="box_title">发货信息</view>
				<view class="hflex jbetween cell" v-if="pageData.user_address">
					<view class="left">收货信息</view>
					<view class="right">{{pageData.user_address.address_name}} , {{pageData.user_address.address_phone}} , {{pageData.user_address.address_province}}{{pageData.user_address.address_city}}{{pageData.user_address.address_area}}{{pageData.user_address.address_content}}</view>
				</view>
				<view class="hflex jbetween cell" v-if="pageData.status == 5">
					<view class="left">物流单号</view>
					<view class="right hflex acenter">
						<view> {{pageData.user_address.send_number}}</view>
						<image src="/static/images/common/copy.png" style="width: 28rpx;height: 28rpx;" @click="copy(pageData.express_no)"></image>
					</view>
				</view>
			</view>
			<view class="box" v-if="pageData.user">
				<view class="box_title">买家信息</view>
				<view class="hflex jbetween cell">
					<view class="left">买家昵称</view>
					<view class="right text_hide">{{pageData.user.nickname}}</view>
				</view>
				<view class="hflex jbetween cell">
					<view class="left">联系电话</view>
					<view class="right">{{pageData.user.phone}}</view>
				</view>
			</view>
			<view class="box">
				<view class="box_title">商品信息</view>
				<view >
					<block v-for="(item,index) in pageData.goods_item" :key="index">
						<view class="items hflex acenter">
							<image :src="item.goods_cover" class="item-img"></image>
							<view class="item-right">
								<view class="hflex acenter jbetween">
									<view class="item_name text_hide">{{item.goods_name}}</view>
									<view class="item_price">￥<span style="font-size: 30rpx;">{{item.price_selling}}</span></view>
								</view>
								<view class="hflex jbetween" style="padding: 20rpx 0 0;">
									<view class="norm text_hide">{{item.goods_spec}}</view>
									<view class="left_text">X{{item.stock_sales}}</view>
								</view>
							</view>
						</view>
					</block>
				</view>
				<view class="hflex acenter jbetween cell">
					<view class="left" style="color: #888888;">运费</view>
					<view class="right" style="color: #888888;">￥0.00</view>
				</view>
				<view class="hflex jend cell" v-if="pageData.goods_item">
					<view class="right">
						共{{pageData.goods_item.length}}件商品 实付款￥<span style="font-size: 32rpx;color: #222;">{{pageData.payment_amount}}</span>
					</view>
				</view>
			</view> 
			<view class="box">
				<view class="box_title">订单信息</view>
				<view class="hflex jbetween cell">
					<view class="left">订单编号</view>
					<view class="hflex acenter">
						<view class="right">{{pageData.order_no}} </view>
						<view class="right1" @click="copy(pageData.order_no)"> | 复制</view>
					</view>
				</view>
				<view class="hflex jbetween cell">
					<view class="left">备注</view>
					<view class="right">{{pageData.order_remark}}</view>
				</view>
				<view class="hflex jbetween cell">
					<view class="left">下单时间</view>
					<view class="right">{{pageData.create_at}}</view>
				</view>
				<view class="hflex jbetween cell" v-if="pageData.status == 4 || pageData.status == 5 || pageData.status == 6">
					<view class="left">付款时间</view>
					<view class="right">{{pageData.payment_datetime}}</view>
				</view>
				<view class="hflex jbetween cell" v-if="pageData.status == 4 || pageData.status == 5 || pageData.status == 6">
					<view class="left">支付方式</view>
					<view class="right">{{pageData.payment_type}}</view>
				</view>
				<view class="hflex jbetween cell" v-if="pageData.status == 5 || pageData.status == 6">
					<view class="left">发货时间</view>
					<view class="right">{{pageData.user_address.send_datetime}}</view>
				</view>
			</view>
		</view>
		<view class="bottom hflex acenter jend">
			<view class="btn1 btn2 hflex acenter jcenter" v-if="pageData.status == 0 ||pageData.status == 2 || pageData.status == 3"@click="chat">联系买家</view>
			<view class="hflex acenter jend" v-if="pageData.status == 4">
				<view class="btn1 hflex acenter jcenter" @click="chat">联系买家</view>
				<view class="btn1 btn2 hflex acenter jcenter" @click="send(pageData.id)">立即发货</view>
			</view>
			<view class="btn1 hflex acenter jcenter" v-if="pageData.status == 5 ||pageData.status == 6"@click="chat">联系买家</view>
		</view>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	var that = ''
	export default {
		data() {
			return {
				id: '',
				pageData: {},
				time: 0,
				timeData: {},
			}
		},
		onLoad(options) {
			that = this
			that.id = options.id
			that.getData()
		},
		methods: {
			getData() {
				$api.req({
					url: '/data/api.business.Order/order_info',
					method: 'POST',
					data: {
						order_id: that.id
					}
				}, function(res) {
					console.log(that.id);
					if(res.code == 1) {
						for(var i=0;i<res.data.goods_item.length;i++) {
							if(res.data.goods_item[i].goods_cover) {
								var temp = res.data.goods_item[i].goods_cover.split('|')
								res.data.goods_item[i].goods_cover = temp[0]
							}
						}
						that.pageData = res.data
						for(var i=0;i<that.pageData.goods_item.length;i++) {
							that.pageData.goods_item[i].goods_spec = $api.resetspec(that.pageData.goods_item[0].goods_spec)
						}
						console.log("商品数据",that.pageData);
						that.computTime()
					} else {
						$api.info(res.info)
					}
				})
			},
			// 倒计时
			onChange(e) {
				that.timeData = e
			},
			// 计算倒计时
			computTime() {
				var date = new Date(that.pageData.create_at).getTime() + ( that.pageData.time * 60 * 1000);
				var nowDate = new Date().getTime()
				that.time = date - nowDate
			},
			copy(value) {
				uni.setClipboardData({
					data: value,
					success: function () {
						$api.info('复制成功')
					}
				});
			},
			chat() {
				var my = uni.getStorageSync("myUsername");
				var nameList = {
				  myName: my,
				  your: that.pageData.huanxinID,
				};
				uni.navigateTo({
				  url: "/pages/chatroom/chatroom?username=" + JSON.stringify(nameList),
				});
			},
			send(id) {
				$api.jump('/pages/order/send?id=' + id)
			},
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		background: #F4F4F4;
		.top {
			width: 100%;
			padding: 20rpx 30rpx 24rpx;
			.state {
				font-size: 36rpx;
				font-weight: bold;
				color: #222222;
				line-height: 50rpx;
				padding-right: 24rpx;
			}
			.blue_bg {
				// width: 124rpx;
				padding: 0 14rpx;
				height: 32rpx;
				background: #506DFF;
				border-radius: 18rpx 0px 18rpx 18rpx;
				font-size: 16rpx;
				text-align: center;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 32rpx;
			}
			.blue_bg2 {
				// width: 256rpx;
				padding: 0 14rpx;
				height: 32rpx;
				background: #E7EBFF;
				border-radius: 18rpx;
				font-size: 16rpx;
				font-weight: bold;
				color: #222222;
				line-height: 32rpx;
			}
			.time {
				padding-left: 16rpx;
			}
			.subTitle {
				font-size: 24rpx;
				font-weight: 400;
				color: #888888;
				line-height: 34rpx;
			}
		}
		.center {
			width: 100%;
			box-sizing: border-box;
			padding: 0 30rpx;
			.box {
				width: 100%;
				background: #FFFFFF;
				border-radius: 20rpx;
				box-sizing: border-box;
				padding: 0 20rpx;
				margin-top: 20rpx;
				.box_title {
					font-size: 32rpx;
					font-weight: 600;
					color: #222222;
					line-height: 44rpx;
					padding: 28rpx 0 24rpx;
				}
				.cell {
					padding-bottom: 24rpx;
					.left {
						width: 240rpx;
						font-size: 26rpx;
						font-weight: 400;
						color: #222222;
						line-height: 36rpx;
					}
					.right {
						max-width: 400rpx;
						font-size: 26rpx;
						font-weight: 400;
						color: #555555;
						line-height: 36rpx;
					}
					.right1 {
						font-size: 26rpx;
						font-weight: 400;
						color: #333333;
						line-height: 36rpx;
					}
				}
				.items {
					padding: 20rpx 0 32rpx;
					border-bottom: 1rpx solid #F4F4F4;
					.item-img {
						width: 160rpx;
						height: 160rpx;
						border-radius: 24rpx;
					}
					.item-right {
						width:calc(100% - 160rpx);
						padding-left: 20rpx;
						.item_name {
							font-size: 30rpx;
							font-weight: 400;
							color: #222222;
							line-height: 42rpx;
						}
						.item_price {
							font-size: 20rpx;
							font-weight: 600;
							color: #222222;
							line-height: 24rpx;
						}
						.norm {
							max-width: 300rpx;
							width: max-content;
							// height: 42px;
							background: #F5F5F5;
							border-radius: 12rpx;
							box-sizing: border-box;
							padding: 12rpx;
							font-size: 20rpx;
							font-weight: 400;
							color: #888888;
							line-height: 28rpx;
						}
						.left_text {
							font-size: 24rpx;
							font-weight: 500;
							color: #888888;
							line-height: 28rpx;
						}
					}
				}
				.items:nth-last-child(1) {
					border: none;
				}
			}
			.box:nth-last-child(1) {
				margin-bottom: 186rpx;
			}
		}
		.bottom {
			width: 100%;
			height: 166rpx;
			background: #FFFFFF;
			box-sizing: border-box;
			padding: 0 30rpx;
			position: fixed;
			z-index: 99;
			bottom: 0;
			.btn1 {
				width: 208rpx;
				height: 86rpx;
				border-radius: 38rpx;
				border: 1rpx solid #787878;
				font-size: 30rpx;
				font-weight: 400;
				color: #222222;
				line-height: 76rpx;
				margin-left: 20rpx;
			}
			.btn2 {
				background: #506DFF;
				border: none;
				color: #FFFFFF;
			}
		}
	
	}
</style>