<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">
					<view class="filter_label">分切暂存位</view>
					<view class="filter_input_wraper">
						<search-box v-model="val1" />
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">气胀轴规格</span>
					</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index1" :localdata="options1" @change="selectChange1"></uni-data-select>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submitbar">
			<button class="zd-col-5 btn-submit btn-default" @tap="clearUp">清空</button>
			<button class="zd-col-8 btn-submit btn-success" :class="{'btn-info': !val1 || !index1}" @tap="toSure1">清除</button>
			<button class="zd-col-8 btn-submit btn-success" :class="{'btn-info': !val1 || !index1}" @tap="toSure3">气胀轴绑定</button>
		</view>
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确定" title="提示" :content="content" @confirm="dialogConfirm"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {toCleanCutCacheInventory, slitterShaftBinding} from '@/utils/getData3.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				options1: [{text: '3寸4代', value: '3-4'}, {text: '3寸5代', value: '3-5'}, {text: '6寸5代', value: '6-5'}],
				index1: '',
				content: '',
				type: ''
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			selectChange1(e) {
				this.index1 = e
			},
			dialogConfirm () {
				if (this.type === 1) {
					this._toCleanCutCacheInventory()
				} else if (this.type === 3) {
					this._slitterShaftBinding()
				}
			},
			toSure1 () {
				if (!this.val1) {
					return
				}
				this.content = '确认是否清除点位数据？'
				this.type = 1
				this.$refs.alertDialog.open()
			},
			async _toCleanCutCacheInventory () {
				try {
					let res = await toCleanCutCacheInventory(this.val1)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					console.log(e)
				}
			},
			toSure3 () {
				if (!this.val1 || !this.index1) {
					return
				}
				this.content = '确认是否绑定气胀轴？'
				this.type = 3
				this.$refs.alertDialog.open()
			},
			async _slitterShaftBinding () {
				let obj = this.options1.find(item => item.value === this.index1)
				try {
					let res = await slitterShaftBinding(this.val1, obj)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					console.log(e)
				}
			},
			clearUp () {
				this.val1 = ''
				this.index1 = ''
				this.disabled = false
				this.disabled1 = false
				this.disabled2 = false
			}
		}
	}
</script>