<!-- 拣货管理 -->
<template>
  <div class="page-container">
    <!-- 顶部信息栏 -->
    <PageHeader title="拣货管理" />

    <!-- 主内容区域 -->
    <main class="main-content">
      <!-- 页面标题 -->
      <!-- <div class="page-title">
        <h2>拣货管理</h2>
      </div> -->

      <!-- 筛选区域 -->
      <FilterPanel :default-collapsed="false" :enable-collapse="false" :active-count="getActiveFilterCount()">
        <div class="filter-form">
          <div class="filter-item">
            <label class="filter-label">名称:</label>
            <van-field
              v-model="filterForm.inventoryName" placeholder="输入名称" class="filter-input"
              @keyup.enter="getList"
            />
          </div>
          <div class="filter-item">
            <label class="filter-label">编号:</label>
            <van-field
              v-model="filterForm.inventoryNo" placeholder="输入编号" class="filter-input"
              @keyup.enter="getList"
            />
          </div>
          <div class="filter-item">
            <label class="filter-label">类型:</label>
            <v-select
              v-model="filterForm.inventoryType" :options="inventoryTypeList" :reduce="item => item.value"
              label="label" placeholder="选择类型" :clearable="true" :filterable="true" class="filter-select"
              @update:model-value="getList"
            >
              <template #no-options>
                <span>无该选项数据</span>
              </template>
            </v-select>
          </div>
          <div class="filter-item">
            <label class="filter-label">仓库:</label>
            <v-select
              v-model="filterForm.warehouseId" :options="warehouseList" :reduce="item => item.id" label="name"
              placeholder="选择仓库" :clearable="true" :filterable="true" class="filter-select"
              @update:model-value="getList"
            >
              <template #no-options>
                <span>无该选项数据</span>
              </template>
            </v-select>
          </div>
          <div class="filter-item">
            <label class="filter-label">货位:</label>
            <van-field
              v-model="filterForm.positionName" placeholder="输入货位名称" class="filter-input"
              @keyup.enter="getList"
            />
          </div>
          <div class="filter-item filter-buttons">
            <van-button type="primary" @click="getList">
              <i class="fas fa-search mr-1" /> 搜索
            </van-button>
            <van-button class="ml-2" @click="handleReset">
              <i class="fas fa-redo mr-1" /> 重置
            </van-button>
          </div>
        </div>
      </FilterPanel>

      <!-- 卡片容器 -->
      <div class="card-container">
        <!-- 全选控制栏 -->
        <div v-if="materialList.length > 0" class="select-all-bar">
          <van-checkbox :model-value="isAllSelected" @update:model-value="toggleSelectAll">
            <span class="select-all-text">全选当前页（已选 {{ selectedIds.length }} 项）</span>
          </van-checkbox>
        </div>

        <!-- 卡片列表区域  -->
        <div class="card-list-wrapper">
          <!-- 空状态 -->
          <van-empty v-if="materialList.length === 0" description="暂无数据" />

          <!-- 卡片列表 -->
          <div v-else class="card-list">
            <div
              v-for="(item, index) in materialList" :key="item.id || index"
              :class="{ 'selected-card': selectedIds.includes(item.id) }" class="inventory-card"
              @click="toggleSelect(item.id)"
            >
              <div class="card-header">
                <div class="card-header-left">
                  <van-checkbox
                    :model-value="selectedIds.includes(item.id)" @click.stop
                    @update:model-value="checked => handleCheckboxChange(checked, item.id)"
                  />
                  <div class="custom-avatar ml-3">
                    <i :class="getInventoryIcon(item.inventoryType)" />
                  </div>
                  <div class="ml-4 card-title-info">
                    <div class="card-name">{{ item.inventoryName }}</div>
                    <div class="card-subtitle">编号: {{ item.inventoryNo }}</div>
                  </div>
                </div>
                <div class="card-header-right">
                  <div class="card-location">
                    <i class="fas fa-map-marker-alt mr-2" />
                    <span>{{ item.positionName || '-' }}</span>
                    <span class="mx-2">/</span>
                    <span>{{ item.warehouseName || '-' }}</span>
                  </div>
                </div>
              </div>

              <!-- 卡片展开内容：配送方式选择（只有选中时显示） -->
              <div v-if="selectedIds.includes(item.id)" class="card-delivery-section" @click.stop>
                <div class="delivery-options">
                  <!-- 配送方式选择 -->
                  <div class="delivery-option-item">
                    <label class="option-label">配送方式：</label>
                    <div class="delivery-method-buttons">
                      <button
                        :class="['delivery-btn', 'agv-btn', { 'active': item.deliveryMethod === 'AGV_Delivery', 'disabled': item.deliveryType === '人工配送' }]"
                        :disabled="item.deliveryType === '人工配送'" @click="changeDeliveryMethod(item, 'AGV_Delivery')"
                      >
                        <i class="fas fa-robot" /> AGV 配送
                      </button>
                      <button
                        :class="['delivery-btn', 'manual-btn', { 'active': item.deliveryMethod === 'Manual_Delivery', 'disabled': item.deliveryType === '强制AGV配送' }]"
                        :disabled="item.deliveryType === '强制AGV配送'"
                        @click="changeDeliveryMethod(item, 'Manual_Delivery')"
                      >
                        <i class="fas fa-user" /> 人工配送
                      </button>
                    </div>
                    <span
                      v-if="item.deliveryType" class="delivery-type-badge"
                      :class="getDeliveryTypeBadgeClass(item.deliveryType)"
                    >
                      {{ item.deliveryType }}
                    </span>
                  </div>

                  <!-- 配送位置选择（仅 AGV 配送时显示） -->
                  <div v-if="item.deliveryMethod === 'AGV_Delivery'" class="delivery-location-item">
                    <label class="option-label">配送位置：</label>
                    <v-select
                      v-model="item.selectedLocation" :options="locator" placeholder="请选择" :clearable="false"
                      class="location-select"
                    >
                      <template #no-options>
                        <span>无该选项数据</span>
                      </template>
                    </v-select>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <!-- 分页区域（固定底部） -->
        <div v-if="materialList.length > 0" class="pagination-wrapper">
          <span class="text-gray-600">共 {{ materialList.length }} 条数据</span>
        </div>
      </div>
    </main>
    <!-- 底部完成按钮 -->
    <div class="bottom-actions">
      <van-button
        type="primary" size="large" :disabled="selectedIds.length === 0" class="complete-btn"
        @click="handleComplete"
      >
        <i class="fas fa-check-circle mr-2" />
        拣货 ({{ selectedIds.length }})
      </van-button>
    </div>

    <!-- 拣货完成确认弹窗 -->
    <van-dialog
      v-model:show="completeModalVisible" title="拣货完成" show-cancel-button class-name="large-dialog"
      confirm-button-text="确认" cancel-button-text="取消" @confirm="handleCompleteConfirm" @cancel="handleCompleteCancel"
    >
      <div class="large-dialog-content">
        <p>领料申请已完成，配送任务已创建！请确认是否返回主页？</p>
        <!-- <p class="dialog-subtitle">如果是请点击【确认】按钮</p> -->
      </div>
    </van-dialog>
  </div>
  <Loading v-if="loading" />
</template>

<script setup>
import { useRouter } from 'vue-router';
import { ref, reactive, computed, onMounted } from 'vue';
import { showNotify } from 'vant';
import vSelect from 'vue-select';
import 'vue-select/dist/vue-select.css';
import PageHeader from '../common/PageHeader.vue';
import FilterPanel from '../common/FilterPanel.vue';
import { list, createStockOut } from '../api/stockOut.js';
import { getWarehouseList, queryIdleLocator } from '../api/stock.js';

const router = useRouter();

const warehouseList = ref([]);

// 筛选表单
const filterForm = reactive({
    inventoryName: '',
    inventoryNo: '',
    inventoryType: undefined,
    warehouseId: undefined,
    positionName: '',
});
const inventoryTypeList = ref([
    { value: 'Clamp', label: '工装' },
    { value: 'Instrument', label: '设备' },
    { value: 'FinishProduct', label: '成品' },
]);
// 表格加载状态
const loading = ref(false);

// 完成弹窗控制
const completeModalVisible = ref(false);

// 物料列表数据
const materialList = ref([]);

// 分页配置
const pagination = reactive({
    start: 1,
    lang: 10,
    total: 0,
});

//  所选集合
const selectedIds = ref([]);
const selectedRows = ref([]);

// 计算是否全选
const isAllSelected = computed(() => {
    if (materialList.value.length === 0) return false;
    return materialList.value.every(item => selectedIds.value.includes(item.id));
});

// 可配送位置
const locator = ref([]);

// 计算激活的筛选条件数量
const getActiveFilterCount = () => {
    let count = 0;
    if (filterForm.inventoryName) count++;
    if (filterForm.inventoryNo) count++;
    if (filterForm.inventoryType) count++;
    if (filterForm.warehouseId) count++;
    if (filterForm.positionName) count++;
    return count;
};

// 根据 deliveryType 初始化配送方式
const initDeliveryMethod = item => {
    if (item.deliveryType === '人工配送') {
    // 人工配送：只能人工，不可切换
        item.deliveryMethod = 'Manual_Delivery';
        item.selectedLocation = '';
    } else if (item.deliveryType === '强制AGV配送') {
    // 强制AGV配送：只能AGV，不可切换为人工
        item.deliveryMethod = 'AGV_Delivery';
        if (!item.selectedLocation) {
            item.selectedLocation = '';
        }
    } else if (item.deliveryType === '可选AGV配送') {
    // 可选AGV配送：默认人工，可切换为AGV
        item.deliveryMethod = item.deliveryMethod || 'Manual_Delivery';
        item.selectedLocation = item.selectedLocation || '';
    }
};

// 切换选择
const toggleSelect = id => {
    const index = selectedIds.value.indexOf(id);
    if (index > -1) {
        selectedIds.value.splice(index, 1);
        // 同时移除 selectedRows 中对应的项
        selectedRows.value = selectedRows.value.filter(item => item.id !== id);
    } else {
        selectedIds.value.push(id);
        // 添加到 selectedRows 并初始化配送字段
        const item = materialList.value.find(item => item.id === id);
        if (item) {
            // 初始化配送字段
            initDeliveryMethod(item);
            selectedRows.value.push(item);
        }
    }
};

// 处理复选框变化
const handleCheckboxChange = (checked, id) => {
    if (checked) {
        if (!selectedIds.value.includes(id)) {
            selectedIds.value.push(id);
            const item = materialList.value.find(item => item.id === id);
            if (item) {
                // 初始化配送字段
                initDeliveryMethod(item);
                selectedRows.value.push(item);
            }
        }
    } else {
        const index = selectedIds.value.indexOf(id);
        if (index > -1) {
            selectedIds.value.splice(index, 1);
            selectedRows.value = selectedRows.value.filter(item => item.id !== id);
        }
    }
};

// 全选/取消全选
const toggleSelectAll = checked => {
    if (checked) {
    // 全选当前页所有项（累加模式）
        materialList.value.forEach(item => {
            if (!selectedIds.value.includes(item.id)) {
                selectedIds.value.push(item.id);
                initDeliveryMethod(item);
                selectedRows.value.push(item);
            }
        });
    } else {
    // 取消全选当前页
        const currentPageIds = materialList.value.map(item => item.id);
        selectedIds.value = selectedIds.value.filter(id => !currentPageIds.includes(id));
        selectedRows.value = selectedRows.value.filter(row => !currentPageIds.includes(row.id));
    }
};

// 获取设备类型图标
const getInventoryIcon = type => {
    const iconMap = {
        '工装': 'fas fa-cube',
        '设备': 'fas fa-cogs',
        '成品': 'fas fa-box',
    };
    return iconMap[type] || 'fas fa-cube';
};

// 获取配送类型徽章样式
const getDeliveryTypeBadgeClass = deliveryType => {
    const classMap = {
        '人工配送': 'badge-manual',
        '强制AGV配送': 'badge-agv-force',
        '可选AGV配送': 'badge-agv-optional',
    };
    return classMap[deliveryType] || '';
};

// 重置筛选条件
const handleReset = () => {
    filterForm.inventoryName = '';
    filterForm.inventoryNo = '';
    filterForm.inventoryType = undefined;
    filterForm.warehouseId = undefined;
    filterForm.positionName = '';
    getList();
};

// 加入领料申请
const addToRequisition = record => {
    if (!selectedIds.value.includes(record.id)) {
        selectedIds.value.push(record.id);
        // 初始化配送字段
        initDeliveryMethod(record);
        selectedRows.value.push(record);
    }
};

// 领料申请，直接验证并提交
const handleComplete = async () => {
    if (selectedIds.value.length === 0) {
        showNotify({ type: 'warning', message: '请至少选择一个物料' });
        return;
    }

    // 验证选择了 AGV 配送的物料是否都选择了配送位置
    const agvItems = selectedRows.value.filter(item => item.deliveryMethod === 'AGV_Delivery');
    const hasEmptyLocation = agvItems.some(item => !item.selectedLocation);

    if (hasEmptyLocation) {
        showNotify({ type: 'warning', message: '请为所有 AGV 配送的物料选择配送位置' });
        return;
    }

    const params = [];
    selectedRows.value.forEach(item => {
        params.push({
            stockOutPrepareLineId: item.id,
            deliveryMethod: item.deliveryMethod,
            positionEndNo: item.selectedLocation.value,
        });
    });

    console.log('提交参数:', params);
    await generateCFStockOut(params);
};


// 配送方式变更处理
const changeDeliveryMethod = (item, method) => {
    item.deliveryMethod = method;
    // 当选择人工配送时，清空配送位置
    if (method === 'Manual_Delivery') {
        item.selectedLocation = '';
    }
    console.log('配送方式变更:', item.inventoryName, item.deliveryMethod);
};


// 获取物料列表
const getList = async () => {
    loading.value = true;
    try {
        const params = {
            ...filterForm,
            userId: JSON.parse(localStorage.getItem('#LoginInfo')).userId,
        };
        const res = await list(params);
        loading.value = false;

        if (res.errorCode === 0) {
            if (res.datas && res.datas.length > 0) {
                const testData = res.datas;
                // ========== 测试数据模拟开始 ==========
                // const testData = res.datas.map((item, index) => {
                //     const types = ['人工配送', '强制AGV配送', '可选AGV配送'];
                //     return {
                //         ...item,
                //         // 循环分配不同的配送类型用于测试
                //         deliveryType: types[index % 3] || item.deliveryType,
                //     };
                // });
                // ========== 测试数据模拟结束 ==========

                // 保留已选中物料的配送方式设置
                materialList.value = testData.map(item => {
                    // 查找该物料是否在已选中列表中
                    const selectedItem = selectedRows.value.find(selected => selected.id === item.id);

                    if (selectedItem) {
                        // 如果已选中，保留其配送方式和位置设置，并更新 selectedRows 中的引用
                        const updatedItem = {
                            ...item,
                            deliveryMethod: selectedItem.deliveryMethod,
                            selectedLocation: selectedItem.selectedLocation,
                        };

                        // 更新 selectedRows 中的对应项，保持引用同步
                        const index = selectedRows.value.findIndex(row => row.id === item.id);
                        if (index !== -1) {
                            selectedRows.value[index] = updatedItem;
                        }

                        return updatedItem;
                    } else {
                        // 未选中，初始化为空
                        return {
                            ...item,
                            deliveryMethod: '',
                            selectedLocation: '',
                        };
                    }
                });
                pagination.total = materialList.value.length;
            } else {
                materialList.value = [];
            }
        } else {
            showNotify({ type: 'danger', message: res.errorMessage });
        }
    } catch (error) {
        loading.value = false;
        console.error('获取物料列表API调用失败:', error);
        showNotify({ type: 'danger', message: '获取物料列表API调用失败' });
        return;
    }
};
// 生成CF出库单
const generateCFStockOut = async params => {
    loading.value = true;
    try {
        const res = await createStockOut(params);

        if (res.errorCode === 0) {
            showNotify({ type: 'success', message: '领料完成' });
            selectedIds.value = [];
            selectedRows.value = [];
            // 显示完成确认弹窗
            completeModalVisible.value = true;
        } else {
            showNotify({ type: 'danger', message: res.errorMessage });
        }

    } catch (error) {
        console.error('生成CF出库单API调用失败:', error);
        showNotify({ type: 'danger', message: '生成CF出库单API调用失败' });
    } finally {
        loading.value = false;
    }
};

// 处理完成确认
const handleCompleteConfirm = () => {
    completeModalVisible.value = false;
    router.push('/home');
    // showToast('领料申请已完成，配送任务已创建！');
};

// 处理完成取消
const handleCompleteCancel = () => {
    completeModalVisible.value = false;
    // 留在当前页面，刷新列表
    getList();
};

// 获取仓库列表
const getWarehouse = async () => {
    try {
        const res = await getWarehouseList();

        if (res.errorCode === 0) {
            if (res.datas && res.datas.length > 0) {
                warehouseList.value = res.datas;
            } else {
                warehouseList.value = [];
            }
        } else {
            showNotify({ type: 'danger', message: res.errorMessage });
        }
    } catch (error) {
        console.error('获取仓库列表API调用失败:', error);
        showNotify({ type: 'danger', message: '获取仓库列表API调用失败' });
    } finally {
        loading.value = false;
    }
};
// 获取空闲货位
const getIdleLocator = async () => {
    try {
        const res = await queryIdleLocator();

        if (res.errorCode === 0) {
            if (res.datas && res.datas.length > 0) {
                locator.value = res.datas.map(item => {
                    return {
                        label: item.positionName,
                        value: item.positionNo,
                    };
                });
            } else {
                locator.value = [];
            }
        } else {
            showNotify({ type: 'warning', message: res.errorMessage });
        }
    } catch (error) {
        console.error('获取空闲货位API调用失败:', error);
        showNotify({ type: 'danger', message: '获取空闲货位API调用失败' });
    }
};

onMounted(() => {
    getWarehouse();
    getList();
    getIdleLocator();
});
</script>

<style scoped>
/* 页面容器 - 固定高度布局 */
.page-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: #f9fafb;
  overflow: hidden;
}

/* 主内容区 - 可滚动 */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

/* 页面标题 */
.page-title {
  margin-bottom: 1.5rem;
}

.page-title h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #111827;
  margin: 0;
}

/* 卡片容器 */
.card-container {
  flex: 1;
  background-color: white;
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* 卡片列表包装器（可滚动区域） */
.card-list-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  min-height: 0;
}

/* 卡片列表（单列布局） */
.card-list {
  display: flex;
  flex-direction: column;
  font-weight: 600;
}

.card-list > * {
  margin-bottom: 1rem;
}

.card-list > *:last-child {
  margin-bottom: 0;
}

/* 分页包装器（固定底部） */
.pagination-wrapper {
  padding: 0.5rem 1.5rem;
  border-top: 1px solid #e5e7eb;
  background-color: #fafafa;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

/* 底部操作按钮 */
.bottom-actions {
  position: sticky;
  bottom: 0;
  padding: 0 1rem 1rem 1rem;
  background-color: #f9fafb;
  display: flex;
  justify-content: flex-end;
  z-index: 10;
}

/* 筛选表单 */
.filter-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.filter-form > * {
  margin-right: 1rem;
  margin-bottom: 0.4rem;
}

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

.filter-item > * {
  margin-right: 0.5rem;
}

.filter-item > *:last-child {
  margin-right: 0;
}

.filter-label {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  color: #374151;
}

.filter-select {
  width: 200px;
  position: relative;
  z-index: 100;
}

.filter-input {
  width: 200px;
}

:deep(.filter-input .van-cell) {
  padding: 8px 12px !important;
  border: 1px solid #ccc !important;
  border-radius: 4px !important;
  background-color: white !important;
  min-height: 32px !important;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

:deep(.filter-input .van-cell::after) {
  display: none !important;
}

:deep(.filter-input .van-field__body) {
  border: none !important;
}

:deep(.filter-input .van-field__control) {
  font-size: 14px;
}

/* Vue Select 样式 */
:deep(.v-select) {
  font-size: 14px;
}

:deep(.v-select .vs__dropdown-toggle) {
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 4px 8px;
  min-height: 32px;
  background: white;
}

:deep(.v-select .vs__dropdown-menu) {
  z-index: 9999 !important;
  border: 1px solid #d1d5db;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

:deep(.v-select .vs__selected) {
  margin: 2px;
  padding: 0 4px;
}

:deep(.v-select .vs__search) {
  padding: 0;
  margin: 0;
}

:deep(.v-select .vs__actions) {
  padding: 0 4px;
}

.filter-buttons {
  display: flex;
}

.filter-buttons > * {
  margin-right: 0.5rem;
}

.filter-buttons > *:last-child {
  margin-right: 0;
}

/* 库存卡片样式 */
.inventory-card {
  cursor: pointer;
  transition: all 0.25s ease;
  border: 2px solid #e5e7eb;
  background-color: #ffffff;
  border-radius: 0.5rem;
}

.inventory-card:hover {
  border-color: #93c5fd;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
}

.inventory-card.selected-card {
  border-color: #3b82f6 !important;
  background-color: #eff6ff;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.2);
}

/* 卡片标题区域 */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 1rem 1.5rem;
}

.card-header > * {
  margin-right: 1.5rem;
}

.card-header > *:last-child {
  margin-right: 0;
}

.card-header-left {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.card-header-right {
  display: flex;
  align-items: center;
}

.card-header-right > * {
  margin-left: 1rem;
}

.card-header-right > *:first-child {
  margin-left: 0;
}

/* 卡片标题信息 */
.card-title-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card-title-info > * {
  margin-bottom: 0.25rem;
}

.card-title-info > *:last-child {
  margin-bottom: 0;
}

.card-name {
  font-size: 1.2rem;
  font-weight: 600;
  color: #111827;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-subtitle {
  font-size: 0.875rem;
  color: #6b7280;
  line-height: 1.4;
}

/* 卡片位置信息 */
.card-location {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  background-color: #f3f4f6;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  color: #374151;
  white-space: nowrap;
}

.card-location i {
  color: #3b82f6;
}

/* 自定义头像 */
.custom-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background-color: #3b82f6;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  flex-shrink: 0;
}

/* 卡片配送方式选择区域 */
.card-delivery-section {
  padding: 1rem 1.5rem;
  background-color: #f8fafc;
  border-top: 1px solid #e5e7eb;
}

.delivery-options {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
}

.delivery-options > * {
  margin-right: 2rem;
  margin-bottom: 1rem;
}

.delivery-option-item {
  display: flex;
  align-items: center;
}

.delivery-option-item > * {
  margin-right: 0.75rem;
}

.delivery-option-item > *:last-child {
  margin-right: 0;
}

.delivery-location-item {
  display: flex;
  align-items: center;
}

.delivery-location-item > * {
  margin-right: 0.75rem;
}

.delivery-location-item > *:last-child {
  margin-right: 0;
}

.option-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  min-width: 80px;
  margin: 0;
}

/* 配送方式按钮容器 */
.delivery-method-buttons {
  display: flex;
  border-radius: 4px;
  overflow: hidden;
}

/* 配送方式按钮样式 */
.delivery-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 16px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid #d1d5db;
  background-color: white;
  color: #374151;
  cursor: pointer;
  transition: all 0.2s;
  height: 32px;
  min-width: 110px;
}

.delivery-btn > * {
  margin-right: 6px;
}

.delivery-btn > *:last-child {
  margin-right: 0;
}

.delivery-btn:first-child {
  border-radius: 4px 0 0 4px;
  border-right: none;
}

.delivery-btn:last-child {
  border-radius: 0 4px 4px 0;
}

.delivery-btn i {
  font-size: 14px;
}

/* AGV配送按钮 - 蓝色 */
.delivery-btn.agv-btn.active {
  background-color: #3b82f6;
  color: white;
  border-color: #3b82f6;
}

.delivery-btn.agv-btn:hover:not(.disabled):not(.active) {
  background-color: #eff6ff;
  border-color: #3b82f6;
  color: #3b82f6;
}

/* 人工配送按钮 - 蓝色 */
.delivery-btn.manual-btn.active {
  background-color: #3b82f6;
  color: white;
  border-color: #3b82f6;
}

.delivery-btn.manual-btn:hover:not(.disabled):not(.active) {
  background-color: #f3f4f6;
  border-color: #9ca3af;
}

/* 禁用状态 */
.delivery-btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.delivery-type-badge {
  margin-left: 0.75rem;
  padding: 0.25rem 0.625rem;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
}

/* 人工配送徽章 - 灰色 */
.delivery-type-badge.badge-manual {
  background-color: #eff6ff;
  color: #4b5563;
}

/* 强制AGV配送徽章 - 蓝色 */
.delivery-type-badge.badge-agv-force {
  background-color: #82b0ec;
  color: #1e40af;
}

/* 可选AGV配送徽章 - 绿色 */
.delivery-type-badge.badge-agv-optional {
  background-color: #adf8d1;
  color: #065f46;
}

/* 配送位置选择器样式 */
.location-select {
  width: 200px;
}

/* 按钮样式 */
:deep(.van-button--primary) {
  background-color: #3b82f6;
  border-color: #3b82f6;
}

:deep(.van-button--primary:active) {
  background-color: #2563eb;
  border-color: #2563eb;
}

.complete-btn {
  background-color: #10b981 !important;
  border-color: #10b981 !important;
  width: auto;
  padding: 0 24px;
}

:deep(.complete-btn.van-button--primary) {
  background-color: #10b981 !important;
  border-color: #10b981 !important;
}

:deep(.complete-btn.van-button--primary:active) {
  background-color: #059669 !important;
  border-color: #059669 !important;
}

:deep(.van-button--disabled) {
  opacity: 0.5;
  cursor: not-allowed;
}

:deep(.van-cell) {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 6px 8px !important;
}

:deep(.v-select .vs__dropdown-toggle) {
  padding: 6px 8px !important;
}

/* 全选控制栏 */
.select-all-bar {
  background-color: white;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
}

.select-all-text {
  font-size: 0.95rem;
  color: #374151;
  font-weight: 500;
}

/* 大弹窗样式，适合触摸屏 */
:deep(.large-dialog) {
  width: 85vw !important;
  max-width: 600px !important;
  border-radius: 16px !important;
}

:deep(.large-dialog .van-dialog__header) {
  padding: 2rem 1.5rem 1rem !important;
  font-size: 1.5rem !important;
  font-weight: 700 !important;
  color: #111827 !important;
}

.large-dialog-content {
  padding: 1.5rem 2rem 2.5rem !important;
}

.large-dialog-content p {
  margin: 0 0 1rem 0;
  font-size: 1.25rem !important;
  line-height: 1.8 !important;
  color: #374151 !important;
  text-align: center;
}

.large-dialog-content p:last-child {
  margin-bottom: 0;
}

.large-dialog-content .dialog-subtitle {
  font-size: 1.125rem !important;
  color: #6b7280 !important;
}

:deep(.large-dialog .van-dialog__footer) {
  padding: 1rem 1.5rem 1.5rem !important;
  display: flex;
}

:deep(.large-dialog .van-dialog__footer > *) {
  margin-right: 1rem;
}

:deep(.large-dialog .van-dialog__footer > *:last-child) {
  margin-right: 0;
}

:deep(.large-dialog .van-dialog__cancel),
:deep(.large-dialog .van-dialog__confirm) {
  flex: 1;
  height: 56px !important;
  font-size: 1.125rem !important;
  font-weight: 600 !important;
  border-radius: 8px !important;
  border: none !important;
}

:deep(.large-dialog .van-dialog__cancel) {
  background-color: #f3f4f6 !important;
  color: #374151 !important;
}

:deep(.large-dialog .van-dialog__cancel:active) {
  background-color: #e5e7eb !important;
}

:deep(.large-dialog .van-dialog__confirm) {
  background-color: #10b981 !important;
  color: white !important;
}

:deep(.large-dialog .van-dialog__confirm:active) {
  background-color: #059669 !important;
}

/* 大弹窗蒙层 */
:deep(.van-overlay) {
  background-color: rgba(0, 0, 0, 0.6) !important;
}
</style>
