<template>
	<view>
		<view class="grxx">
			<view class="grxxItem">
				<view class="sfzhm">
					<text>姓名</text>
					<input v-model="name" class="uni-input" focus />
				</view>
				
				<view class="sfzhm">
					<text>是否填报</text>
					<picker @change="handleIsSubmitChange" :value='index' :range="isSubmitArray">
						<view class="uni-input">{{isSubmitArray[index]}}</view>
					</picker>
				</view>
				
				<view class="sfzhm">
					<text>人员类型</text>
					<picker @change="handleMemberTypeChange" :value='memberTypeIndex' :range="memberTypeArray">
						<view class="uni-input">{{memberTypeArray[memberTypeIndex]}}</view>
					</picker>
				</view>
				
				<view class="sfzhm">
					<text>所属部门</text>
					<picker @change="handleDepartmentChange" :value='departmentIndex' :range="departmentArray">
						<view class="uni-input">{{departmentArray[departmentIndex]}}</view>
					</picker>
				</view>
				<view class="sfzhm">
					<button type="primary" @click="searchData">查询</button>
				</view>
			</view>
		</view>
		<uni-table :loading="loading" @selection-change="selects" border stripe>
			<!-- 表头行 -->
			<uni-tr>
				<uni-th align="center">姓名</uni-th>
				<uni-th align="center">手机号</uni-th>
				<uni-th align="center">所属部门</uni-th>
			</uni-tr>
			<!-- 表格数据行 -->
			<uni-tr v-for="(item,index) in userList" :key="index">
				<uni-td align="center">{{item.name}}</uni-td>
				<uni-td align="center">{{item.phone}}</uni-td>
				<uni-td align="center">{{item.department}}</uni-td>
			</uni-tr>
		</uni-table>
		<!-- 时间选择器 -->
		<view v-show="picTime" class="picTime">
			<view class="uni-padding-wrap">
				<button type="default" @click="picQx">取消</button>
				<button type="default" @click="picQd">确定</button>
			</view>
			<view class="pickers">
				<picker-view v-if="visible" :indicator-style="indicatorStyle" :value="value" @change="bindChange"
					class="picker-view">
					<picker-view-column>
						<view class="item" v-for="(item,index) in years" :key="index">{{item}}年</view>
					</picker-view-column>
					<picker-view-column>
						<view class="item" v-for="(item,index) in months" :key="index">{{item}}月</view>
					</picker-view-column>
					<picker-view-column>
						<view class="item" v-for="(item,index) in days" :key="index">{{item}}日</view>
					</picker-view-column>
				</picker-view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		postRequest,
		getRequest
	} from '@/api/api.js'
	export default {
		data() {
			const date = new Date()
			const years = []
			const year = date.getFullYear()
			const months = []
			const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
			const days = []
			const day = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()
			for (let i = date.getFullYear() - 2; i <= date.getFullYear(); i++) {
				years.push(i)
			}
			for (let i = 1; i <= 12; i++) {
				if (i < 10) {
					months.push('0' + i)
				} else {
					months.push(i)
				}
			}
			for (let i = 1; i <= 31; i++) {
				if (i < 10) {
					days.push('0' + i)
				} else {
					days.push(i)
				}
			}
			return {
				userList: [],
				total: 0,
				loading: false,
				tableData: {
					companyId: "",
					current: 1,
					id: "",
					officeId: "",
					openId: "",
					userType: '',
					orders: [{
						asc: true,
						column: ""
					}],
					size: 10
				},
				isnb: 0,
				picTime: false,
				time: '',
				name: '',
				
				index: 0, 
				isSubmit: '',
				isSubmitArray: ['是', '否'],
				
				memberTypeIndex: 0,
				memberTypeArray: ['院内人员','第三方人员'],
				
				departmentIndex: 0,
				departmentArray: ['中国建设','中国城建'],


				years,
				months,
				days,
				timers: year + '-' + month + '-' + day,
				value: [9999, month - 1, day - 1],
				visible: true,
				indicatorStyle: `height: 50px;`,
			}
		},
		mounted() {
			let userType = uni.getStorageSync('userType')
			this.tableData.userType = userType;
			this.loading = true;
			let date = new Date();
			let mouth = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
			let dates = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate();
			this.time = date.getFullYear() + "-" + mouth + "-" + dates; //表示当前日期
			let data = {
				type: 0, //0:每日流调，1：临时流调，2：在院流调
				createDate: this.time
			}
			this.getList();
		},
		methods: {
			searchData() {
				if (this.time == '') {
					uni.showModal({
						title: '提示',
						showCancel: false,
						content: '时间不能为空',
						success: function(res) {

						}
					})
				}
				if (this.numData == '') {
					uni.showModal({
						title: '提示',
						showCancel: false,
						content: '流调编号不能为空',
						success: function(res) {

						}
					})
				} else {
					this.getList();
				}
			},
			numInput(value) {
				this.numData = value
			},
			//时间选择器变化
			bindChange: function(e) {
				const val = e.detail.value
				let year = this.years[val[0]]
				let month = this.months[val[1]]
				let day = this.days[val[2]]
				let times = year + '-' + month + '-' + day;
				this.time = times;
			},
			//时间选择器点击取消
			picQx() {
				this.picTime = false;
				this.getList();
			},
			picQd() {
				this.picTime = false;
				this.getList();
			},
			//点击弹出时间选择器
			picXs() {
				this.picTime = true
			},
			getList() {
				let data = {
					createDate: this.time,
					type: '0',
					keyWord: this.name
				}
				postRequest('/dailyReportNum/findListByCodeAndType', data).then((res) => {
					if (res.code == '200' && res.data.length > 0) {
						this.loading = false;
						this.userList = res.data;
					} else {
						this.loading = false;
					}
				})
			},
			selects(ss) {
				let list = []
				let index = ss.detail.index;
				index.forEach(item => {
					list.push(this.userList[item].id)
				})
				this.userIdlist = list
			},
			pagi(e) {
				this.tableData.current = e.current;
				this.getList()
			},
			clickNum(officeId, areaType, type) {
				let data = {
					officeId,
					areaType,
					type,
					schedul: this.time,
					reportNum: this.numData
				}
				uni.navigateTo({
					url: `/pages/list/dsfList/dsfList?data=${JSON.stringify(data)}`
				})
			},
			clickName(item) {
				uni.navigateTo({
					url: `/pages/mrldgl/inputMainInfo`
				})
			},
			handleIsSubmitChange: function(e) {
				this.index = e.target.value
			},
			handleMemberTypeChange: function(e) {
				this.memberTypeIndex = e.target.value
			},
			handleDepartMentChange: function(e) {
				this.departmentIndex = e.target.value
			},
		}
	}
</script>

<style>
	.nav {
		padding: 10px;
		display: flex;
		justify-content: space-evenly;
	}

	.nav button {
		width: 32%;
		height: 10%;
		margin: 0 3px;
		font-size: 13px;
	}

	.butts {
		background-color: #007AFF;
		color: white;
	}

	.nav view button {
		width: 39%;
	}

	.grxxItem {
		border-radius: 5px;
		padding: 10px;
		margin: 10px;
		box-shadow: 0px 2px 15px 3px rgba(0, 0, 0, 0.1);
	}

	/deep/.uni-combox__input {
		font-size: 14px;
	}

	.grxxItem .ygxm {
		padding: 10px;
		background-color: #3297ff;
		color: white;
	}

	.grxxItem .sfzhm {
		padding: 10px;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 10px;
		font-size: 84%;
		color: #999999;
		position: relative;
	}

	.sfzhm image {
		width: 28rpx;
		height: 30rpx;
	}

	.sfzhm input {
		width: 70%;
	}

	.sfzhm:first-of-type input {
		width: 30%;
	}

	.grxxItem .mdd {
		justify-content: left;
	}

	.grxxItem .mdd input {
		width: 70%;
		margin-left: 10px;
	}

	.hxx {
		position: absolute;
		color: red;
		left: 3px;
		top: 25%;
	}

	.grxxItem .sfzhm:last-of-type {
		border: none;
	}

	/* 时间选择器 */
	.picTime {
		z-index: 10;
		height: 100%;
		width: 100%;
		background-color: rgba(0, 0, 0, 0.5);
		position: fixed;
		bottom: 0;
		left: 0;
	}

	.uni-padding-wrap {
		position: absolute;
		bottom: 400rpx;
		left: 0;
		width: 750rpx;
		background-color: white;
		display: flex;
		justify-content: center;
		padding: 10px 0;
	}

	.uni-padding-wrap button {
		height: 30px;
		line-height: 30px;
		font-size: 15px;
	}

	.uni-padding-wrap button:last-of-type {
		background-color: #007AFF;
		color: white;
	}

	.pickers {
		position: fixed;
		bottom: 0;
		left: 0;
		text-align: center;
		width: 750rpx;
		height: 400rpx;
		margin-top: 20rpx;
		background-color: white;
	}

	.pickers .picker-view {
		width: 750rpx;
		height: 400rpx;
		margin-top: 20rpx;
		background-color: white;
	}

	.tabButton {
		color: #007AFF;
		text-decoration: underline;
		font-size: 14px;
		background-color: white;
	}

	.tabButton::after {
		border: 0;
	}

	.tab {
		font-size: 14px;
		background-color: white;
	}

	.tab::after {
		border: 0;
	}
</style>
