<template>
	<view class="zd_container">
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">载具编码</span>
					</view>
					<view class="zd-col-19 filter_select">
						<search-box
						v-model="val1"
						/>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-22 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="toPop">物料报废</button>
		</view>
		<view class="zd_content msg_wrapper" :class="show ? 'popshow' : 'pophide'">
			<view class="pop-line"></view>
			<view class="msg_content">
				<view class="zd-row">
					<view class="zd-col-24">
						<span class="filter_label">确定是否执行物料报废？</span>
					</view>
				</view>
			</view>
			<view class="zd-row submit-bar">
				<button class="zd-col-11 button-default" @tap.stop="show = false">关闭</button>
				<button class="zd-col-11 button-primary" :disabled="disabled" @tap="_materialScrap">确定</button>
			</view>
		</view>
		<view v-if="show" class="msg_mask"></view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {materialScrap} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				show: false,
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			toPop () {
				if (this.val1) {
					this.show = true
				}
			},
			async _materialScrap () {
				this.disabled = true
				try {
					let res = await materialScrap(this.val1)
					this.show = false
					this.disabled = false
					this.val1 = ''
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>
