<template>
	<view class="container">
		<!-- <image class="bkg" mode="aspectFill" src="@/static/order-bg.png"></image> -->
		<!-- <view class="user">
			<u-navbar :background="{'background':'transparent'}" title-color="#000" :border-bottom="false" title="订单详情"></u-navbar>
		</view> -->
		<view class="order">
			<view class="order-title">基本信息</view>
			<view class="order-item">
				<view class="order-item-info">
					<view>
						<text>编号：</text><text>{{info.no}}</text>
					</view>
					<view>
						<text>预约时间：</text><text>{{info.time}}</text>
					</view>
					<!-- 					<view>
						<text>结束时间：</text><text>2025-01-17 15:30</text>
					</view> -->
					<view>
						<text>联系人：</text><text>{{info.appoint_name}}</text>
					</view>
					<view class="flex-center" @click.stop="callTel(info.appoint_mobile)">
						<view>
							<text>联系人电话：</text><text>{{info.appoint_mobile}}</text>
						</view>
						<view style="margin-left:10rpx">
							<u-icon name="phone-fill" color="#d61b24"></u-icon>
						</view>
					</view>
					<view>
						<text>医院：</text><text>{{info.hospital?info.hospital.name:''}}</text>
					</view>
				</view>
			</view>

			<view class="order-item">
				<view class="order-item-info">
					<view>
						<text>是否可以自理：</text><text>{{info.my_provide===1?'可以自理':'不能自理'}}</text>
					</view>
					<view>
						<text>就诊人：</text><text>{{info.user_archive?info.user_archive.name:''}}/{{base.getAgeFromId(info.user_archive?info.user_archive.idcard:'')}}</text>
					</view>
					<view>
						<view>就诊资料：</view>
						<view class="order-item-img">
							<image v-for="(item,index) in imgs" :src="item" @click="imgPreview(index)"></image>
						</view>
					</view>
				</view>
			</view>


			<view class="order-item">
				<view class="order-item-info">
					<view>
						<view>其他要求：</view>
						<view>{{info.content?info.content:'暂无'}}</view>
					</view>

				</view>
			</view>
			<view class="order-title" v-if="info.accompany_order_log && info.accompany_order_log.length>0">服务记录</view>
			<view class="order-item" v-if="info.accompany_order_log && info.accompany_order_log.length>0">
				<view class="order-item-info">
					<view>
						<view v-for="item in info.accompany_order_log">
							<block v-for="s in statusList">
								<view v-if="item.status===s.id">
									{{item.created_at}} {{s.name}}：
								</view>
							</block>
							<view  class="order-item-img">
								<image v-for="(i,index) in item.files" :src="i.url" @click="imgPreviewList(item.files,index)"></image>
							</view>
							<view>{{item.remark}}</view>
						</view>
					</view>

				</view>
			</view>


			<view class="order-item">
				<view>服务照片：</view>
				<u-upload :action="action" ref="uUpload" :header="{
				  ['Authorization']: `Bearer ${vuex_token}`,
				}"></u-upload>
			</view>
			<view class="order-item">
				<view class="order-item-input">
					<u-input :border="true" v-model="form.statusName" @click="isShowStatus = true" type="select"
						placeholder="请选择状态"></u-input>
				</view>
				<view class="order-item-input">
					<u-input :border="true" v-model="form.remark" type="textarea" placeholder="备注"></u-input>
				</view>
			</view>
			<view class="order-btn">
				<view @click="$u.throttle(submit,2000)">提交</view>
			</view>
			<u-select v-model="isShowStatus" value-name="id" @confirm="confirmStatus" label-name="name"
				:list="statusList"></u-select>
		</view>
	</view>
</template>

<script>
	import {
		statusList
	} from "@/common/const.js"
	import {
		ROOTPATH as baseUrl
	} from "@/common/config.js";
	export default {
		data() {
			return {
				imgs: [],
				type: 'index',
				action: '',
				id: '',
				isShowStatus: false,
				form: {
					status: '',
					statusName: '',
					remark: ''
				},
				action: `${baseUrl}/api/nurse/upload-file`,
				statusList: [],
				info: {}
			}
		},
		onLoad(options) {
			this.statusList = statusList
			this.id = options.id ? options.id : ''
			this.type = options.type ? options.type : 'index'
			this.getDetail(this.id)
		},
		methods: {
			toUrl() {
				uni.navigateTo({
					url: '/package_sub/order/orderDetail'
				})
			},
			imgPreview(index) {
				uni.previewImage({
					current: index, // 当前显示图片索引
					urls: this.imgs // 需要预览的图片http链接列表
				});
			},
			imgPreviewList(list,index){
				let imgs = []
				list.map(item=>{
					imgs.push(item.url)
				})
				console.log("imgs",imgs)
				uni.previewImage({
					current: index, // 当前显示图片索引
					urls: imgs // 需要预览的图片http链接列表
				});
			},
			callTel(tel) {
				if (this.base.isNull(tel)) {
					return
				}
				uni.makePhoneCall({
					phoneNumber: tel
				});
			},
			confirmStatus(e) {
				this.form.status = e[0].value
				this.form.statusName = e[0].label
			},
			async getDetail(id) {
				const res = await this.$u.api.orderDetail({
					id: id
				})
				this.info = res
				this.form.status = res.status
				this.form.remark = res.remark
				if (res.files.length > 0) {
					res.files.map(item => {
						this.imgs.push(item.url)
					})
				}
				this.statusList.map(item => {
					if (item.id === res.status) {
						this.form.statusName = item.name
					}
				})
				console.log("res", res)
			},
			submit() {
				let that = this
				let url = this.type === 'index' ? '/pages/index/index' : '/package_sub/order/order'
				this.form.file_ids =
					this.$refs.uUpload?.lists
					?.filter((val) => {
						return val.progress === 100;
					})
					?.map((i) => i.response?.id) || [];
				this.$u.api.saveOrder({
					id: this.info.id,
					...this.form
				}).then(res => {
					that.base.toast("提交成功", 1500, function() {
						setTimeout(function() {
							if (that.type === 'index') {
								uni.switchTab({
									url: url
								})
							} else {
								uni.redirectTo({
									url: url
								})
							}
						}, 1500)
					})
				})
				console.log("123")
			},


		}

	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100vw;
		height: 100vh;
		background-color: #fff;
		font-size: 32rpx;

		.bkg {
			position: absolute;
			top: 0;
			left: 0;
			width: 100vw;
			height: 686rpx;
		}

		.user {
			font-size: 36rpx;
			color: #000;
			position: relative;
			padding: 20rpx;
		}

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

			.u-icon {
				margin-left: 10rpx;
			}
		}

		.order {
			margin: 20rpx;
			position: relative;
			padding-bottom: 40rpx;

			&-title {
				font-size: 36rpx;
				color: #000;
				position: relative;
				padding: 20rpx;
			}

			&-item {
				background-color: #fff;
				padding: 20rpx;
				box-shadow: 1rpx 1rpx 10rpx rgba(0, 0, 0, 0.2);
				border-radius: 10rpx;
				margin-bottom: 30rpx;

				&-info {
					padding: 20rpx 0;

					&>view {
						margin-bottom: 10rpx;
					}
				}

				&-img {
					display: flex;
					flex-wrap: wrap;

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

				&-input {
					margin-bottom: 20rpx;
				}
			}

			&-btn {
				padding: 0 65rpx;

				&>view {
					font-size: 33rpx;
					border-radius: 60rpx;
					margin-bottom: 35rpx;
					height: 90rpx;
					line-height: 90rpx;
					text-align: center;
					color: #fff;
					background: linear-gradient(-90deg, #e26165 0%, #c10d12 94%, #c10d12 100%);
					box-shadow: 1rpx 1rpx 10rpx #c10d12;
				}
			}
		}
	}
</style>