<template>
	<view class="zd_container">
		<nav-bar :title="title"></nav-bar>
		<view class="zd-row jccenter tab-item-wraper">
			<view class="zd-col-16 zd-row">
				<view class="tab-item" :class="{'tab-item_active': tab === 1}" @tap="tab=1">叫料</view>
				<view class="tab-item" :class="{'tab-item_active': tab === 2}" @tap="tab=2">满料</view>
				<view class="tab-item" :class="{'tab-item_active': tab === 3}" @tap="tab=3">送空盅</view>
			</view>
		</view>
		<view class="zd_content zd_content_1">
			<view class="zd_wrapper">
				<view v-show="tab === 2" class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">载具编码</span>
					</view>
					<view class="zd-col-19 filter_select">
						<search-box
						v-model="val1"
						/>
					</view>
				</view>
				<view v-show="tab === 1 || tab === 2" class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">点位</span>
					</view>
					<view class="zd-col-19 filter_select">
						<zxz-uni-data-select v-model="index1" filterable :localdata="options1"></zxz-uni-data-select>
					</view>
				</view>
				<view v-show="tab === 3" class="zd-row border-bottom">
					<view class="zd-col-7">
						<span class="filter_label">下个点位类型</span>
					</view>
					<view class="zd-col-17 filter_select">
						<zxz-uni-data-select v-model="index2" filterable :localdata="options2"></zxz-uni-data-select>
					</view>
				</view>
				<view v-show="tab === 3" class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">点位编码</span>
					</view>
					<view class="zd-col-19 filter_select">
						<search-box
						v-model="val2"
						/>
					</view>
				</view>
			</view>
			<view v-show="tab === 1" 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 dataList1" :key="e.pointCode" @click="toChose1(e)" :class="{'checked': e.pointCode === pkId1}">
								<td>{{e.pointCode}}</td>
								<td>{{e.materialCode}}</td>
								<td>{{e.instorageTime}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
			<view v-show="tab === 2" class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th class="fontcol1">工单编号</th>
								<th>计划数量</th>
								<th>实际数量</th>
								<th>计划重量</th>
								<th>实际重量</th>
								<th>物料标识</th>
								<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 dataList2" :key="i" @click="toChose2(e)" :class="{'checked': e.workorder_code === pkId2}">
								<td class="fontcol1">{{e.workorder_code}}</td>
								<td>{{e.plan_qty}}</td>
								<td>{{e.real_qty}}</td>
								<td>{{e.plan_weight}}</td>
								<td>{{e.real_weight}}</td>
								<td>{{e.material_ratio}}</td>
								<td>{{e.raw_material_code}}</td>
								<td>{{e.produce_order}}</td>
								<td>{{e.produce_date}}</td>
								<td>{{e.vehicle_type}}</td>
								<td>{{e.point_code}}</td>
								<td>{{e.point_name}}</td>
								<td>{{e.region_code}}</td>
								<td>{{e.region_name}}</td>
								<td>{{['未生产', '已下发', '生产中', '暂停', '完成', '暂存中'][Number(e.workorder_status) - 1]}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view v-show="tab === 1" class="zd-row submit-bar">
			<button class="zd-col-5 button-default" @tap="index1 = ''">清空</button>
			<button class="zd-col-8 button-primary" :class="{'button-info': !pkId1 || !index1}" :disabled="disabled1" @tap="_cbjqlTask">拆包机叫料</button>
			<button class="zd-col-8 button-primary" :class="{'button-info': !index1}" @tap="show = true">呼叫空盅</button>
		</view>
		<view v-show="tab === 2" class="zd-row submit-bar">
			<button class="zd-col-6 button-default" @tap="index1 = '', val1 = ''">清空</button>
			<button class="zd-col-15 button-primary" :class="{'button-info': !pkId2 || !val1 || !index1}" :disabled="disabled2" @tap="_cbjmlTask">满料入库</button>
		</view>
		<view v-show="tab === 3" class="zd-row submit-bar">
			<button class="zd-col-6 button-default" @tap="index2 = '', val2 = ''">清空</button>
			<button class="zd-col-15 button-primary" :class="{'button-info': !val2 || !index2}" :disabled="disabled4" @tap="_cbjskTask">空料位送空蛊</button>
		</view>
		<view class="zd_content msg_wrapper" :class="show ? 'popshow' : 'pophide'">
			<view class="pop-line"></view>
			<view class="msg_content">
				<view class="zd-row">
					<view class="zd-col-24">
						<span class="filter_label">确定是否呼叫空蛊？</span>
					</view>
				</view>
			</view>
			<view class="zd-row submit-bar">
				<button class="zd-col-11 button-default" @tap.stop="show = false">关闭</button>
				<button class="zd-col-11 button-primary" :disabled="disabled3" @tap="_cbjqkTask">确定</button>
			</view>
		</view>
		<view v-if="show" class="msg_mask"></view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {unpackShelfInfo, getCbjPoint, cbjqlTask, hnWorkOrder,cbjmlTask,cbjqkTask, cbjskTask} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				tab: 1,
				title: '',
				options1: [],
				index1: '',
				dataList1: [],
				pkId1: '',
				val1: '',
				dataList2: [],
				pkId2: '',
				disabled1: false,
				disabled2: false,
				disabled3: false,
				show: false,
				options2: [{value: 'CBJXLW', text: '拆包机下料位'},{value: 'KLHW', text: '困料货架'}],
				index2: '',
				val2: '',
				disabled4: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		created () {
			this._unpackShelfInfo()
			this._getCbjPoint()
			this._hnWorkOrder()
		},
		methods: {
			/**货架上未拆包料盅信息 */
			async _unpackShelfInfo () {
				let res = await unpackShelfInfo()
				this.dataList1 = [...res]
			},
			/** 拆包机点位下拉框*/
			async _getCbjPoint () {
				let res = await getCbjPoint()
				this.options1 = [...res]
			},
			toChose1 (e) {
				this.pkId1 = this.pkId1 === e.pointCode ? '' : e.pointCode
			},
			/** 拆包机叫料 */
			async _cbjqlTask () {
				this.disabled1 = true
				if (!this.pkId1 || !this.index1) {
					this.disabled1 = false
					return
				}
				try {
					let res = await cbjqlTask(this.pkId1, this.index1)
					this.pkId1 = ''
					this.disabled1 = false
					this._unpackShelfInfo()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled1 = false
				}
			},
			/** 查询混碾工单 */
			async _hnWorkOrder () {
				let res = await hnWorkOrder()
				this.dataList2 = [...res]
			},
			toChose2 (e) {
				this.pkId2 = this.pkId2 === e.workorder_code ? '' : e.workorder_code
			},
			/** 满料入库 */
			async _cbjmlTask () {
				this.disabled2 = true
				if (!this.pkId2 || !this.val1 || !this.index1) {
					this.disabled2 = false
					return
				}
				try {
					let res = await cbjmlTask(this.pkId2, this.val1, this.index1)
					this.pkId2 = ''
					this.disabled2 = false
					this._hnWorkOrder()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled2 = false
				}
			},
			/** 呼叫空盅 */
			async _cbjqkTask () {
				this.disabled3 = true
				try {
					let res = await cbjqkTask(this.index1)
					this.show = false
					this.disabled3 = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled3 = false
				}
			},
			/** 拆包机空料位送空蛊 */
			async _cbjskTask () {
				this.disabled4 = true
				try {
					let res = await cbjskTask(this.index2, this.val2)
					this.disabled4 = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled4 = false
				}
			}
		}
	}
</script>

<style lang="stylus">
@import '../../common/style/mixin.styl';
.msg_wrapper
	height auto
	min-height 30%
</style>
