<template>
	<view class="hzIndex">
		<hzHeader title="服务申请受理"></hzHeader>
		<view class="hzContent">
			<view class="main">
				<view class="tab-box">
					<view style="width: 33%;" class="tab-item" :class="currentTabIndex == 0 ? 'active_tab' : ''"
						@click="currentTabIndex = 0">全部<view class="activeLine" v-if="currentTabIndex == 0"></view>
					</view>
					<view style="width: 33%;" class="tab-item" :class="currentTabIndex == 1 ? 'active_tab' : ''"
						@click="currentTabIndex = 1">进行中<view class="activeLine" v-if="currentTabIndex == 1"></view>
					</view>
					<view style="width: 33%;" class="tab-item" :class="currentTabIndex == 2 ? 'active_tab' : ''"
						@click="currentTabIndex = 2">已完成<view class="activeLine" v-if="currentTabIndex == 2"></view>
					</view>
				</view>
				<view class="reservation-box" v-if="currentTabIndex == 0" style="position: relative;">
					<view class="list-box" v-if="repair0.length > 0">
						<view class="detail" v-for="(item, index) in repair0" :key="index">
							<!-- @click="details(item)" -->
							<view class="detail_header" @click="details(item)">
								<image src="/static/img/serverIcon.png" mode=""
									style="width: 35upx;height: 40upx;margin-left: 20upx;vertical-align: middle;">
								</image>
								<text class="font-tilte">服务申请</text>
								<text v-if="item.STATE =='0'" class="font-result"
									style="color: #ff9000;background-color: #FFEFE3;">待处理</text>
								<text v-if="item.STATE =='1'" class="font-result"
									style="color: #ff9000;background-color: #FFEFE3;">进行中</text>
								<text v-if="item.STATE =='2'" class="font-result"
									style="color: #0DB0A7;background-color: #C1EFEA;">已完成</text>
							</view>
							<view class="detail_msg">
								<view class="info-item" @click="details(item)">
									<text>服务类型：</text>
									<text class="infoSpan">{{item.DATA_VALUE}}</text>
								</view>
								<view class="info-item" @click="details(item)">
									<text>办公室：</text>
									<text class="infoSpan">{{item.OFFICE}}</text>
								</view>
								<view class="info-item" @click="details(item)">
									<text>服务时间：</text>
									<text class="infoSpan">{{ item.APPLICANT_TIME}}</text>
								</view>
								<view v-if="item.USER_NAME" class="info-item" @click="details(item)">
									<text>申请人：</text>
									<text class="infoSpan">{{ item.USER_NAME }}</text>
								</view>
							</view>
						</view>
					</view>
					<content-none v-if="!repair0.length > 0" :padTop="20"></content-none>
				</view>
				<!-- 维修中 -->
				<view class="reservation-box" v-if="currentTabIndex == 1">
					<view class="list-box" v-if="repair1.length > 0">
						<view style="position: relative;" class="detail" v-for="(item, index) in repair1" :key="index">
							<view v-if="item.urgent==1"
								style="position: absolute;top: 40%;left: 36%;transform:rotate(-60deg);">
								<image src="../../static/imgs/jiaji2.png" style="height: 150upx;width: 150upx;"></image>
							</view>
							<view class="detail_header" @click="details(item)">
								<image src="/static/img/serverIcon.png" mode=""
									style="width: 35upx;height: 40upx;margin-left: 20upx;vertical-align: middle;">
								</image>
								<text class="font-tilte">服务申请</text>
								<text v-if="item.STATE =='0'" class="font-result"
									style="color: #ff9000;background-color: #FFEFE3;">待处理</text>
								<text v-if="item.STATE =='1'" class="font-result"
									style="color: #ff9000;background-color: #FFEFE3;">进行中</text>
								<text v-if="item.STATE =='2'" class="font-result"
									style="color: #0DB0A7;background-color: #C1EFEA;">已完成</text>
							</view>
							<view class="detail_msg">
								<view class="info-item" @click="details(item)">
									<text>服务类型：</text>
									<text class="infoSpan">{{item.DATA_VALUE}}</text>
								</view>
								<view class="info-item" @click="details(item)">
									<text>办公室：</text>
									<text class="infoSpan">{{item.OFFICE}}</text>
								</view>
								<view class="info-item" @click="details(item)">
									<text>服务时间：</text>
									<text class="infoSpan">{{ item.APPLICANT_TIME}}</text>
								</view>
								<view v-if="item.USER_NAME" class="info-item" @click="details(item)">
									<text>申请人：</text>
									<text class="infoSpan">{{ item.USER_NAME }}</text>
								</view>
							</view>
						</view>
					</view>
					<content-none v-else :padTop="20"></content-none>
				</view>
				<!-- 已办结 -->
				<view class="reservation-box" v-if="currentTabIndex == 2">
					<!-- <view style="background-color: white;padding: 20upx 0upx;">
					<view class="form-item searchv">
						<picker style="width: 33%;float: left;" class="time " mode="date" @change="startDateChange">
							<view class="">{{ startDate }}</view>
						</picker>
						<text class="timecenter">至</text>
						<picker style="width: 33%;float: right;" class="time " mode="date" @change="endDateChange">
							<view class="">{{ endDate }}</view>
						</picker>
					</view>
				</view> -->

					<view class="list-box" v-if="repair2.length > 0" style="margin-top: 20upx;">
						<view style="position: relative;" class="detail" v-for="(item, index) in repair2" :key="index">
							<view v-if="item.urgent==1"
								style="position: absolute;top: 40%;left: 36%;transform:rotate(-60deg);">
								<image src="../../static/imgs/jiaji2.png" style="height: 150upx;width: 150upx;"></image>
							</view>

							<view class="detail_header" @click="details(item)">
								<image src="/static/img/serverIcon.png" mode=""
									style="width: 35upx;height: 40upx;margin-left: 20upx;vertical-align: middle;">
								</image>
								<text class="font-tilte">服务申请</text>
								<text v-if="item.STATE =='0'" class="font-result"
									style="color: #ff9000;background-color: #FFEFE3;">待处理</text>
								<text v-if="item.STATE =='1'" class="font-result"
									style="color: #ff9000;background-color: #FFEFE3;">进行中</text>
								<text v-if="item.STATE =='2'" class="font-result"
									style="color: #0DB0A7;background-color: #C1EFEA;">已完成</text>
							</view>
							<view class="detail_msg">
								<view class="info-item" @click="details(item)">
									<text>服务类型：</text>
									<text class="infoSpan">{{item.DATA_VALUE}}</text>
								</view>
								<view class="info-item" @click="details(item)">
									<text>办公室：</text>
									<text class="infoSpan">{{item.OFFICE}}</text>
								</view>
								<view class="info-item" @click="details(item)">
									<text>服务时间：</text>
									<text class="infoSpan">{{ item.APPLICANT_TIME}}</text>
								</view>
								<view v-if="item.USER_NAME" class="info-item" @click="details(item)">
									<text>申请人：</text>
									<text class="infoSpan">{{ item.USER_NAME }}</text>
								</view>
							</view>
						</view>
					</view>
					<content-none v-else :padTop="20"></content-none>
				</view>
				<load-more v-if="currentTabIndex == 0" :loadingType="loadingType0"
					:contentText="contentText"></load-more>
				<load-more v-if="currentTabIndex == 1" :loadingType="loadingType1"
					:contentText="contentText"></load-more>
				<load-more v-if="currentTabIndex == 2" :loadingType="loadingType2"
					:contentText="contentText"></load-more>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getDate,
		alertTip,
		callbackRequest,
		getStorage,
		regPhone,
		formatDate
	} from '@/common/util.js';
	import {
		getAllDept,
		getPropertyByUserId
	} from '@/common/api.js';
	import loadMore from '@/components/loadMore.vue';
	import contentNone from '@/components/contentNone.vue';
	export default {
		data() {
			return {
				page1: 1,
				pageSize1: 10,
				loadingType1: 0, //0-loading前；1-loading中；2-没有更多了
				page2: 1,
				pageSize2: 10,
				loadingType2: 0, //0-loading前；1-loading中；2-没有更多了
				page0: 1,
				pageSize0: 10,
				loadingType0: 0, //0-loading前；1-loading中；2-没有更多了
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '正在加载...',
					contentnomore: '没有更多数据了'
				},
				userId: getStorage('userInfo').id,
				currentTabIndex: 0,
				deptList: [], //部门列表
				departmentIndex: 0, //选择的部门下标
				formatDate: formatDate,
				repair0: [],
				repair1: [],
				repair2: [],
			};
		},
		components: {
			loadMore,
			contentNone
		},
		onLoad(option) {
			this.currentTabIndex = option.currentTabIndex || 0;
		},
		onShow() {
			if (this.currentTabIndex == 0) {
				this.page0 = 1;
				this.loadingType0 = 0;
				this.initData();
			} else if (this.currentTabIndex == 1) {
				this.page1 = 1;
				this.loadingType1 = 0;
				this.initData();
			} else if (this.currentTabIndex == 2) {
				this.page2 = 1;
				this.loadingType2 = 0;
				this.initData();
			}
		},
		watch: {
			currentTabIndex: function(newVal, oldVal) {
				if (newVal == 0) {
					this.page0 = 1;
					this.loadingType0 = 0;
					this.initData();
				} else if (newVal == 1) {
					this.page1 = 1;
					this.loadingType1 = 0;
					this.initData();
				} else if (newVal == 2) {
					this.page2 = 1;
					this.loadingType2 = 0;
					this.initData();
				}
			}
		},
		methods: {

			initData() {
				let params = {};
				if (this.currentTabIndex == 0) {
					params = {
						method: getPropertyByUserId,
						data: {
							userId: this.userId,
							type: '1',
							pageNum: this.page0,
							pageSize: this.pageSize0,
						}
					};
				} else if (this.currentTabIndex == 1) {
					params = {
						method: getPropertyByUserId,
						data: {
							userId: this.userId,
							type: '1',
							pageNum: this.page1,
							pageSize: this.pageSize1,
							state: '1'
						}
					};
				} else if (this.currentTabIndex == 2) {
					params = {
						method: getPropertyByUserId,
						data: {
							userId: this.userId,
							type: '1',
							pageNum: this.page2,
							pageSize: this.pageSize2,
							state: '2'
						}
					};
				}
				callbackRequest(params).then(res => {
					res = res.data;
					if (res.returnCode == 1) {
						if (this.currentTabIndex == 0) {
							if (this.page0 == 1) {
								this.repair0 = res.returnData || [];
							} else {
								if (res.returnData.length > 0) {
									this.repair0 = this.repair0.concat(res.returnData);
									this.loadingType0 = 0;
								} else {
									this.loadingType0 = 2;
								}
							}
						} else if (this.currentTabIndex == 1) {
							if (this.page1 == 1) {
								this.repair1 = res.returnData || [];
							} else {
								if (res.returnData.length > 0) {
									this.repair1 = this.repair1.concat(res.returnData);
									this.loadingType1 = 0;
								} else {
									this.loadingType1 = 2;
								}
							}
						} else if (this.currentTabIndex == 2) {
							if (this.page2 == 1) {
								this.repair2 = res.returnData || [];
							} else {
								if (res.returnData.length > 0) {
									this.repair2 = this.repair2.concat(res.returnData);
									this.loadingType2 = 0;
								} else {
									this.loadingType2 = 2;
								}
							}
						}
					} else {
						alertTip(res.returnMsg);
					}
				});
			},
			details: function(item) {
				uni.navigateTo({
					url: 'service-record-detail?id=' + item.ID
				});
			},
		},
		onReachBottom() {
			if (this.currentTabIndex == 0) {
				if (this.loadingType0 !== 0) {
					return;
				}
				this.loadingType0 = 1;
				this.page0 = this.page0 + 1;
				this.initData();
			} else if (this.currentTabIndex == 1) {
				if (this.loadingType1 !== 0) {
					return;
				}
				this.loadingType1 = 1;
				this.page1 = this.page1 + 1;
				this.initData();
			} else if (this.currentTabIndex == 2) {
				if (this.loadingType2 !== 0) {
					return;
				}
				this.loadingType2 = 1;
				this.page2 = this.page2 + 1;
				this.initData();
			}
		}
	};
</script>

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

	.searchv {
		text-align: center;
		width: 90%;
		height: 78upx;
		margin-left: 5%;
	}

	.jlsearch {
		width: 90%;
		margin-left: 5%;
		border: 1px solid #e5e5e5;
		color: #666;
		border-radius: 10upx;
		font-size: 28upx;
		padding: 20upx 20upx;
	}

	.timecenter {
		font-size: 26upx;
		margin-left: 10upx;
		margin-right: 10upx;
		margin-top: 20upx;
		height: 78upx;
		line-height: 78upx;
	}

	.time {
		font-size: 28upx;
		display: inline-block;
		border: 1px solid #e5e5e5;
		border-radius: 10upx;
		color: #666;
		padding: 20upx;
	}

	.statusgr {
		float: right;
		margin-right: 30upx;
		color: #00c277;
	}

	.main {
		margin: 180upx 00upx 0;
		position: relative;
		z-index: 10;

		.tab-box {
			overflow: hidden;
			// border-radius: 10upx 10upx 0 0;
			// background: rgba(132, 149, 167, 0.8);
			height: 80upx;
			margin-bottom: 20upx;

			.tab-item {
				float: left;
				height: 70upx;
				width: 34%;
				font-size: 30upx;
				// color: #e5f6ff;
				text-align: center;
				line-height: 70upx;
			}

			.active_tab {
				// background: #fff;
				color: #333;
				border-radius: 10upx 10upx 0 0;
				font-weight: bold;
			}

			.activeLine {
				background: linear-gradient(90deg, #50CBA1 0%, #06AEA6 100%), #5685F2;
				border-radius: 10upx;
				width: 60upx;
				height: 10upx;
				margin-left: 75upx;
			}
		}

		.reservation-box {

			.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 {
		.detail {
			// margin-top: 10upx;
			margin-bottom: 14upx;
			background: #ffffff;
			border-radius: 4upx;
			margin-bottom: 20upx;
		}

		.detail_header {
			padding: 30upx 30upx;
			border-bottom: 1px solid #eee;
		}

		.detail_header .blueSign {
			height: 30upx;
			width: 10upx;
			background: #00c277;
			display: inline-block;
			margin: 10upx 14upx 0 0;
		}

		.detail_header .font-tilte {
			display: inline-block;
			font-size: 32upx;
			font-weight: bold;
			color: #333;
			margin-left: 20upx;
			vertical-align: middle;
		}

		.detail_header .font-result {
			width: 160upx;
			height: 60upx;
			line-height: 60upx;
			text-align: center;
			border-radius: 50upx;
			display: inline-block;
			float: right;
			font-size: 26upx;
			// color: #00c277;
			margin-right: 20upx;
			vertical-align: top;
		}

		.detail_header .font-result-1 {
			display: inline-block;
			float: right;
			font-size: 26upx;
			color: red;
			line-height: 50upx;
			vertical-align: top;
		}

		.detail_msg {
			padding: 20upx 30upx;
			overflow: hidden;
		}

		.detail_msg .info-item {
			margin-bottom: 10upx;
			font-size: 28upx;

			text {
				display: inline-block;
				width: 140upx;
				color: #999;
			}

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

		.comment-btn {
			float: right;
			font-size: 24upx;
			border-radius: 10upx;
			color: #fff;
			line-height: 50upx;
			text-align: center;
			min-width: 140upx;
			background-color: #00c277;
		}

		.comment-yc {
			float: right;
			font-size: 24upx;
			border-radius: 10upx;
			color: #fff;
			line-height: 50upx;
			text-align: center;
			min-width: 140upx;
			background-color: #00c277;
		}
	}

	.comment-item {
		overflow: hidden;
		margin-top: 20rpx;

		.user-head {
			float: left;
			width: 90upx;
			height: 90upx;
			border-radius: 50%;

			image {
				width: 100%;
				height: 100%;
				border-radius: 50%;
			}
		}

		.fr-content {
			margin: 0 0 0upx 110upx;
			border-bottom: 1px solid #f5f5f5;
			padding-bottom: 26upx;

			.name {
				font-size: 28upx;
				font-weight: bold;
				line-height: 44upx;
			}

			.date {
				float: right;
				font-size: 26upx;
				color: #666;
				line-height: 44upx;
			}

			.grade {
				padding-bottom: 10upx;

				text {
					display: inline-block;
					font-size: 26upx;
					color: #666;
					line-height: 36upx;
					vertical-align: top;
					padding-right: 20upx;
				}

				image {
					width: 36upx;
					height: 36upx;
					margin-right: 8upx;
					vertical-align: top;
				}
			}

			.comment-content {
				font-size: 26upx;
				color: #666;
				line-height: 40upx;
				margin: 6upx;
			}

			.food-list {
				padding: 10rpx 0 0;
				overflow: hidden;

				.food-item {
					float: left;
					margin-right: 10rpx;
					font-size: 24rpx;
					line-height: 30rpx;
					color: $assistColor;
					padding: 4rpx 16rpx;
					border: 1px solid $assistColor;
				}
			}
		}
	}
</style>