<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">
						<zxz-uni-data-select v-model="index1" filterable :localdata="options1" @inputChange="inputChange1" @change="selectChange1"></zxz-uni-data-select>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label">母托盘编码</view>
					<view class="filter_input_wraper">
						<input type="text" class="filter_input" v-model="obj.vehicle_code" disabled>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label">子托盘编码</view>
					<view class="filter_input_wraper">
						<input type="text" class="filter_input" v-model="obj.vehicle_code2" disabled>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label">载具数量</view>
					<view class="filter_input_wraper">
						<input type="number" class="filter_input" v-model="obj.vehicle_qty" disabled>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar_new">
			<button class="zd-col-7 submit-button_c" @tap="toClear">清空</button>
			<button class="zd-col-15 submit-button_new" :class="{'btn-disabled': index1 === ''}" :disabled="disabled" @tap="toSure">确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import {queryCleanPoint, pointclean}  from '@/utils/getData2.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				disabled: false,
				options1: [],
				index1: '',
				obj: {}
			};
		},
		created () {
			this._queryCleanPoint()
		},
		methods: {
			inputChange1 (e) {
				// console.log(e)
			},
			selectChange1(e) {
				if (e) {
					this.options1.map(el => {
						if (el.point_code === e) {
							this.obj = el
						}
					})
				} else {
					this.obj = {}
				}
			},
			/** 点位查询 下拉框显示 */
			async _queryCleanPoint () {
				let res = await queryCleanPoint('CB')
				this.options1 = [...res]
				this.options1.map(el => {
				this.$set(el, 'value', el.point_code)
				this.$set(el, 'text', el.point_name)
				})
			},
			toClear () {
				this.index1 = ''
				this.obj = {}
			},
			toSure () {
				this.disabled = true
				if (this.index1 === '') {
					this.disabled = false
					return
				}
				uni.showModal({
					title: '提示',
					content: '确认清空点位信息',
					confirmColor: '#ff6a00',
					success: (res) => {
						if (res.confirm) {
							this._pointclean()
						} else if (res.cancel) {
							this.disabled = false
						}
					}
				})
			},
			async _pointclean () {
				try {
					let res = await pointclean(this.index1)
					if (res.code === '1') {
						this.toClear()
					}
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

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