<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" @handleDel="handleDel"/>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label filter_input_disabled">区域</span>
					</view>
					<view class="zd-col-18 filter_select">
						<uni-data-select v-model="index1" :localdata="options1" disabled></uni-data-select>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">物料编码</span>
					</view>
					<view class="zd-col-13">
						<search-box v-model="materialData.material_code"/>
					</view>
					<button class="mini-btn" type="primary" @tap="toJump('material?title=物料维护')">查询</button>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label filter_input_disabled">物料名称</span>
					</view>
					<view class="zd-col-18">
						<input type="text" class="filter_input filter_input_disabled" v-model="materialData.material_name" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label filter_input_disabled">物料类别</span>
					</view>
					<view class="zd-col-18">
						<input type="text" v-model="materialData.class_name" class="filter_input filter_input_disabled" disabled>
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">批号</span>
					</view>
					<view class="zd-col-18">
						<input type="text" v-model="pcsn" class="filter_input">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">数量</span>
					</view>
					<view class="zd-col-18">
						<input type="number" v-model="num" class="filter_input">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">计量单位</span>
					</view>
					<view class="zd-col-18">
						<input type="text" class="filter_input" v-model="unit">
					</view>
				</view>
				<view class="zd-row border-bottom">
					<view class="zd-col-6">
						<span class="filter_label">备注</span>
					</view>
					<view class="zd-col-18">
						<input type="text" class="filter_input" v-model="mark">
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-5 button-default" @tap="toEmpty">清空</button>
			<button class="zd-col-18 button-primary" :class="{'button-info': !val1 || JSON.stringify(materialData) === '{}'}" :disabled="disabled" @tap="_confirmStock">确认收货</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryPointRegion, confirmStock} from '@/utils/getData3.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				options1: [],
				index1: '',
				materialData: {},
				num: '',
				unit: 'KG',
				mark: '',
				disabled: false,
				pcsn: ''
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		onShow () {
			if (this.$store.getters.publicObj !== '') {
				this.materialData = this.$store.getters.publicObj
				this.$store.dispatch('setPublicObj', '')
			}
		},
		methods: {
			onInput(e) {
				// console.log('输入内容:', e.detail.value)
			},
			handleChange (e) {
				if (e) {
					this._queryPointRegion(e)
				}
			},
			handleDel () {
			},
			toJump (name) {
				uni.navigateTo({
					url: `/pages/hdyy/wbc/${name}`
				})
			},
			/** 下拉框*/
			async _queryPointRegion () {
				try {
					let res = await queryPointRegion(this.val1)
					if (res && res.data) {
						this.options1 = [...res.data]
						this.index1 = this.options1[0].value
					} else {
						this.options1 = []
					}
				} catch (e) {
					this.options1 = []
				}
			},
			toEmpty () {
				this.val1 = ''
				this.index1 = ''
				this.materialData = {}
				this.pcsn = ''
				this.num = ''
				this.unit = 'KG'
				this.mark = ''
			},
			async _confirmStock () {
				this.disabled = true
				if (!this.val1 || JSON.stringify(this.materialData) === '{}') {
					this.disabled = false
					return
				}
				try {
					let res = await confirmStock(this.val1, this.index1, this.materialData.material_id, this.materialData.material_code, this.materialData.material_name, this.pcsn, this.num, this.unit, this.mark)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.toEmpty()
					this.disabled = false
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>
<style lang="stylus">
.input-container {
  background-color: #fff;
  border-radius: 16rpx;
  padding: 30rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
  margin-bottom: 40rpx;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
//   border: 2rpx solid #e0e0e0;
  border-radius: 12rpx;
  overflow: hidden;
  transition: border-color 0.3s;
}

.input-wrapper:focus-within {
  border-color: #007AFF;
}

.input-field {
  flex: 1;
  height: 80rpx;
//   padding: 0 24rpx;
  font-size: 28rpx;
  color: #333;
}

.placeholder {
  color: #999;
  font-size: 28rpx;
}

.picker {
  width: 80rpx;
  height: 80rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f8f8f8;
  border-left: 2rpx solid #e0e0e0;
}

.picker-trigger {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.picker-text {
  font-size: 24rpx;
  color: #666;
}

.custom-dialog-mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.custom-dialog {
  width: 600rpx;
  background: #fff;
  border-radius: 16rpx;
  overflow: hidden;
}

.dialog-title {
  padding: 30rpx;
  font-size: 32rpx;
  text-align: center;
  border-bottom: 1rpx solid #eee;
}

.dialog-body {
  padding: 40rpx;
}

.dialog-input {
  width: 100%;
  height: 80rpx;
  border: 1rpx solid #ddd;
  border-radius: 8rpx;
  padding: 0 20rpx;
  text-align: center;
}

.dialog-footer {
  display: flex;
  border-top: 1rpx solid #eee;
}

.dialog-footer button {
  flex: 1;
  border-radius: 0;
  margin: 0;
}
</style>
