<template>
	<view class="content_white">
		<view class="content_padding" style="margin-bottom: 20rpx;">
			<uni-search-bar v-model="inputvalue" @input="search" :focus="true"></uni-search-bar>
		</view>
		<scroll-view :scroll-top="0" :style="{height: windowHeight + 'px'}" scroll-y="true" lower-threshold="200" class="scrollY" @scrolltolower="scroll"
		>
			<view @click="topoInfo(item)" v-for="(item, index) in list" :key="index" style="padding: 40rpx;20rpx;background: white;margin-bottom: 20rpx;" class="subtitle_text_black">
				<view class="list_view">
					<span>{{item.vendorId}}</span>
					<span>{{item.statusName}}</span>
					<span>{{item.typeName}}</span>
				</view>
				<view class="list_view">
					<span>{{item.inWarehouseName}}</span>
					<span>{{item.poDate}}</span>
				</view>
				<view class="list_view">
					<span>{{item.vendorName}}</span>
					<button style="width: 160rpx;height: 60rpx;margin: 0;" class="subtitle_text_white" type="primary" @click.stop="topoTracking(item.id)">订单跟踪</button>
				</view>
			</view>
			<uni-load-more class="loading" :status="load" v-show="loadFlag"></uni-load-more>
		</scroll-view>
	</view>
</template>
<script>
	import _ from 'lodash'
	export default {
		data(){
			return {
				inputvalue: '',
				search: null,
				scroll:null,
				listnum:1,
				list:[],
				load:'loading',
				loadFlag: false,
				params: {}
			}
		},
		onLoad() {
			this.search =  _.debounce(this.searchOrder, 300)
			this.scroll =  _.throttle(this.lower, 300)
			this.restList()
			this.getList()
		},
		onShow() {
			uni.$on('screenParams', res => {
				this.params = res
				uni.$off('screenParams');
				this.getList()
			})
		},
		onNavigationBarButtonTap(){
			uni.navigateTo({
				url: './screen'
			})
		},
		computed:{
			windowHeight () {
				return this.$store.state.windowHeight
			}
		},
		created(){
			
		},
		methods:{
			topoTracking(id){
				uni.navigateTo({
					url:`./tailInfo?id=${id}`
				})
			},
			searchOrder(){
				this.restList()
				this.getList()
			},
			restList(){
				this.listnum = 1
				this.list = []
				this.load = 'loading'
			},
			getList(){
				this.loadFlag = true
				let params = {
					"query": this.inputvalue,
					"page": this.listnum,
					"row": 10,
					...this.params
				}
				console.log(params)
				this.$minApi.uniapp("/eidpws/wmsApp/appApi/po/findPurchaseOrders", params)
				.then((response) => {
					if (response.status) { 
						this.list.push(...response.data)
						if (response.data.length === 0) {
							this.listnum -= 1
							this.load = 'noMore'
						}
						console.log(this.list)
					}
				})
				.catch((error) => {
				})
				.finally(() => {
					if(this.load !== 'noMore') {
						this.loadFlag = false
					}
				})
			},
			lower(){
				if(this.load !== 'noMore'){
					this.listnum += 1
					this.getList()
				}
			},
			topoInfo(item){
				uni.navigateTo({
					url:`./poInfo?info=${JSON.stringify(item)}`
				})
			}
		}
	}
</script>
<style scoped lang="scss">
	@import '../../style_public/common.scss';
	.title_time{
		text-align: center;
		margin: 20rpx 0;
	}
	.spance_bottom{
		padding-bottom: 10rpx;
	}
	.list_view{
		display: flex;
		justify-content: space-between;
		padding-bottom: 20rpx;
	}
</style>