<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">
						<search-box
						v-model="val1"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">母卷号</span>
					</view>
					<view class="zd-col-19">
						<search-box
						v-model="val2"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">收卷辊码</span>
					</view>
					<view class="zd-col-19">
						<input v-model="val5" type="text" class="filter_input">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">是否烘烤</span>
					</view>
					<view class="relative zd-col-19">
						<switch :checked="isChecked" color="#6798ef"/>
						<text @tap="setWStatus" style="position: absolute;display: inline-block;width: 52px; height: 32px;left: 0;"></text>
					</view>
				</view>
			</view>
			<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_msg">{{obj.container_name}}</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">烘烤状态</span>
					</view>
					<view class="zd-col-19 filter_msg">{{obj.status}}</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">提示</span>
					</view>
					<view class="zd-col-19 filter_msg">{{obj.tip}}</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-5 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-8 button-primary" :class="{'button-info': !val1 || !val5 || !val2}" :disabled="disabled" @tap="_doModifyRawInfos">修改信息</button>
			<button class="zd-col-8 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_bakingQuality('1')">质检合格</button>
			<!-- <button class="zd-col-6 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_bakingQuality('0')">再次烘烤</button> -->
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {getHotTempPointInfo, bakingQuality, doModifyRawInfos} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				val2: '',
				isChecked: false,
				obj: {container_name: '-', status: '-', tip: '-'},
				disabled: false,
				val5: ''
			};
		},
		watch: {
			val1(value) {
				this.checkInputs(value, this.val2);
			},
			val2(value) {
				this.checkInputs(this.val1, value);
			}
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			async _getHotTempPointInfo () {
				let res = await getHotTempPointInfo(this.val1, this.val2)
				this.obj = res
			},
			checkInputs(val1, val2) {
				if (val1 && val2) {
					this._getHotTempPointInfo()
				}
			},
			setWStatus () {
				this.isChecked = !this.isChecked
			},
			clearUp () {
				this.val1 = ''
				this.val2 = ''
				this.isChecked = false
				this.val5 = ''
				this.obj = {container_name: '-', status: '-', tip: '-'}
				this.disabled = false
			},
			async _bakingQuality (type) {
				this.disabled = true
				if (!this.val1) {
					this.disabled = false
					return
				}
				try {
					let res = await bakingQuality(this.val1, type)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			async _doModifyRawInfos () {
				this.disabled = true
				if (!this.val1 || !this.val5 || !this.val2) {
					this.disabled = false
					return
				}
				try {
					let checked = this.isChecked ? '1' : '0'
					let res = await doModifyRawInfos(this.val1, this.val2, checked, this.val5)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus" scoped>
>>>.uni-date-x--border
	border-color: transparent;
</style>
