<template>
	<view class="content">
		<nav-bar title="发货确认"></nav-bar>
		<view class="filter-confirm-wrap">
			<view class="filter-confirm-wrap-inner">
				<view class="filter-wrap">
					<view class="search-item filter-item">
						<label class="search-label">发货区点位</label>
						<view class="filter_input_wraper">
							<uni-data-select v-model="index1" :localdata="options1" @change="selectChange1"></uni-data-select>
						</view>
					</view>
					<view class="search-item filter-item">
						<label class="search-label">载具号</label>
						<view class="filter_input_wraper">
							<search-box
							v-model="val1"
							/>
						</view>
					</view>
				</view>
				<view class="confirm-button-wrap confirm-button-wrap-c">
					<button class="confirm-button" :class="{'confirm-button_disabled': !val1 || !index1}" :disabled="disabled1" @tap="toSure1">点位解绑</button>
					<button class="confirm-button" :class="{'confirm-button_disabled': !val1 || !index1}" :disabled="disabled2" @tap="toSure2">全部解绑</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {finishproductPoint, releasepoint} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				options1: [],
				index1: '',
				val1: '',
				dataList: [],
				disabled1: false,
				disabled2: false
			};
		},
		created () {
			this._finishproductPoint()
		},
		methods: {
			/** 选择器1 */
			selectChange1(e) {
				this.index1 = e
			},
			async _finishproductPoint () {
				let res = await finishproductPoint('2')
				this.options1 = [...res]
			},
			toSure1 () {
				this.disabled1 = true
				if (!this.index1 || !this.val1) {
					this.disabled1 = false
					return
				}
				this._releasepoint('one')
			},
			toSure2 () {
				this.disabled2 = true
				if (!this.index1 || !this.val1) {
					this.disabled2 = false
					return
				}
				this._releasepoint('all')
			},
			async _releasepoint (type) {
			  try {
				let res = await releasepoint(this.index1, this.val1, type) 
				this.disabled1 = false
				this.disabled2 = false
				this.index1 = ''
				this.val1 = ''
				uni.showToast({
					title: res.message,
					icon: 'none'
				})
			  } catch (e) {
				this.disabled1 = false
				this.disabled2 = false
			  }
			}
		}
	}
</script>

<style lang="stylus" scoped>
@import '../../common/style/mixin.styl';
.filter-confirm-wrap
	_wh(calc(100% - 30px), calc(100% - 72px))
	background-color #fff
	border-radius 12px
	margin 15px auto
	_fj()
.filter-confirm-wrap-inner
	width 50%
	background-color #fff
	border-radius 12px
	padding-bottom 15px
	margin 0 auto
.filter-wrap
	width 100%
	padding 0 15px
	_fj(center,,column,)
.filter-item
	width 100%
.confirm-button-wrap-c
	justify-content center
	margin-top 50px
</style>