<template>
	<view class="billall">
		<u-cell-group class="toptemplate">
			<u-cell :title="mytitle" @click="floorchange">
				<u-icon slot="icon" size="40" color="#fff" name="map"></u-icon>
				<u-icon slot="right-icon" size="40" color="#fff" name="search"></u-icon>
			</u-cell>
		</u-cell-group>
		<view class="topbill">
			<view class="topbilledit" @click="xunjianchange">
				<view class="changetime1">
					{{xjlx}}
				</view>
				<view class="changetime2">
					<u-icon name="arrow-down-fill" color="#666666" size="20"></u-icon>
				</view>
			</view>
			<view class="topbilledit" @click="typechange">
				<view class="changetime1">
					{{xjry}}
				</view>
				<view class="changetime2">
					<u-icon name="arrow-down-fill" color="#666666" size="20"></u-icon>
				</view>
			</view>
		</view>
		<!-- 列表 -->
		<!-- <t-table>
			<t-tr>
				<t-th>序号</t-th>
				<t-th>姓名</t-th>
				<t-th>年龄</t-th>
				<t-th>爱好</t-th>
				<t-th>操作</t-th>
			</t-tr>
			<t-tr v-for="item in tableList" :key="item.id">
				<t-td>{{ item.id + 1 }}</t-td>
				<t-td>{{ item.name }}</t-td>
				<t-td>{{ item.age }}</t-td>
				<t-td>{{ item.hobby }}</t-td>
				  <t-td align="left"> <u-button @click="edit(item)"  size="small" type="primary" :plain="true" text="编辑"></u-button></t-td>

			</t-tr>
		</t-table> -->

		<view class="u-listdata">
			<view style="padding:10rpx 0 0 30rpx">
				共有 <span style="color: red">{{totalnumber}}</span>条记录
			</view>

			<u-list @scrolltolower="scrolltolower" :pagingEnabled='true'>
				<u-list-item v-for="(item, index) in indexList" :key="index">
					<view class="companylist">
						<h3>{{item.position}}</h3>
						<view class="Currentamount">
							巡检类型: 安保
						</view>
						<view class="Currentamount">
							巡检人员: {{item.circuitPerson.realName}}
						</view>
						<view class="Currentamount">
							联系电话:￥{{item.circuitPerson.mobile}}
						</view>
						<view class="Currentamount">
							巡检时间: {{item.circuitTime}}
						</view>
					</view>

				</u-list-item>
			</u-list>

		</view>


		<u-picker :show="showtypexunjian" :itemHeight="80" :columns="columnstypexunjian" keyName="dictLabel" @confirm="confirmxunjian"
			@cancel='cancelxunjian'>
		</u-picker>

		<u-picker :show="showtype" :itemHeight="80" :columns="columnstype" keyName="realName" @confirm="confirmtype" @cancel='canceltype'>
		</u-picker>

		<u-picker :show="showfloor" :itemHeight="80" ref="uPicker" :loading="loading" @confirm="confirmfloor" @cancel='cancelfloor'
			:columns="columns" keyName="orgName" @change="changeHandler"></u-picker>
		<u-notify ref="uNotify" :show="showdct" message="服务器请求失败"></u-notify>
	</view>
</template>

<script>
	// import tTable from '@/components/t-table/t-table.vue';
	// import tTh from '@/components/t-table/t-th.vue';
	// import tTr from '@/components/t-table/t-tr.vue';

	import cellGroup from '../../../uni_modules/uview-ui/libs/config/props/cellGroup';

	// import tTd from '@/components/t-table/t-td.vue';
	export default {
		components: {
			// tTable,
			// tTh,
			// tTr,
			// tTd
		},
		data() {
			const currentDate = this.getDate({
				format: 'yyyy-mm'
			})
			return {
				totalnumber: 0,
				showtypexunjian: false,
				setyesno: true,
				// tableList: [{
				// 		id: 0,
				// 		name: '张三',
				// 		age: '19',
				// 		hobby: '游泳'
				// 	},
				// 	{
				// 		id: 1,
				// 		name: '李四',
				// 		age: '21',
				// 		hobby: '绘画'
				// 	},
				// ],
				indexList: [],
				xjlx: '巡检类型',

				dataList: [],
				dataForm: {
					//projectId: "",
					buildingId: "",
					storeyId: "",
					circuitType: "",
					circuitPersonId: "",			
					page: 1,
					limit: 10,
				},
				showtype: false,
				showdct: false,
				mytitle: '',
				alldata: [],
				showfloor: false,
				loading: false,
				columns: [],
				columnData: [],
				pd: true,

				xjry: '巡检人员',
				showPicker: false,
				myday: currentDate,
				columnstypexunjian: [],

				columnstype: [],



			}
		},
		//监听页面加载，其参数为上个页面传递的数据，参数类型为 Object（用于页面传参
		onLoad() {
			let getDictDataList = uni.getStorageSync('getDictDataList');
			console.log('111111111111111111', getDictDataList)

			for (let i = 0; i < getDictDataList.length; i++) {
				if (getDictDataList[i].dictType == 'ReviewType') {
					let pushdata = {
						dictLabel: "全部",
						dictValue: "",
					}
					getDictDataList[i].dataList.unshift(pushdata)
					this.columnstypexunjian = [getDictDataList[i].dataList]
				}
			}

			this.getUserList();
			this.getfloor();
			//	this.loadmore();
		},
		//监听页面初次渲染完成。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady() {
			// 微信小程序需要用此写法

		},

		//监听页面隐藏
		onHide() {},
		//监听窗口尺寸变化
		onResize() {},
		//监听页面卸载
		onUnload() {},
		//监听用户下拉动作，一般用于下拉刷新
		onPullDownRefresh() {},


		methods: {
			getUserList() {
				this.$api.get('/user/list',{ page: 1,
					limit: 999999,})
						.then(res=>{
							//	console.log('111111111111111111',res.data.data)
							this.columnstype=[res.data.data]
						})
			},
			scrolltolower() {
				if (this.pd) {
					this.getalldata();
				} else {
					return
				}
			},
			xunjianchange() {
				this.showtypexunjian = true;
			},
			cancelxunjian() {
				this.showtypexunjian = false;
			},
			confirmxunjian(e) {
				  console.log('111111111111111111',e)
				this.xjry = e.value[0].dictLabel;
				 this.dataForm.circuitType = e.value[0].dictValue;
				this.indexList=[];
				this.dataForm.page = 1;
				this.getalldata();
				this.showtypexunjian = false;
			},

			getalldata() {
				this.$api.get('/circuitrecord/page', this.dataForm)
					.then(res => {

						this.totalnumber = res.data.data.total;
						//  console.log('111111111111111111',res.data.data.list)
						if (res.data.data.list.length != 0) {
							this.indexList.push(...res.data.data.list);
							this.dataForm.page = this.dataForm.page + 1;
							this.pd = true;

						} else {
							uni.showToast({
								title: '暂无更多数据了',
								icon: 'none',
								duration: 1500
							})
							this.pd = false;
							//this.jfnodata=true
						}


					})
			},

			canceltype() {
				this.showtype = false;
			},
			confirmtype(e) {
				  console.log('111111111111111111',e)
				this.showtype = false;
				this.xjry = e.value[0].realName;
				this.dataForm.circuitPersonId = e.value[0].id;
				this.indexList=[];
				this.dataForm.page = 1;
				this.getalldata();
			},
			typechange() {
				this.showtype = true;
			},
			
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				// day = day > 9 ? day : '0' + day;
				return `${year}-${month}`;
			},
			getfloor() {
				this.$api.get('/control/getOrgStructureTree/', {})
					.then(res => {

						if (res.data.code == 0) {
							//this.dataForm.projectId = res.data.data[0].orgId;

							this.mytitle = res.data.data[0].orgName;
							this.alldata = res.data.data[0].childrenList;
							//console.log('111111111111111111',  res.data.data[0].childrenList)
							this.columns = [
								res.data.data[0].childrenList,
								res.data.data[0].childrenList[0].childrenList
							]
							let allfloor = [];
							for (let i = 0; i < res.data.data[0].childrenList.length; i++) {
								allfloor.push(res.data.data[0].childrenList[i].childrenList)
							}
							//  console.log('111111111111111111',allfloor)
							this.columnData = allfloor;
							this.indexList=[];
							this.dataForm.page = 1;
							this.getalldata();
						} else {
							this.showdct = true
						}
					})
			},

			floorchange() {
				this.showfloor = true;
			},
			changeHandler(e) {
				const {
					columnIndex,
					index,
					// 微信小程序无法将picker实例传出来，只能通过ref操作
					picker = this.$refs.uPicker
				} = e
				if (columnIndex === 0) {
					this.loading = true
					picker.setColumnValues(1, this.columnData[index])
					this.loading = false
				}
			//	this.getalldata();
			},
			confirmfloor(e) {
				console.log('222222', e.value)
				this.mytitle = e.value[0].orgName + e.value[1].orgName;
				this.dataForm.buildingId = e.value[0].orgId;
				this.dataForm.storeyId = e.value[1].orgId;
				this.showfloor = false;
				this.indexList=[];
				this.dataForm.page = 1;
				this.getalldata();
			},
			cancelfloor() {
				this.showfloor = false;
			},


		}
	}
</script>

<style lang="scss">
	.Currentamount {
		padding-left: 30rpx;
		height: 50rpx;
		line-height: 50rpx;
		color: #BCB3A7;

		span {
			color: #FA5555;
			padding-left: 9rpx;
		}
	}

	.Callfee {
		width: 100rpx;
		height: 45rpx;
		text-align: center;
		line-height: 45rpx;
		color: #5C8FFF;
		border: 1px solid #5C8FFF;
		font-size: 22rpx;
		position: absolute;
		bottom: 10rpx;
		right: 10px;
		font-weight: bold;
	}

	.companylist {
		margin: 20rpx 30rpx;
		background: #fff;
		height: 280rpx;
		border-radius: 10px;
		position: relative;

		h3 {
			height: 70rpx;
			line-height: 70rpx;
			padding-left: 30rpx;
		}
	}

	.settled {
		background-color: #09C700;
		width: 100rpx;
		height: 40rpx;
		text-align: center;
		line-height: 40rpx;
		color: #fff;
		font-size: 14rpx;
		position: absolute;
		top: 0px;
		right: 0px;
		border-top-right-radius: 10rpx;
		border-bottom-left-radius: 10rpx;
	}

	.outstanding {
		background-color: #FA5555;
		width: 100rpx;
		height: 40rpx;
		text-align: center;
		line-height: 40rpx;
		color: #fff;
		font-size: 14rpx;
		position: absolute;
		top: 0px;
		right: 0px;
		border-top-right-radius: 10rpx;
		border-bottom-left-radius: 10rpx;
	}



	.billall {}

	.topbill {
		display: flex;
		justify-content: space-around;
		align-items: center;
		height: 100rpx;
		background-color: #e6e6e6;
	}

	.topbilledit {
		display: flex;
		justify-content: space-around;
		align-items: center;
	}

	.changetime1 {
		padding-right: 10rpx;
	}
</style>
