gaoluyang
2 天以前 a868d0b4a9b892bd921b5261757b4eced153d9ce
进销存升级
1.销售台账页面代码重构
2.发货台账页面联调
已修改2个文件
208 ■■■■ 文件已修改
src/views/salesManagement/deliveryLedger/index.vue 122 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/salesManagement/salesLedger/index.vue 86 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/salesManagement/deliveryLedger/index.vue
@@ -32,15 +32,33 @@
        <el-table-column align="center" type="selection" width="55" />
        <el-table-column align="center" label="序号" type="index" width="60" />
        <el-table-column label="销售订单" prop="salesContractNo" show-overflow-tooltip />
        <el-table-column label="发货订单号" prop="shippingNo" show-overflow-tooltip />
        <el-table-column label="客户名称" prop="customerName" show-overflow-tooltip />
        <el-table-column label="发货时间" prop="shippingDate" show-overflow-tooltip />
        <el-table-column label="发货车牌号" prop="shippingCarNumber" show-overflow-tooltip />
        <el-table-column label="快递公司" prop="expressCompany" show-overflow-tooltip />
        <el-table-column label="快递单号" prop="expressNumber" show-overflow-tooltip />
        <el-table-column label="审核状态" prop="status" align="center" width="120">
          <template #default="scope">
            <el-tag :type="getApprovalStatusType(scope.row.status)">
              {{ getApprovalStatusText(scope.row.status) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="150" align="center">
          <template #default="scope">
            <el-button link type="primary" size="small" @click="openForm('edit', scope.row)">编辑</el-button>
            <el-button link type="danger" size="small" @click="handleDeleteSingle(scope.row)">删除</el-button>
            <el-button
              link
              type="primary"
              size="small"
              :disabled="!isApproved(scope.row.status)"
              @click="openForm('edit', scope.row)">编辑</el-button>
            <el-button
              link
              type="danger"
              size="small"
              :disabled="!isApproved(scope.row.status)"
              @click="handleDeleteSingle(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
@@ -266,6 +284,12 @@
// 打开弹框
const openForm = async (type, row) => {
  // 编辑时检查审核状态
  if (type === 'edit' && row && !isApproved(row.status)) {
    proxy.$modal.msgWarning("只能编辑审核通过的数据");
    return;
  }
  operationType.value = type;
  const baseUrl = import.meta.env.VITE_APP_BASE_API;
  
@@ -401,13 +425,19 @@
// 批量删除
const handleDelete = () => {
  let ids = [];
  if (selectedRows.value.length > 0) {
    ids = selectedRows.value.map((item) => item.id);
  } else {
  if (selectedRows.value.length === 0) {
    proxy.$modal.msgWarning("请选择数据");
    return;
  }
  // 检查选中的行是否都是"审核通过"状态
  const notApprovedRows = selectedRows.value.filter(row => !isApproved(row.status));
  if (notApprovedRows.length > 0) {
    proxy.$modal.msgWarning("只能删除审核通过的数据");
    return;
  }
  const ids = selectedRows.value.map((item) => item.id);
  ElMessageBox.confirm("选中的内容将被删除,是否确认删除?", "删除", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
@@ -426,6 +456,12 @@
// 单个删除
const handleDeleteSingle = (row) => {
  // 检查是否为"审核通过"状态
  if (!isApproved(row.deliveryLedger)) {
    proxy.$modal.msgWarning("只能删除审核通过的数据");
    return;
  }
  ElMessageBox.confirm("此操作将删除该记录,是否确认?", "删除", {
    confirmButtonText: "确认",
    cancelButtonText: "取消",
@@ -525,6 +561,80 @@
  }
};
// 获取审核状态文本
const getApprovalStatusText = (status) => {
  if (status === null || status === undefined || status === '') {
    return '待审核';
  }
  // 如果是数字
  if (typeof status === 'number') {
    const statusMap = {
      0: '待审核',
      1: '审核中',
      2: '审核拒绝',
      3: '审核通过'
    };
    return statusMap[status] || '待审核';
  }
  // 如果是字符串,直接返回或映射
  const statusStr = String(status).trim();
  const statusTextMap = {
    '待审核': '待审核',
    '审核中': '审核中',
    '审核拒绝': '审核拒绝',
    '审核通过': '审核通过',
    '0': '待审核',
    '1': '审核中',
    '2': '审核拒绝',
    '3': '审核通过'
  };
  return statusTextMap[statusStr] || statusStr || '待审核';
};
// 获取审核状态标签类型(颜色)
const getApprovalStatusType = (status) => {
  if (status === null || status === undefined || status === '') {
    return 'info';
  }
  // 如果是数字
  if (typeof status === 'number') {
    const typeMap = {
      0: 'info',      // 待审核 - 灰色
      1: 'warning',   // 审核中 - 黄色
      2: 'danger',    // 审核拒绝 - 红色
      3: 'success'    // 审核通过 - 绿色
    };
    return typeMap[status] || 'info';
  }
  // 如果是字符串
  const statusStr = String(status).trim();
  const typeTextMap = {
    '待审核': 'info',
    '审核中': 'warning',
    '审核拒绝': 'danger',
    '审核通过': 'success',
    '0': 'info',
    '1': 'warning',
    '2': 'danger',
    '3': 'success'
  };
  return typeTextMap[statusStr] || 'info';
};
// 检查审核状态是否为"审核通过"
const isApproved = (status) => {
  if (status === null || status === undefined || status === '') {
    return false;
  }
  // 如果是数字,3 表示审核通过
  if (typeof status === 'number') {
    return status === 3;
  }
  // 如果是字符串
  const statusStr = String(status).trim();
  return statusStr === '审核通过' || statusStr === '3';
};
onMounted(() => {
  getList();
});
src/views/salesManagement/salesLedger/index.vue
@@ -42,23 +42,27 @@
      <el-table :data="tableData" border v-loading="tableLoading" @selection-change="handleSelectionChange"
        :expand-row-keys="expandedRowKeys" :row-key="(row) => row.id" show-summary style="width: 100%"
        :summary-method="summarizeMainTable" @expand-change="expandChange" height="calc(100vh - 18.5em)">
        <el-table-column align="center" type="selection" width="55" />
        <el-table-column type="expand">
        <el-table-column align="center" type="selection" width="55" fixed="left"/>
        <el-table-column type="expand" width="60" fixed="left">
          <template #default="props">
            <el-table :data="props.row.children" border show-summary :summary-method="summarizeChildrenTable">
              <el-table-column align="center" label="序号" type="index" width="60" />
              <el-table-column align="center" label="序号" type="index"/>
              <el-table-column label="产品大类" prop="productCategory" />
              <el-table-column label="规格型号" prop="specificationModel" />
              <el-table-column label="单位" prop="unit" />
              <el-table-column label="产品状态" width="100px" align="center">
                            <el-table-column label="产品状态"
                                                             width="100px"
                                                             align="center">
                <template #default="scope">
                  <el-tag v-if="scope.row.approveStatus === 0" type="info">未出库</el-tag>
                  <el-tag v-if="scope.row.approveStatus === 1" type="success">已出库</el-tag>
                  <el-tag v-if="scope.row.approveStatus === 2" type="warning">审核中</el-tag>
                  <el-tag v-if="scope.row.approveStatus === 3" type="success">审核成功</el-tag>
                  <el-tag v-if="scope.row.approveStatus === 4" type="danger">审核失败</el-tag>
                                    <el-tag v-if="scope.row.approveStatus === 1"
                                                    type="success">充足</el-tag>
                                    <el-tag v-else
                                                    type="danger">不足</el-tag>
                </template>
              </el-table-column>
                            <el-table-column label="发货状态" prop="shippingStatus" width="140" align="center" show-overflow-tooltip />
                            <el-table-column label="快递公司" prop="expressCompany" show-overflow-tooltip />
                            <el-table-column label="快递单号" prop="expressNumber" show-overflow-tooltip />
              <el-table-column label="发货车牌" minWidth="100px" align="center">
                <template #default="scope">
                  <div>
@@ -67,11 +71,14 @@
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="发货日期" minWidth="100px" align="center">
                            <el-table-column label="发货日期"
                                                             minWidth="100px"
                                                             align="center">
                <template #default="scope">
                  <div>
                    <div v-if="scope.row.shippingDate">{{ scope.row.shippingDate }}</div>
                    <el-tag v-else type="info">未发货</el-tag>
                                        <el-tag v-else
                                                        type="info">-</el-tag>
                  </div>
                </template>
              </el-table-column>
@@ -83,7 +90,14 @@
            <!--操作-->
              <el-table-column Width="60px" label="操作" align="center">
                <template #default="scope">
                  <el-button :disabled="scope.row.approveStatus!==2 || scope.row.approveStatus!==5" link type="primary" size="small" @click="openDeliveryForm(scope.row)">发货</el-button>
                  <el-button
                    link
                    type="primary"
                    size="small"
                    :disabled="scope.row.approveStatus !== 1 || !!scope.row.shippingDate || !!scope.row.shippingCarNumber"
                    @click="openDeliveryForm(scope.row)">
                    发货
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
@@ -113,8 +127,8 @@
      <pagination v-show="total > 0" :total="total" layout="total, sizes, prev, pager, next, jumper"
        :page="page.current" :limit="page.size" @pagination="paginationChange" />
    </div>
    <el-dialog v-model="dialogFormVisible" :title="operationType === 'add' ? '新增销售台账页面' : '编辑销售台账页面'" width="70%"
      @close="closeDia">
    <FormDialog v-model="dialogFormVisible" :title="operationType === 'add' ? '新增销售台账页面' : '编辑销售台账页面'" :width="'70%'"
      :operation-type="operationType" @close="closeDia" @confirm="submitForm" @cancel="closeDia">
      <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
        <el-row :gutter="30">
          <el-col :span="12">
@@ -372,6 +386,12 @@
                </el-row>
            </el-form>
        </FormDialog>
        <!-- 附件列表弹窗 -->
        <FileListDialog
            ref="fileListRef"
            v-model="fileListDialogVisible"
            title="附件列表"
        />
        <!-- 打印预览弹窗 -->
        <el-dialog
            v-model="printPreviewVisible"
@@ -811,7 +831,7 @@
    const params = { ...rest, ...page };
    // 移除录入日期的默认值设置,只保留范围日期字段
    delete params.entryDate;
    ledgerListPage(params)
    return ledgerListPage(params)
        .then((res) => {
            tableLoading.value = false;
            tableData.value = res.records;
@@ -819,6 +839,7 @@
                item.children = [];
            });
            total.value = res.total;
            return res;
        })
        .catch(() => {
            tableLoading.value = false;
@@ -1833,13 +1854,21 @@
    getSalesLedgerWithProducts({ id: row.id, type: 1 }).then((res) => {
        if (fileListRef.value) {
            fileListRef.value.open(res.salesLedgerFiles)
            fileListDialogVisible.value = true
        }
    });
}
// 打开发货弹框
const openDeliveryForm = (row) => {
    // 校验:只有产品状态为充足且未发货时才能发货
    if (row.approveStatus !== 1) {
        proxy.$modal.msgWarning("产品状态不足,无法发货");
        return;
    }
    if (row.shippingDate || row.shippingCarNumber) {
        proxy.$modal.msgWarning("该产品已发货,无法重复发货");
        return;
    }
    currentDeliveryRow.value = row;
  deliveryForm.value = {
    type: "货车",
@@ -1861,8 +1890,11 @@
        return;
      }
      const approveUserIds = approverNodes.value.map(node => node.userId).join(",");
      // 保存当前展开的行ID,以便发货后重新加载子表格数据
      const currentExpandedKeys = [...expandedRowKeys.value];
      const salesLedgerId = currentDeliveryRow.value.salesLedgerId;
      addShippingInfo({
        salesLedgerId: currentDeliveryRow.value.salesLedgerId,
        salesLedgerId: salesLedgerId,
        salesLedgerProductId: currentDeliveryRow.value.id,
        type: deliveryForm.value.type,
                approveUserIds,
@@ -1870,7 +1902,25 @@
        .then(() => {
          proxy.$modal.msgSuccess("发货成功");
          closeDeliveryDia();
          getList();
          // 刷新主表数据
          getList().then(() => {
            // 如果之前有展开的行,重新加载这些行的子表格数据
            if (currentExpandedKeys.length > 0) {
              // 使用 Promise.all 并行加载所有展开行的子表格数据
              const loadPromises = currentExpandedKeys.map(ledgerId => {
                return productList({ salesLedgerId: ledgerId, type: 1 }).then((res) => {
                  const index = tableData.value.findIndex((item) => item.id === ledgerId);
                  if (index > -1) {
                    tableData.value[index].children = res.data;
                  }
                });
              });
              Promise.all(loadPromises).then(() => {
                // 恢复展开状态
                expandedRowKeys.value = currentExpandedKeys;
              });
            }
          });
        })
    }
  });