<template>
	<view class="hzIndex">
		<hzHeader title="药品受理"></hzHeader>
		<view class="container hzContent">
			<view class="main">
				<!-- <view class="tab-box">
					<view class="tab-item active_tab">药品订购受理</view>
				</view> -->
				<!-- 预约记录列表 -->
				<view>
					<view class="list-box" v-if="reservationList.length > 0">
						<view class="detail-box" v-for="(item, index) in reservationList" :key="index">
							<!-- <view @click="detail"> -->
							<view class="detail_header" @click="detail(item)">
								<text class="blueSign"></text>
								<text class="font-tilte">{{ item.createTime }}</text>
								<!-- <text class="slect_icon"></text> -->
								<!-- <text class="font-result">{{ item.status }}</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>
									<view 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>
									</view>
									<!-- <text class="infoSpan">{{ item.desc }}</text> -->
								</view>
								<!-- </view> -->
								<!-- <view class="comment-btn1" @click="feedback">反馈预计到货日期</view> -->
								<view class="comment-btn" v-if="item.endremind==0" @click="remindPickUpDrugs(item)">取药通知
								</view>
								<view class="comment-btn" v-if="item.endremind!=0"
									style="background: #EEEEEE;color: #666;">已通知</view>
							</view>

						</view>
					</view>
					<content-none v-else :padTop="20"></content-none>
				</view>
				<load-more :loadingType="loadingType" :contentText="contentText"></load-more>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getDate,
		alertTip,
		callbackRequest,
		getStorage,
		regPhone,
		formatDate
	} from '@/common/util.js';
	import {
		getAllDept,
		getDrugsApplyList,
		remindPickUpDrugs
	} from '@/common/api.js';
	import loadMore from '@/components/loadMore.vue';
	import contentNone from '@/components/contentNone.vue';
	export default {
		data() {
			return {
				page: 1,
				pageSize: 10,
				loadingType: 0, //0-loading前；1-loading中；2-没有更多了
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				},
				userId: getStorage('userInfo').id,
				currentTabIndex: 1,
				date: getDate(), //获取近30天日期
				chooseDateIndex: 0, //选中的日期
				times: [],
				chooseTimeIndex: null,
				deptList: [], //部门列表
				departmentIndex: 0, //选择的部门下标
				applyPersonName: getStorage('userInfo').username, //申请人姓名
				applyPersonMobile: getStorage('userInfo').telnumber, //申请人手机
				commentList: [],
				reservationList: [
					// { userName: '王建兴', deptName: '创新事业部', phone: '15000000000', time: '2019-12-01', expect: '2019年12月下旬', desc: '阿莫西林 x 1盒, 布洛芬 x 1盒' },
					// { userName: '王建兴', deptName: '创新事业部', phone: '13112011201', time: '2019-11-01', expect: '2019年11月下旬', desc: '头孢地尼分散片 x 2盒' },
					// { userName: '王建兴', deptName: '创新事业部', phone: '15000000000', time: '2019-10-01', expect: '2019年10月下旬', desc: '999感冒灵 x 1盒' },
					// { userName: '王建兴', deptName: '创新事业部', phone: '15000000000', time: '2019-09-01', expect: '2019年09月下旬', desc: '健胃消食片 x 1盒' }
				],
				formatDate: formatDate
			};
		},
		components: {
			loadMore,
			contentNone
		},
		onLoad(option) {

			this.page = 1;
			this.loadingType = 0;
			this.getDrugsApplyList();
		},
		methods: {
			// 反馈按钮
			feedback() {

			},
			getDrugsApplyList() {
				var data = {
					userId: this.userId,
					page: this.page,
					pageSize: this.pageSize,
					status: 1
				};
				let params = {
					method: getDrugsApplyList,
					data: data
				};
				callbackRequest(params).then(res => {

					if (res.data.returnCode == 1) {
						if (this.page == 1) {
							this.reservationList = res.data.returnData || [];
						} else {
							if (res.data.returnData != null && res.data.returnData.length > 0) {
								this.reservationList = this.reservationList.concat(res.data.returnData);
								this.loadingType = 0;
							} else {
								this.loadingType = 2;
							}
						}
					}
				});
			},
			//获取部门列表
			getDepartment() {
				let data = {
					method: getAllDept,
					data: {}
				};
				callbackRequest(data).then(res => {
					if (res.data.returnCode == 1) {
						this.deptList = res.data.returnData;
					}
				});
			},
			detail(item) {
				uni.navigateTo({
					url: `/pages/medical/drugsApprovalDetail?id=` + item.id
				});
			},
			remindPickUpDrugs(item) {
				let data = {
					method: remindPickUpDrugs,
					data: {
						id: item.id,
						userId: item.user_id,
					}
				};
				callbackRequest(data).then(res => {
					if (res.data.returnCode == 1) {
						item.endremind = item.endremind + 1;
						alertTip("已通知");
					}
				});
			}
		},
		onReachBottom() {
			if (this.loadingType !== 0) {
				return
			}
			this.loadingType = 1;
			this.page = this.page + 1;
			this.getDrugsApplyList();
		}
	};
</script>

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

	.container {
		padding: 24upx;

		.main {

			.reservation-box {
				background: #fff;

				.time-box {
					overflow: hidden;
					padding-top: 20rpx;

					.time-item {
						float: left;
						width: 196rpx;
						margin: 0 0rpx 20rpx 20rpx;
						font-size: 26rpx;
						text-align: center;
						line-height: 32rpx;
						padding: 10rpx 0;
						position: relative;
						border: 1px solid #ccc;
						box-sizing: border-box;

						.time-text {
							color: #666;

							text {
								padding: 0 6rpx;
								color: #00c277;
							}

							.color-666 {
								color: #666;
							}
						}

						.icon {
							position: absolute;
							right: 0;
							bottom: 0;
							width: 36rpx;
							height: 36rpx;
							display: none;
						}
					}

					.active {
						border: 1px solid #00c277;

						.icon {
							display: block;
						}
					}
				}

				.form-box {
					// padding: 20upx 30upx 50upx;
					background: #fff;

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

						.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;
							}
						}

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

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

					.form-item:last-child {
						border-bottom: 0px;
					}
				}

				/* 评论 */
				.evaluate {
					padding-top: 30upx;
					border-top: 1px solid #eee;
				}

				.evaluate .title {
					font-size: 28upx;
					color: #333;
					font-weight: bold;
					line-height: 40upx;
					padding: 0 30rpx 30rpx;
				}

				.evaluate .evaluate_item {
					border-bottom: 1px solid #eeeeee;
					padding: 0 0 30upx 50upx;
				}

				.evaluate .evaluate_item:last-child {
					border: none;
				}

				.evaluate .evaluate_item .user {
					padding: 20upx 0;
				}

				.evaluate .evaluate_item .user .username {
					font-size: 28rpx;
					color: #666;
					display: inline-block;
					vertical-align: top;
					padding-right: 20upx;
				}

				.evaluate .evaluate_item .user span image {
					width: 40upx;
					height: 40upx;
					margin-right: 5upx;
				}

				.evaluate .evaluate_item .text {
					font-size: 28upx;
					color: #666;
					line-height: 40upx;
				}
			}
		}

		.scroll-view {
			padding-top: 30upx;
			white-space: nowrap;
			width: 100%;
			height: 120upx;

			.time-item-box {
				padding: 0 10upx;
				margin: 0 16upx;
				display: inline-block;

				.time {
					display: block;
					width: 100%;
					font-size: 28upx;
					color: #666;
				}

				.week {
					display: block;
					width: 100%;
					font-size: 28upx;
					color: #666;
				}
			}

			.time-active {
				.time {
					color: #00c277;
				}

				.week {
					color: #00c277;
				}
			}
		}
	}

	.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: 140upx;
			}

			.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;
		}
	}
</style>