<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-3">
						<span class="filter_label">点位</span>
					</view>
					<view class="zd-col-12">
						<search-box
						v-model="val1"
						/>
					</view>
					<button class="zd-col-4 button-primary button-primary_s" @tap="_queryOrderInfo">查询</button>
					<button class="zd-col-4 button-default button-primary_s" @tap="clearUp">清空</button>
				</view>
			</view>
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>序号</th>
								<th class="td_3">母卷号</th>
								<th>机台编号</th>
								<th>是否烘烤</th>
								<th>烘烤时间/小时</th>
								<th>质检时间</th>
								<th>大小卷</th>
								<th>烘烤温度</th>
								<th>所在位置</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" @click="toCheck(e)" :class="{'checked': e.workorder_id === pkId}">
								<td>{{ i + 1 }}</td>
								<td class="td_3">{{e.container_name}}</td>
								<td>{{e.resource_name}}</td>
								<td>{{['否', '是'][Number(e.is_baking)]}}</td>
								<td>{{e.baking_time}}</td>
								<td>{{e.update_time}}</td>
								<td>{{['大卷', '小卷'][Number(e.is_baking) - 1]}}</td>
								<td>{{e.baking_temperature}}</td>
								<td>{{e.zc_point}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-5 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_slitvehicleReturn">空轴送回</button>
			<button class="zd-col-5 button-primary" :class="{'button-info': !val1 || !pkId}" :disabled="disabled" @tap="_slitcallSlitterRoll">呼叫母卷</button>
			<button class="zd-col-5 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_slitsendSlitterRoll">母卷送回</button>
			<button class="zd-col-4 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_slitallowCoiling('1')">确认上料</button>
			<button class="zd-col-4 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_slitallowCoiling('2')">允许离开</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryOrderInfo, slitvehicleReturn, slitcallSlitterRoll, slitsendSlitterRoll, slitallowCoiling} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				dataList: [],
				pkId: '',
				pkObj: {},
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
			this._queryOrderInfo()
		},
		methods: {
			async _queryOrderInfo () {
				let res = await queryOrderInfo()
				this.dataList = [...res.data]
			},
			toCheck (e) {
				this.pkId = e.workorder_id === this.pkId ? '' : e.workorder_id
				this.pkObj = e.workorder_id === this.pkId ? e : {}
			},
			clearUp () {
				this.val1 = ''
				this.dataList = []
				this.pkId = ''
				this.pkObj = {}
				this.disabled = false
			},
			async _slitvehicleReturn () {
				this.disabled = true
				if (!this.val1) {
					this.disabled = false
					return
				}
				try {
					let res = await slitvehicleReturn(this.val1)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			async _slitcallSlitterRoll () {
				this.disabled = true
				if (!this.pkId || !this.val1) {
					this.disabled = false
					return
				}
				try {
					let res = await slitcallSlitterRoll(this.pkObj.workorder_id, this.val1, this.pkObj.zc_point, this.pkObj.resource_name)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			async _slitsendSlitterRoll () {
				this.disabled = true
				if (!this.val1) {
					this.disabled = false
					return
				}
				try {
					let res = await slitsendSlitterRoll(this.val1)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			async _slitallowCoiling (type) {
				this.disabled = true
				if (!this.val1) {
					this.disabled = false
					return
				}
				try {
					let res = await slitallowCoiling(this.val1, type)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus" scoped>
.button-primary
	font-size: 24rpx;
</style>
