<template>
	<view class="zd_container">
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="zd-row">
					<view class="zd-col-7">
						<span class="filter_label">设备</span>
					</view>
					<view class="zd-col-17 filter_select">
						<zxz-uni-data-select v-model="index" :localdata="options" @change="selectChange"></zxz-uni-data-select>
					</view>
				</view>
			</view>
			<view class="zd_wrapper">
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">上轴子卷号</span>
					</view>
					<view class="zd-col-17 filter_msg">{{obj.up}}</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">下轴子卷号</span>
					</view>
					<view class="zd-col-17 filter_msg">{{obj.down}}</view>
				</view>
				<view class="zd-row">
					<view class="zd-col-7">
						<span class="filter_label">提示</span>
					</view>
					<view class="zd-col-17 filter_msg">{{obj.msg}}</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-8 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-15 button-primary" :class="{'button-info': !index}" :disabled="disabled" @tap="_slitterDown">确认下卷</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {getSlitterDeviceBox, querySlitterDeviceSubVolumeInfos, slitterDown} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				options: [],
				index: '',
				obj: {up: '-', down: '-', msg: '-'},
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
			this._getSlitterDeviceBox()
		},
		methods: {
			async _getSlitterDeviceBox () {
				let res = await getSlitterDeviceBox()
				this.options = [...res]
			},
			selectChange (e) {
				this._querySlitterDeviceSubVolumeInfos(e)
			},
			async _querySlitterDeviceSubVolumeInfos (e) {
				try {
					let res = await querySlitterDeviceSubVolumeInfos(e)
					this.obj = res.data
				} catch (e) {
					console.log(e)
				}
			},
			clearUp () {
				this.index = ''
				this.obj = {up: '-', down: '-', msg: '-'}
				this.disabled = false
			},
			async _slitterDown () {
				this.disabled = true
				if (!this.index) {
					this.disabled = false
					return
				}
				try {
					let res = await slitterDown(this.index)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus" scoped>
.zd_content
	height: calc(100% - var(--status-bar-height) - 212rpx);
	padding: 20rpx 14rpx 0 14rpx;
.grid-wraper
	height: 100%;
	overflow: auto;
.slide_new table td, .slide_new table th
	overflow: visible;
</style>
