<template>
	<view id="myapp" class="bodyA">
		<!-- 滚动区域 -->
		<view class="content">
			<van-pull-refresh v-model="refreshFlag" success-text="刷新成功" @refresh="refreshFn">
				<van-list v-if="dataList.length != 0" offset="100" :immediate-check="false" v-model="listLoadingFlag"
					:finished="finishFlag" finished-text="没有更多了" @load="Load">
					<view class="list" v-for="(item,index) in dataList" :key="index" @click="toPage(item)">
						<view class="modeTitle splitLineBorderBot">
							{{item.convenientOperationForm.title}}
							<view class="state" :class="[item.currentStateDesc=='评估中'?'act':'']">
								{{item.currentStateDesc}}
							</view>
						</view>
						<view class="listLabel">{{item.convenientOperationForm.formName1}}
							<span class="valMsg">{{item.convenientOperationForm.formValue1}}</span>
						</view>
						<view class="listLabel" v-if="item.convenientOperationForm.rowNum >= 2">
							{{item.convenientOperationForm.formName2}}
							<span class="valMsg">{{item.convenientOperationForm.formValue2}}</span>
						</view>
						<view class="listLabel" v-if="item.convenientOperationForm.rowNum >= 3">
							{{item.convenientOperationForm.formName3}}
							<span class="valMsg">{{item.convenientOperationForm.formValue3}}</span>
						</view>
						<view class="listLabel" v-if="item.convenientOperationForm.rowNum >= 4">
							{{item.convenientOperationForm.formName4}}
							<span class="valMsg">{{item.convenientOperationForm.formValue4}}</span>
						</view>
						<view class="listLabel" v-if="item.convenientOperationForm.rowNum >= 5">
							{{item.convenientOperationForm.formName5}}
							<span class="valMsg">{{item.convenientOperationForm.formValue5}}</span>
						</view>
					</view>


				</van-list>
				<van-empty :description="descriptionVal" v-if="dataList.length == 0" />
			</van-pull-refresh>
		</view>
		<!-- 底部 -->
		<!-- <view class="footer">
            <van-button class="footerBtn">按钮</van-button>
        </view> -->
	</view>
</template>

<script>
	import {
		WaitList
	} from '@/common/api.js';
	import {
		callbackRequest,
		callbackRequestNoLoading,
		setStorage,
		getStorage,
		sureAlterTip,
		devEnv,
		alertTip,
		wxSdk,
		formatImgUrl,
		formatDate
	} from '@/common/util.js';
	import {
		formDateChange,
		getImage
	} from '@/common/common.js'
	export default {
		data() {
			return {
				// code
				descriptionVal: '暂无数据', // 无数据&异常文本
				listLoadingFlag: false,
				finishFlag: false,
				refreshFlag: false,
				pageNum: 1,
				dataList: [],
				timer: null,
				code: '',
				codeTm: '1',
			}
		},
		onNavigationBarButtonTap(val) {
			console.log('111', val)
			if (val.index == 0) {
				this.golistA()
			} else {
				this.golist()
			}
		},
		onReady() {
			// #ifdef H5
			// h5 临时方案
			// const btn = document.getElementsByClassName('uni-btn-icon')[1]
			// btn.style.display = 'none'
			// const btn1 = document.getElementsByClassName('uni-btn-icon')[2]
			// btn1.style.display = 'none'
			// #endif
		},
		onShow(options) {
			this.pageNum = 1
			this.dataList = []
			this.getList();
		},
		methods: {
			// code
			back() {
				// window.history.back()
				window.location.href = './indexIndex.html'
			},
			toPage(obj) {
				console.log(obj);
				let moduleId = obj.moduleId
				let role = ''
				if (moduleId == 17 && obj.currentStateDesc == '待派单') {
					role = 'wyqt'
				} else if (moduleId == 17 && (obj.currentStateDesc == '待接单' || obj.currentStateDesc == '维修中')) {
					role = 'wxbz'
				}
				if (moduleId == 77) {
					uni.setStorageSync('haircutId', {
						applyType: moduleId,
						openType: 0
					});
				}
				if (moduleId == 88) {
					uni.setStorageSync('haircutId', {
						applyType: moduleId,
						openType: 0,
						isShow: 0,
					});
				}
				uni.navigateTo({
					url: obj.examineRoute + '?id=' + obj.businessId + '&&role=' + role
				})
				return
				// let moduleId = obj.moduleId
				// let userRole = JSON.parse(sessionStorage.getItem('userRole'));
				// console.log('==>', moduleId);
				let dicObj = {
					qryType: {
						2: '检查',
						3: '手术',
						4: '住院',
						5: '挂号',
						20: '口腔挂号',
					}
				}
				// 就医模块查询跳转参数
				let itemObj = {
					qryType: dicObj.qryType[moduleId], // 类型（中文）
					id: obj.businessId, // 就医数据返显id
					todo: '1', // 丁总约定的 待办flag
				}
				uni.setStorageSync('haircutId', {
					applyType: moduleId,
					openType: 0,
					isShow: 0,
				});
				let url = ''
				if (moduleId == 2 || moduleId == 3 || moduleId == 4 || moduleId == 5 || moduleId == 20) {
					url = obj.examineRoute + '?id=' + obj.businessId + '&item=' + JSON.stringify(itemObj)
				} else {
					url = obj.examineRoute + '?id=' + obj.businessId + '&role=wyqt' + '&type=1'
				}
				uni.navigateTo({
					url: url
				})
				return
				// let moduleId = obj.moduleId
				// let userRole = JSON.parse(sessionStorage.getItem('userRole'));
				// console.log('==>', moduleId);
				// let dicObj = {
				// 	qryType: {
				// 		2: '检查',
				// 		3: '手术',
				// 		4: '住院',
				// 		5: '挂号',
				// 		20: '口腔挂号',
				// 	}
				// }
				// 就医模块查询跳转参数
				// let itemObj = {
				// 	qryType: dicObj.qryType[moduleId], // 类型（中文）
				// 	id: obj.businessId, // 就医数据返显id
				// 	todo: '1', // 丁总约定的 待办flag
				// }

				// moduleId 与 applyType 转换
				let applyTypeObj = {
					'6': '06', // 理发
					'12': '07', // 餐券领取
				};

				// 缓存入参
				let fkParams = {
					id: obj.businessId,
					applyType: moduleId,
					openType: 0,
				}
				storage.set(fkParams)
				switch (moduleId) {
					case '1':
						// 临时餐券申请
						window.location.href = "./mealVoucher_couponApproval.html?id=" + obj.businessId
						break;
					case '2':
					case '3':
					case '4':
					case '5':
					case '20':
						// 就医管理 检查2 手术3 住院4 挂号5
						window.location.href = "./jyzs_qrService.html?item=" + JSON.stringify(itemObj)
						break;
					case '7':
						// 员工卡申请
						window.location.href = "./index_parcart.html?from=1"
						break;
					case '8':
						// 访客预约
						window.location.href = "./index_visitorReservation.html?from=1"
						break;
					case '9':
						// 临时停车
						window.location.href = "./park-apply-approval-finish.html"
						break;
					case '10':
						// 施工申请
						window.location.href = "./constructionss.html"
						break;
					case '12':
						// 餐券领取
						window.location.href = "./coupongLists.html"
						break;
					case '17':
						// 故障报修
						let roleA = ['51'];
						let roleFlagA = roleA.some(role => userRole.includes(role));
						let roleB = ['52'];
						let roleFlagB = roleB.some(role => userRole.includes(role));
						let roleC = ['53', '54', '55', '56'];
						let roleFlagC = roleC.some(role => userRole.includes(role));

						let urlA;
						if (roleFlagA) {
							// 前台
							urlA = './faultReporting_detail_qt.html?uia=' + obj.businessId;
						} else if (roleFlagB) {
							// 后勤部
							urlA = './PropertyAdminDetail_zb.html?recordId=' + obj.businessId;
						} else if (roleFlagC) {
							// 班组
							urlA = './PropertyTeamServicesDetail_zb.html?recordId=' + obj.businessId;
						} else {
							// 用户及其他
							urlA = "./faultReportDetails.html?id=" + obj.businessId;
						}
						window.location.href = urlA;

						// window.location.href = "./faultReportDetails.html?id=" + obj.businessId;
						break;
					case '18':
						// 便捷服务
						let url1;
						let role1 = ['51'];
						let roleFlag1 = role1.some(role => userRole.includes(role));
						let role2 = ['52'];
						let roleFlag2 = role2.some(role => userRole.includes(role));

						if (roleFlag1) {
							// 前台
							url1 = './PropertyTeamServicesDetail_qt.html?uia=' + obj.businessId;
						} else if (roleFlag2) {
							// 后勤部
							url1 = './PropertyAdminServicesDetail_zb.html?id=' + obj.businessId;
						} else {
							// 用户及其他
							url1 = "./propertyServices_details.html?id=" + obj.businessId;
						}
						window.location.href = url1;
						break;
					case '19':
						// 公务用车
						let url2;
						let role3 = ['64']; //公务用车调度员
						let roleFlag3 = role3.some(role => userRole.includes(role));
						let role4 = ['65']; //后勤部保卫处
						let roleFlag4 = role4.some(role => userRole.includes(role));

						if (roleFlag3) {
							//公务用车调度员
							url2 = './officialCar_detail.html?vehiclesId=' + obj.businessId;
						} else if (roleFlag4) {
							//后勤部保卫处
							url2 = './officialCar_detail.html?vehiclesId=' + obj.businessId + '&type=1';
						} else {
							// 用户及其他
							url2 = './officialCar_detail.html?vehiclesId=' + obj.businessId;
						}
						window.location.href = url2;
						break;
					default:
						console.log('default');
						break;
				}

				// mealVoucher_couponApproval.html?id=100789  临时餐券申请  applyType=>20/21
				// visitorAppointment1.3.html  访客预约  applyType=>02
				// parcart.html  员工卡    applyType=>03
				// constructionss.html  施工申请 applyType=>08
				// park-apply-approval-finish.html  临时停车申请  applyType=>04
				// coupongListester.html  餐券申请  applyType=>01
				// 缺失新增：↓
				// jyzs_qrService.html?item={}  就医  必传字段 qryType/user_id/id  JSON.stringfy()
				// xxxx 理发 【不做跳转】
				// xxxx 故障报修 【不做跳转】
			},
			// 下拉刷新
			refreshFn() {
				this.codeTm = '';
				setTimeout(() => {
					// console.log('refreshFn start');
					// this.refreshFlag = false;
					this.dataList = [];
					this.pageNum = 1;
					this.getList();
				}, 1000);
			},
			// 列表加载更多
			Load() {
				if (this.timer) {
					clearTimeout(this.timer)
				}
				this.timer = setTimeout(() => {
					if (this.dataList.length > 0) {
						this.pageNum = this.pageNum + 1;
						this.getList();
					}
				}, 500)

			},
			//
			getList() {
				const that = this;
				let params = {
					method: WaitList,
					convenientState: '4',
					pageNum: this.pageNum,
					pageSize: 10,
				};
				console.log(params);
				callbackRequest(params).then(res => {
					console.log(res);
					let msg;
					if (res.returnCode == 1) {
						let resData = res.returnData;
						let arr;

						arr = that.dataList.concat(resData)
						that.dataList = arr;

						that.finishFlag = resData.length < 10;
						that.listLoadingFlag = false;
						that.refreshFlag = false;
						msg = '未查询到数据'
						// Object.entries(myColors)
					} else {
						msg = '数据异常'
					}

					that.code = 'n';
					that.codeTm = 'n';
					that.descriptionVal = msg;
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	uni-page-body {
		background-color: #f2f6fa !important;
		min-height: 100% !important;
		height: auto !important;
	}

	.content {
		/* font-size: .48*37*2upx; */
		padding: .4*37*2upx;
	}

	.list {
		background-color: #fff;
		border-radius: .3*37*2upx;
		margin-bottom: .4*37*2upx;
		font-size: .4*37*2upx;
		padding: .26*37*2upx;
	}

	.list .modeTitle {
		font-weight: normal;
		padding-bottom: 0.2*37*2upx;

		display: flex;
		align-items: center;
	}

	.modeTitle::after {
		top: .1*37*2upx;
		bottom: .3*37*2upx;
		height: auto;
	}

	.modeTitle .state {
		margin-left: auto;
		border-radius: .4324*37*2upx;
		padding: 0.12*37*2upx 0.4*37*2upx;
		font-size: .34*37*2upx;
		background-color: #E9F2FF;
		color: #359AFD;
	}

	.modeTitle .act {
		/* color: #fff;
	        background-color: #54D48B; */
	}

	.list .listLabel {
		color: #97A5B1;
		margin-bottom: .15*37*2upx;
	}
</style>