<template>
	<view class="box">
		<view class="boxtop">
			<view class="boxtopb">
				<!-- <view class="boxflex" @click="getChoseFn">
					<image :src="buimg" class="boxtopba"></image>
					<view class="boxtopbb" :style="role?'':'color:#AAAAAA;'">{{role||'选择部门'}}</view>
					<image :src="upimg" class="boxtopbc"></image>
				</view> -->
				<view class="boxflex" @click="getAddFn" v-if="checkPermi(['system:schedule:add'])">
					<image :src="rulesimg" class="boxtopbd"></image>
					<view class="boxtopbe">添加考勤设置</view>
				</view>
			</view>
		</view>
		
		
		<card-list :datainfo="prolist" type='rule' :wtdt="wtdt"   @getdetail='goDetail' @getDelFn="getDelFn"></card-list>
		
		<view>
			<view class="exele">
				<view class="box" style="padding-top: 0;display: none;">
					<table @change="change">
						<tr class="tr_one">
							<th style="width: 120upx; text-align: center;">部门</th>
							<th style="width: 280upx; text-align: center;">打卡距离</th>
							<th style="width: 240upx; text-align: center;">打卡次数</th>
							<th style="width: 110upx; text-align: center;">操作</th>
						</tr>
						<scroll-view scroll-y class="scroll-view" upper-threshold="40" lower-threshold="40"
							@scrolltolower="bot_btn">
							<tr v-for="(item,index) in prolist" :key="index"
								:class=" [index%2  ==0 ? 'two_tr two_trtwo':'two_tr']" @click="chakn(item)">
								<td style="width: 120upx; text-align: center;">
									{{ item.deptName == null ? '暂无信息' :  item.deptName}}
								</td>
								<td style="width: 280upx; text-align: center;">
									<!-- 	{{ item.dept&&item.dept.deptName == null ? '暂无信息' :  item.dept.deptName}}</td> -->
									{{ item.kaRadius==null ? '暂无信息' :  item.kaRadius}}
								</td>
								<!-- <td style="width: 40upx; text-align: center;">{{item.gender == null? '暂无信息' : item.gender }}</td> -->
								<td style="width: 240upx; text-align: center;">
									{{item.kaNum == null? '暂无信息' : item.kaNum }}
								</td>
								<td style="width: 110upx; color: #1678FF;text-align: center;text-decoration: underline;"
									@click.stop="goDetail(item.kaoqinId)">详情</td>
							</tr>
							<view class="shax" v-if="prolist.length>0">
								{{wtdt}}
							</view>
							<view class="zanwu " v-else><text>暂无数据</text></view>
						</scroll-view>

					</table>
				</view>

			</view>
		</view>
		<!-- 部门 -->
		<selectMorePicker ref="picker" :title="auiPicker.title" :layer="auiPicker.layer" :titflag='auiPicker.titflag'
			:data="auiPicker.data" @callback="pickerCallback"></selectMorePicker>	
	</view>
</template>

<script>
	import {getdeptTreeNow,clocklist,getXiuconfigDel} from "@/api/work/check.js"
	import selectMorePicker from "@/components/selectMorePicker.vue"
	import selectPicker from '@/components/selectPicker.vue'
	import {
		selectDictLabel
	} from '@/utils/common.js'
	import cardList from "@/work/components/clock/cardlist.vue"
	import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
	export default {
		data() {
			return {
				rulesimg: require("@/work/static/clock/krules.png"),
				buimg: require("@/work/static/clock/chosebm.png"),
				addimg: require("@/work/static/clock/addry.png"),
				upimg: require("@/work/static/clock/up.png"),
				closeimg: require("@/work/static/clock/close.png"),
				rimg: require("@/work/static/clock/right.png"),
				prolist: [{deptName:'人事部',kaTimeAmIn:'08:00',kaTimePmOut:'19:00'}],
				wtdt: '',
				nickName: '',
				auiPicker: {
					title: '选择部门',
					layer: null,
					titflag: true,
					data: []
				},
				uplatflag: false,
				listite: {
					"roleName": '',
					"roleId": ''
				},
				rolelist: [],
				role: '',
				deptId: this.$store.state.user.deptId,
				roleId: '',
				rangekey: "dictLabel",
				pageNum: 1,
				pageSize: 10,
				reachflag: true,
				deptName: '',
				rolefalg: true,
				rolevalue:[]
			}
		},
		components: {
			selectMorePicker,
			selectPicker,
			cardList
		},
		onShow() {
			
		},
		onLoad() {
			uni.$on('reashlist',(res)=>{
				this.pageNum = 1;
				this.prolist = [];
				this.reachflag=true;
				this.clocklist()
			})
			this.clocklist()
			// this.getdeptTreeNow();
			
		},
		onUnload() {
			uni.$off('reashlist')
		},
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.clocklist()
			}
		},
		methods: {
			checkPermi,checkRole,
			getClose() {
				this.uplatflag = false;
			},
			getDelFn(data){
				var that=this;
				getXiuconfigDel(data).then(res=>{
					if(res.code==200){
						this.$toast("删除成功")
						setTimeout(function() {
							that.getSearch()
						}, 1500);
					}
				})
			},

			getSearch() {
				this.pageNum = 1;
				this.prolist = [];
				this.reachflag=true;
				this.clocklist()
			},
			getChoseFn() {
				this.$refs.picker.open().then(function() {
					console.log('picker打开');
				});
				// this.$tab.navigateTo("/work/pages/lock")
			},
			change(){
				
			},
			vacRolChange(e) {
				// this.params.houseType=e[0].label;
			},
			goDetail(e) {
				this.$tab.navigateTo("/work/pages/clock/setswork?id="+e)
			},
			getAddFn() {
				this.$tab.navigateTo("/work/pages/clock/setswork?fromurl=rule")
			},
			pickerCallback(e) {
				const _this = this;
				let result = '';
				e.data.forEach(function(item, index) {
					if (index == 0) {
						result += item.label;
					} else {
						result += '/' + item.label;
					}
				});
				var len = e.data.length - 1
				if (_this.uplatflag) {
					_this.deptName = e.data[len].label;
					_this.deptId = e.data[len].id;
				} else {
					_this.role = result;
					this.deptId = e.data[len].id;
					this.pageNum = 1;
					this.prolist = [];
					this.reachflag=true;
					this.clocklist()
				}
			},
			clocklist() {
				var that = this;
				var params = {
					// nickName: this.nickName,
					// deptId: this.deptId,
					pageSize: this.pageSize,
					pageNum: this.pageNum,
				}
				clocklist(params).then(res => {
					if (res.code == 200) {
						if (res.rows.length < this.pageSize) {
							this.reachflag = false
							this.wtdt = '到底了~';
						} else {
							var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -
								1)
							if (num < res.total) {
								this.reachflag = true
								this.wtdt = '上拉加载更多'
							} else {
								this.reachflag = false
								this.wtdt = '到底了~';
							}
						}
						if (this.pageNum == 1) {
							this.prolist = res.rows;
						} else {
							this.prolist = this.prolist.concat(res.rows)
						}
					} else {
						this.$toast(res.msg)
					}
				})
			},
			getdeptTreeNow() {
				getdeptTreeNow().then(res => {
					if (res.code == 200) {
						this.auiPicker.data = res.data
					} else {
						this.$toast(res.msg)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		padding-top: 100rpx;background-color: #F2F2F2;min-height: 100vh;box-sizing: border-box;
	}

	.boxtop {
		padding: 0 34rpx;
		position: fixed;left:0;right:0;top: 0;z-index: 5;background-color: #FFFFFF;
		.boxtopa {
			padding: 14rpx 0;
			display: flex;
			align-items: center;

			input {
				height: 64rpx;
				background: #E6E6E6;
				border-radius: 28rpx;
				flex: 1;
				background: #E6E6E6;
				padding: 0 30rpx;
				line-height: 64rpx;
				border-radius: 28rpx;
				font-size: 32rpx;
			}

			view {
				width: 120rpx;
				height: 64rpx;
				background: #1678FF;
				border-radius: 28rpx;
				font-size: 32rpx;
				color: #FFFFFF;
				margin-left: 8rpx;
				flex: 0 0 auto;
				text-align: center;
				line-height: 64rpx;
			}
		}

		.boxtopb {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 32rpx 0;

			.boxflex {
				display: flex;
				align-items: center;

				.boxtopba {
					width: 26rpx;
					height: 24rpx;
					margin-right: 16rpx;
				}

				.boxtopbb {
					font-size: 32rpx;
					color: #1678FF;
					margin-right: 16rpx;
				}

				.boxtopbc {
					width: 14rpx;
					height: 14rpx;
				}

				.boxtopbd {
					width: 28rpx;
					height: 28rpx;
					margin-right: 16rpx;
				}

				.boxtopbe {
					font-size: 30rpx;
					color: #6CBC0A;
				}
			}
		}
	}

	.tab {
		.tabs {
			.one_tab {
				color: #1678FF !important;

			}

			.one_tabqie {
				border-bottom: 8rpx solid #1678FF;

			}
		}
	}

	.exele {
		.box {
			table {
				border-spacing: 0rpx;
			}

			.tr_one {
				display: flex;
				// padding: 0 20rpx;
				box-sizing: border-box;
				justify-content: space-between;

				th {
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #000000;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					line-height: 78rpx;
					height: 78rpx;
					box-sizing: border-box;
				}
			}

			.two_tr {
				display: flex;
				// padding: 0 20rpx;
				box-sizing: border-box;
				justify-content: space-between;

				td {
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #343434;

					min-height: 82rpx;
					padding: 20rpx 0;
					box-sizing: border-box;
					display: flex;
					align-items: center;
					justify-content: center;

				}

				// .tdse {
				// 	color: #E60012 !important;
				// }
				// .apply_span_xl{
				// 	color: #32B16C !important;
				// }
				// .apply_span_xltwo{
				// 	color: #ffa200 !important;
				// }
				// .apply_span_xlfive{
				// 	color: #4c4b4b !important;
				// }
				// .apply_span_xlthreo{
				// 	color: #f00404 !important;
				// }
				// .apply_span_xlforu{
				// 	color: #aaaaaa !important;
				// }
				// .coiu {
				// 	color: #EC1717;
				// }
			}

			.two_trtwo {
				background-color: #F2F2F2;
			}
		}

	}

	.zanwu {
		text-align: center;
		padding-top: 20upx;

		span {
			font-size: 30upx;
		}
	}

	// 搜索条件width: 562rpx;
	.bgbox {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		z-index: 19;
		background: rgba(0, 0, 0, 0.5);
	}

	.sfixed {
		min-height: 760rpx;
		background: #FFFFFF;
		border-radius: 14rpx;
		padding: 40rpx 34rpx;
		box-sizing: border-box;
		position: fixed;
		left: 60rpx;
		right: 60rpx;
		top: 50%;
		transform: translateY(-50%);
		z-index: 29;
		max-height: calc(100vh - 280rpx);
		overflow-y: auto;

		.sfixed_tit {
			font-size: 32rpx;
			font-weight: bold;
			color: #343434;
			line-height: 44rpx;
			text-align: center;
		}

		.sfixed_clo {
			width: 20rpx;
			height: 20rpx;
			position: absolute;
			left: 34rpx;
			top: 44rpx;
		}

		.sfixed_box {
			padding-top: 20rpx;
			margin-bottom: 80rpx;

			.sfixed_inp {
				width: 100%;
				height: 76rpx;
				background: #F2F2F2;
				padding: 0 34rpx;
				box-sizing: border-box;
				font-size: 32rpx;
				color: #333333;
				margin-top: 30rpx;
			}
		}

		.sfixed_btn {
			width: 100%;
			height: 76rpx;
			border: 0px solid #00B034;
			border-radius: 6rpx;
			font-size: 34rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 76rpx;

			&.btn1 {
				background: #1678FF;
				color: #FFFFFF;
			}

			&.btn2 {
				border: 2rpx solid #F02828;
				color: #F02828;
				margin-top: 28rpx;
			}


		}

	}

	.address {
		display: flex;
		align-items: center;
		padding: 24rpx 0;

		.addtita {
			flex: 0 0 auto;
			font-size: 34rpx;
			font-weight: bold;
			color: #343434;
		}

		.addressa {
			display: flex;
			align-items: center;
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			overflow: hidden;

			.addsa {
				font-size: 30rpx;
				color: #333333;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				flex: 1;
				text-align: right;
			}

			.addsimg {
				width: 10rpx;
				height: 18rpx;
				margin-left: 10rpx;
				flex: 0 0 auto;
			}

			// .adds{
			// 	display: flex;align-items: center;justify-content: flex-start;padding:10rpx 20rpx;min-width: 220rpx;box-sizing: border-box;}
		}

		.addclear {
			color: #EA2929;
			font-size: 32rpx;
			flex: 0 0 auto;
			height: 60rpx;
			line-height: 60rpx;
			width: 128rpx;
			text-align: center
		}
	}

	.delbox {
		width: 580rpx;
		background: #FFFFFF;
		border-radius: 14px;
		position: fixed;
		top: 50%;
		left: 80rpx;
		right: 80rpx;
		padding: 48rpx 34rpx 72rpx;
		box-sizing: border-box;
		z-index: 5;
		margin-top: -210rpx;

		.deltit {
			font-size: 34rpx;
			font-weight: bold;
			color: #343434;
			text-align: center;
			line-height: 40rpx;
		}

		.del_img {
			width: 34rpx;
			height: 34rpx;
			position: absolute;
			right: 34rpx;
			top: 44rpx;
		}

		.del_btn {
			width: 100%;
			height: 76rpx;
			background: #00B034;
			border-radius: 6rpx;
			font-size: 34rpx;
			font-weight: bold;
			color: #FFFFFF;
			text-align: center;
			line-height: 76rpx;
		}

		.del_list {
			display: flex;
			padding: 60rpx 0 40rpx;
			flex-wrap: wrap;

			.del_lista {
				width: 116rpx;
				height: 64rpx;
				background: #CACACA;
				border-radius: 32rpx;
				font-size: 32rpx;
				font-weight: 500;
				color: #FFFFFF;
				text-align: center;
				line-height: 64rpx;
				margin: 0 10rpx 20rpx 0;

				&.act {
					background-color: #019FE8;
				}
			}
		}
	}
	
</style>
