<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-9">
						<span class="filter_label">成品称重暂存区</span>
					</view>
					<view class="zd-col-15 filter_select">
						<uni-data-select v-model="index" :localdata="options" @change="selectChange"></uni-data-select>
					</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="_doSubVolumeDown">子卷下线</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {getWeightCacheInfos, doSubVolumeDown} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				index: '',
				options: [],
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
			this._getWeightCacheInfos()
		},
		methods: {
			async _getWeightCacheInfos () {
				let res = await getWeightCacheInfos()
				this.options = [...res]
			},
			async _doSubVolumeDown () {
				this.disabled = true
				if (!this.index) {
					this.disabled = false
					return
				}
				try {
					let res = await doSubVolumeDown(this.index)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			clearUp () {
				this.index = ''
				this.disabled = false
			}
		}
	}
</script>

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