<template>
	<view class="main">
		<view class="one"> <text>{{info.zhStatus}}</text> </view>
		<view class="two">
			<view class="two_1">
				<image v-if="info.source&&info.source.file.length>0" class="image"
					:src="info.source.file&&info.source.file.length>0?info.source.file[0].url:''">
				</image>
				<image v-else class="image" :src="config.logo_url&&config.logo_url.length>0?config.logo_url[0].url:''">
				</image>
				<text v-if="info.type=='0'">酒店民宿</text>
				<text v-else>景区门票</text>
			</view>
			<view class="two_2">
				<view class="left">
					<image v-if="info.source&&info.source.file.length>0" class="image"
						:src="info.source.file&&info.source.file.length>0?info.source.file[0].url:''">
					</image>
					<image v-else class="image"
						:src="config.logo_url&&config.logo_url.length>0?config.logo_url[0].url:''">
					</image>
				</view>
				<view class="right">
					<view class="right_1">
						<view class="left">
							<view class="name textOver">{{info.source_name||'暂无'}}</view>
							<view class="other">{{info.zhType||'暂无'}}</view>
							<view class="other">{{info.zhPerson||'暂无'}}</view>
						</view>
						<view class="right">
							<view class="other">
								￥{{info.source.money||'0'}}
							</view>
							<view class="other">
								×{{info.num||'0'}}
							</view>
						</view>
					</view>
					<view class="right_2">
						合计：￥{{info.money||'0'}}
					</view>
				</view>
			</view>
		</view>
		<view class="thr">
			<view class="thr_1">优惠</view>
			<view class="other">商品总价：￥{{info.money||'0'}} <text>（共{{info.num||'0'}}件）</text> </view>
			<view class="other">优惠：￥{{info.coupon_money||'0'}}</view>
			<view class="other">实付：￥{{info.total_money||'0'}}</view>
		</view>
		<view class="four">
			<view class="four_1">订单信息</view>
			<view class="other">订单编号：{{info._id||'暂无'}}</view>
			<view class="other">下单时间：{{info.buy_time||'暂无'}}</view>
		</view>
		<view class="four">
			<view class="four_1">用户信息</view>
			<view class="list" v-for="(item, index) in info.identity" :key="index">
				<view class="other">游客{{index+1}}</view>
				<view class="other">真实姓名：{{item.name||'暂无'}}</view>
				<view class="other">证件号码：{{item.card||'暂无'}}</view>
				<view class="other">手机号码：{{ getProps(item.phone) }}</view>
			</view>
		</view>
		<view class="four">
			<view class="four_1">支付信息</view>
			<view class="other">支付时间：{{info.pay_time||'暂无'}}</view>
			<view class="other">交易快照：当发生交易纠纷时可作为交易凭证 ></view>
			<view class="other">支付数据：{{info.pay||'暂无'}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				config: {
					logo_url: []
				},
				user: {},
				info: {
					source: {
						file: []
					}
				},
				statusList: [],
				personList: [],
				typeList: [],
			}
		},
		onLoad: async function(e) {
			const that = this;
			that.$set(that, `id`, e && e.id || '');
			that.searchConfig();
			that.searchToken();
			await that.searchOther();
			that.search();
		},
		methods: {
			searchConfig() {
				const that = this;
				try {
					const res = uni.getStorageSync('config');
					if (res) that.$set(that, `config`, res);
				} catch (e) {
					uni.showToast({
						title: err.errmsg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			searchToken() {
				const that = this;
				try {
					const res = uni.getStorageSync('token');
					if (res) that.$set(that, `user`, res);
				} catch (e) {
					uni.showToast({
						title: err.errmsg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			async search() {
				const that = this;
				if (that.id) {
					const res = await that.$api(`/order/${that.id}`, 'GET', {})
					if (res.errcode == '0') {
						const status = that.statusList.find(i => i.value == res.data.status)
						if (status) res.data.zhStatus = status.label
						if (res.data && res.data.source && res.data.source.person) {
							const person = that.personList.find(i => i.value == res.data.source.person)
							if (person) res.data.zhPerson = person.label
						}
						if (res.data && res.data.source && res.data.source.type) {
							const type = that.typeList.find(i => i.value == res.data.source.type)
							if (type) res.data.zhType = type.label
						}
						that.$set(that, `info`, res.data)
					} else {
						uni.showToast({
							title: res.errmsg,
						});
					}
				}
			},
			// 整理电话号
			getProps(phone) {
				if (!phone) return '暂无';
				return phone.replace(/^(\d{3})(\d{4})(\d{4})$/, '$1****$2');
			},
			// 查询其他信息
			async searchOther() {
				const that = this;
				let res;
				// 查询类型
				res = await that.$api(`/dictData`, 'GET', {
					type: 'order_status',
					is_use: '0',
				})
				if (res.errcode == '0') that.$set(that, `statusList`, res.data);
				// 出游人群
				res = await that.$api(`/dictData`, 'GET', {
					type: 'ticket_person',
					is_use: '0',
				})
				if (res.errcode == '0') that.$set(that, `personList`, res.data);
				// 服务特色
				res = await that.$api(`/dictData`, 'GET', {
					type: 'ticket_type',
					is_use: '0',
				})
				if (res.errcode == '0') that.$set(that, `typeList`, res.data);
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		display: flex;
		flex-direction: column;
		background-image: linear-gradient(to top, rgba(241, 241, 241, 1), rgba(135, 206, 250, 1), rgba(0, 122, 255, 1));

		.one {
			padding: 5vw;
			font-size: var(--font20Size);
			font-weight: bold;
		}

		.two {
			background-color: var(--mainColor);
			border-radius: 5px;
			margin: 2vw 2vw 0 2vw;
			padding: 2vw;

			.two_1 {
				display: flex;
				align-items: center;

				.image {
					width: 8vw;
					height: 8vw;
					border-radius: 8vw;
				}

				text {
					padding: 0 0 0 2vw;
				}
			}

			.two_2 {
				display: flex;
				justify-content: space-between;
				margin: 2vw 0 0 0;
				padding: 0 2vw;

				.left {
					width: 20vw;

					.image {
						width: 20vw;
						height: 20vw;
						border-radius: 1vw;
					}
				}

				.right {
					width: 65vw;
					margin: 0 0 0 2vw;

					.right_1 {
						display: flex;
						justify-content: space-between;

						.left {
							width: 55vw;

							.name {
								font-size: var(--font14Size);
							}

							.other {
								padding: 2px 0 0 0;
								font-size: var(--font12Size);
								color: var(--f85Color);
							}
						}

						.right {
							width: 10vw;
							text-align: right;

							.other {
								padding: 2px 0 0 0;
								font-size: var(--font12Size);
								color: var(--f85Color);
							}
						}
					}

					.right_2 {
						text-align: right;
						font-size: var(--font12Size);
					}
				}
			}
		}

		.thr {
			background-color: var(--mainColor);
			border-radius: 5px;
			margin: 2vw 2vw 0 2vw;
			padding: 2vw;

			.thr_1 {
				font-size: var(--font14Size);
				font-weight: bold;
				margin: 1vw 0;
			}

			.other {
				padding: 2px 0 0 0;
				font-size: var(--font12Size);
				color: var(--f85Color);
			}
		}

		.four {
			background-color: var(--mainColor);
			border-radius: 5px;
			margin: 2vw 2vw 0 2vw;
			padding: 2vw;

			.four_1 {
				font-size: var(--font14Size);
				font-weight: bold;
				margin: 1vw 0;
			}

			.list {
				border: 1px solid #d5d5da;
				border-radius: 5px;
				margin: 2vw 0 0 0;
				padding: 2vw;
			}

			.other {
				padding: 2px 0 0 0;
				font-size: var(--font12Size);
				color: var(--f85Color);
			}
		}
	}
</style>