<template>
	<view class="zd_container">
		<nav-bar title="指令管理"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>任务号</th>
								<th>指令号</th>
								<th>起点</th>
								<th>终点</th>
								<th>状态</th>
								<th>执行步骤</th>
								<th>载具号</th>
								<th>优先级</th>
								<th>创建时间</th>
								<th>agv车号</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" @click="toCheck(e)" :class="{'checked': e.inst_uuid === pkId}">
								<td>{{e.task_no}}</td>
								<td>{{e.inst_no}}</td>
								<td>{{e.start_devicecode}}</td>
								<td>{{e.next_devicecode}}</td>
								<td>{{e.inst_status}}</td>
								<td>{{e.inst_step}}</td>
								<td>{{e.carrier}}</td>
								<td>{{e.priority}}</td>
								<td>{{e.create_time}}</td>
								<td>{{e.carno}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="submit-bar">
			<button class="submit-button" :class="{'btn-disabled': !pkId}" :disabled="disabled1" @tap="toSure1('1')">指令撤销</button>
			<button class="submit-button" :class="{'btn-disabled': !pkId}" :disabled="disabled2" @tap="toSure2('2')">重新下发</button>
			<button class="submit-button" :class="{'btn-disabled': !pkId}" :disabled="disabled3" @tap="toSure3('3')">强制完成</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import {insts, inst} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				keyword: '',
				startPoint: '',
				endPoint: '',
				dataList: [],
				disabled1: false,
				disabled2: false,
				disabled3: false,
				pkId: ''
			};
		},
		created () {
		    this._insts(this.keyword, this.startPoint, this.endPoint)
		  },
		methods: {
			async _insts () {
				let res = await insts(this.keyword, this.startPoint, this.endPoint)
				if (res.code === '1') {
					this.dataList = [...res.result]
				} else {
					uni.showToast({
						title: res.desc,
						icon: 'none'
					})
				}
			},
			async _inst (type) {
				try {
					let res = await inst(type, this.pkId)
					if (res.code === '1') {
						this.disabled1 = false
						this.disabled2 = false
						this.disabled3 = false
						this.pkId = ''
						this._insts()
						uni.showToast({
							title: res.desc,
							icon: 'none'
						})
					} else {
						uni.showToast({
							title: res.desc,
							icon: 'none'
						})
						this.disabled1 = false
						this.disabled2 = false
						this.disabled3 = false
					}
				} catch (err) {
					this.disabled1 = false
					this.disabled2 = false
					this.disabled3 = false
				}
			},
			toCheck (e) {
				this.pkId = this.pkId === e.inst_uuid ? '' : e.inst_uuid
			},
			toSure1 (type) {
				this.disabled1 = true
				if (!this.pkId) {
					this.disabled1 = false
					return
				}
				this._inst(type)
			},
			toSure2 (type) {
				this.disabled2 = true
				if (!this.pkId) {
					this.disabled2 = false
					return
				}
				this._inst(type)
			},
			toSure3 (type) {
				this.disabled3 = true
				if (!this.pkId) {
					this.disabled3 = false
					return
				}
				this._inst(type)
			}
		}
	}
</script>

<style lang="stylus">
</style>
