<template>
	<view class="app">
		<u-navbar :is-back="false" :background="background" class="u-navbar">
			<image :src="require('@/pagesC/images/fanhui.png')" mode="" @tap="goprevious"></image>
			<view class="title" v-if="list.orderStatus=='WAIT_PAY'" @tap="goprevious">待付款</view>
			<view class="title" v-if="list.orderStatus=='WAIT_REFUND'" @tap="goprevious">退款中</view>
			<view class="title" v-if="list.orderStatus=='CANCEL'" @tap="goprevious">已取消</view>
			<view class="title" v-if="list.orderStatus=='WAIT_RECEIVED_GOODS'" @tap="goprevious">待接单</view>

			<view class="title" v-if="list.orderStatus=='COMPLETED'" @tap="goprevious">待评价</view>
			<view class="title" v-if="list.orderStatus=='RECEIVED_GOODS'" @tap="goprevious">待服务</view>
			<view class="title" v-if="list.orderStatus=='EVALUATED'" @tap="goprevious">已评价</view>

			<view class="title" v-if="list.orderStatus=='PAY'" @tap="goprevious">待发货</view>
			<view class="title" v-if="list.orderStatus=='REFUNDED'" @tap="goprevious">已退款</view>
			<view class="title" v-if="list.orderStatus=='WAIT_RETURNED_GOODS'" @tap="goprevious">待退货</view>
			<view class="title" v-if="list.orderStatus=='RETURNED_GOODS'" @tap="goprevious">退款成功</view>

		</u-navbar>

		<view class="time" style="" v-if="list.orderStatus=='WAIT_PAY'">
			<!-- v-if="list.orderStatus!='WAIT_PAY' -->
			剩余付款时间：
			<u-count-down style='' :timestamp="timestamp">
			</u-count-down>
		</view>
		<view class="OrderStatus" v-if="list.orderStatus=='REFUNDED'||list.orderStatus=='CANCEL'">
			订单已关闭
		</view>

		<view class="content">
			<view class="service">
				<image :src="require('@/pagesC/images/persone.png')" mode=""></image>
				<span>医生服务</span>
			</view>
			<view class="orderitem">
				<view class="details">
					<image :src="baseurl+list.personPictureUrl" mode=""></image>
					<view class="ppointment">
						<view class="doctorname">
							<span>{{list.hospitalPersonName}}</span>
						</view>
						<view class="reservation">
							<span>齐鲁医院</span>
							<span v-if="list.academicTitle=='DEPUTY_CHIEF_PHYSICIAN'">副主任医师</span>
							<span v-if="list.academicTitle=='CHIEF_PHYSICIAN'">主任医师</span>
							<span v-if="list.academicTitle=='ATTENDING_DOCTOR'">主治医师</span>
							<span v-if="list.academicTitle=='PHYSICIAN'">医师</span>
							<span v-if="list.academicTitle=='HEALER'">医士</span>
							<span v-if="list.academicTitle=='RESIDENT_PHYSICIAN'">住院医师</span>
						</view>

					</view>
				</view>

			</view>
			<view class="doctordetails">
				<view class="doctorphone">
					医生电话
				</view>
				<view class="phone" v-if="list.personPhone">
					·{{list.personPhone}}
				</view>
			</view>
			<view class="doctordetails">
				<view class="doctorphone">
					预约时间
				</view>
				<view class="phone" v-if="list.healthAppointDate">
					{{list.healthAppointDate}}
				</view>
			</view>
			<view class="doctordetails">
				<view class="doctorphone">
					预约日期
				</view>
				<view class="phone" v-if="order.appointmentDate">
					{{order.appointmentDate}}
				</view>
			</view>
			<view class="doctordetails">
				<view class="doctorphone">
					预约开始时间点
				</view>
				<view class="phone" v-if="order.appointmentStartTime">
					{{order.appointmentStartTime}}
				</view>
			</view>
			<view class="doctordetails">
				<view class="doctorphone">
					预约结束时间点
				</view>
				<view class="phone" v-if="order.appointmentEndTime">
					{{order.appointmentEndTime}}
				</view>
			</view>
			<view class="doctordetailstwo">
				<view class="doctorphonetwo">
					问题简述
				</view>
				<view class="phonetwo advicetwo" v-if="order.problemDescription">
					{{order.problemDescription}}
				</view>
			</view>
			<view class="doctordetailstwo">
				<view class="doctorphonetwo">
					患者个体情况说明
				</view>
				<view class="phonetwo advicetwo" v-if="order.situationDescription">
					{{order.situationDescription}}
				</view>
			</view>
			<view class="doctordetailstwo">
				<view class="doctorphonetwo">
					问题描述
				</view>
				<view class="phonetwo advicetwo" v-if="order.problemStatement">
					{{order.problemStatement}}
				</view>
			</view>
			<view class="doctordetailstwo">
				<view class="doctorphonetwo">
					病例
				</view>
				<view class="phonetwo advicetwo" v-if="order.medicalRecord">
					{{order.medicalRecord}}
				</view>
			</view>
			<!-- <view class="doctordetailstwo">
				<view class="doctorphonetwo">
					咨询内容
				</view>
				<view class="phonetwo advicetwo" v-if="list.healthConsultationContent">
					·{{list.healthConsultationContent}}
				</view>
			</view> -->
			<view class="amount">
				<span>订单金额</span><span>￥{{list.totalPrice}}</span>

			</view>
			<!-- 	<view class="amount">
				<span>预约日期</span><span>￥{{list.appointmentDate}}</span>

			</view> -->
			<!-- <view class="doctordetailstwo">
				<view class="doctorphonetwo">
					备注
				</view>
				<view class="phonetwo advicetwo" v-if="list.remark">
					·{{list.remark}}
				</view>
			</view> -->

		</view>
		<view class="bottom">
			<!-- <span>更多</span> -->
			<!-- <span @tap="cancle">取消订单</span> -->
			<view class="buy" @tap="cancle"
				v-if="list.orderStatus!='WAIT_PAY'&&list.orderStatus!='EVALUATED'&&list.orderStatus!='WAIT_REFUND'&&list.orderStatus!='COMPLETED'&&list.orderStatus!='RECEIVED_GOODS'&&list.orderStatus!='REFUNDED'">
				<view class="pay">
					取消订单
				</view>
			</view>
			<!-- <span @tap="cancle"
				v-if="list.orderStatus!='WAIT_PAY'&&list.orderStatus!='EVALUATED'&&list.orderStatus!='WAIT_REFUND'&&list.orderStatus!='COMPLETED'&&list.orderStatus!='RECEIVED_GOODS'&&list.orderStatus!='REFUNDED'">取消订单</span> -->

			<!-- <span@tap="evaluate" v-if="list.orderStatus=='COMPLETED'">服务评价</span> -->
		</view>
		<view class="buy" v-if="list.orderStatus == 'WAIT_PAY'" @tap='pay'>
			<view class="pay">
				去支付
			</view>
		</view>
		<!-- 	<u-popup v-model="evaluateshow" mode="bottom" length="45%" border-radius="30" :closeable='true'>
			<view class="evaluate">
				服务评价
			</view>
			<view class="star">
				<u-rate size="70" active-color="#F4EA2A" v-model="countvalue" inactive-color="#b2b2b2" gutter="20"></u-rate>
				<span>非常差/差/满意/非常满意</span>
			</view>
			<view class="submits">
				提交
			</view>
		</u-popup> -->

		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		confirmReceipt,
		ssgoodsOrder,
		ssgoodsOrderdata,
	} from '@/api/pagesB/CommodityOrder/index.js'
	import baseurl from '@/api/baseurl.js'
	import {
		appletGoodsOrderPay
	} from '@/api/pagesB/confirmOrder/index.js'
	export default {
		data() {
			return {
				baseurl: '',
				timestamp: 0,
				countvalue: 0,
				list: [],
				// 评价弹框
				background: {
					backgroundColor: '#26A888',
				},
				evaluateshow: false,
				orderTypeList: {
					orderNo: '',

				},
				order: [],

			}
		},
		onLoad(options) {
			// if(options.item){
			this.list = JSON.parse(options.item)
			// console.log(this.list, '555')
			// this.orderTypeList.orderStatus = this.list.orderStatus
			// this.orderTypeList.goodsOrderId = this.list.goodsOrderId
			this.orderTypeList.orderNo = this.list.goOrderNo
			// goOrderNo



			// }
			// this.orderTypeList.patientId = uni.getStorageSync('patientId');
			// this.orderTypeList.openid = uni.getStorageSync('openid');
			// if (value && value2) {
			// 	that.orderTypeList.patientId = value
			// 	that.orderTypeList.openid = value2
			// }
			this.goodsOrderinfo()
			// console.log(this.list, '99')
			this.baseurl = baseurl

		},
		methods: {
			goprevious() {
				uni.navigateBack({
					delta: 1
				})
				return true;
			},
			//支付
			pay() {
				var that = this
				let paydata = this.list
				paydata.openid = uni.getStorageSync('openid')
				paydata.payType = "WECHAT_PAY"
				paydata.paymentPrice = this.list.totalPrice
				paydata.orderChannel = 'WECHAT_APPLET'
				paydata.orderNo = this.list.goOrderNo
				appletGoodsOrderPay(paydata).then(response => {
					if (response.code == 200) {
						uni.requestPayment({
							timeStamp: response.data.timeStamp,
							nonceStr: response.data.nonceStr,
							package: response.data.prepayId,
							signType: response.data.signType,
							paySign: response.data.paySign,
							success: function(res) {
								uni.setStorageSync("Refresh", 'Refresh')
								that.goodsOrderinfo()
								that.$refs.uToast.show({
									title: '支付成功',
									type: 'success',
									duration: 1500,
									url: `/pagesB/paysuccess/paysuccess?delta=${2}`
								})
							},
							fail: function(err) {
								that.$refs.uToast.show({
									title: '取消支付',
									type: 'error',
									duration: 1500
								})
							}
						});
					} else {
						that.$refs.uToast.show({
							title: response.msg,
							type: 'error',
							duration: 1500
						})
					}
				})
			},
			goodsOrderinfo() {
				ssgoodsOrderdata(this.orderTypeList).then(
					res => {
						console.log(res)
						this.order = res.data
						var ordertimes = this.order.orderTime.replaceAll(/\-/gi, "/")
						var time = new Date(ordertimes).getTime() / 1000 + (60 * 60 * 2)
						var times = new Date().getTime() / 1000
						this.timestamp = time - times
						// console.log(this.timestamp, '8585')
						if (this.timestamp >= 0) {
							this.timecount = this.timestamp
							this.Timers = setInterval(() => {
								this.timecount--;
							}, 1000)
						}
					})
			},
			// 取消订单
			cancle() {
				var list = this.list
				uni.navigateTo({
					url: `/pagesB/refundType/refundType?list=${JSON.stringify(this.list)}`
				})
			},
			// 服务评价
			evaluate() {
				this.evaluateshow = true;

			},

		}
	}
</script>
<style lang="scss">
	@import './consulted.scss'
</style>