<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-5">
						<span class="filter_label">点位</span>
					</view>
					<view class="zd-col-19">
						<search-box
						v-model="val1"
						/>
					</view>
				</view>
				<view class="zd-row">
					<view class="zd-col-5">
						<span class="filter_label">工序</span>
					</view>
					<view class="zd-col-19 filter_select">
						<uni-data-select v-model="index" :localdata="options"></uni-data-select>
					</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>优先级</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" @click="toCheck(e)" :class="{'checked': e.vehicle_code === pkId}">
								<td>{{e.vehicle_code}}</td>
								<td>{{e.order_code}}</td>
								<td>{{e.region_code}}</td>
								<td>{{e.material_qty}}</td>
								<td>{{e.due_date}}</td>
								<td>{{e.priority}}</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" @tap="_selectOrderByRegion">查询</button>
		</view>
		<view class="msg_wrapper" :class="show ? 'popshow' : 'pophide'">
			<view class="pop_content">
				<view class="zd_wrapper grid-wraper">
					<view class="slide_new">
						<table>
							<thead>
								<tr>
									<th>订单号</th>
									<th>交期时间</th>
									<th>物料数量</th>
									<th>工序</th>
								</tr>
							</thead>
							<tbody>
								<tr v-for="(e, i) in popList" :key="i">
									<td>{{e.order_code}}</td>
									<td>{{e.due_date}}</td>
									<td>{{e.material_qty}}</td>
									<td>{{e.region_code}}</td>
								</tr>
							</tbody>
						</table>
					</view>
				</view>
			</view>
			<view class="zd-row submit-bar">
				<button class="zd-col-11 button-default" @tap="pkId = '', show = false, popList = []">取消</button>
				<button class="zd-col-11 button-primary" :class="{'button-info': !popList.length}" :disabled="disabled" @tap="_callMater">叫料</button>
			</view>
		</view>
		<view v-show="show" class="msg_mask"></view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	// import {regionList, selectOrderByRegion, fabMaterial} from '@/utils/mork2.js'
	import {regionList, selectOrderByRegion, fabMaterial, callMater} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				options: [],
				index: '',
				disabled: false,
				dataList: [],
				pkId: '',
				show: false,
				popList: []
			};
		},
		onLoad (options) {
			this.title = options.title
			this._regionList()
		},
		methods: {
			async _regionList () {
				let res = await regionList()
				this.options = [...res.content]
				this.options.map(el => {
					this.$set(el, 'text', el.label)
				})
			},
			clearUp () {
				this.val1 = ''
				this.index = ''
				this.dataList = []
				this.disabled = false
				this.pkId = ''
				this.show = false
				this.popList = []
			},
			async _selectOrderByRegion () {
				let res = await selectOrderByRegion(this.index, this.val1)
				this.dataList = [...res.content]
			},
			toCheck (e) {
				this.pkId = e.vehicle_code
				this._fabMaterial(this.pkId)
				this.show = true
			},
			async _fabMaterial (e) {
				let res = await fabMaterial(e)
				this.popList = [...res]
			},
			async _callMater () {
				this.disabled = true
				if (!this.popList.length) {
					this.disabled = false
					return
				}
				try {
					let res = await callMater(this.popList, this.val1, this.pkId)
					this.clearUp()
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

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