<template>
	<view>
		<u-cell-group>
		    <u-cell
		        center
				isLink
				v-for="item in list"
				:key="item.id"
				@click="toEdit(item)"
		    >
			<view slot="label">
				<view class="u-kh">
					<view>
						{{item.purchaseBillNo}}
					</view>
				</view>
				<view class="u-time">
					发货单号: {{item.sendBillNo}}
				</view>
				<view class="u-time">创建时间：{{item.createDate}}</view>
				<view class="u-time" v-if="item.stockPutTime">入库时间：{{item.stockPutTime}}</view>
			</view>
			<view slot="value">
				<text class="u-text" :style="{color: (item.auditState == 'PUT_WAREHOUSE_AUDIT_REJECT'|| item.auditState == 'WAIT_PUT_WAREHOUSE') ? '#00aaff' : '#999'}">{{item.auditStateDictValue}}</text>
			</view>
			</u-cell>
			<view v-if="list.length==0&&status != 'loading'">
				<u-empty :iconSize="60" text="暂无数据" :marginTop="100"></u-empty>
			</view>
			<view style="padding: 30rpx 0;">
				<u-loadmore :status="status" />
			</view>
		</u-cell-group>
		<chooseWarehouse :openPick="openPick" @close="openPick=false" @change="changeWarehouse"></chooseWarehouse>
	</view>
</template>

<script>
	import { receivingStockList } from '@/config/api.js'
	import chooseWarehouse from './chooseWarehouse.vue'
	export default{
		components: { chooseWarehouse },
		data(){
			return {
				list: [],
				pageSize: 10,
				pageNo: 1,
				total: 0,
				status: 'loadmore',
				warehouseList: [],
				openPick: false,
				editRow: null
			}
		},
		onLoad() {
			var _this = this
			this.status = 'loading'
			this.getList()
		},
		onShow() {
			if(this.$store.state.vuex_isRefash){
				this.pageNo = 1
				this.getList()
				this.$store.state.vuex_isRefash = false
			}
		},
		methods:{
			getList(){
				receivingStockList({pageSize:this.pageSize,pageNo:this.pageNo}).then(res => {
					if(res.status == 200){
						const list = res.data.list
						this.total = res.data.count
						if(this.pageNo == 1){
							this.list = list
						}else{
							this.list = this.list.concat(list)
						}
						if(this.list.length < this.total){
							this.status = 'loadmore'
						}else{
							this.status = 'nomore'
						}
					}
				})
			},
			toEdit(item){
				// 入库
				if(item.auditState == 'PUT_WAREHOUSE_AUDIT_REJECT' || item.auditState == 'WAIT_PUT_WAREHOUSE'){
					this.editRow = item
					this.openPick = true
				}
			},
			changeWarehouse(e){
				console.log(e)
				this.$store.state.vuex_tempData = e
				this.openPick = false
				uni.navigateTo({
					url:"/pages/purchasing/index?receivingBillSn="+this.editRow.receivingBillSn+"&id="+this.editRow.id
				})
			},
			onReachBottom(){
				const pageNums = Math.ceil(this.total / this.pageSize)
				if(this.pageNo < pageNums){
					this.pageNo = this.pageNo + 1
					this.status = 'loading'
					this.getList()
				}else{
					this.status = 'nomore'
				}
			}
		}
	}
</script>

<style lang="scss">
	.u-time{
		color: $uni-text-color-grey;
		font-size: 30upx;
	}
	.u-kh{
		font-size: 34upx;
		display: flex;
	}
	.u-text{
		font-size: 30upx;
	}
</style>