<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">
						 <u-cell-group>
						 	<u-cell-item v-for="(item, index) in list" :key="item.userId" @click="setNewAdmin(item)" :title="item.name+'/'+item.mobile"></u-cell-item>
						 </u-cell-group>
					 </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>
</template>

<script>
	import {searchEmployee} 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,
				adminId: null
			}
		},
		onShow() {
			this.getRow(1)
		},
		onLoad(opts) {
			this.adminId = opts.adminId
		},
		computed:{
			userInfo(){
				return this.$store.state.vuex_userInfo
			},
		},
		methods:{
			// 查询列表
			getRow (pageNo) {
			  let _this = this
			  if (pageNo) {
			    this.pageNo = pageNo
			  }
			  let params = {
			    pageNo:this.pageNo,
			    pageSize:this.pageSize,
				isManager: 0
			  }
			  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"
				}
			},
			// 设为负责人
			setNewAdmin(row){
				this.$store.state.vuex_nowStaffData = row
				uni.navigateTo({
					url: "/pages/storeManage/editAdminAuth?adminId="+this.adminId
				})
			},
		}
	}
</script>

<style lang="less">
	.page-body{
		height: 100vh;
		padding:0;
		.scroll-list{
			flex-grow: 1;
			.check-order-list{
				padding: 10upx 20upx;
				u-radio{
					> view{
						background: #ffffff;
						border-radius: 20upx;
						box-shadow: 1px 1px 3px #EEEEEE;
						margin: 10rpx 0;
						padding: 20rpx;
						>view:last-child{
							flex-grow: 1;
						}
					}
				}
			}
		}
	}
</style>