<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>
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>订单号</th>
								<th>下一道工序</th>
								<th>交期时间</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i">
								<td>{{e.order_code}}</td>
								<td>
									<view class="td_select">
										<uni-data-select v-model="e.region_code" :localdata="options" @change="selectChange"></uni-data-select>
									</view>
								</td>
								<td>
									<uni-datetime-picker
										type="datetime"
										v-model="e.due_date"
										@change="changeLog"
									/>
								</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-7 button-default" @tap="clearUp">清空</button>
			<button class="zd-col-8 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_fabOrders">查询</button>
			<button class="zd-col-8 button-primary" :class="{'button-info': !dataList.length}" :disabled="disabled" @tap="_updateOrder">入库确认</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	// import {regionList, fabOrders} from '@/utils/mork2.js'
	import {regionList, fabOrders, updateOrder} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				options: [],
				index: '',
				disabled: false,
				dataList: [],
				show: false
			};
		},
		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)
				})
			},
			async _fabOrders () {
				let res = await fabOrders(this.val1)
				this.dataList = [...res]
			},
			selectChange (val) {
			},
			changeLog (e) {
			},
			clearUp () {
				this.dataList = []
				this.disabled = false
			},
			async _updateOrder () {
				this.disabled = true
				if (!this.dataList.length) {
					this.disabled = false
					return
				}
				try {
					let res = await updateOrder(this.dataList)
					this.clearUp()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus" scoped>
.zd_content
	height: calc(100% - var(--status-bar-height) - 212rpx);
	padding: 20rpx 14rpx 0 14rpx;
.grid-wraper
	height: 100%;
	overflow: auto;
.slide_new table td, .slide_new table th
	overflow: visible;
</style>
