<template>
	<view class="content">

		<view class="fixed-top">

			<view class="search-user flex-y-center " style="position: relative;">
				<view class="search-content flex-y-center">
					<icon type="search" size="18" />
					<input confirm-type="search" v-model="seTval" @confirm="confirm" @input="getSearch"
						class="flex-grow-1" type="text" placeholder-style="font-size:26rpx" placeholder="请输入关键词" />
					<view class="flex-center" style="margin-left: 10rpx;" @click.stop="onDel" v-if="seTval">
						<icon type="clear" size="18" />
					</view>
				</view>
				<view class="search-btn" @click="search">
					搜索
				</view>
			</view>

			<view class="box-pack-between headerScreen flex-y-center">
				<view class="flex-y-center flex-grow-1 ft26 header-text">
					<view style="width: 100%;" class="flex-grow-1 flex-center " data-text="1"
						:class="act_index==1?'act':''" @click="onTopBtnTap(1)">
						<view class="text-1" style="width: auto; max-width: 300rpx;">
							{{level_text}}
						</view>
						<view class="d3"></view>
					</view>
					<!-- <view style="width: 50%;" class="flex-grow-1 flex-center text-1" data-text="2"
					:class="act_index==2?'act':''" @click="onTopBtnTap(2)">
					<view class="text-1" style="width: auto; max-width: 300rpx;">
						{{type_text}}
					</view>
					<view class="d3"></view>
				</view> -->
				</view>
			</view>
		</view>

		<uni-popup ref="popup" type="top" :top="top" :maskClass="maskClass">
			
			<view class="showpay">
				<block v-if='act_index==1'>
					<view class="box-li" :class="store_id==0?'active':''" @click="Onlevel(0,'全部')" 
					data-text='全部'>全部
					</view>
					<scroll-view scroll-y="true" style="height: 400rpx;">
						<view class="box-li" v-for="(item,index) of tableTypeList" :key='index'
							:class="item.id==store_id?'active':''" @click="Onlevel(item.id,item.title)">
							{{item.title}}
						</view>
					</scroll-view>
				</block>
				<block v-if='act_index==2'>
					<view class="box-li" :class="status==2?'active':''" @click="onStatus(2,'全部')" data-text='全部'>全部
					</view>
					<view class="box-li" :class="status==1?'active':''" @click="onStatus(1,'已签到')" data-text='已签到'>已签到
					</view>
					<view class="box-li" :class="status==0?'active':''" @click="onStatus(0,'未签到')" data-text='未签到'>未签到
					</view>
				</block>
			</view>
			
		</uni-popup>

		<view class="header-hg200"></view>

		<view class="list">

			<view @click="detail(item.id,item.admin_id)" class="item" v-for="(item,index) in list" :key="index">

				<view class="top flex flex-y-center box-pack-between">
					<view class="name">{{item.nickname}} </view>
					<view class="flex-y-center" style="padding-right: 10rpx;min-width: 114rpx;">
						{{item.sex=='男'?'♂':'♀'}} {{item.sex}}
					</view>
				</view>

				<view class="content flex flex-y-center box-pack-between" hover-class="nav-hover">
					<view class="cell flex flex-y-center">
						<view class="title">门店：</view>
						<view class="desc">{{item.title}}</view>
					</view>
				</view>

				<view class="content flex flex-y-center box-pack-between" hover-class="nav-hover">
					<view class="cell flex flex-y-center">
						<view class="title">真实姓名：</view>
						<view class="desc">{{item.name}}</view>
					</view>
				</view>

				<view class="content flex flex-y-center box-pack-between" hover-class="nav-hover">
					<view class="cell flex flex-y-center">
						<view class="title">手机号码：</view>
						<view class="desc">{{item.phone}}</view>
					</view>
					<!-- 				<view class="cell flex flex-y-center">
						<view class="title">密码：</view>
						<view class="desc">{{item.pass}}</view>
					</view> -->
				</view>

				<view class="content flex flex-y-center box-pack-between" hover-class="nav-hover">
					<view class="cell flex flex-y-center">
						<view class="title">密码：</view>
						<view class="desc">{{item.pass}}</view>
					</view>
				</view>

				<view class="content flex flex-y-center box-pack-between" hover-class="nav-hover">
					<view class="cell flex flex-y-center">
						<view class="title">创建时间：</view>
						<view class="desc">{{item.addtime}}</view>
					</view>
				</view>
			</view>
			<block v-if='list.length<=0'>
				<no-none></no-none>
			</block>
		</view>

		<view class="header-hg100"></view>

		<view class="footer-bar">
			<view class="content flex flex-center">
				<navigator :url="`./staffAdd?type=${type}`" class="btn">+新增员工</navigator>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 2,
				seTval: '',
				page: 1,
				list: [],
				admin_id: '',
				store_id: '',
				is_bottom: false,
				keywords: "",
				level_text: '门店',
				tableTypeList: [],
				act_index:1
			}
		},

		onLoad(e) {
			this.type = e.type;
			this.admin_id = uni.getStorageSync("admin_id");
			this.store_id = uni.getStorageSync("store_id");
			this.shop_store_index();
		},

		onShow() {
			this.list = [];
			this.getData(1)
		},

		onReachBottom() {
			if (!this.is_bottom) {
				this.getData(this.page + 1)
			}
		},

		methods: {
			shop_store_index() {
				let storeinfo = uni.getStorageSync("storeinfo");
				this.request({
					url: 'Smdcshop/shop_store_index',
					data: {
						admin_id: this.admin_id,
					}
				}).then(res => {
					if (res.code == 200) {
						if (res.data.length > 0) {
							this.tableTypeList = res.data;
						} else {

							this.tableTypeList = [{
								title: storeinfo.title,
								id: storeinfo.id,
							}];
			
						}
					}
				})
			},
			
			onTopBtnTap(e) {
				this.act_index = e;
				this.$refs.popup.open();
			},
			
			getSearch(e) {
				if (!e.detail.value) {
					this.list = [];
					this.keywords = "";
					this.getData(1);
				}
				this.keywords = e.detail.value;
			},

			onDel() {
				this.seTval = '';
				this.list = [];
				this.keywords = "";
				this.getData(1);
			},

			confirm(e) {
				this.list = [];
				this.keywords = e.detail.value;
				this.getData(1);
			},

			search(e) {
				this.list = [];
				this.getData(1);
			},

			detail(id, admin_id) {
				let type = this.type;
				uni.navigateTo({
					url: `./staffDetail?id=${id}&type=${type}`
				})
			},

			Onlevel(e, text) {
				this.store_id = e;
				this.level_text = text;
				this.list = [];
				this.getData(1);
				this.$refs.popup.close();
			},

			del(id) {
				uni.showModal({
					title: '提示',
					content: '是否要删除？',
					showCancel: true,
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.request({
								url: 'Smdcshop/horn_delect',
								data: {
									id: id,
								},
							}).then(res => {
								console.log(res, "res")
								if (res.code === 200 || res.code === "200") {
									uni.showToast({
										title: "删除成功",
										icon: "none",
									})
									setTimeout(() => {
										this.getData(1)
									}, 2000)
								}
							}).catch((res) => {
								uni.showToast({
									title: res.message,
									icon: "none",
								})
							});
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},

			getData(page) {
				if (page == 1) {
					this.list = []
					this.page = 1
					this.is_bottom = false
				}
				this.request({
					url: 'Smdcshop/staff_index',
					data: {
						admin_id: this.admin_id,
						page,
						serch: this.keywords,
						limit: 10,
						store_id: this.store_id,
					}
				}).then(res => {
					if (res.code == 200 && res.data.length) {
						this.list = this.list.concat(res.data)
						this.page = page
					} else {
						this.is_bottom = true
					}
				})
			}
		}
	}
</script>

<style>
	@import url("./static/css/common.css");

	page {
		background: #F9F9F9;
	}
	
	.fixed-top {
		position: fixed;
		top: 0rpx;
		width: 100%;
	}
	
	.search-user {
		z-index: 999;
		position: fixed;
		left: 0;
		width: 100%;
		height: 100rpx;
		background: #FFFFFF;
		margin-left: 15rpx;
		border-bottom: 1rpx solid #F1F1F1;
	}

	.search-user .search-content {
		width: 83%;
		height: 70rpx;
		background: #F1F1F1;
		border-radius: 100rpx;
		padding: 0 20rpx;

	}

	.search-user .search-content icon {
		margin-right: 10rpx;
	}

	.search-user .search-btn {
		margin-left: 20rpx;
		font-size: 28rpx;
	}

	.headerScreen {
		height: 100rpx;

		z-index: 999;
		background: #fff;
		border-bottom: 1rpx solid #F1F1F1;
	}
	.showpay {
		width: 100%;
		z-index: 10;
		background: #FFFFFF;
	}
	.box-li {
		background-color: #fff;
		text-align: center;
		border-bottom: 1rpx solid #f1f1f1;
		height: 80rpx;
		line-height: 80rpx;
		font-size: 26rpx;
	}

	page .active {
		color: #007AFF;
	}
	.d3 {
		width: 0;
		height: 0;
		border-width: 12rpx;
		border-style: solid;
		border-color: #000 transparent transparent transparent;
		margin-top: 14rpx;
		margin-left: 6rpx;
	}
	.header-hg200 {
		height: 210rpx;
	}

	/* 	.header-hg100 {
		height: 100rpx;
	} */

	.del {
		height: 44rpx;
		line-height: 44rpx;
		padding: 0 15rpx;
		font-size: 24rpx;
		background-color: #FF5722;
		margin-right: 25rpx;
		color: #fff;
		border-radius: 4rpx;
	}

	.list {
		padding: 30rpx 25rpx;
	}

	.list .item {
		border-radius: 8rpx;
		overflow: hidden;
		padding-left: 30rpx;
		background-color: #fff;
		margin-bottom: 30rpx;
	}

	.list .item .top {
		border-bottom: 1rpx solid #f5f5f5;
		padding: 10rpx 0;
	}

	.list .item .top .name {
		font-size: 30rpx;
		font-weight: bold;
	}

	.list .item .top .type-btn {
		zoom: 0.7;
		margin-right: 25rpx;
	}

	.list .item .content {
		padding: 20rpx 0 24rpx;
	}

	.list .item .content .cell {
		flex: none;
		box-sizing: border-box;
		padding-right: 20rpx;
		font-size: 26rpx;
		line-height: 37rpx;
		color: #666;
	}

	.list .item .content .cell .title {
		color: #99A0AD;
	}
</style>
