<style lang="scss">
	.container{
		height:100%;
		background:#f6f6f6;
		scroll-view{
			flex-grow: 1;
			height:1rpx;
			background:#fff;
			view{
				color:#777;
				padding:20rpx 30rpx;
				border-bottom:1rpx solid rgba(221, 221, 221, 0.5);
			}
		}
	}
</style>
<template>
	<view class="container flex">
		<d-search v-model="searchVal.supplier" @search="clean();search()"/>
		<scroll-view scroll-y @scrolltolower="search">
			<view v-for="(v,k) in list" :key="k" @click="select(v.supplier)">{{v.supplier}}</view>
			<u-empty v-if="list.length<=0" text=" " width="70%" icon="/static/noData.png"/>
		</scroll-view>
	</view>
</template>
<script>
import request from '@/common/request'
export default {
	data(){
		return{
			searchVal:{
				supplier:"",
				pageNo:1,
				pageSize:20
			},
			list:[],
			total:0,
			eventChannel:null,
		}
	},
	onLoad(options){
		this.eventChannel=this.getOpenerEventChannel()
		this.searchVal.supplier=options.data||""
		this.search()
	},
	methods:{
		clean(){
			this.searchVal.pageNo=1
			this.list=[]
			this.total=0
		},
		async search(){
			if(this.total==0 || this.list.length<this.total){
				var res=await request("/api/goods/supplierShow",{
					params: this.searchVal
				})
				if(res.statu){
					this.list=res.data.records
					this.total=res.data.total
					this.searchVal.pageNo++
				}else{
					uni.showModal({
						title:"提示",
						content:res.msg||"获取供应商列表失败!",
						showCancel:false,
					})
				}
			}
		},
		select(e){
			this.eventChannel.emit("update",e)
			uni.navigateBack()
		}
	}
}
</script>