<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">{{$t('filter.cutstagingpoint')}}</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">{{$t('grid.sub-roll-number')}}</span>
					</view>
					<view class="filter_input_wraper">
						<search-box
						v-model="val2"
						/>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submitbar">
			<button class="zd-col-4 btn-submit btn-default" @tap="clearUp">{{$t('button.clear')}}</button>
			<button class="zd-col-4 btn-submit btn-success" :class="{'btn-info': !val1}" @tap="toSure1">{{$t('button.cleanup')}}</button>
			<button class="zd-col-7 btn-submit btn-success" :class="{'btn-info': !val1 || !val2}" @tap="toSure2">{{$t('button.zjbind')}}</button>
			<button class="zd-col-8 btn-submit btn-success" :class="{'btn-info': !val1 || !val2}" @tap="toSure3">{{$t('button.qzzbind')}}</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, toSubvolumeBinding, toShaftBinding} from '@/utils/getData3.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				val2: '',
				content: '',
				type: ''
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			dialogConfirm () {
				if (this.type === 1) {
					this._toCleanCutCacheInventory()
				} else if (this.type === 2) {
					this._toSubvolumeBinding()
				} else if (this.type === 3) {
					this._toShaftBinding()
				}
			},
			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)
				}
			},
			toSure2 () {
				if (!this.val1 || !this.val2) {
					return
				}
				this.content = '确认是否绑定子卷？'
				this.type = 2
				this.$refs.alertDialog.open()
			},
			async _toSubvolumeBinding () {
				try {
					let res = await toSubvolumeBinding(this.val1, this.val2)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					console.log(e)
				}
			},
			toSure3 () {
				if (!this.val1 || !this.val2) {
					return
				}
				this.content = '确认是否绑定气胀轴？'
				this.type = 3
				this.$refs.alertDialog.open()
			},
			async _toShaftBinding () {
				try {
					let res = await toShaftBinding(this.val1, this.val2)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					console.log(e)
				}
			},
			clearUp () {
				this.val1 = ''
				this.val2 = ''
				this.disabled = false
				this.disabled1 = false
				this.disabled2 = false
			}
		}
	}
</script>