<template>
	<view class="container">
		<cu-custom bgColor="bg-gradual-pink" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">空容器出库</block>
		</cu-custom>
		<view class="example">
			<uni-forms ref="form" :model="formData" labelWidth="80px">

				<uni-forms-item label="空容器"  name="palletCode">
					<uni-easyinput  v-model="ktpCode"  disabled />
				</uni-forms-item>
				<uni-forms-item label="货位编号" name="locCode">
					<uni-easyinput v-model="formData.locCode" placeholder="请扫描货位编号" @blur="trimLocInput"/>
				</uni-forms-item>
				<uni-forms-item label="容器数量" name="skuQty" >
					<uni-easyinput v-model="formData.skuQty" disabled type="number" placeholder="请输入物料数量"/>
				</uni-forms-item>
 
 
			</uni-forms>

		  <view class="button-group">
		    <button type="primary" style="width: 200px;" :disabled="isButtonDisabled" @click="submitPallet">呼叫出库</button>

		  </view>

		</view>
		<view class="cu-modal" :class="msgModalName=='Modal'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">{{msgTitleName}}</view>
					<view class="action" @tap="hideMsgModal">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl">
					{{msg}}
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	import {
		getSkuDictionary,getSkuTypes
	} from "@/api/wms/sku.js"
	import {
		callEmptyOut
	} from "@/api/wms/bill.js"
	import {
		getDictionary
	} from "@/api/wms/dictData.js"
	import {
		formatDate
	} from 'tough-cookie';
	export default {
		data() {
			return {
				isButtonDisabled:false,
				autoCall:true,
				ktpCode:"KTP0001",
				msgTitleName:'标题',
				msg:'消息',
				msgModalName:"",
				//表单中的数据信息	
				formData: {
					locCode: "",
					skuQty: "1"
				},
				rules: {
					locCode: {
						rules: [{
							required: true,
							errorMessage: '请扫码货位号'
						}]
					},
					skuQty: {
						rules: [{
							required: true,
							errorMessage: '请输入物料数量'
						}]
					}
				},

			};
		},
		onLoad() {
		
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},

		watch: {

		},
		methods: {
			
			//去除空格
			trimLocInput(event) {
			    this.formData.locCode = event.target.value.trim();
			},
			//呼叫AGV
			submitPallet: function() {
				//this.msgModalName='Modal'
				this.isButtonDisabled = true; 
                this.$modal.loading("请等待...")
                if(!this.formData.locCode){
                    this.$modal.closeLoading()
                }
				const whcode=this.$store.state.user.warehouse[0]?.warehouseCode;
                var data={
					locCode:this.formData.locCode,
					userCode:this.$store.state.user.name,
					warehouseCode:whcode
                }
                callEmptyOut(data).then(response => {
                    console.log("response", response)
                    this.$modal.msgSuccess("呼叫入库成功")
                }).finally(() => {
                this.isButtonDisabled = false; // 恢复按钮可用
                this.$modal.closeLoading()
                });
			},
			hideMsgModal(e) {
				//关闭信息模态框
				this.msgModalName = null;
			},
			 
		}
	}
</script>

<style lang="scss">
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}

	page {
		background-color: #ffffff;
	}

	.example {
		padding: 15px;
		background-color: #fff;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
		flex: 1;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		line-height: 35px;
		margin-left: 10px;
	}
 .switch-item {
   display: flex;
   align-items: center;
   justify-content: space-between;
   padding: 10px;
   border-bottom: 1px solid #eee;
 }
</style>