<!--托盘信息查询-->
<template>
	<view class="container">
		<cu-custom :isBack="true">
			<block slot="backText"></block>
			<block slot="content"> 出库解绑</block>
		</cu-custom>
		<view class="example">
			<uni-forms ref="form" labelWidth="80px">
				<uni-forms-item label="货位编号" name="locCode">
					<view class="fromItem">
						<view class="flex-twice  padding-0 radius">
							<uni-easyinput v-model="locCode" placeholder="请扫描货位编号" @blur="queryLocInfo" />
						</view>
					</view>
				</uni-forms-item>
				<uni-forms-item label="容器编号" name="palletCode">
					<view class="fromItem">
						<uni-easyinput v-model="palletCode" placeholder="请扫描容器编号" @blur="queryPalleInfo" />
					</view>
				</uni-forms-item>
				<view style="margin-top: 10px;">
					<checkbox-group class="block" @change="CheckboxChange">
						<checkbox :class="isNoticeAGV ? 'checked':''" value="Y"
							:checked="isNoticeAGV ? true: false">
						</checkbox>
						<label style="margin: 10px;">通知AGV系统</label>
					</checkbox-group>
			
				</view>
			</uni-forms>
			<button class="cu-btn  bg-blue " style="position: absolute; right: 20px;" @click="getOutPlts" >刷新</button>
			
<div>
    <!-- 循环渲染 outPltList 列表 -->
    <div v-for="(out, index) in outPltList" :key="out.palletCode || index">
      <!-- 第一个元素绑定特殊样式类 -->
      <p :class="{ 'first-item': index === 0 }">
        货位：{{out.locCode}}   容器编号：{{out.palletCode}}
      </p>
      <p :class="{ 'first-item': index === 0 }">
        入库时间：{{out.entryTime}}
      </p>
	<div class="dashed-line"></div>

    </div>
  </div>
		</view>
		<bottomBtn :isSubmit="true" :isWhite="false" position="fixed" :texts="['确认出库解绑']" @onSubmit="handleClear">
		</bottomBtn>
	</view>
</template>

<script>
	import {
		queryPalletInfoByLocCode,
		queryPalletInfoByPalletCode,
		getOutPltList,
		fullCageOut
	} from "@/api/wms/project.js"
	import {
		bottomBtn
	} from '@/components/bottomBtn/bottomBtn.vue'
	export default {
		data() {
			return {
				locCode: "", // 输入的货位编号
				palletCode:"",
				isNoticeAGV:true,
				outPltList:[],
				rules: {
					locCode: {
						rules: [{
							required: true,
							errorMessage: '货位编号不能为空'
						}]
					}
				}
			};
		},
		component: {
			bottomBtn
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		 mounted() {
			this.getOutPlts()
		},
		methods: {
			CheckboxChange(e) {
			
				var items = e.detail.value
				this.isNoticeAGV= items.includes('Y')
			
				console.log('isNoticeAGV',this.isNoticeAGV)
			},
			// 查询货位信息
			async queryLocInfo() {
				if (!this.locCode) return

				this.$modal.loading("查询中...")
				try {
					const {
						code,
						data
					} = await queryPalletInfoByLocCode({
						locCode: this.locCode
					})
					if (code === 200) {
						
						if (!data) {
							this.$modal.msg("该货位未绑定托盘信息")
							this.palletCode=""
						}else{
							this.palletCode = data.palletCode
						}
					}else{
						this.palletCode=""
					}
				} catch (e) {
					console.error(e)
				} finally {
					this.$modal.closeLoading()
				}
			},
			// 查询货位信息
			async queryPalleInfo() {
				if (!this.palletCode) return
			
				this.$modal.loading("查询中...")
				try {
					const {
						code,
						data
					} = await queryPalletInfoByPalletCode({
						palletCode: this.palletCode
					})
					if (code === 200) {
						if (!data) {
							this.$modal.msg("未找的容器信息")
							this.locCode=""
						}else{
							this.locCode = data.locCode
						}
					}else{
						this.locCode=""
					}
				} catch (e) {
					console.error(e)
				} finally {
					this.$modal.closeLoading()
				}
			},
			// 显示清空确认对话框
			showClearConfirm() {
				if (!this.locCode) {
					return this.$modal.msg("请先输入货位编号")
				}

				uni.showModal({
					title: '确认清空',
					content: `确定要清空货位【${this.locCode}】下的所有托盘吗？`,
					confirmText: '确定清空',
					confirmColor: '#DD524D',
					cancelText: '取消',
					success: res => {
						if (res.confirm) {
							this.handleClear()
						}
					}
				})
			},

			async getOutPlts(){
				const ret = await getOutPltList()
				console.log(ret);
				if(!ret.success||!ret.data||ret.data.length<1){
					this.$modal.msgError("无容器需要出库解绑")
				}
				this.outPltList = ret.data
			},
			// 执行清空操作
			async handleClear() {
				if(!this.locCode){
					this.$modal.msgError("请扫码货位编号")
					return;
				}
				if(!this.palletCode){
					this.$modal.msgError("当前货位未绑定容器，不用解绑")
					return;
				}
				this.$modal.loading("解绑中...")
				try {
					const {
						code,
						msg
					} = await fullCageOut({
						locCode: this.locCode,
						containerCode:this.palletCode,
						noticeAGV:this.isNoticeAGV
					})
					if (code === 200) {
						this.$modal.msgSuccess("解绑成功")
						this.locList = [] // 清空列表
						this.locCode = "" // 清空输入
						this.palletCode=""
						this.getOutPlts()
					} else {
						this.$modal.msgError(msg || "解绑失败")
					}
				} catch (e) {
					console.error(e)
					this.$modal.msgError("请求失败")
				} finally {
					this.$modal.closeLoading()
				}
			}

		}
	}
</script>

<style lang="scss">
	/* 定义第一个元素的样式：加粗 + 字号变大 */
	.first-item {
	  font-weight: bold; /* 字体加粗 */
	  font-size: 18px;    /* 字号变大，可根据需求调整数值 */
	  margin: 0;          /* 可选：清除默认边距，优化排版 */
	}
	
	/* 非第一个元素的默认样式（可选，用于对比） */
	p {
	  font-size: 14px;    /* 默认字号 */
	  margin: 0;
	}
	/* 内部虚线样式 */
	.dashed-line {
	  width: 100%;
	  height: 1px;
	  background: dashed #ccc;
	  /* 兼容写法：通过渐变实现虚线 */
	  background: linear-gradient(to right, #ccc 50%, transparent 50%);
	  background-size: 8px 1px; /* 控制虚线的间距和粗细 */
	  margin: 5px 0;
	}
	.container {
		background: rgb(242, 243, 245);
		height: 100vh;
	}

	.uni-forms-item {
		border-bottom: 1px solid #E5E6EB;
		margin-bottom: 0;
		padding: 24rpx 0;
	}

	::v-deep .uni-forms-item__label {
		color: #1D2129;
		font-size: 28rpx;
		font-weight: 400;
	}

	::v-deep .uni-select {
		border: 0px;
	}

	::v-deep.uni-select__input-placeholder {
		font-size: 28rpx;
		font-weight: 400;
		color: #86909C;
	}

	.textarea {
		background-color: #F2F3F5;
		width: 100%;
	}

	::v-deep.full-width-textarea {
		width: 100% !important;
		border: unset !important;
	}

	::v-deep .is-input-border {
		border: unset;
	}

	::v-deep .uni-easyinput__placeholder-class {
		font-size: 28rpx;
		color: #86909C;
	}

	::v-deep .uni-input-input {
		font-size: 28rpx;
	}

	::v-deep .uni-select__input-placeholder {
		font-size: 28rpx;
		color: #86909C;
	}

	::v-deep .uniui-bottom {
		display: none;
	}

	::v-deep .uniui-top {
		display: none;
	}

	.fromItem {
		display: flex;
		align-items: center;
	}

	.example {
		padding: 0 24rpx;
		background-color: #fff;
		width: 702rpx;
		border-radius: 24rpx;
		margin: 24rpx auto;

	}

	/* 原有样式保留 */
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}

	page {
		background-color: #ffffff;
	}

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

	.button {
		margin: 15px 0;
	}
</style>