<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}}
							<!-- :class="[item.currentStateDesc=='评估中'?'act':'']" -->
							<view class="state">{{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 {
		myApplyList
	} 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,
				pageLoadingFlag: '',
				pageLoadingFlag_tm: '1',
				permissions: [],
			}
		},
		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: {
			back() {
				// window.history.back()
				window.location.href = './indexIndex.html'
			},
			// code
			toPage(obj) {
				console.log(obj);
				let moduleId = obj.moduleId
				let role = ''
				if (moduleId == 17 && obj.currentStateDesc == '待评价') {
					role = 'user'
				}
				if (moduleId == 77) {
					uni.setStorageSync('haircutId', {
						applyType: moduleId,
						openType: 7
					});
				}
				if (moduleId == 88) {
					uni.setStorageSync('haircutId', {
						applyType: moduleId,
						openType: 2
					});
				}
				uni.navigateTo({
					url: obj.applicationRoute + '?id=' + obj.businessId + '&&role=' + role,
				})
				return
				// let moduleId = obj.moduleId
				// let userRole = JSON.parse(sessionStorage.getItem('userRole'));

				// 就医助手类型
				let dicObj = {
					qryType: {
						2: '检查',
						3: '手术',
						4: '住院',
						5: '挂号',
						20: '口腔挂号'
					}
				}
				let url = ''
				uni.setStorageSync('haircutId', {
					applyType: moduleId,
					openType: 2
				});
				if (moduleId == 2 || moduleId == 3 || moduleId == 4 || moduleId == 5 || moduleId == 20) {
					url = obj.applicationRoute + '?id=' + obj.businessId + "&qry=" + dicObj.qryType[moduleId] + "&todo=1"
				} else {
					url = obj.applicationRoute + '?id=' + obj.businessId
				}
				uni.navigateTo({
					url: url
				})
				return
				// let moduleId = obj.moduleId
				// let userRole = JSON.parse(sessionStorage.getItem('userRole'));

				// 就医助手类型
				// let dicObj = {
				// 	qryType: {
				// 		2: '检查',
				// 		3: '手术',
				// 		4: '住院',
				// 		5: '挂号',
				// 		20: '口腔挂号'
				// 	}
				// }

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

				// 就医模块查询跳转参数
				let itemObj = {
					qryType: dicObj.qryType[moduleId] || '', // 类型（中文）
					// user_id: xx,  // 就医userId
					id: obj.businessId, // 就医数据返显id
					todo: 1, // 丁总约定的 待办flag

					// 适配餐券领取缓存入参 狗东西
					openType: 2,
					applyType: applyTypeObj[moduleId] || ''
				}
				storage.set(itemObj)
				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_examine_detail.html?id=" + obj.businessId + "&qry=" + dicObj
							.qryType[moduleId] + "&todo=1"
						break;
					case '6':
						// 理发
						window.location.href = "./lsy_reservationDetail.html?id=" + obj.businessId;
						break;
					case '7':
						// 员工卡申请
						window.location.href = "./index_parcart.html?from=2"
						break;
					case '8':
						// 访客预约
						window.location.href = "./index_visitorReservation.html?from=2"
						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 = "./mealVoucher_packageCoupon.html"
						break;
					case '17':
						// 故障报修
						window.location.href = "./faultReportDetails.html?id=" + obj.businessId;
						break;
					case '18':
						// 便捷服务
						window.location.href = "./propertyServices_details.html?id=" + obj.businessId;;
						break;
					case '19':
						// 便捷服务
						window.location.href = './officialCar_detail.html?vehiclesId=' + obj.businessId;
						break;
					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.pageLoadingFlag_tm = '';
				setTimeout(() => {
					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: myApplyList,
					pageNum: this.pageNum,
					pageSize: 10,
					convenientState: '',
				};
				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.pageLoadingFlag = 'n';
					that.pageLoadingFlag_tm = '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;
		position: relative;
	}

	.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;
		font-size: .3784*37*2upx;
	}

	.list .listLabel .valMsg {
		color: #0e1a24;
	}

	.list .footerBtnA {
		position: absolute;
		bottom: 0.4*37*2upx;
		right: 0.3*37*2upx;
		padding: 0.2*37*2upx 0.4*37*2upx;
		border-radius: 0.2*37*2upx;
		font-size: .32*37*2upx;
		border: 1px solid #0e1a24;
		color: #0e1a24;
	}
</style>