<template>
	<view class="page-body flex flex_column">
		<swiper class="scroll-list" :current="swiperCurrent">
			<swiper-item class="swiper-item" style="height: 100%;width: 100%;overflow: hidden;">
				<scroll-view scroll-y style="height: 100%;width: 100%;overflow: auto;" @scrolltolower="onreachBottom">
					<view style="height: 20rpx;" ></view>
					<view  
					class="check-order-list" 
					v-for="(item,index) in list" 
					:key="item.id" 
					>
						<view class="flex align_center justify_between" @click="editPerson(item)">
							<view class="flex_1">
								<view class="u-name">
									<text style="margin-right: 0.5rem;">{{item.name}}</text>
									<u-icon :name="item.sex==1?'man':'woman'" size="28" :color="item.sex==1?'#00aaff':'#ffaaaa'"></u-icon>
								</view>
								<view class="u-mobile">
									<text v-if="item.isManager == 1">门店负责人 / </text>
									<text v-if="item.isManager == 0 && item.roleNames">{{item.roleNames}} / </text>
									{{item.mobile}}
								</view>
							</view>
							<view>
								<u-icon size="34" name="edit-pen"></u-icon>
							</view>
						</view>
					 </view>
					 <view style="padding:0 30upx 30upx;">
						 <u-empty :src="`/static/nodata.png`" icon-size="180" :text="noDataText" img-width="120" v-if="list.length==0 && status!='loading'" mode="list"></u-empty>
						 <u-loadmore v-if="(total>=list.length&&list.length)||status=='loading'" :status="status" />
					 </view>
				</scroll-view>
			</swiper-item>
		</swiper>
		<view class="footer flex align_center justify_center">
			<u-button @click="editIsManage()" v-if="userInfo&&userInfo.superAdmin==1&&!hasOnlyAdmin" :throttle-time="100" shape="circle" type="error" plain>
				更换负责人
			</u-button>
			<u-button @click="editPerson(null)" :throttle-time="100" :custom-style="{ background: '#066cff', color: '#fff' }" shape="circle" type="info">
				新增员工
			</u-button>
		</view>
	</view>
</template>

<script>
	import {searchEmployee, delEmployee } from '@/api/employee'
	import moment from 'moment'
	export default{
		name:'personnel',
		data(){
			return{
				status: 'loading',
				noDataText: '暂无数据',
				current: 0,
				swiperCurrent: 0,
				// 查询条件
				pageNo: 1,
				pageSize: 20,
				list: [],
				total: 0,
			}
		},
		onShow() {
			this.getRow(1)
		},
		computed:{
			userInfo(){
				return this.$store.state.vuex_userInfo
			},
			hasOnlyAdmin(){
				return this.list.length ==1 && this.list[0].isManager == 1 || this.list.length == 0
			}
		},
		methods:{
			// 查询列表
			getRow (pageNo) {
			  let _this = this
			  if (pageNo) {
			    this.pageNo = pageNo
			  }
			  let params = {
			    pageNo:this.pageNo,
			    pageSize:this.pageSize
			  }
			  this.status = "loading"
			  searchEmployee(params).then(res => {
				if (res.code == 200 || res.status == 204 || res.status == 200) {
				  if(_this.pageNo>1){
					  _this.list = _this.list.concat(res.data.list || [])
				  }else{
					  _this.list = res.data.list || []
				  }
				  _this.total = res.data.count || 0
				} else {
				  _this.list = []
				  _this.total = 0
				  _this.noDataText = res.message
				}
				 
				_this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
			  })
			},
			// scroll-view到底部加载更多
			onreachBottom() {
				if(this.list.length < this.total){
					this.pageNo += 1
					this.getRow()
				}else{
					this.status = "nomore"
				}
			},
			// 编辑员工
			editPerson(row){
				this.$store.state.vuex_nowStaffData = row;
				uni.navigateTo({
					url: "/pages/storeManage/addPerson"
				})
			},
			// 更换负责人
			editIsManage(){
				uni.navigateTo({
					url: "/pages/storeManage/editIsManage"
				})
			}
		}
	}
</script>

<style lang="less">
	.page-body{
		height: 100vh;
		padding:0;
		.scroll-list{
			flex-grow: 1;
			.check-order-list{
				background: #ffffff;
				padding: 10upx 20upx;
				margin: 0 25rpx 25rpx 25rpx;
				border-radius: 20upx;
				box-shadow: 1px 1px 3px #EEEEEE;
				> view{
					padding: 0.8rem 0.5rem;
					.u-name{
						font-size: 32rpx;
						margin-bottom: 0.5rem;
					}
					.u-mobile{
						color: #666;
					}
				}
			}
		}
		.footer{
			padding: 0.6rem;
			background: #ffffff;
			u-button{
				width: 45%;
				margin: 0 2%;
			}
		}
	}
</style>