<template>
	<view class="zd_container">
		<nav-bar title="半成品出库"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">物料规格</span>
					</view>
					<view class="filter_input_wraper">
						<search-box
						v-model="val1"
						@handleChange="handleChange"
						/>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label">点位</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index" :localdata="options" @change="selectChange"></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>
								<th>载具号</th>
								<th>数量</th>
								<th>所属工序</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" :class="{'checked': e.checked}">
								<td>{{Number(i) + 1}}</td>
								<td><span class="iconfont icon_unchecked" :class="{'icon_checked': e.checked}" @tap="toCheck(e)">&#xe66b;</span></td>
								<td>{{e.struct_code}}</td>
								<td>{{e.material_spec}}</td>
								<td>{{e.material_code}}</td>
								<td>{{e.material_name}}</td>
								<td>{{e.storagevehicle_code}}</td>
								<td>{{e.canuse_qty}}</td>
								<td>{{e.workprocedure_name}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="submit-bar">
			<button class="submit-button" :class="{'btn-disabled': !index && !checkArr.length}" :disabled="disabled" @tap="toSure">出库确认</button>
			<button class="submit-button" @tap="_iosOutgetIvt(val1)">查询</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {iosOutgetIvt, iosOutgetPoint, iosOutconfirm} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				options: [],
				index: '',
				val1: '',
				dataList: [],
				checkArr: [],
				disabled: false
			};
		},
		created () {
			this._iosOutgetPoint()
		},
		methods: {
			handleChange (e) {
				this._iosOutgetIvt(e)
			},
			/** 选择器 */
			selectChange(e) {
				this.index = e
			},
			/** 点位下拉框查询 */
			async _iosOutgetPoint () {
				let res = await iosOutgetPoint()
				res.data.map(el => {
					this.$set(el, 'value', el.point_code)
					this.$set(el, 'text', el.point_name)
				})
				this.options = [...res.data]
			},
			/** grid查询 */
			async _iosOutgetIvt (e) {
				let res = await iosOutgetIvt(e, this.index)
				res.data.map(el => {
					this.$set(el, 'checked', false)
				})
				this.dataList = [...res.data]	
			},
			toCheck (e) {
				e.checked = !e.checked
				this.checkArr = this.dataList.filter(i => { return i.checked === true })
			},
			/** 确认 */
			async toSure () {
				this.disabled = true
				if (!this.index || !this.checkArr.length) {
					this.disabled = false
					return
				}
				try {
					let res = await iosOutconfirm(this.checkArr, this.index)
					this.disabled = false
					this.dataList = []
					this._iosOutgetPoint()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

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