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

<script>
	import workItem from './workItem.vue'
	export default {
		components : {
			workItem,
		},
		props : {
			height : {
				default : 'auto'
			},
			api : {
				default : 'employeeQueryJobList'
			},
			keyName : {}
		},
		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
						this.total = res.result.total
					}
				})
			},
			loadMoreData(){
				if(this.queryParams.pageSize <= this.list.length){
					this.queryParams.pageSize += 10
					this.getData()
				}
			},
		}
	}
</script>

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