<template>
	<view class="page-detail">
		<!-- 基本信息 -->
		<view class="info-group">
			<!-- 车次 -->
			<view class="info-item">
				<text class="info-label" v-if="isEdit"><text class="required">*</text>车次</text>
				<text class="info-label" v-else>车次</text>
				<view v-if="isEdit" class="info-input-wrap">
					<u-input v-model="form.TrainNumber" placeholder="请输入" />
				</view>
				<text class="info-value" v-else>{{ form.TrainNumber || '--' }}</text>
			</view>

			<!-- 单位名称 -->
			<view class="info-item">
				<text class="info-label" v-if="isEdit"><text class="required">*</text>单位名称</text>
				<text class="info-label" v-else>单位名称</text>
				<view v-if="isEdit" class="info-input-wrap">
					<u-input v-model="form.UnitName" :clearable="false" type="select" placeholder="请选择" @click="handleShowUnit" />
				</view>
				<text class="info-value" v-else>{{ form.UnitName || '--' }}</text>
			</view>

			<!-- 驾驶员姓名 -->
			<view class="info-item">
				<text class="info-label" v-if="isEdit"><text class="required">*</text>驾驶员姓名</text>
				<text class="info-label" v-else>驾驶员姓名</text>
				<view v-if="isEdit" class="info-input-wrap">
					<u-input v-model="form.DriverName" placeholder="请输入" />
				</view>
				<text class="info-value" v-else>{{ form.DriverName || '--' }}</text>
			</view>

			<!-- 驾驶员电话 -->
			<view class="info-item">
				<text class="info-label" v-if="isEdit"><text class="required">*</text>驾驶员电话</text>
				<text class="info-label" v-else>驾驶员电话</text>
				<view v-if="isEdit" class="info-input-wrap">
					<u-input v-model="form.DriverPhone" placeholder="请输入" type="number" />
				</view>
				<text class="info-value" v-else>{{ form.DriverPhone || '--' }}</text>
			</view>

			<!-- 车牌号 -->
			<view class="info-item">
				<text class="info-label" v-if="isEdit"><text class="required">*</text>车牌号</text>
				<text class="info-label" v-else>车牌号</text>
				<view v-if="isEdit" class="info-input-wrap">
					<u-input v-model="form.LicensePlateNumber" placeholder="请输入" />
				</view>
				<text class="info-value" v-else>{{ form.LicensePlateNumber || '--' }}</text>
			</view>

			<!-- 联系人姓名 -->
			<view class="info-item">
				<text class="info-label" v-if="isEdit"><text class="required">*</text>联系人姓名</text>
				<text class="info-label" v-else>联系人姓名</text>
				<view v-if="isEdit" class="info-input-wrap">
					<u-input v-model="form.ContactName" placeholder="请输入" />
				</view>
				<text class="info-value" v-else>{{ form.ContactName || '--' }}</text>
			</view>

			<!-- 联系人电话 -->
			<view class="info-item">
				<text class="info-label" v-if="isEdit"><text class="required">*</text>联系人电话</text>
				<text class="info-label" v-else>联系人电话</text>
				<view v-if="isEdit" class="info-input-wrap">
					<u-input v-model="form.ContactPhone" placeholder="请输入" type="number" />
				</view>
				<text class="info-value" v-else>{{ form.ContactPhone || '--' }}</text>
			</view>

			<!-- 备注 -->
			<view class="info-item">
				<text class="info-label">备注</text>
				<view v-if="isEdit" class="info-input-wrap">
					<u-input v-model="form.Remark" placeholder="请输入" type="textarea" />
				</view>
				<text class="info-value" v-else>{{ form.Remark || '--' }}</text>
			</view>

			<!-- 状态 -->
			<view class="info-item">
				<text class="info-label">状态</text>
				<text class="info-value">{{ form.StateName || '--' }}</text>
			</view>

			<!-- 扫码添加 -->
			<view class="info-item info-link" v-if="form.TrainNumberId && isEdit" @click="handleScan">
				<text class="info-label">扫码添加</text>
				<view class="scan-icon">
					<u-icon name="scan" :size="36" color="#3577FF"></u-icon>
				</view>
			</view>
		</view>

		<!-- 包装列表 -->
		<view class="package-group" v-if="form.TrainNumberId">
			<view class="section-title">
				<text>包装列表</text>
				<text class="section-count">({{ BZList.length }})</text>
			</view>
			<view v-for="(item, index) in BZList" :key="index" class="package-card">
				<view class="card-header">
					<text class="card-title">{{ item.PackagingCode || '--' }}</text>
					<view class="del-btn" @click="handleDeletePackage(item)" v-if="isEdit">
						<u-icon name="trash" :size="36" color="#ffffff"></u-icon>
					</view>
				</view>
				<view class="card-body">
					<view class="card-row">
						<text class="row-label">预制工作包</text>
						<text class="row-value">{{ item.StackingPosition || '--' }}</text>
					</view>
				</view>
			</view>
			<view v-if="BZList.length === 0" class="package-empty">
				<u-empty text="暂无数据" mode="list"></u-empty>
			</view>
		</view>

		<!-- 底部按钮 -->
		<view class="bottom-btns" v-if="isEdit">
			<u-button size="medium" type="primary" :disabled="disabledBtn" @click="handleSave(0)">保存</u-button>
			<u-button size="medium" type="success" :disabled="disabledBtn" @click="handleSave(1)">发货</u-button>
		</view>
		<view class="bottom-btns" v-if="form.State === 1">
			<u-button size="medium" type="warning" :disabled="disabledBtn" @click="handleSign">签收</u-button>
		</view>

		<!-- 单位选择弹窗 -->
		<nbd-select v-model="showUnitSelect" v-model:model="selectedUnit" :show-search="true" title="选择单位"
			:list="unitList" label-key="UnitName" value-key="UnitId" @confirm="handleUnitConfirm" />
	</view>
</template>

<script setup>
</script>