<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">
						<search-box v-model="val1" @handleChange="handleChange1"/>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">空轴/母卷</span>
					</view>
					<view class="filter_input_wraper">
						<search-box 
						v-model="val2"
						/>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label">是否有货</view>
					<view class="filter_input_wraper">
						<input type="text" class="filter_input" v-model="val3" :class="{'filter_input_disabled': disabled0}" :disabled="disabled0">
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submitbar">
			<button class="zd-col-11 btn-submit btn-success letter-30" :class="{'btn-info': !val1 || !val2}" :disabled="disabled" @tap="_pointOperate('1')">绑定</button>
			<button class="zd-col-11 btn-submit btn-success letter-30" :class="{'btn-info': !val1 || !val2}" :disabled="disabled" @tap="_pointOperate('2')">解绑</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {pointOperate, pointStatusQuery} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				val1: '',
				val2: '',
				val3: '',
				disabled0: true,
				disabled: false
			};
		},
		methods: {
			handleChange1 (e) {
				this._pointStatusQuery(e)
			},
			/** 查询 */
			async _pointStatusQuery (val1) {
				if (!val1) {
					return
				}
				let res = await pointStatusQuery(val1)
				this.val2 = res.data.container_name
				this.val3 = res.data.have_goods
			},
			async _pointOperate (type) {
				this.disabled = true
				if (!this.val1 || !this.val2) {
					this.disabled = false
					return
				}
				try {
					let res = await pointOperate(this.val1, this.val2, type)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.val1 = ''
					this.val2 = ''
					this.val3 = ''
					this.disabled = false
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

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