<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">区域</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index1" :localdata="options1" @change="selectChange1"></uni-data-select>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">管芯规格</span>
					</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index2" :localdata="options2" @change="selectChange2"></uni-data-select>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">子卷重量</span>
					</view>
					<view class="filter_input_wraper">
						<!-- <input type="number" class="filter_input" v-model="val3"> -->
						<number-input
						v-model="numberValue"
						:min="0"
						:max="999.999"
						input-class="filter_input"
						/>
					</view>
				</view>
			</view>
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>序号</th>
								<th class="th_2">托盘号</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>{{Number(i) + 1}}</td>
								<td class="td_2">{{e.vehicle_code}}</td>
								<td>{{e.material_code}}</td>
								<td>{{e.material_name}}</td>
								<td>{{e.total_num}}</td>
								<td>{{e.point_code}}</td>
								<td>{{e.product_area}}</td>
								<td>{{e.product_area_name}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submitbar">
			<button class="zd-col-5 btn-submit btn-default letter-30" @tap="clearUp">清空</button>
			<button class="zd-col-8 btn-submit btn-success letter-30" :class="{'btn-info': !index2}" :disabled="disabled" @tap="_moveStock">备货</button>
			<button class="zd-col-8 btn-submit btn-success" @tap="_showPapervehicleView">刷新</button>
		</view>
		<up-top ref="UT" :scrollTop="top"></up-top>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import NumberInput from '@/components/NumberInput.vue'
	import {showPapervehicleView, moveStock, queryProductArea, queryPaperMaterial} from '@/utils/getData4.js'
	export default {
		components: {
			NavBar,
			SearchBox,
			NumberInput
		},
		data() {
			return {
				numberValue: 1,
				// val3: '',
				title: '',
				top: 0,
				options1: [],
				index1: '',
				options2: [],
				index2: '',
				disabled: false,
				dataList: []
			};
		},
		onLoad (options) {
			this.title = options.title
			this._queryProductArea()
			this._queryPaperMaterial()
			this._showPapervehicleView()
		},
		onPageScroll(e) {
			this.$refs.UT.topData(e.scrollTop)
		},
		methods: {
			/** 区域下拉框查询 */
			async _queryProductArea () {
				let res = await queryProductArea()
				this.options1 = [...res.data]
			},
			selectChange1(e) {
				this.index1 = e
				if (e) {
					this._queryPaperMaterial(e)
				} else {
					this.index2 = ''
				}
			},
			/** 管芯规格下拉框 */
			async _queryPaperMaterial (e) {
				let res = await queryPaperMaterial(e)
				this.options2 = [...res.data]
			},
			selectChange2(e) {
				this.index2 = e
			},
			async _paperQueryPaperMaterial () {
				let res = await paperQueryPaperMaterial()
				this.dataList = [...res.rows]
			},
			async _moveStock () {
				this.disabled = true
				if (!this.index1 || !this.index2) {
					this.disabled = false
					return
				}
				try {
					let res = await moveStock(this.index1)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.disabled = false
				} catch (e) {
					this.disabled = false
				}
			},
			clearUp () {
				this.index1 = ''
				this.index2 = ''
				this.options2 = []
				this.upL = ''
				this.upR = ''
				this.lowL = ''
				this.lowR = ''
				this.disabled = false
			},
			async _showPapervehicleView () {
				let res = await showPapervehicleView(this.index1, this.index2)
				if (res) {
					this.dataList = [...res]
				}
			}
		}
	}
</script>
<style>
.custom-input {
  border: 1px solid #ccc;
  border-radius: 4px;
  /* padding: 8px 12px; */
  font-size: 16px;
  width: 100%;
  height: 30px;
  line-height: 30px;
}
</style>
