<template>
	<view class="app">
		<view class="time" style="" v-if="order.orderStatus=='WAIT_PAY'">
			剩余付款时间：
			<u-count-down style='' :timestamp="timestamp">
			</u-count-down>
		</view>
		<view class="OrderStatus" v-if="order.orderStatus=='REFUNDED'||order.orderStatus=='CANCEL'">
			订单已关闭
		</view>
		<view class="content">
			<view class="name">
				店铺名称
				<image src="../../static/huijiantou.png" mode=""></image>
			</view>
			<view class="details">
				<view class="detailslist">
					<image :src="baseurl+order.attributePitureUrl" mode=""></image>
					<view class="model">
						<view class="top">
							<span>{{order.goodsName}}</span>
							<span>￥{{order.goodsPrice}}</span>
						</view>
						<view class="bottom">
							<span class="box">型号：{{order.goodsAttributeName}}</span>
							<span class="box">X{{order.goodsCount}}</span>
						</view>
						<view class="refund" @tap='gorefundType'
							v-if="order.orderStatus != 'WAIT_PAY'&& order.orderStatus!='CANCEL'&&order.orderStatus!='WAIT_REFUND'&&order.orderStatus!='REFUNDED'&&order.orderStatus!='RETURNED_GOODS'&&order.orderStatus!='WAIT_RETURNED_GOODS'">
							申请退款
						</view>
						<view class="refund" v-if="order.orderStatus=='WAIT_REFUND'" @tap='goAftersalesdetails(order)'>
							退款中
						</view>
						<view class="refund" v-if="order.orderStatus=='REFUNDED'">
							退款成功
						</view>
						<!-- <view class="refund" v-if="order.orderStatus=='RETURNED_GOODS'">
							退货中
						</view> -->
						<view class="refund" v-if="order.orderStatus=='WAIT_RETURNED_GOODS'">
							待退货
						</view>
					</view>
				</view>
				<view class="payinfo">
					<text class="pay">实付款</text>
					<text class="price">￥{{order.totalPrice}}</text>
				</view>
			</view>
		</view>
		<view class="info">
			<view>收货人：<text>{{order.receiver}}</text></view>
			<view>联系电话：<text>{{order.phone}}</text></view>
			<view>收货地址：<text>{{order.receiveAddress}}</text></view>
			<view>订单编号：<text>{{order.goOrderNo}}</text></view>
			<!-- <span>获得积分：<text>30点积分</text></span> -->
			<view>下单时间：<text>{{order.orderTime}}</text></view>
			<view v-if="order.orderStatus=='REFUNDED'">退款时间：<text>{{order.updateTime}}</text></view>
			<!-- <span>发货时间：<text>2022-10-28 11：31：26</text></span> -->
			<!-- <span>成交时间：<text>2022-10-28 11：31：26</text></span> -->
		</view>
		<view class="buy" v-if="order.orderStatus == 'WAIT_PAY'">
			<view class="pay">
				去支付
			</view>
		</view>
		<view class="buy" v-if="order.orderStatus == 'EVALUATED'" @tap='golookrate'>
			<view class="pay" style="background-color: #4C7BC9;">
				查看评价
			</view>
		</view>
		<view class="buy" v-if="order.orderStatus == 'RECEIVED_GOODS'" @tap='rate'>
			<view class="pay" style="background-color: #60c5f1;">
				去评价
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		goodsOrder
	} from '@/api/CommodityOrder/index.js'
	import baseurl from '@/api/baseurl.js'
	import {
		appletGoodsOrderPay
	} from '@/api/confirmOrder/index.js'
	export default {
		data() {
			return {
				baseurl: '',
				order: {},
				patientId: '',
				orderStatus: '',
				pageSize: 10,
				pageNum: 1,
				timestamp: 0, //倒计时
			}
		},
		methods: {
			//查看评价
			golookrate() {
				uni.navigateTo({
					url: `/pages/lookrate/lookrate?item=${JSON.stringify(this.order)}`
				})
			},
			//评价
			rate() {
				uni.navigateTo({
					url: `/pages/goodsorderRate/goodsorderRate?item=${JSON.stringify(this.order)}&delta=${4}`
				})
			},
			//退款页面
			gorefundType() {
				uni.navigateTo({
					url: `/pages/refundType/refundType?order=${JSON.stringify(this.order)}`
				})
			},
			goodsOrderinfo(goodsOrderId) {
				goodsOrder(this.patientId, this.orderStatus, goodsOrderId, this.pageSize, this.pageNum).then(res => {
					this.order = res.rows[0]
					var time = new Date(this.order.orderTime).getTime() / 1000 + (60 * 60 * 24)
					var times = new Date().getTime() / 1000
					this.timestamp = time - times
				})
			},
			//跳转售后详情
			goAftersalesdetails(item) {
				uni.navigateTo({
					url: `/pages/Aftersalesdetails/Aftersalesdetails?goodsOrderId=${item.goodsOrderId}`
				})
			},
		},
		onLoad(options) {
			this.baseurl = baseurl
			let that = this
			try {
				const value = uni.getStorageSync('patientId');
				if (value) {
					that.patientId = value
					that.goodsOrderinfo(options.goodsOrderId)
				}
			} catch (e) {
				// error
			}

			/* 	uni.getStorage({
					key: 'patientId',
					success: function(res) {
						that.patientId = res.data
						that.goodsOrderinfo(options.goodsOrderId)
					}
				}); */
		}
	}
</script>
<style lang="scss">
	@import "./orderDetails.scss";
</style>
