<template>
	<view class="container" :class="{disableScroll:disableScroll}">
		<view class="info-box order-status">
			<view class="status-text">
				<span class="status">订单状态：{{getStatusTxt(orderInfo.status)}}</span>
			</view>
		</view>
		<view class="order-info">
			<image :src="orderInfo.hospitalVo.logoUrl" mode="aspectFill"></image>
			<view class="info-content">
				<span class="name">{{orderInfo.hospitalVo.name || '-'}}</span>
				<span class="address">
					<u-icon name="map" color="#999999" size="14"></u-icon>
					<span class="txt">{{orderInfo.hospitalVo.address || '-'}}</span>
				</span>
				<!-- <span class="area">所属区：{{orderInfo.hospitalVo.areaName || '-'}}</span> -->
			</view>
		</view>
		<view class="info-box">
			<view class="info-item">
				<span class="title">所在科室</span>
				<span class="txt">{{orderInfo.hospitalDepartmentName || '-'}}</span>
			</view>
			<u-line></u-line>
			<view class="info-item">
				<span class="title">房床号</span>
				<span class="txt">{{orderInfo.roomNumber || '-'}}</span>
			</view>
			<u-line></u-line>
			<view class="info-item info-item-spa">
				<span class="title">备注</span>
				<span class="txt">{{orderInfo.remarks || '-'}}</span>
			</view>
		</view>
		<view class="info-box">
			<view class="info-item">
				<span class="title">就诊人</span>
				<span class="txt">{{orderInfo.patientVo.name || '-'}}（{{orderInfo.patientVo.mobile || '-'}}）</span>
			</view>
		</view>
		<view class="info-box">
			<view class="info-item">
				<span class="title">服务产品</span>
				<span class="txt">{{orderInfo.serviceName || '-'}}</span>
			</view>
			<u-line></u-line>
			<view class="info-item">
				<span class="title">期望时间</span>
				<span class="txt">{{orderInfo.expectedTime}}</span>
			</view>
		</view>
		<view class="info-box">
			<span class="title-m">基本信息</span>
			<view class="info-item">
				<span class="title">订单号</span>
				<span class="txt">{{orderInfo.orderNo || '-'}}</span>
			</view>
			<u-line></u-line>
			<view class="info-item">
				<span class="title">下单时间</span>
				<span class="txt">{{orderInfo.createTime}}</span>
			</view>
			<u-line></u-line>
			<view class="info-item">
				<span class="title">下单数量</span>
				<span
					class="txt">{{orderInfo.orderNum || '-'}}（{{  getUnitTxt(orderInfo.serviceUnit) }}）</span>
			</view>
			<u-line></u-line>
			<view class="info-item">
				<span class="title">销售价格</span>
				<span class="txt">￥{{orderInfo.sellingPrice || "0.00"}}</span>
			</view>
			<u-line></u-line>
			<view class="info-item">
				<span class="title">应付金额</span>
				<span class="txt">￥{{orderInfo.totalPrice || "0.00"}}</span>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getOrderDetail,
		getServiceUnit,
		getOrderStatus,
	} from '@/api/order.js'

	export default {
		components: {},
		data() {
			return {
				orderInfo: {
					serviceUnit: ''
				},
				typeList: [],
				couponList: [],
				disableScroll: false,
				timer: null,
				unitList: [],
			}
		},
		onLoad(options) {
			this.getInfoById(options.id);
			this.getOrderStatus();
			this.getServiceUnit();
		},
		onShow() {
			// this.getOrderStatus();
			// this.getInfoById(options.id);
		},
		onUnload() {
			// 当页面关闭或卸载时清除定时器

		},
		methods: {
			getStatusTxt(value) {
				let obj = this.typeList.find(item => item.code == value);;
				return obj ? obj.value : '待确认'
			},
			getUnitTxt(value) {
				let obj = this.unitList.find(item => item.code == value);;
				return obj ? obj.value : ''
			},
			//查询订单状态
			getOrderStatus() {
				let that = this;
				getOrderStatus().then(res => {
						if (res.code == 200) {
							let data = res.data.orderStatus;
							data.unshift({
								value: '全部',
								code: '',
							})
							this.typeList = data;
						}

					})
					.catch((err) => {
						console.log(err);
					})

			},
			//查询订单状态
			getServiceUnit() {
				let that = this;
				getServiceUnit().then(res => {
						if (res.code == 200) {
							this.unitList = res.data.serviceUnit;
						}

					})
					.catch((err) => {
						console.log(err);
					})

			},

			getInfoById(id) {
				let that = this;
				uni.showLoading({
					title: '加载中',
					mask: true,
				});
				getOrderDetail(id).then(res => {
						if (res.code == 200) {
							let data = res.data;
							this.orderInfo = data;
						}
					})
					.catch((err) => {
						console.log(err);
					})
					.finally(() => {
						uni.hideLoading();
					});
			},

		},
	}
</script>

<style lang='scss' scoped>
	.container {
		padding: 20rpx 20rpx 100rpx;

		.order-status {
			padding: 40rpx 20rpx !important;

			.status-text {
				text-align: center;
				font-weight: bold;
				font-size: 40rpx;
				color: #4c96d6;
			}
		}

		.order-info {
			display: flex;
			align-items: center;
			padding: 20rpx;
			background: #fff;
			border-radius: 10rpx;
			margin-bottom: 20rpx;

			image {
				width: 180rpx;
				height: 180rpx;
				border-radius: 10rpx;
				margin-right: 20rpx;
			}

			.info-content {
				display: flex;
				flex-direction: column;
				flex: 1;

				.name {
					word-break: break-all;
					font-size: 32rpx;
					color: #333;
					font-weight: bold;
				}

				.address {
					font-size: 28rpx;
					color: #666;
					margin-top: 20rpx;

					width: 100%;
					font-weight: 500;
									line-height: 35rpx;
					display: flex;
					justify-content: flex-start;
					align-items: flex-start;
					overflow: hidden; //超出的文本隐藏
					text-overflow: ellipsis; //溢出用省略号显示
					white-space: normal; //处理元素中的 空白
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
					display: -moz-box;
					-moz-line-clamp: 2;
					-moz-box-orient: vertical;
					overflow-wrap: break-word;
					word-break: break-all;

					::v-deep .u-icon {
						display: inline-block;
					}

					.txt {
						margin-left: 15rpx;
					}
				}

				.area {
					font-size: 28rpx;
					color: #666;
					margin-top: 10rpx;
				}
			}
		}

		.info-box {
			padding: 20rpx;
			background: #fff;
			border-radius: 10rpx;
			margin-bottom: 20rpx;

			.info-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 30rpx 0;

				.title {
					width: 250rpx;
					font-size: 28rpx;
					color: #333;
				}

				.txt {
					/* flex: 1; */
					max-width: 540rpx;
					text-align: left;
					font-size: 28rpx;
					color: #757575;
				}
			}

			.info-item-spa {
				align-items: flex-start;
				flex-direction: column;

				.txt {
					margin-left: 0;
					margin-top: 20rpx;
					text-align: left;
				}
			}
		}

		.title-m {
			/* 竖线和文字对齐 */
			display: flex;
			align-items: center;
			padding: 20rpx 0;
			font-size: 28rpx;
			color: #333;
			font-weight: bold;
			line-height: 28rpx;

			/* 左边加一个竖线 */
			&::before {
				content: '';
				display: inline-block;
				width: 6rpx;
				height: 30rpx;
				background: #4B91D1;
				margin-right: 10rpx;
			}
		}
	}
</style>