<template>
	<view class="detail-page">
		<!-- 顶部导航 -->
		<u-navbar title="查看详情" :is-back="true" back-icon-color="#fff" :background="{'background':'#1479ff'}"
			title-color="#fff" :border-bottom="false"></u-navbar>
		<view class="b-border"></view>
		<!-- 订单信息 -->
		<view class="order-info">
			<view class="info-item">
				<text class="label">订单号</text>
				<text class="value">{{orderInfo.no}}</text>
			</view>
			<view class="info-item">
				<text class="label">服务项目</text>
				<text class="value">{{orderInfo.accompany_product?orderInfo.accompany_product.name:''}}</text>
			</view>
			<view class="info-item">
				<text class="label">服务时间</text>
				<text class="value">{{orderInfo.time}}</text>
			</view>

			<view class="info-item" v-if="orderInfo.type === 2">
				<text class="label">服务地址</text>
				<text class="value">{{item.city?item.city:'' }}</text>
			</view>
			<view class="info-item" v-else>
				<text class="label">就诊医院</text>
				<text class="value">{{orderInfo.hospital?orderInfo.hospital.name:''}}</text>
			</view>
			<view class="info-item">
				<text class="label">联系人</text>
				<text class="value">{{orderInfo.appoint_name?orderInfo.appoint_name:''}}</text>
			</view>
			<view class="info-item">
				<text class="label">联系方式</text>
				<text class="value">{{orderInfo.appoint_mobile?orderInfo.appoint_mobile:''}}</text>
			</view>
			<view class="info-item">
				<text class="label">被服务人</text>
				<text class="value">{{orderInfo.user_archive?orderInfo.user_archive.name:''}}</text>
			</view>

			<view class="info-item">
				<text class="label">是否可以自理</text>
				<text class="value">{{orderInfo.my_provide===1?'可以自理':'不能自理'}}</text>
			</view>
			<view class="info-item info-item-reason">
				<text class="label">就诊资料</text>
				<view class="value">
					<view class="order-item-img">
						<image v-for="(item,index) in imgs" :src="item" @click="imgPreview(index)"></image>
					</view>
				</view>
			</view>
			<view class="info-item  info-item-reason">
				<text class="label">其他需求</text>
				<text class="value">{{orderInfo.content?orderInfo.content:''}}</text>
			</view>

			<view class="info-item">
				<text class="label">订单金额</text>
				<text class="value">¥{{orderInfo.price}}</text>
			</view>

			<view class="info-item">
				<text class="label">原始金额</text>
				<text class="value">¥{{orderInfo.from_price}}</text>
			</view>

			<view class="info-item" v-if="orderInfo.status===3||orderInfo.status===4">
				<text class="label">待付金额</text>
				<text class="value price">¥{{orderInfo.diff_price}}</text>
			</view>
			<view class="info-item info-item-reason">
				<text class="label">修改原因</text>
				<text class="value reason">{{orderInfo.update_price_reason?orderInfo.update_price_reason:''}}</text>
			</view>
		</view>
		<!-- 服务记录 -->
		<!-- <view class="order-info" v-if="orderInfo.accompany_order_log && orderInfo.accompany_order_log.length>0">
			<view class="info-item info-item-reason">
				<text class="label">服务记录</text>
				<view class="value">
					<view class="">
						<view v-for="item in orderInfo.accompany_order_log">
							<view>备注：{{item.remark}}</view>
							<view class="order-item-img">
								<image v-for="(i,index) in item.files" :src="i.url"
									@click="imgPreviewList(item.files,index)"></image>
							</view>
						</view>
					</view>
				</view>
			</view>

		</view> -->
		<!-- 支付二维码 -->
		<view class="payment-popup" v-if="orderInfo.status===3">
			<view class="title">付款二维码</view>
			<view class="amount">
				<text class="symbol">¥</text>
				<text class="number">{{orderInfo.diff_price}}</text>
			</view>

			<view class="qr-code">
				<!-- <image :src="qrCodeUrl" mode="aspectFit"></image> -->
				<uqrcode v-if="myQrcode" ref="uqrcode" canvas-id="qrcode" :value="myQrcode" :sizeUnit="'rpx'"
					:size="200" :options="{ 
					margin: 10,
				 }"></uqrcode>
			</view>

			<view class="tips">
				<text>请扫码支付差额</text>
				<text class="sub-tips">支付完成后订单将自动完成</text>
			</view>
			<view class="close-btn">
				<u-button size="mini" shape="circle" type="default" :custom-style="parStyle"
					@click="isPayCode">我已支付</u-button>
			</view>
		</view>

	</view>
</template>

<script>
	import uqrcode from '@/uni_modules/Sansnn-uQRCode/components/uqrcode/uqrcode.vue'
	export default {
		components: {
			uqrcode
		},
		data() {
			return {
				myQrcode: '',
				imgs: [],
				orderId: '',
				orderInfo: {},
				parStyle: {
					'background': 'linear-gradient(to right, #476de4, #7bb9f7)',
					'color': '#fff',
					'font-size': '28rpx',
					'padding': '0 30rpx',
					'margin-left': '15rpx'
				},
			}
		},
		onLoad(options) {
			// 获取订单详情
			this.orderId = options.id
			this.getOrderDetail(options.id);
		},
		methods: {
			imgPreview(index) {
				uni.previewImage({
					current: index, // 当前显示图片索引
					urls: this.imgs // 需要预览的图片http链接列表
				});
			},
			async getOrderDetail(orderId) {
				// 调用接口获取订单详情
				const res = await this.$u.api.orderDetail({
					id: orderId
				})
				this.orderInfo = res
				let _arr = []
				if (res.files.length > 0) {
					res.files.map(item => {
						_arr.push(item.url)
					})
					this.imgs = _arr
				}
				if (res.status === 3) {
					await this.getCode(res.no)
				}
			},
			async getCode(no) {
				const res = await this.$u.api.payCode({
					no: no
				})
				if (res.result.return_code === 'SUCCESS') {
					if (res.result.code_url) {
						this.myQrcode = res.result.code_url
					} else {
						uni.showToast({
							icon: 'none',
							title: res.result.err_code_des || '获取失败'
						})
					}

				} else {
					uni.showToast({
						icon: 'none',
						title: '获取失败'
					})
				}

			},
			isPayCode() {
				this.myQrcode = ''
				this.getOrderDetail(this.orderId)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.detail-page {
		min-height: 100vh;
		background: #f5f5f5;
		padding-bottom: 40rpx;

		.b-border {
			width: 100%;
			height: 30rpx;
			border-radius: 0 0 120rpx 120rpx;
			background-color: #1479ff;
		}

		.order-info {
			background: #fff;
			border-radius: 20rpx;
			margin: 30rpx;
			box-shadow: 0 4rpx 16rpx #e6eaf1;
			padding: 0 30rpx;

			.info-item {
				padding: 30rpx;
				display: flex;
				justify-content: space-between;
				// margin-bottom: 30rpx;
				border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);

				.label {
					color: #666;
					font-size: 28rpx;
				}

				.value {
					color: #333;
					font-size: 28rpx;

					// &.price {
					// 	color: #f56c6c;
					// 	font-weight: bold;
					// }
					&.reason {
						color: #999;
					}
				}
			}

			.info-item-reason {
				flex-wrap: wrap;

				&>text {
					width: 100%
				}
			}

			.order-item-img {
				display: flex;
				flex-wrap: wrap;

				image {
					width: 140rpx;
					height: 140rpx;
					margin: 10rpx;
				}
			}
		}

		.payment-popup {
			background: #fff;
			border-radius: 20rpx;
			margin: 30rpx;
			box-shadow: 0 4rpx 16rpx #e6eaf1;
			padding: 30rpx;

			.title {
				font-size: 32rpx;
				color: #333;
				text-align: center;
				font-weight: 500;
				margin-bottom: 20rpx;
			}

			.amount {
				text-align: center;
				margin-bottom: 20rpx;

				.symbol {
					font-size: 36rpx;
					color: #000;
				}

				.number {
					font-size: 48rpx;
					color: #d80808;
					font-weight: bold;
				}
			}

			.qr-code {
				width: 200rpx;
				height: 200rpx;
				margin: 0 auto 20rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.tips {
				text-align: center;
				margin-bottom: 20rpx;

				text {
					display: block;
					color: #333;
					font-size: 28rpx;
					line-height: 1.8;
				}

				.sub-tips {
					color: #999;
					font-size: 24rpx;
				}
			}

			.close-btn {
				width: 80%;
				margin: 0 auto;
				display: flex;
				justify-content: center;
			}
		}
	}
</style>