<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-6">
						<span class="filter_label">点位/载具</span>
					</view>
					<view class="zd-col-18">
						<search-box v-model="keyword" @handleChange="handleChange"/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label filter_input_disabled">当前站点</span>
					</view>
					<view class="zd-col-18">
						<input type="text" v-model="currentData.point_cdoe" class="filter_input filter_input_disabled" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-4">
						<span class="filter_label filter_input_disabled">任务号</span>
					</view>
					<view class="zd-col-8">
						<input type="text" v-model="currentData.task_code" class="filter_input filter_input_disabled" disabled>
					</view>
					<view class="zd-col-4">
						<span class="filter_label filter_input_disabled">AGV</span>
					</view>
					<view class="zd-col-8">
						<input type="text" v-model="currentData.car_no" class="filter_input filter_input_disabled" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-4">
						<span class="filter_label filter_input_disabled">起点</span>
					</view>
					<view class="zd-col-8">
						<input type="text" v-model="currentData.point_cdoe1" class="filter_input filter_input_disabled" disabled>
					</view>
					<view class="zd-col-4">
						<span class="filter_label filter_input_disabled">终点</span>
					</view>
					<view class="zd-col-8">
						<input type="text" v-model="currentData.point_cdoe2" class="filter_input filter_input_disabled" disabled>
					</view>
				</view>
			</view>
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>序号</th>
								<th>载具</th>
								<th>物料编码</th>
								<th>物料名称</th>
								<th>批次</th>
								<th>重量(kg)</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">
								<td>{{i+1}}</td>
								<td>{{e.source_form_type}}</td>
								<td>{{e.source_form_date}}</td>
								<td>{{e.material_code}}</td>
								<td>{{e.material_spec}}</td>
								<td>{{e.pcsn}}</td>
								<td>{{e.assign_qty}}</td>
								<td>{{e.qty}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-5 button-default" @tap="toEmpty">清空</button>
			<button class="zd-col-9 button-primary" :class="{'button-info': JSON.stringify(currentData) === '{}'}" :disabled="disabled" @tap="_confirmGet">确认取货</button>
			<button class="zd-col-9 button-primary" :class="{'button-info': JSON.stringify(currentData) === '{}'}" :disabled="disabled" @tap="_confirmPut">确认放货</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryPointInfo} from '@/utils/mork2.js'
	import {confirmGet, confirmPut} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				keyword: '',
				currentData: {},
				dataList: [],
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			handleChange (e) {
				if (e) {
					this._queryPointInfo(e)
				}
			},
			async _queryPointInfo (e) {
				try {
					let res = await queryPointInfo(e)
					if (res && res.data) {
						this.currentData = res.data
						this.dataList = [...res.data.rows]
					} else {
						this.currentData = {}
						this.dataList = []
					}
				} catch (e) {
					this.currentData = {}
					this.dataList = []
				}
			},
			toEmpty () {
				this.keyword = ''
				this.currentData = {}
				this.dataList = []
				this.disabled = false
			},
			async _confirmGet () {
				this.disabled = true
				if (JSON.stringify(this.currentData) === '{}') {
					this.disabled = false
					return
				}
				try {
					let res = await confirmGet(this.currentData.point_code)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.toEmpty()
				} catch (e) {
					this.disabled = false
				}
			},
			async _confirmPut () {
				this.disabled = true
				if (JSON.stringify(this.currentData) === '{}') {
					this.disabled = false
					return
				}
				try {
					let res = await confirmPut(this.currentData.point_code)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.toEmpty()
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>