src/views/salesManagement/salesLedger/index.vue
@@ -42,7 +42,7 @@
        <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 :data="props.row.children" border show-summary :summary-method="(param) => summarizeChildrenTable(param, props.row)">
              <el-table-column align="center" label="序号" type="index"/>
              <el-table-column label="产品大类" prop="productCategory" />
              <el-table-column label="规格型号" prop="specificationModel" />
@@ -89,9 +89,9 @@
              </el-table-column>
              <el-table-column label="数量" prop="quantity" />
              <el-table-column label="税率(%)" prop="taxRate" />
              <el-table-column label="含税单价(元)" prop="taxInclusiveUnitPrice" :formatter="formattedNumber" />
              <el-table-column label="含税总价(元)" prop="taxInclusiveTotalPrice" :formatter="formattedNumber" />
              <el-table-column label="不含税总价(元)" prop="taxExclusiveTotalPrice" :formatter="formattedNumber" />
              <el-table-column label="含税单价(元)" prop="taxInclusiveUnitPrice" :formatter="sensitiveAmountFormatter" />
              <el-table-column label="含税总价(元)" prop="taxInclusiveTotalPrice" :formatter="sensitiveAmountFormatter" />
              <el-table-column label="不含税总价(元)" prop="taxExclusiveTotalPrice" :formatter="sensitiveAmountFormatter" />
            <!--操作-->
              <el-table-column Width="60px" label="操作" align="center">
                <template #default="scope">
@@ -122,7 +122,7 @@
        <el-table-column label="备注" prop="remarks" width="200" show-overflow-tooltip />
        <el-table-column fixed="right" label="操作" width="130" align="center">
          <template #default="scope">
            <el-button link type="primary" @click="openForm('edit', scope.row)" :disabled="!scope.row.isEdit || scope.row.hasProductionRecord">编辑</el-button>
            <el-button link type="primary" @click="openForm('edit', scope.row)" :disabled="!scope.row.isEdit || scope.row.hasProductionRecord || !canEditLedger(scope.row)">编辑</el-button>
            <el-button link type="primary" @click="downLoadFile(scope.row)">附件</el-button>
          </template>
        </el-table-column>
@@ -674,6 +674,7 @@
import useFormData from "@/hooks/useFormData.js";
import dayjs from "dayjs";
import { getCurrentDate } from "@/utils/index.js";
import {listCustomerPrivatePool} from "@/api/basicData/customerFile.js";
const userStore = useUserStore();
const { proxy } = getCurrentInstance();
@@ -923,7 +924,49 @@
   });
};
const formattedNumber = (row, column, cellValue) => {
   if (cellValue === undefined || cellValue === null || cellValue === "") {
      return "0.00";
   }
   return parseFloat(cellValue).toFixed(2);
};
const findLedgerRecordByRow = (row) => {
   if (!row) return null;
   if (
      row.maintainer !== undefined ||
      row.maintainerName !== undefined ||
      row.entryPerson !== undefined ||
      row.entryPersonName !== undefined
   ) {
      return row;
   }
   if (row.salesLedgerId !== undefined && row.salesLedgerId !== null) {
      return tableData.value.find((item) => String(item.id) === String(row.salesLedgerId)) || null;
   }
   return null;
};
const isCurrentUserMaintainer = (row) => {
   const ledgerRecord = findLedgerRecordByRow(row);
   if (!ledgerRecord) return true;
   const currentUserId = String(userStore.id ?? "");
   const currentNickName = String(userStore.nickName ?? "").trim();
   const maintainerId = ledgerRecord.maintainerId ?? ledgerRecord.entryPerson;
   const maintainerName =
      ledgerRecord.maintainerName ?? ledgerRecord.maintainer ?? ledgerRecord.entryPersonName;
   if (maintainerId !== undefined && maintainerId !== null && String(maintainerId) !== "") {
      return String(maintainerId) === currentUserId;
   }
   if (maintainerName !== undefined && maintainerName !== null && String(maintainerName).trim() !== "") {
      return String(maintainerName).trim() === currentNickName;
   }
   return true;
};
const canEditLedger = (row) => isCurrentUserMaintainer(row);
const canDeleteLedger = (row) => isCurrentUserMaintainer(row);
const sensitiveAmountFormatter = (row, column, cellValue) => {
   if (!isCurrentUserMaintainer(row)) {
      return "*****";
   }
   return formattedNumber(row, column, cellValue);
};
// 获取tree子数据
const getModels = (value) => {
@@ -1038,7 +1081,19 @@
   ]);
};
// 子表合计方法
const summarizeChildrenTable = (param) => {
const summarizeChildrenTable = (param, parentRow) => {
   if (!isCurrentUserMaintainer(parentRow)) {
      const { columns } = param;
      return columns.map((column, index) => {
         if (index === 0) {
            return "合计";
         }
         if (["taxInclusiveUnitPrice", "taxInclusiveTotalPrice", "taxExclusiveTotalPrice"].includes(column.property)) {
            return "*****";
         }
         return "";
      });
   }
   return proxy.summarizeTable(param, [
      "taxInclusiveUnitPrice",
      "taxInclusiveTotalPrice",
@@ -1047,14 +1102,18 @@
};
// 打开弹框
const openForm = async (type, row) => {
   if (type === "edit" && row && !canEditLedger(row)) {
      proxy.$modal.msgWarning("当前系统登录人不是维护人,不能编辑数据");
      return;
   }
   operationType.value = type;
   form.value = {};
   productData.value = [];
   selectedQuotation.value = null;
   let userLists = await userListNoPage();
   userList.value = userLists.data;
   customerList().then((res) => {
      customerOption.value = res;
   listCustomerPrivatePool({current: -1,size:-1}).then((res) => {
      customerOption.value = res.data.records;
   });
   form.value.entryPerson = userStore.id;
   if (type === "add") {
@@ -1090,8 +1149,9 @@
   // 先确保客户列表已加载,便于后续回填 customerId
   if (!customerOption.value || customerOption.value.length === 0) {
      try {
         const res = await customerList();
         customerOption.value = res;
         listCustomerPrivatePool({current: -1,size:-1}).then((res) => {
            customerOption.value = res.data.records;
         });
      } catch (e) {
         // ignore,允许用户后续手动选择客户
      }
@@ -1430,6 +1490,11 @@
      proxy.$modal.msgWarning("请选择数据");
      return;
   }
   const unauthorizedRows = selectedRows.value.filter((row) => !canDeleteLedger(row));
   if (unauthorizedRows.length > 0) {
      proxy.$modal.msgWarning("当前登录用户不是录入人,不能删除该数据");
      return;
   }
   const ids = selectedRows.value.map((item) => item.id);
   // 检查是否有已进行发货或发货完成的销售订单,若有则不允许删除