<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-6">
						<span class="filter_label">点位</span>
					</view>
					<view class="zd-col-18">
						<search-box
						v-model="val1"
						@handleChange="handleChange"
						/>
					</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>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i">
								<td>{{i+1}}</td>
								<td>{{e.point_code}}</td>
								<td>{{e.point_name}}</td>
								<td>{{e.get_status}}</td>
								<td>{{e.put_status}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-7 button-primary" :class="{'button-info': !dataList.length}" :disabled="disabled" @tap="_putConfirm">放货完成</button>
			<button class="zd-col-7 button-primary" :class="{'button-info': !dataList.length}" :disabled="disabled" @tap="_getConfirm">取货完成</button>
			<button class="zd-col-7 button-primary" :class="{'button-info': !dataList.length}" :disabled="disabled" @tap="_reduce">复位</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryPointInfo, putConfirm, getConfirm, reduce} from '@/utils/getData3.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				dataList: [],
				disabled: false
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			toEmpty () {
				this.val1 = ''
				this.dataList = []
				this.disabled = false
			},
			handleChange (e) {
				if (e) {
					this._queryPointInfo()
				}
			},
			async _queryPointInfo () {
				try {
					let res = await queryPointInfo(this.val1)
					if (res && res.data) {
						this.dataList = [...res.data]
					} else {
						this.dataList = []
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				} catch (e) {
					this.dataList = []
				}
			},
			async _putConfirm () {
				this.disabled = true
				if (!this.dataList.length) {
					this.disabled = false
					return
				}
				try {
					let res = await putConfirm(this.dataList)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.toEmpty()
				} catch (e) {
					this.disabled = false
				}
			},
			async _getConfirm () {
				this.disabled = true
				if (!this.dataList.length) {
					this.disabled = false
					return
				}
				try {
					let res = await getConfirm(this.dataList)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.toEmpty()
				} catch (e) {
					this.disabled = false
				}
			},
			async _reduce () {
				this.disabled = true
				if (!this.dataList.length) {
					this.disabled = false
					return
				}
				try {
					let res = await reduce(this.dataList)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.toEmpty()
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style scoped>
.filter_picker {
	text-align: center
}
</style>