<template>
	<view class="content">
		<nav-bar title="任务管理"></nav-bar>
		<view class="search-confirm-wrap">
			<view class="search-wrap">
				<view class="search-item">
					<label class="search-label">关键字</label>
					<view class="filter_input_wraper">
						<search-box
						v-model="val1"
						/>
					</view>
				</view>
			</view>
			<view class="confirm-button-wrap">
				<button class="confirm-button" @tap="toSearch()">查询</button>
				<button class="confirm-button" :disabled="disabled" @tap="toSure()">强制完成</button>
				<button class="confirm-button" :disabled="disabled" @tap="toSure()">重新下发</button>
				<button class="confirm-button" :disabled="disabled" @tap="toSure()">确认</button>
			</view>
		</view>
		<view class="grid-wrap">
			<table class="grid-table">
				<thead>
					<tr>
						<th>选择</th>
						<th>指令编号</th>
						<th>设备编号</th>
						<th>条码</th>
						<th>起点</th>
						<th>目的</th>
						<th>目的2</th>
					</tr>
				</thead>
				<tbody>
					<tr v-for="e in dataList" :key="e.instruct_uuid"  @click="toRadio(e)">
						<td>
							<view class="iconfont icon-check" :class="{'icon-checked': pkId === e.instruct_uuid}"></view>
						</td>
						<td>{{e.instructoperate_num}}</td>
						<td>{{e.wcsdevice_code}}</td>
						<td>{{e.vehicle_code}}</td>
						<td>{{e.startpoint_code}}</td>
						<td>{{e.nextpoint_code}}</td>
						<td>{{e.nextpoint_code2}}</td>
					</tr>
				</tbody>
			</table>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {getCacheLine, cacheLineOutBoxExceptionQuery, cacheLineOutBoxExceptionConfirm} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				val1: '',
				dataList: [],
				pkId: '',
				disabled: false
			};
		},
		created() {
			this._cacheLineOutBoxExceptionQuery()
		},
		methods: {
			toSearch () {
			  this.dataList = []
			  this.pkId = ''
			  this._cacheLineOutBoxExceptionQuery()
			},
			async _cacheLineOutBoxExceptionQuery () {
				let res = await cacheLineOutBoxExceptionQuery()
				this.dataList = [...res]
			},
			async toSure () {
			  this.disabled = true
			  if (!this.pkId) {
				uni.showToast({
					title: '请选择',
					icon: 'none'
				})
				this.disabled = false
				return
			  }
			  try {
				let res = await cacheLineOutBoxExceptionConfirm(this.val1) 
				this.disabled = false
				this.toSearch()
				uni.showToast({
					title: res.message,
					icon: 'none'
				})
			  } catch (e) {
				this.disabled = false
			  }
			},
			toRadio (e) {
			  this.pkId = this.pkId === e.instruct_uuid ? '' : e.instruct_uuid
			}
		}
	}
</script>

<style lang="stylus" scoped>
@import '../../common/style/mixin.styl';
.grid-wrap
	height: calc(100% - 237px); /** 42+ 15*6+ 35*3 */
</style>