<template>
	<view class="zd_container">
		<!-- <nav-bar title="虚拟区发货"></nav-bar> -->
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">{{$t('filter.woodenbox')}}</span>
					</view>
					<view class="filter_input_wraper">
						<search-box ref="scanChild" v-model="val1" @handleChange="handleChange1" 
						/>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">{{$t('grid.bill-code')}}</span>
					</view>
					<view class="filter_input_wraper">
						<search-box v-model="val2" @handleChange="handleChange2"/>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label">{{$t('grid.bill-type')}}</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index"  :placeholder="$t('uni.dataSelect.placeholder')" :emptyTips="$t('uni.dataSelect.emptyTips')" :localdata="options" @change="selectChange"></uni-data-select>
					</view>
				</view>
			</view>
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>{{$t('grid.bill-code')}}</th>
								<th>{{$t('grid.bill-type')}}</th>
								<th>{{$t('grid.source-code')}}</th>
								<th>{{$t('grid.date')}}</th>
								<th>{{$t('grid.personnel')}}</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" @click="toCheck(e)" :class="{'checked': e.bill_code === pkId, 'bgyellow': e.colro_flag === '1'}">
								<td>{{e.bill_code}}</td>
								<td>{{e.bill_type_name}}</td>
								<td>{{e.source_bill_code}}</td>
								<td>{{e.biz_date}}</td>
								<td>{{e.person_name}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submitbar">
			<button class="zd-col-15 btn-submit btn-success letter-30" :class="{'btn-info': !pkId}" :disabled="disabled1" @tap="toSure">{{$t('button.confirm')}}</button>
			<button class="zd-col-6 btn-submit btn-success letter-30" @tap="_virtualbillQuery(val1, val2)">{{$t('button.search')}}</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {virtualbillQuery, virtualbillType} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				val2: '',
				options: [],
				index: '',
				dataList: [],
				pkId: '',
				pkObj: {},
				disabled1: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		created () {
			this._virtualbillQuery(this.val1, this.val2)
			this._virtualbillType()
		},
		mounted () {
			this.$refs.scanChild.handleFocus()
		},
		methods: {
			handleChange1 (e) {
				this._virtualbillQuery(e, this.val2)
			},
			handleChange2 (e) {
				this._virtualbillQuery(this.val1, e)
			},
			/** 选择器 */
			selectChange(e) {
				this.index = e
			},
			/** 下拉框查询 */
			async _virtualbillType () {
				let res = await virtualbillType()
				this.options = [...res.data]
			},
			/** 初始化查询 */
			async _virtualbillQuery (val1, val2) {
				let res = await virtualbillQuery(val1, val2, this.index)
				this.dataList = [...res.data]
			},
			toSure () {
				if (this.pkId) {
					uni.navigateTo({
						url: '/pages/SecondPhase/XuniDeliveryConfirm?billcode=' + this.pkObj.bill_code + '&title=' + this.title
					})
				}
			},
			toCheck (e) {
				this.pkId = this.pkId === e.bill_code ? '' : e.bill_code
				this.pkObj = this.pkId === e.bill_code ? e : {}
			}
		}
	}
</script>
