<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-7">
						<span class="filter_label">点位</span>
					</view>
					<view class="zd-col-17">
						<search-box
						v-model="val1"
						/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">流转单号</span>
					</view>
					<view class="zd-col-17">
						<input v-model="val2" type="text" class="filter_input" @blur="handleConfirm" @confirm="handleConfirm">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">温度</span>
					</view>
					<view class="zd-col-17">
						<input v-model="val3" type="number" class="filter_input">
					</view>
					<view class="zd-col-2 filter_label">度</view>
				</view>
				<view class="zd-row">
					<view class="zd-col-7">
						<span class="filter_label">时间</span>
					</view>
					<view class="zd-col-17">
						<uni-datetime-picker
							type="datetime"
							:value="time"
							@change="dateChange"
						/>
					</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.roll_type}}</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.is_baking}}</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-4 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-6 button-primary" :class="{'button-info': !val1 || !val2 || !val3}" :disabled="disabled" @tap="_doModifyRawInfos">修改信息</button>
			<button class="zd-col-6 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_bakingQuality('1')">质检合格</button>
			<button class="zd-col-6 button-primary" :class="{'button-info': !val1 || !val2}" :disabled="disabled" @tap="_bakingQuality('2')">再次烘烤</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: '',
				val3: '',
				time: '',
				obj: {roll_type: '-', is_baking: '-', msg: '-'},
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			clearUp () {
				this.val1 = ''
				this.val2 = ''
				this.val3 = ''
				this.time = ''
				this.obj = {roll_type: '-', is_baking: '-', msg: '-'}
				this.disabled = false
			},
			handleConfirm () {
				if (this.val2) {
					this._getHotTempPointInfo()
				}
			},
			async _getHotTempPointInfo () {
				let res = await getHotTempPointInfo(this.val1, this.val2)
				this.obj = res
			},
			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
				}
			},
			dateChange (e) {
				this.time = e
			},
			async _doModifyRawInfos () {
				this.disabled = true
				if (!this.val1 || !this.val2 || !this.val3) {
					this.disabled = false
					return
				}
				try {
					let res = await doModifyRawInfos(this.val1, this.val2, this.val3, this.time)
					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>
