<template>
	<view class="hzIndex">
		<hzHeader title="就诊预约受理"></hzHeader>
		<view class="container hzContent">
			<view class="main">
				<view class="tab-box">
					<view class="tab-item" :class="currentTabIndex == 0 ? 'active_tab' : ''"
						@click="currentTabIndex = 0">
						未审批
						<view class="tabBottom" v-if="currentTabIndex == 0"></view>
					</view>
					<view class="tab-item" :class="currentTabIndex == 1 ? 'active_tab' : ''"
						@click="currentTabIndex = 1">
						已审批
						<view class="tabBottom" v-if="currentTabIndex == 1"></view>
					</view>
				</view>
				<!-- <view v-if="currentTabIndex == 0" style="height: 80upx;background: white;padding-left: 10upx;line-height: 68upx;border-bottom: 2upx solid #eee;">
				<radio-group @change="checkRadioChange" style="width: 80%;float: left;">
					<label class="radio" style="margin-right: 10upx;font-size: 26upx;" v-for="(item, index) in items" :key="item.value" >
						<radio  :value="item.value" :checked="item.checked" style="transform:scale(0.9)" color="#00c277"/>
						{{item.name}}
					</label>
				</radio-group>
			</view> -->

				<!-- 未审批列表 -->
				<view class="list-box" v-if="currentTabIndex == 0">
					<view class="detail-box" v-for="(item, index) in list0" :key="index">
						<!-- <view @click="detail"> -->
						<view class="detail_header" @click="detail(item)">
							<image class="blueSign" src="@/static/haircut/ypyd.png" mode=""></image>
							<text class="font-tilte">药品预定</text>
							<!-- <text style="color: #666;" v-if="item.status==0" class="font-result">待审核</text>
							<text  v-if="item.status==1" class="font-result">已同意</text>
							<text style="color: red;" v-if="item.status==2" class="font-result">已拒绝</text> -->
						</view>
						<view class="detail_msg">
							<view class="info-item" @click="detail(item)">
								<text>姓名:</text>
								<text class="infoSpan">{{ item.user_name }}</text>
							</view>
							<view class="info-item" @click="detail(item)">
								<text>联系电话:</text>
								<text class="infoSpan">{{ item.tel_number }}</text>
							</view>
							<view class="info-item" @click="detail(item)">
								<text>部门:</text>
								<text class="infoSpan">{{ item.dept_name }}</text>
							</view>
							<view class="info-item" @click="detail(item)">
								<text>预计到货时间:</text>
								<text class="infoSpan">{{ item.pickDate }}</text>
							</view>
							<view class="info-item" @click="detail(item)">
								<text>详情:</text>
								<text class="infoSpan"><text v-for="(item1, index1) in item.detailList"
										:key="index1"><text
											v-if="index1!=0">，</text>{{ item1.drugs_name}}x{{item1.drugs_num}}</text>
								</text>
							</view>
						</view>

					</view>
				</view>

				<!-- 已审批列表 -->
				<view class="list-box" v-if="currentTabIndex == 1">
					<view class="detail-box" v-for="(item, index) in list1" :key="index">
						<!-- <view @click="detail"> -->
						<view class="detail_header" @click="detail(item)">
							<image class="blueSign" src="@/static/haircut/ypyd.png" mode=""></image>
							<text class="font-tilte">药品预定</text>
							<!-- <text style="color: #666;" v-if="item.status==0" class="font-result">待审核</text> -->
							<text v-if="item.status==1" class="font-result">已同意</text>
							<text style="color: red;" v-if="item.status==2" class="font-result">已拒绝</text>
						</view>
						<view class="detail_msg">
							<view class="info-item" @click="detail(item)">
								<text>姓名:</text>
								<text class="infoSpan">{{ item.user_name }}</text>
							</view>
							<view class="info-item" @click="detail(item)">
								<text>联系电话:</text>
								<text class="infoSpan">{{ item.tel_number }}</text>
							</view>
							<view class="info-item" @click="detail(item)">
								<text>部门:</text>
								<text class="infoSpan">{{ item.dept_name }}</text>
							</view>
							<view class="info-item" @click="detail(item)">
								<text>预计到货时间:</text>
								<text class="infoSpan">{{ item.pickDate }}</text>
							</view>
							<view class="info-item" @click="detail(item)">
								<text>详情:</text>
								<text class="infoSpan"><text v-for="(item1, index1) in item.detailList"
										:key="index1"><text
											v-if="index1!=0">，</text>{{ item1.drugs_name}}x{{item1.drugs_num}}</text>
								</text>
							</view>
							<view class="info-item" @click="detail(item)">
								<text>预定时间:</text>
								<text class="infoSpan">{{ item.createTime }}</text>
							</view>
						</view>

					</view>
				</view>
				<content-none v-if="currentTabIndex == 0 && list0.length == 0" :padTop="20"></content-none>
				<content-none v-if="currentTabIndex == 1 && list1.length == 0" :padTop="20"></content-none>
			</view>
			<load-more v-show="currentTabIndex == 0 " :loadingType="loadingType0"
				:contentText="contentText0"></load-more>
			<load-more v-show="currentTabIndex == 1 " :loadingType="loadingType1"
				:contentText="contentText1"></load-more>
			<!-- <view v-if="checkedListId.length>0" style="position: fixed;bottom:0upx;height: 50upx;width: 100%;z-index: 9999;">
		</view> -->
		</view>
	</view>
</template>

<script>
	import uniCalendar from '@/components/uni-calendar/uni-calendar.vue';
	import {
		getDrugsApplyList
	} from '@/common/api.js';
	import {
		callbackRequest,
		alertTip,
		getStorage
	} from '@/common/util.js';
	import loadMore from '@/components/loadMore.vue';
	import datetimePicker from '@/components/dateTime.vue';
	import contentNone from '@/components/contentNone.vue';
	import UniPopup from "@/components/uni-popup/uni-popup.vue"
	import xflSelect from '../../components/xfl-select/xfl-select1.vue'
	export default {
		data() {
			return {
				userId: getStorage('userInfo').userId,
				currentTabIndex: 0,
				page0: 1,
				pageSize0: 10,
				loadingType0: 2, //0-loading前；1-loading中；2-没有更多了
				page1: 1,
				pageSize1: 10,
				loadingType1: 2, //0-loading前；1-loading中；2-没有更多了
				list0: [],
				list1: [],
				stateList: ['待审核', '已通过', '已拒绝'],

				contentText0: {
					contentdown: '上拉加载更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				},
				contentText1: {
					contentdown: '上拉加载更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				},
				items: [{
						value: '0',
						name: '全选',
						checked: false
					},
					{
						value: '1',
						name: '取消选择',
						checked: false
					},
				],
				objList: [],
				paramsDataList: [],
				checkedListId: [],
			};
		},
		components: {
			loadMore,
			contentNone,
			UniPopup,
			xflSelect
		},
		watch: {
			currentTabIndex: function(newVal, oldVal) {
				this.currentTabIndex = newVal;
				if (this.currentTabIndex == 0) {
					this.page0 = 1;
					this.loadingType0 = 0;

				} else if (this.currentTabIndex == 1) {
					this.page1 = 1;
					this.loadingType1 = 0;

				}
				this.getDrugsApplyList();
			}

		},
		onLoad(options) {
			this.currentTabIndex = options.currentTabIndex || 0;
		},
		onShow() {
			this.getDrugsApplyList();
		},
		methods: {
			detail(item) {
				uni.navigateTo({
					url: `/pages/medical/drugsApprovalDetail?id=` + item.id
				});
			},
			getDrugsApplyList() {
				var data = {};
				if (this.currentTabIndex == 0) {
					data = {
						userId: this.userId,
						page: this.page0,
						pageSize0: this.pageSize,
						status: 0
					};
				} else {
					data = {
						userId: this.userId,
						page: this.page1,
						pageSize1: this.pageSize,
						status: 3
					};
				}
				let params = {
					method: getDrugsApplyList,
					data: data
				};
				callbackRequest(params).then(res => {
					if (res.data.returnCode == 1) {
						let result = res.data.returnData || [];
						if (this.currentTabIndex == 0) {
							if (this.page0 == 1) {
								this.list0 = result;
							} else {
								if (result.length > 0) {
									this.list0 = [...this.reservationList0, result];
									this.loadingType0 = 0;
								} else {
									this.loadingType0 = 2;
								}
							}
						} else {
							if (this.page1 == 1) {
								this.list1 = result;
							} else {
								if (result.length > 0) {
									this.list1 = [...this.reservationList1, result];
									this.loadingType1 = 0;
								} else {
									this.loadingType1 = 2;
								}
							}
						}

					} else {
						alertTip(res.data.returnMsg);
					}
				});
			},

			toDetail(url) {
				uni.navigateTo({
					url
				});
			},
			checkBox(e, item) {
				e.stopPropagation();
				e.preventDefault();
				let that = this;
				let box = (item.checkValue = !item.checkValue);
				// for(var i=0;i<that.list.length;i++){
				// 	if(item.detail_id == that.list[i].detail_id){
				// 		that.list[i].checkValue = item.checkValue;
				// 	}
				// }
				var arr = [];
				if (that.checkedListId.length > 0 && that.checkedListId[0].appointmentType != item.appointmentType) {
					alertTip("请选择来访类型相同的数据进行审批！");
					that.$set(item, 'checkValue', false);

					//item.checkValue=false;
					var index = 0;
					for (var i = 0; i < that.list.length; i++) {
						if (item.detail_id == that.list[i].detail_id) {
							index = i;
						}
					}
					that.$set(that.list, index, item);
				} else {
					that.appointmentTypeForPopup = item.appointmentType;
				}
				if (item.checkValue) {
					that.checkedListId.push(item);

				} else {
					for (var i = 0; i < that.checkedListId.length; i++) {
						if (item.detail_id != that.checkedListId[i].detail_id) {
							arr.push(that.checkedListId[i]);
						}
					}
					that.checkedListId = arr;
				}
			},
			checkRadio(e, item) {
				let that = this;
				let box = (item.checked = !item.checked);
			},
			getCheckBoxList() {
				let that = this;
				var checkedList = [];
				for (var i = 0; i < that.list.length; i++) {
					if (that.list[i].checkValue) {
						checkedList.push(that.list[i]);
					}
				}
				var objList = [];
				var paramsDataList = [];
				for (var i = 0; i < checkedList.length; i++) {
					if (checkedList[i].checkValue) {
						var obj = {
							userId: this.userId,
							applyId: "",
							applyType: "",
							userLevel: this.userLevel,
							appointmentType: "",
						}; //分三种情况
						obj.applyId = checkedList[i].detail_id;
						obj.appointmentType = checkedList[i].appointmentType;
						objList.push(obj);
						var paramsData = {};
						paramsData.id = this.circulationId;
						paramsData.applyId = checkedList[i].id;
						paramsData.userLevel = this.userLevel;
						paramsDataList.push(paramsData);
					}
				}
				that.objList = objList;
				that.paramsDataList = paramsDataList;
				//this.openButPopup();

				// }
			},
			submit(type) {
				this.getCheckBoxList();
				let objList = this.objList;
				for (var i = 0; i < objList.length; i++) {
					objList[i].applyType = type;
				}
				let params = {
					"method": updateVisitorInfoBatch, // 申请的审批
					"data": {
						list: objList
					} //分三种情况
				};
				var self = this;
				var content = "是否确认拒绝";
				if (type == 2) {
					content = "是否确认同意";
				}
				uni.showModal({
					title: '提示',
					content: content,
					success: function(res) {
						if (res.confirm) {
							callbackRequest(params)
								.then(res => {
									const url = '/pages/invite2/invite2?type=1';
									alertTip(res.data.returnMsg);
									setTimeout(function() {
										uni.redirectTo({
											url
										});
									}, 10);
								})
						}
					}
				})

			},
			inputSel(e) {
				this.circulationId = "";
				if (e.detail.value == "") {
					this.finalList = this.list;
					this.showList = true;
					return
				}
				var finalList = [];
				for (var i = 0; i < this.list.length; i++) {
					let ite = this.list[i].value;
					// 包含某一字符串
					if (ite.indexOf(e.detail.value) !== -1) {
						finalList = finalList.concat(ite);
					}
				}
				this.finalList = finalList;
				this.showList = true;
			},
			changeSel(newVal) {
				//console.log(newVal);
				this.circulationId = newVal.orignItem.id;
				//this.uinfo.orgName = newVal.newVal;
			},
			clearSel() {
				this.circulationId = "";
				this.finalList = this.list;
				this.showList = true;
			},
			openButPopup() {
				this.$refs.butPopup.open()
			},
			closeButPopup() {
				this.$refs.butPopup.close()
			},
			checkRadioChange: function(e) {
				let that = this;
				var values = e.detail.value;
				that.appointmentTypeForPopup = values == 2 ? "" : values
				for (var i = 0; i < that.list.length; i++) {
					if (values == that.list[i].appointmentType) {
						that.list[i].checkValue = true;
					} else {
						that.list[i].checkValue = false;
					}
				}
				var arr = [];
				for (var i = 0; i < that.list.length; i++) {
					if (that.list[i].checkValue) {
						arr.push(that.list[i]);
					}
				}
				that.checkedListId = arr;
			}
		},
		onReachBottom() {
			// if (this.loadingType !== 0 ) {
			// 	return;
			// }
			// this.loadingType = 1;
			// this.page = this.page + 1;
			// this.getMyList();
		}
	};
</script>

<style lang="scss" scoped>
	@import '@/static/css/common.scss';

	page {
		// background: #f8f8f8;
	}

	.container {
		padding: 24upx;
		margin-top: 150upx;

		.main {

			.tab-box {
				width: 80%;
				display: flex;
				font-size: 32upx;
				color: #555555;

				.active_tab {
					font-weight: 800;

				}

				.tab-item {
					width: 40%;

					.tabBottom {
						width: 28%;
						height: 4upx;
						border-radius: 5px;
						background-image: linear-gradient(to right, #64E182, #1CA7B2);
					}
				}
			}

			.form-box {
				padding: 20upx 30upx 0upx;
				margin-bottom: 20upx;
				background: #fff;

				.form-item {
					overflow: hidden;
					border-bottom: 1px solid #eee;
					padding: 30upx 0;

					.label {
						float: left;
						width: 150upx;
						font-size: 28upx;
						color: #333;
						font-weight: bold;
						line-height: 50upx;
					}

					.ipt-box {
						margin-left: 160upx;

						input {
							width: 100%;
							height: 50upx;
							line-height: 50upx;
							font-size: 26upx;
							color: #666;
						}

						.pic {
							width: 60upx;
							height: 60upx;
							line-height: 80upx;
						}
					}

					.select {
						.arrow {
							float: right;
							width: 16upx;
							height: 29upx;
							margin-top: 10upx;
						}

						input {
							width: 70%;
						}
					}

					.jian {
						width: 50upx;
						height: 50upx;
						margin-left: 280upx;
					}

					.select {
						.arrow {
							float: right;
							width: 16upx;
							height: 29upx;
							margin-top: 10upx;
						}

						.picker {
							height: 50upx;
							line-height: 50upx;
							font-size: 26upx;
							color: #666;
						}
					}
				}

				.sure-btn {
					width: 100%;
					height: 80upx;
					font-size: 28upx;
					color: #fff;
					text-align: center;
					line-height: 80upx;
					border-radius: 8upx;
					background: #0066cc;
					background: linear-gradient(to right, #ffc200, #ff9000);
					/*设置按钮为渐变颜色*/
					margin-top: 50upx;
				}
			}

			.list-box {
				margin: unset;
				margin-top: 24upx;

				.detail-box {
					// margin-top: 10upx;
					margin-bottom: 24upx;
					background: #ffffff;
					border-radius: 20upx;
					padding: 24upx;
				}

				.detail_header {
					padding: 15upx 0upx;
					border-bottom: 1px solid #eee;
					display: flex;
					flex-direction: row;
					align-items: center;
					position: relative;
				}

				.detail_header .blueSign {
					width: 48upx;
					height: 48upx;
				}

				.detail_header .font-tilte {
					display: inline-block;
					font-weight: bold;
					font-size: 18px;
					color: #333333;
					margin-left: 16upx;
				}

				.detail_header .font-result {
					display: inline-block;
					position: absolute;
					width: 80*2upx;
					height: 28*2upx;
					right: 0upx;
					background: #C1EFEA;
					border-radius: 15px 15px 15px 15px;
					font-size: 28upx;
					color: #0DB0A7;
					text-align: center;
					line-height: 28*2upx;
				}

				.detail_msg {
					display: grid;
					margin-top: 20upx;
				}

				.detail_msg .info-item {
					font-size: 28upx;
					color: #999999;
					margin-bottom: 10upx;
					font-size: 28upx;
					line-height: 50upx;

					text {
						display: inline-block;
						width: 200upx;
					}

					.infoSpan {
						width: auto;
						font-size: 28upx;
						color: #666;
						float: right;
					}
				}

				.detail_msg .info-item:nth-of-type(6) {
					padding-bottom: 24upx;
					border-bottom: 1px solid #EBEFF7;
				}

				.detail_msg .info-item:last-child {
					padding-bottom: 24upx;
					border-bottom: 0px solid #000;
				}

				.comment-btn {
					margin-top: 24upx;
					width: 84*2upx;
					height: 32*2upx;
					border-radius: 16*2upx;
					border: 1px solid #0DB0A7;
					font-size: 28upx;
					color: #0DB0A7;
					line-height: 32*2upx;
					text-align: center;
					min-width: 140upx;
					justify-self: end;
				}

				.bg-ccc {
					border-color: #CACACA;
					color: #CACACA;
					background-color: #fff !important;
				}
			}
		}
	}

	#addbtn {
		height: 120upx;
		background-color: #ffffff;
		padding: 30upx;
		border-radius: 30upx;
		color: #333333;
		border-bottom: 0.033333rem solid #eee;
		align-items: center;
		position: relative;
		margin-top: 20upx;
	}

	.addbtn view text:nth-child(1) {
		font-size: 32upx;
		margin-left: 220upx;
		color: #00c277;
	}

	.addbtn view text:nth-child(2) {
		font-size: 32upx;
		margin-left: 180upx;
		color: #00c277;
	}

	.tips {
		font-size: 22upx;
		// margin-left: 80upx;
		margin-top: 20upx;
	}

	uni-radio .uni-radio-input {
		-webkit-appearance: none;
		appearance: none;
		margin-right: 5px;
		outline: 0;
		border: 1px solid #d1d1d1;
		background-color: #fff;
		border-radius: 50%;
		width: 18px !important;
		height: 18px !important;
		position: relative;
	}
</style>