<template>
	<scroll-view 
	scroll-y="true" 
	:style="{height: height}"
	@scrolltolower="loadMoreData">
		<view class="bossList">
			<view
				@click="$utils.navigateTo('/pages_order/work/userDetail?id=' + item.id)"
				:key="index"
				v-for="(item, index) in list">
				<userItem :item="keyName ? item[keyName] : item"
				:headImage="item.headImage"
				:sex="item.sex"
				/>
			</view>
			
			<uv-empty mode="list" v-if="list.length == 0"></uv-empty>
		</view>
	</scroll-view>
</template>

<script>
	import userItem from './userItem.vue'
	export default {
		components : {
			userItem,
		},
		props : {
			height : {
				default : 'auto'
			},
			api : {
				default : 'bossQueryJobList'
			},
			handleData : {},
			keyName : {
				default : ''
			}
		},
		data() {
			return {
				queryParams: {
					pageNo: 1,
					pageSize: 10,
				},
				total : 0,
				list : [],
			}
		},
		methods: {
			getData(params, query){
				if(uni.getStorageSync('token')){
					this.queryParams.token = uni.getStorageSync('token')
				}
				
				let queryParams = {
					pageNo: this.queryParams.pageNo,
					pageSize: this.queryParams.pageSize,
				}
				
				if(params && params.length > 0){
					params.forEach(n => {
						queryParams[n.name] = n.value
					})
				}
				
				if(query){
					for(let key in query){
						queryParams[key] = query[key]
					}
				}
				
				this.$api(this.api, queryParams, res => {
					uni.stopPullDownRefresh()
					if(res.code == 200){
						this.list = res.result.records || res.result
						this.total = res.result.total || res.result.length
						this.handleData && this.handleData(this)
					}
				})
			},
			loadMoreData(){
				if(this.queryParams.pageSize <= this.list.length){
					this.queryParams.pageSize += 10
					this.getData()
				}
			},
		}
	}
</script>

<style scoped lang="scss">
.bossList {
	&>view{
		margin: 20rpx;
	}
}
</style>