<template>
	<view class="zd_container">
		<nav-bar title="入库"></nav-bar>
		<view class="zd_content">
			<view class="flow_wrapper" v-for="e in dataList" :key="e.point_code">
				<view class="zd-row">
					<view class="zd-col-24">
						<view class="zd-row">
							<view class="zd-col-2">
								<view class="zd-row flow_icon_item_1">
									<view class="iconfont icon_start_point">&#xe820;</view>
								</view>
							</view>
							<view class="zd-col-22">
								<view class="zd-row flow_start_item" @tap="checkcode(e)" :class="{'flow_start_item_checked': pkId === e.point_code}">
									<view class="zd-col-12 pdl20 pdr20 font-size-1">{{e.point_code}}</view>
									<view class="zd-col-12 pdr20 font-size-2">{{e.point_name}}</view>
									<view v-show="pkId === e.point_code" class="iconfont icon_choosed">&#xe66b;</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="submit-bar_new">
			<button class="zd-col-11 submit-button_new" :class="{'btn-disabled': !pkId}" :disabled="disabled1" @tap="_callEmptyVehicle">呼叫空托</button>
			<button class="zd-col-11 submit-button_new" :class="{'btn-disabled': !pkId}" :disabled="disabled2" @tap="_fullVehicleIn">满托入库</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryPoints, callEmptyVehicle, fullVehicleIn} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				dataList: [],
				disabled1: false,
				disabled2: false,
				pkId: ''
			};
		},
		created () {
			this._queryPoints()
		},
		methods: {
			/** 初始化查询 */
			async _queryPoints () {
				let res = await queryPoints('1')
				this.dataList = [...res]	
			},
			checkcode (e) {
				this.pkId = this.pkId === e.point_code ? '' : e.point_code
			},
			/** 呼叫空托 */
			async _callEmptyVehicle () {
				this.disabled1 = true
				if (!this.pkId) {
					this.disabled1 = false
					return
				}
				try {
					let res = await callEmptyVehicle(this.pkId)
					this.disabled1 = false
					this.pkId = ''
					this._queryPoints()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled1 = false
				}
			},
			/** 满托入库 */
			async _fullVehicleIn () {
				this.disabled2 = true
				if (!this.pkId) {
					this.disabled2 = false
					return
				}
				try {
					let res = await fullVehicleIn(this.pkId)
					this.disabled2 = false
					this.pkId = ''
					this._queryPoints()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled2 = false
				}
			}
		}
	}
</script>

<style lang="stylus">
</style>
