<template>
	<view class="zd_container">
		<!-- <nav-bar title="点位管理"></nav-bar> -->
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="filter_item is-required">
					<view class="filter_label_wraper">
						<span class="filter_label">{{$t('grid.point-code')}}</span>
					</view>
					<view class="filter_input_wraper">
						<search-box v-model="val1" @handleChange="handleChange1"/>
					</view>
				</view>
				<view class="filter_item is-required">
					<view class="filter_label_wraper">
						<span class="filter_label">{{$t('filter.empty-shaft')}}/{{$t('filter.mother-roll')}}</span>
					</view>
					<view class="filter_input_wraper">
						<search-box 
						v-model="val2"
						/>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label">{{$t('grid.is-stock')}}</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="handleConfirm('1')">绑定</button>
			<button class="zd-col-11 btn-submit btn-success letter-30" :class="{'btn-info': !val1 || !val2}" :disabled="disabled" @tap="handleConfirm('2')">解绑</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import { confirmAction } from '@/utils/utils.js'
	import {pointOperate, pointStatusQuery} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				val2: '',
				val3: '',
				disabled0: true,
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		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 handleConfirm(type) {
				if (!this.val1 || !this.val2) {
					return
				}
				const isConfirmed = await confirmAction("确认操作", "确定要执行此操作吗？")
				if (isConfirmed) {
					this._pointOperate(type)
				}
			},
			async _pointOperate (type) {
				this.disabled = true
				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>
