<template>
	<view>
		<u-tabs barWidth="83" fontSize="34" :current="current" :scrollable="false" :list="nav_tabs" @change="tabsCilck"></u-tabs>
		<!-- 信息展示 -->
		<view class="order_box">
			<!-- medicine -->
			<image class="medicine_pic" :src="img_url+'medicine.png'" mode="" @click="toMedicine"></image>
			<!-- 审核中 -->
			<view class="audit" v-if="current == 0 && orderList.length!==0">
				<view class="item" v-for="item in orderList">
					<view class="left_box">
						<view class="time">
							<text class="time_text">{{item.createTime.substr(0,10)}}</text>
						</view>
						<view class="left_row">
							<image width="175" height="175" :src="item.pic2"></image>
							<view class="info">
								<text class="info_title">用药人</text>
								<view class="name_box">
									<text class="name">{{item.drugUserList[0].name}}</text>
									<text class="name_btn">{{item.drugUserList[0].labelValue}}</text>
								</view>
								<view class="other_info">
									<text>{{item.drugUserList[0].labelValue.sex == 1?'男': '女'}}</text>
									<!-- <text>{{item.drugUserList[0].age}}岁</text> -->
									<text>{{item.drugUserList[0].phone.substr(0,3)+'****'+item.drugUserList[0].phone.substr(7)}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 已通过 -->
			<view class="pass"  v-if="current == 1 && orderList.length!==0">
				<view class="item">
					<view class="time">
						<text class="time_text">2022-05-01</text>
					</view>
					<u-read-more :toggle="true" showHeight="900" color="#6C6C6C" textIndent="0" fontSize="24rpx"
						closeText="展开(共5件)" openText="收起">
						<view class="goods_item">
							<!-- <image src="../../../static/agreement-tips.png" mode=""></image> -->
							<view class="right_box">
								<text class="title">【消毒杀菌】 有效抑制99.9%细菌 300g/瓶</text>
								<view class="center_box">
									<view class="money_box">
										<!-- <text class="min red"></text> -->
										<text class="bigs red">￥123</text>
									</view>
									<text class="back_iconx">×2</text>
								</view>
								<text>【规格】 预防感冒家庭常备（全家同享） 、粉色</text>
							</view>
						</view>
					</u-read-more>
					<view class="total_box">
						<text class="text_price">合计</text>
						<text class="price">￥12346</text>
					</view>
					<button class="gather" v-if="current==1">去支付</button>
				</view>
			</view>
			
			<view class="empty_box" v-if="orderList.length==0">
				<image :src="IMG_URL+'empty.png'" alt=""></image>
				<text class="text_">{{current==0?'暂无审核记录':'暂无通过记录'}}</text>
			</view>
		</view>

	</view>
</template>

<script>
import config_img from "@/utils/js/config.js";
	import { IMG_URL } from '@/env.js'
	export default {
		data() {
			return {
				IMG_URL,
				img_url: config_img.img_url,
				current: 0,
				nav_tabs: [{
					name: '审核中',
				}, {
					name: '已通过',
				}],
				url: '',
				orderList: [],
				pageNo: 1,
				pageSize: 10,
				total: null,
				isLock: true //锁
			}
		},
		onUnload() {
			uni.switchTab({
				url: this.url
			})
		},
		onLoad() {
			let pages_url = getCurrentPages();
			this.url = pages_url[0].route;
			this.patterPage();
		},
		onPullDownRefresh() {
			this.orderList = [];
			this.pageNo = 1;
			this.total = null;
			this.isLock = true;
			this.patterPage()
		},
		onReachBottom() {
			if(this.isLock){
				this.isLock = false;
				if(this.total !== null && this.pageNo * this.pageSize >= this.total){
					this.$Toast('没有更多数据了哦！');
					setTimeout(()=>{
						this.isLock = true;
					},3000)
					return
				}
				this.pageNo+=1;
				this.patterPage();
			}
		},
		methods: {
			patterPage() {
				uni.showLoading();
				const params = {
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					type: this.current
				}
				this.$api('patterPage',params).then(res => {
					let { code, result, message} = res;
					if(code == 200) {
						if(this.total == null) {
							this.total = result.total;
						}
						// 处理 图片
						result.records.forEach(item => {
							item.pic2 = item.pic.split(',')[0]
						})
						this.orderList = this.orderList.concat(result.records)
						console.log(result);
					}else {
						this.$Toast(message);
					}
					uni.hideLoading()
					uni.stopPullDownRefresh()
					this.isLock = true;
				}).catch(err => {
					uni.hideLoading()
					this.isLock = true;
					uni.stopPullDownRefresh()
					this.$Toast(err.message);
				})
			},
			toMedicine() {
				// prescription 0 标记从哪来 0 从home页来
				uni.navigateTo({
					url: "./medicine/index?type=''&prescription=0"
				})
			},
			tabsCilck(index) {
				console.log(index)
				this.current = index;
				// 初始化
				this.orderList = [];
				this.pageNo = 1;
				this.total = null;
				this.isLock = true;
				this.patterPage();
			},
		}
	}
</script>

<style lang="scss" scoped>
	.empty_box{
		width: 100%;
		height: 76vh;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		image{
			width: 371rpx;
			height: 371rpx;
	
		}
		.text_{
			margin-top: 10rpx;
			font-size: 36rpx;
			font-weight: bold;
			color: #01AEEA;
		}
	}
	/deep/ .u-scroll-box {
		display: flex;
	}

	.order_box {
		background-color: #F5F5F5;
		min-height: 100vh;
		// margin-top: 22rpx;
		padding-bottom: 20rpx;

		.medicine_pic {
			margin: 26rpx 40rpx 0;
			width: 668rpx;
			height: 157rpx;
		}

		.audit {
			.item {
				margin-top: 22rpx;
				background-color: #fff;

				&:first-child {
					margin-top: 27rpx;
				}
			}
		}

		.pass {
			.item {
				margin-top: 17rpx;
				background-color: #fff;

				&:first-child {
					margin-top: 21rpx;
				}
			}
		}

		.item {
			width: 711rpx;
			margin: 0 auto;
			border-radius: 24rpx;
			padding-bottom: 10rpx;
			box-shadow: 0 3rpx 6rpx 0 rgba(0, 0, 0, 0.16);

			.left_box {
			}

			.left_row {
				display: flex;
				margin-left: 40rpx;
				margin-top: 12rpx;
				margin-bottom: 12rpx;

				image {
					width: 175rpx;
					height: 191rpx;
				}

				.info {
					margin-left: 24rpx;
					display: flex;
					flex-direction: column;

					.info_title {
						font-size: 30rpx;
						color: #707070;
						margin-top: 17rpx;
						margin-bottom: 17rpx;
					}

					.name_box {
						font-size: 28rpx;
						color: #000;
						margin-bottom: 17rpx;
						.name{
							font-size: 34rpx;
						}
						.name_btn {
							margin-left: 10rpx;
							font-size: 24rpx;
							color: #0C85FF;
							border-radius: 10rpx;
							border: 1px solid #0C85FF;
							padding: 5rpx 10rpx;
						}
					}

					.other_info {
						display: flex;
						font-size: 32rpx;
						padding-bottom: 23rpx;
						color: #000;

						text {
							margin-right: 38rpx;
						}
					}
				}
			}


			.time {
				width: 648rpx;
				margin: 0 auto;
				padding-top: 15rpx;
				padding-bottom: 15rpx;
				border-bottom: 1px solid rgba(112,112,112,0.2);
				display: flex;
				justify-content: space-between;
				font-size: 32rpx;

				.time_text {
					color: #333;
				}

				.phone {
					color: #01AEEA;
				}
			}

			.goods_item {
				display: flex;
				width: 648rpx;
				margin: 0 auto;
				margin-top: 22rpx;
				padding-bottom: 26rpx;
				border-bottom: 1px solid rgba(112,112,112,0.2);

				&:last-child {
					border-bottom: none;
				}

				image {
					width: 200rpx;
					height: 200rpx;
					border-radius: 20rpx;
				}

				.right_box {
					display: flex;
					flex-direction: column;
					font-size: 26rpx;
					margin-left: 25rpx;

					.title {
						color: #000;
						font-size: 33rpx;
						line-height: 39rpx;
					}

					.center_box {
						display: flex;
						justify-content: space-between;
						color: #01AEEA;
						font-size: 32rpx;

						.money_box {
							.red {
								color: #DB0618;
							}

							.min {
								font-size: 20rpx;
							}

							.bigs {
								font-size: 36rpx;
							}
						}
						.back_money{
							color: #fff;
							background-color: #FFA952;
							border-radius: 15rpx;
							height: 47rpx;
							line-height: 47rpx;
							box-sizing: border-box;
							font-size: 34rpx;
							padding-left: 15rpx;
							padding-right: 15rpx;
						}
						.back_iconx{
							font-size: 38rpx;
						}
					}
				}
			}

			.total_box {
				display: flex;
				width: 648rpx;
				margin: 0 auto;
				justify-content: flex-end;
				font-size: 28rpx;
				// margin-top: 34rpx;
				padding-bottom: 16rpx;
				border-bottom: 1px solid rgba(112,112,112,0.2);
				.sum_back_momey{
					height: 47rpx;
					line-height: 47rpx;
					border-radius: 10rpx;
					padding-left: 15rpx;
					padding-right: 15rpx;
					margin-right: 45rpx;
					color: #fff;
					background-color: #FFA952;
					font-size: 30rpx;
				}
				.text_price{
					font-size: 34rpx;
				}
				.price{
					font-size: 36rpx;
				}
				text {
					&:last-child {
						color: #DB0618;
					}
				}
			}

			.gather {
				width: 235rpx;
				height: 60rpx;
				margin-top: 10rpx;
				margin-right: 21rpx;
				border: 1rpx solid #01AEEA;
				color: #01AEEA;
				font-size: 30rpx;
				border-radius: 30rpx;
				line-height: 60rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}

		position: relative;

		.received {
			position: absolute;
			top: 18rpx;
			right: 122rpx;
			width: 181rpx;
			height: 108rpx;
		}
	}
</style>
