<template>
	<view class="page-body scroll-list">
		<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.userId" 
			>
				<view class="flex align_center justify_between" @click="editPerson(item)">
					<view class="u-name">
						<text style="margin-right: 0.5rem;">{{item.userName}}</text>
					</view>
					<view class="u-mobile">
						<text v-if="item.isManager == 1">门店负责人/ </text>
						<text v-if="item.isManager == 0 && item.roleName">{{item.roleName}} / </text>
						{{item.phone}}
					</view>
				</view>
				<view class="set-item flex align_center justify_between">
					商城是否显示：
					<u-radio-group @change="e=>changeShow(e,item)" v-model="item.show" :width="150">
						<u-radio :name="1">是</u-radio>
						<u-radio :name="0">否</u-radio>
					</u-radio-group>
				</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>
	</view>
</template>

<script>
	import {getShopUserParamList, updateShopUserParam } from '@/api/bizParam.js'
	import moment from 'moment'
	export default{
		name:'personnel',
		data(){
			return{
				status: 'loading',
				noDataText: '暂无数据',
				// 查询条件
				pageNo: 1,
				pageSize: 1000,
				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
			  const shelf = this.$store.state.vuex_storeShelf
			  let params = {
				shelfSn: shelf.shelfSn
			  }
			  this.status = "loading"
			  getShopUserParamList(params).then(res => {
				if (res.code == 200 || res.status == 204 || res.status == 200) {
				  const list = res.data || []
				  list.forEach(item=>{
					  item.show = item.paramMap && item.paramMap.mall_flag && item.paramMap.mall_flag.paramValue
				  })
				  if(_this.pageNo>1){
					  _this.list = _this.list.concat(list)
				  }else{
					  _this.list = list
				  }
				  _this.total = list.length || 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"
				}
			},
			changeShow(e,item){
				console.log(e,item)
				uni.showLoading({
					title: '加载中'
				})
				const userId = item.userId
				const shelf = this.$store.state.vuex_storeShelf
				updateShopUserParam({'userId':userId,'paramValue':e,shelfSn: shelf.shelfSn}).then(res=>{
					uni.hideLoading()
					if(res.status == 200){
						item.show = e
						uni.$emit("refashHome")
					}else{
						item.show = !e ? 1 : 0
					}
					this.list.splice()
					uni.showToast(res.message)
				})
			}
		}
	}
</script>

<style lang="less">
	.page-body{
		height: 100vh;
		padding:0;
	}
	.scroll-list{
		.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.5rem;
				.u-name{
					font-size: 32rpx;
				}
				.u-mobile{
					color: #666;
				}
			}
		}
		.set-item {
			/deep/ .u-radio__label{
				flex: 1;
			}
		}
	}
</style>