<template>
	<view class="zd_container">
		<nav-bar :title="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>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" @click="toCheck(e)" :class="{'checked': e.work_code === pkId}">
								<td>{{e.work_code}}</td>
								<td>{{ e.status }}</td>
								<td>{{ e.mfg_order_name }}</td>
								<td>{{ e.material_code }}</td>
								<td>{{ e.material_name }}</td>
								<td>{{ e.qty }}</td>
								<td>{{ e.require_num }}</td>
								<td>{{ e.remain_num }}</td>
								<td>{{ e.resource_name }}</td>	
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-11 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-11 button-primary" :disabled="disabled" :class="{'button-info': !pkId}" @tap="_handConfirm">确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryWorks, handConfirm} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				disabled: false,
				dataList: [],
				pkId: ''
			};
		},
		onLoad (options) {
			this.title = options.title
			this._queryWorks()
		},
		methods: {
			async _queryWorks () {
				let res = await queryWorks()
				this.dataList = [...res]
			},
			clearUp () {
				this.dataList = []
				this.disabled = false
				this.pkId = ''
			},
			toCheck (e) {
				this.pkId = this.pkId === e.work_code ? '' : e.work_code
			},
			async _handConfirm () {
				this.disabled = true
				if (!this.pkId) {
					this.disabled = false
					return
				}
				try {
					let res = await handConfirm()
					this.clearUp()
					this._queryWorks()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

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