src/views/procurementManagement/procurementLedger/index.vue
@@ -42,6 +42,20 @@
                            clearable
                            @change="changeDaterange" />
          </el-form-item>
          <el-form-item label="入库状态:">
            <el-select v-model="searchForm.stockInStatus"
                       placeholder="请选择"
                       clearable
                       style="width: 240px"
                       @change="handleQuery">
              <el-option label="待入库"
                         value="待入库" />
              <el-option label="入库中"
                         value="入库中" />
              <el-option label="完全入库"
                         value="完全入库" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary"
                       @click="handleQuery"> 搜索
@@ -92,6 +106,16 @@
                               prop="specificationModel" />
              <el-table-column label="单位"
                               prop="unit" />
                               <el-table-column label="入库审核状态"
                               prop="stockInApprovalStatus"
                               width="120">
                <template #default="scope">
                  <el-tag :type="getStockInApprovalStatusType(scope.row.stockInApprovalStatus)"
                          size="small">
                    {{ scope.row.stockInApprovalStatus || '--' }}
                  </el-tag>
                </template>
              </el-table-column>
              <el-table-column label="数量"
                               prop="quantity" />
              <el-table-column label="可用数量"
@@ -143,6 +167,17 @@
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="入库状态"
                         prop="stockInStatus"
                         width="100"
                         show-overflow-tooltip>
          <template #default="scope">
            <el-tag :type="getStockInStatusType(scope.row.stockInStatus)"
                    size="small">
              {{ scope.row.stockInStatus || '--' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="签订日期"
                         prop="executionDate"
                         width="100"
@@ -176,7 +211,7 @@
            <el-button link
                       type="primary"
                       @click="openForm('edit', scope.row)"
                       :disabled="scope.row.approvalStatus !== 1 && scope.row.approvalStatus !== 4">编辑
                       :disabled="scope.row.stockInStatus === '完全入库'">编辑
            </el-button>
            <el-button link
                       type="primary"
@@ -403,6 +438,16 @@
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="入库审核状态"
                           prop="stockInApprovalStatus"
                           width="120">
            <template #default="scope">
              <el-tag :type="getStockInApprovalStatusType(scope.row.stockInApprovalStatus)"
                      size="small">
                {{ scope.row.stockInApprovalStatus || '--' }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column fixed="right"
                           label="操作"
                           min-width="60"
@@ -410,7 +455,8 @@
            <template #default="scope">
              <el-button link
                         type="primary"
                         @click="openProductForm('edit', scope.row, scope.$index)">编辑
                         @click="openProductForm('edit', scope.row, scope.$index)"
                         :disabled="scope.row.stockInApprovalStatus === '完全入库'">编辑
              </el-button>
            </template>
          </el-table-column>
@@ -653,6 +699,7 @@
    getCurrentInstance,
    nextTick,
  } from "vue";
  import { useRoute } from "vue-router";
  import { Search, Delete } from "@element-plus/icons-vue";
  import { ElMessageBox, ElMessage } from "element-plus";
  import { userListNoPage } from "@/api/system/user.js";
@@ -682,6 +729,7 @@
  );
  const { proxy } = getCurrentInstance();
  const route = useRoute();
  const { tax_rate } = proxy.useDict("tax_rate");
  const tableData = ref([]);
  const productData = ref([]);
@@ -693,6 +741,7 @@
  const salesContractList = ref([]);
  const supplierList = ref([]);
  const tableLoading = ref(false);
  const recordId = ref();
  const fileListDialogVisible = ref(false);
  const page = reactive({
    current: 1,
@@ -709,6 +758,7 @@
  // 订单审批状态显示文本
  const approvalStatusText = {
    0: "草稿",
    1: "待审核",
    2: "审批中",
    3: "审批通过",
@@ -718,10 +768,31 @@
  // 获取审批状态标签类型
  const getApprovalStatusType = status => {
    const typeMap = {
      0: "info", // 待审核 - 灰色
      1: "info", // 待审核 - 灰色
      2: "warning", // 审批中 - 橙色
      3: "success", // 审批通过 - 绿色
      4: "danger", // 审批失败 - 红色
    };
    return typeMap[status] || "";
  };
  // 获取入库状态标签类型
  const getStockInStatusType = status => {
    const typeMap = {
      "待入库": "info", // 待入库 - 灰色
      "入库中": "warning", // 入库中 - 橙色
      "完全入库": "success", // 完全入库 - 绿色
    };
    return typeMap[status] || "";
  };
  // 获取入库审核状态标签类型
  const getStockInApprovalStatusType = status => {
    const typeMap = {
      "待入库": "info", // 待入库 - 灰色
      "入库中": "warning", // 入库中 - 橙色
      "完全入库": "success", // 完全入库 - 绿色
    };
    return typeMap[status] || "";
  };
@@ -869,13 +940,10 @@
  const { form, rules } = toRefs(data);
  const { form: searchForm } = useFormData({
    ...data.searchForm,
    // 设置录入日期范围为当天
    entryDate: [
      dayjs().startOf("day").format("YYYY-MM-DD"),
      dayjs().endOf("day").format("YYYY-MM-DD"),
    ],
    entryDateStart: dayjs().startOf("day").format("YYYY-MM-DD"),
    entryDateEnd: dayjs().endOf("day").format("YYYY-MM-DD"),
    // 录入日期不设置默认值
    entryDate: null,
    entryDateStart: undefined,
    entryDateEnd: undefined,
  });
  // 产品表单弹框数据
@@ -1205,10 +1273,10 @@
  };
  // 打开弹框
  const openForm = async (type, row) => {
    // 编辑时检查审核状态,只有待审核(1)和审批失败(4)才能编辑
    // 编辑时检查入库状态,完全入库时不能编辑
    if (type === "edit" && row) {
      if (row.approvalStatus !== 1 && row.approvalStatus !== 4) {
        proxy.$modal.msgWarning("只有待审核和审批失败状态的记录才能编辑");
      if (row.stockInStatus === '完全入库') {
        proxy.$modal.msgWarning("完全入库状态的记录不能编辑");
        return;
      }
    }
@@ -1255,9 +1323,11 @@
        currentId.value = row.id;
        try {
          const purchaseRes = await getPurchaseById({ id: row.id, type: 2 });
          form.value = { ...purchaseRes };
          productData.value = purchaseRes.productData || [];
          form.value = { ...purchaseRes, stockInStatus: row.stockInStatus };
          fileList.value = purchaseRes.storageBlobVOS || [];
          // 使用 productList 接口获取产品列表,以获取入库审核状态
          const productRes = await productList({ salesLedgerId: row.id, type: 2 });
          productData.value = productRes.data || [];
        } catch (error) {
          console.error("加载采购台账数据失败:", error);
          proxy.$modal.msgError("加载数据失败");
@@ -1374,6 +1444,12 @@
  };
  // 打开产品弹框
  const openProductForm = async (type, row, index) => {
    // 编辑时检查产品入库审核状态,完全入库时不能编辑
    if (type === "edit" && row && row.stockInApprovalStatus === '完全入库') {
      proxy.$modal.msgWarning("完全入库状态的产品不能编辑");
      return;
    }
    productOperationType.value = type;
    productOperationIndex.value = index;
    productForm.value = {};
@@ -1544,8 +1620,9 @@
    addOrUpdateSalesLedgerProduct(productForm.value).then(res => {
      proxy.$modal.msgSuccess("提交成功");
      closeProductDia();
      getPurchaseById({ id: currentId.value, type: 2 }).then(res => {
        productData.value = res.productData;
      // 使用 productList 接口刷新产品列表,以获取入库审核状态
      productList({ salesLedgerId: currentId.value, type: 2 }).then(res => {
        productData.value = res.data || [];
      });
    });
  };
@@ -1555,15 +1632,19 @@
      proxy.$modal.msgWarning("请选择数据");
      return;
    }
    // 检查选中的产品中是否有完全入库的
    const hasFullyStocked = productSelectedRows.value.some(
      row => row.stockInApprovalStatus === '完全入库'
    );
    if (hasFullyStocked) {
      proxy.$modal.msgWarning("选中的产品中包含完全入库的产品,无法删除");
      return;
    }
    if (operationType.value === "add") {
      productSelectedRows.value.forEach(selectedRow => {
        const index = productData.value.findIndex(
          product => product.id === selectedRow.id
        );
        if (index !== -1) {
          productData.value.splice(index, 1);
        }
      });
      productData.value = productData.value.filter(
        item => !productSelectedRows.value.includes(item)
      );
      productSelectedRows.value = [];
    } else {
      let ids = [];
      if (productSelectedRows.value.length > 0) {
@@ -1578,8 +1659,9 @@
          delProduct(ids).then(res => {
            proxy.$modal.msgSuccess("删除成功");
            closeProductDia();
            getPurchaseById({ id: currentId.value, type: 2 }).then(res => {
              productData.value = res.productData;
            // 使用 productList 接口刷新产品列表,以获取入库审核状态
            productList({ salesLedgerId: currentId.value, type: 2 }).then(res => {
              productData.value = res.data || [];
            });
          });
        })
@@ -1838,7 +1920,16 @@
  };
  onMounted(() => {
    getList();
    // 检查URL参数中是否有purchaseContractNumber,有则设置到搜索条件
    if (route.query.purchaseContractNumber) {
      // 使用setTimeout确保searchForm已经初始化
      setTimeout(() => {
        searchForm.purchaseContractNumber = route.query.purchaseContractNumber;
        getList();
      }, 0);
    } else {
      getList();
    }
    getTemplateList();
  });
</script>