<template>
	<view class="zd_container">
		<nav-bar title="出库"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">物料</span>
					</view>
					<view class="filter_input_wraper">
						<input type="text" class="filter_input filter_input_disabled pointer" v-model="val1" @tap="getMater">
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">物料余量</span>
					</view>
					<view class="filter_input_wraper">
						<input type="number" class="filter_input" v-model="val2">
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">物料点位</span>
					</view>
					<view class="filter_input_wraper">
						<input type="number" class="filter_input" v-model="val3">
					</view>
				</view>
			</view>
			<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">&#xe61f;</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-6 submit-button_new" :class="{'btn-disabled': !pkId || !$store.getters.publicObj}" :disabled="disabled1" @tap="_fullVehicleOut">满托出库</button>
			<button class="zd-col-6 submit-button_new" :class="{'btn-disabled': !pkId || !$store.getters.publicObj}" :disabled="disabled2" @tap="_vehicleGoBack">余料回库</button>
			<button class="zd-col-10 submit-button_new" :class="{'btn-disabled': !pkId || !$store.getters.publicObj}" :disabled="disabled3" @tap="_fullVehicleOutConfirm">满托出库确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryPoints, fullVehicleOut, vehicleGoBack, fullVehicleOutConfirm} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				val1: '',
				val2: '',
				val3: '',
				dataList: [],
				disabled1: false,
				disabled2: false,
				disabled3: false,
				pkId: ''
			};
		},
		created () {
			this._queryPoints()
		},
		destroyed () {
			this.$store.dispatch('setPublicObj', '')
		},
		onShow() {
			if (this.$store.getters.publicObj) {
				this.val1 = this.$store.getters.publicObj.material_name
				this.val2 = this.$store.getters.publicObj.material_qty
				this.val3 = this.$store.getters.publicObj.point_code
				this.val4 = this.$store.getters.publicObj.vehicle_code
			}
		},
		methods: {
			/** 初始化查询 */
			async _queryPoints () {
				let res = await queryPoints('2')
				this.dataList = [...res]	
			},
			getMater () {
				uni.navigateTo({
					url: '/pages/manage/search-mater'
				})
			},
			checkcode (e) {
				this.pkId = this.pkId === e.point_code ? '' : e.point_code
			},
			/** 满托出库 */
			async _fullVehicleOut () {
				this.disabled1 = true
				if (!this.pkId) {
					this.disabled1 = false
					return
				}
				try {
					let res = await fullVehicleOut(this.val3, this.pkId)
					this.disabled1 = false
					this.pkId = ''
					this.val1 = ''
					this.val2 = ''
					this.val3 = ''
					this.val4 = ''
					this.$store.dispatch('setPublicObj', '')
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled1 = false
				}
			},
			/** 余料回库 */
			async _vehicleGoBack () {
				this.disabled2 = true
				if (!this.pkId) {
					this.disabled2 = false
					return
				}
				try {
					let res = await vehicleGoBack(this.pkId, this.val4, this.val2)
					this.disabled2 = false
					this.pkId = ''
					this.val1 = ''
					this.val2 = ''
					this.val3 = ''
					this.val4 = ''
					this.$store.dispatch('setPublicObj', '')
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled2 = false
				}
			},
			/** 满托出库确认 */
			async _fullVehicleOutConfirm () {
				this.disabled3 = true
				if (!this.pkId) {
					this.disabled3 = false
					return
				}
				try {
					let res = await fullVehicleOutConfirm(this.pkId, this.val4, this.val2)
					this.disabled3 = false
					this.pkId = ''
					this.val1 = ''
					this.val2 = ''
					this.val3 = ''
					this.val4 = ''
					this.$store.dispatch('setPublicObj', '')
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled3 = false
				}
			}
		}
	}
</script>

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