src/views/salesManagement/salesLedger/index.vue
@@ -37,12 +37,12 @@
        </div>
      </div>
      <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%"
        :expand-row-keys="expandedRowKeys" :row-key="(row) => row.id" :row-class-name="tableRowClassName" 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" 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" />
@@ -51,10 +51,12 @@
                                              width="100px"
                                              align="center">
                <template #default="scope">
                           <el-tag v-if="scope.row.approveStatus === 1"
                           <el-tag v-if="scope.row.approveStatus === 1 && (!scope.row.shippingDate || !scope.row.shippingCarNumber)"
                                       type="success">充足</el-tag>
                           <el-tag v-else
                                       type="danger">不足</el-tag>
                           <el-tag v-else-if="scope.row.approveStatus === 0 && (scope.row.shippingDate || scope.row.shippingCarNumber)"
                                       type="success">已出库</el-tag>
                           <el-tag v-else type="danger">不足</el-tag>
                </template>
              </el-table-column>
                     <el-table-column label="发货状态" width="140" align="center">
@@ -87,16 +89,15 @@
              </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">
                  <el-button 
                    link 
                    type="primary"
                    size="small"
                    type="primary"
                    :disabled="!canShip(scope.row)"
                    @click="openDeliveryForm(scope.row)">
                    发货
@@ -117,12 +118,12 @@
        <el-table-column label="录入人" prop="entryPersonName" width="100" show-overflow-tooltip />
        <el-table-column label="录入日期" prop="entryDate" width="120" show-overflow-tooltip />
        <el-table-column label="签订日期" prop="executionDate" width="120" show-overflow-tooltip />
        <el-table-column fixed="right" label="操作" min-width="100" align="center">
        <el-table-column label="交付日期" prop="deliveryDate" width="120" show-overflow-tooltip />
        <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" size="small" @click="openForm('edit', scope.row)">编辑</el-button>
<!--            <el-button link type="primary" size="small" @click="openForm('view', scope.row)">详情</el-button>-->
            <el-button link type="primary" size="small" @click="downLoadFile(scope.row)">附件</el-button>
<!--            <el-button link type="primary" size="small" @click="openDeliveryForm(scope.row)">发货</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>
      </el-table>
@@ -148,7 +149,7 @@
          </el-col>
          <el-col :span="12">
            <el-form-item label="业务员:" prop="salesman">
              <el-select v-model="form.salesman" placeholder="请选择" clearable :disabled="operationType === 'view'">
              <el-select v-model="form.salesman" placeholder="请选择" clearable :disabled="operationType === 'view'" filterable>
                <el-option v-for="item in userList" :key="item.nickName" :label="item.nickName"
                  :value="item.nickName" />
              </el-select>
@@ -158,7 +159,7 @@
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="客户名称:" prop="customerId">
              <el-select v-model="form.customerId" placeholder="请选择" clearable :disabled="operationType === 'view'">
              <el-select v-model="form.customerId" placeholder="请选择" clearable :disabled="operationType === 'view'" filterable>
                <el-option v-for="item in customerOption" :key="item.id" :label="item.customerName" :value="item.id">
                  {{
                    item.customerName + "——" + item.taxpayerIdentificationNumber
@@ -204,6 +205,14 @@
                  </el-form-item>
               </el-col>
            </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="交货日期:" prop="entryDate">
              <el-date-picker style="width: 100%" v-model="form.deliveryDate" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
                              type="date" placeholder="请选择" clearable />
            </el-form-item>
          </el-col>
        </el-row>
            <el-row>
               <el-form-item label="产品信息:" prop="entryDate">
                  <el-button v-if="operationType !== 'view'" type="primary" @click="openProductForm('add')">添加</el-button>
@@ -212,7 +221,8 @@
            </el-row>
            <el-table :data="productData" border @selection-change="productSelected" show-summary
                           :summary-method="summarizeMainTable">
               <el-table-column align="center" type="selection" width="55" v-if="operationType !== 'view'" />
               <el-table-column align="center" type="selection" width="55" v-if="operationType !== 'view'"
                  :selectable="(row) => !isProductShipped(row)" />
               <el-table-column align="center" label="序号" type="index" width="60" />
               <el-table-column label="产品大类" prop="productCategory" />
               <el-table-column label="规格型号" prop="specificationModel" />
@@ -224,20 +234,22 @@
               <el-table-column label="不含税总价(元)" prop="taxExclusiveTotalPrice" :formatter="formattedNumber" />
               <el-table-column fixed="right" label="操作" min-width="60" align="center" v-if="operationType !== 'view'">
                  <template #default="scope">
                     <el-button link type="primary" size="small" @click="openProductForm('edit', scope.row,scope.$index)">编辑</el-button>
                     <el-button link type="primary" size="small"
                        :disabled="isProductShipped(scope.row)"
                        @click="openProductForm('edit', scope.row,scope.$index)">编辑</el-button>
                  </template>
               </el-table-column>
            </el-table>
            <el-row :gutter="30">
               <el-col :span="24">
                  <el-form-item label="备注·:" prop="remark">
                     <el-input v-model="form.remark" placeholder="请输入" clearable type="textarea" :rows="2" :disabled="operationType === 'view'" />
                  <el-form-item label="备注:" prop="remarks">
                     <el-input v-model="form.remarks" placeholder="请输入" clearable type="textarea" :rows="2" :disabled="operationType === 'view'" />
                  </el-form-item>
               </el-col>
            </el-row>
            <el-row :gutter="30">
               <el-col :span="24">
                  <el-form-item label="附件材料:" prop="remark">
                  <el-form-item label="附件材料:" prop="salesLedgerFiles">
                     <el-upload v-model:file-list="fileList" :action="upload.url" multiple ref="fileUpload" auto-upload
                                     :headers="upload.headers" :before-upload="handleBeforeUpload" :on-error="handleUploadError"
                                     :on-success="handleUploadSuccess" :on-remove="handleRemove">
@@ -306,6 +318,15 @@
            </el-table-column>
         </el-table>
         
         <pagination
            v-show="quotationPage.total > 0"
            :total="quotationPage.total"
            layout="total, sizes, prev, pager, next, jumper"
            :page="quotationPage.current"
            :limit="quotationPage.size"
            @pagination="quotationPaginationChange"
         />
         <template #footer>
            <el-button @click="quotationDialogVisible = false">关闭</el-button>
         </template>
@@ -322,11 +343,8 @@
            <el-row :gutter="30">
               <el-col :span="24">
                  <el-form-item label="产品大类:" prop="productCategory">
                     <!-- <el-select v-model="productForm.productCategory" placeholder="请选择" clearable>
                        <el-option v-for="item in userList" :key="item.nickName" :label="item.nickName" :value="item.nickName"/>
                     </el-select> -->
                     <el-tree-select v-model="productForm.productCategory" placeholder="请选择" clearable check-strictly
                                             @change="getModels" :data="productOptions" :render-after-expand="false" style="width: 100%" />
                     <el-tree-select v-model="productForm.productCategory" placeholder="请选择" clearable filterable check-strictly
                                     @change="getModels" :data="productOptions" :render-after-expand="false" style="width: 100%" />
                  </el-form-item>
               </el-col>
            </el-row>
@@ -459,7 +477,6 @@
               <div v-for="(item, index) in printData" :key="index" class="print-page">
                  <div class="delivery-note">
                     <div class="header">
                        <div class="company-name">鼎诚瑞实业有限责任公司</div>
                        <div class="document-title">零售发货单</div>
                     </div>
                     
@@ -477,7 +494,7 @@
                        <div class="info-row">
                           <div>
                              <span class="label">客户名称:</span>
                              <span class="value">{{ item.customerName || '张爱有' }}</span>
                              <span class="value">{{ item.customerName }}</span>
                           </div>
                           <span class="label">单号:</span>
                           <span class="value">{{ item.salesContractNo }}</span>
@@ -610,7 +627,6 @@
                  <div>
                    <el-button
                      type="danger"
                      size="small"
                      @click="removeApproverNode(index)"
                      v-if="approverNodes.length > 1"
                    >删除</el-button>
@@ -658,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();
@@ -694,15 +711,18 @@
      customerId: "",
      entryPerson: "",
      entryDate: "",
    deliveryDate: "",
      maintenanceTime: "",
      productData: [],
      executionDate: "",
    hasProductionRecord: false,
   },
   rules: {
      salesman: [{ required: true, message: "请选择", trigger: "change" }],
      customerId: [{ required: true, message: "请选择", trigger: "change" }],
      entryPerson: [{ required: true, message: "请选择", trigger: "change" }],
      entryDate: [{ required: true, message: "请选择", trigger: "change" }],
    deliveryDate: [{ required: true, message: "请选择", trigger: "change" }],
      executionDate: [{ required: true, message: "请选择", trigger: "change" }],
   },
});
@@ -765,6 +785,12 @@
const quotationSearchForm = reactive({
   quotationNo: "",
   customer: "",
});
// 报价单弹框分页
const quotationPage = reactive({
   current: 1,
   size: 10,
   total: 0,
});
const selectedQuotation = ref(null);
@@ -898,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) => {
@@ -987,6 +1055,23 @@
      expandedRowKeys.value = [];
   }
};
// 添加表行类名方法
const tableRowClassName = ({ row }) => {
  if (!row.deliveryDate) return '';
  if (row.isFh) return '';
  const diff = row.deliveryDaysDiff;
  if (diff === 15) {
    return 'yellow';
  } else if (diff === 10) {
    return 'pink';
  } else if (diff === 2) {
    return 'purple';
  } else if (diff < 2) {
    return 'red';
  }
};
// 主表合计方法
const summarizeMainTable = (param) => {
   return proxy.summarizeTable(param, [
@@ -996,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",
@@ -1005,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") {
@@ -1043,11 +1144,14 @@
const openQuotationDialog = async () => {
   if (operationType.value === "view") return;
   quotationDialogVisible.value = true;
   // 打开弹窗时重置分页到第一页
   quotationPage.current = 1;
   // 先确保客户列表已加载,便于后续回填 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,允许用户后续手动选择客户
      }
@@ -1059,14 +1163,15 @@
   quotationLoading.value = true;
   try {
      const params = {
         // 兼容后端分页字段:这里沿用报价页面已有可用的字段命名
         currentPage: 1,
         pageSize: 100,
         // 后端分页字段:current / size
         current: quotationPage.current,
         size: quotationPage.size,
         ...quotationSearchForm,
         status: "通过",
      };
      const res = await getQuotationList(params);
      quotationList.value = res?.data?.records || [];
      quotationPage.total = res?.data?.total || 0;
   } finally {
      quotationLoading.value = false;
   }
@@ -1075,7 +1180,15 @@
const resetQuotationSearch = async () => {
   quotationSearchForm.quotationNo = "";
   quotationSearchForm.customer = "";
   quotationPage.current = 1;
   await fetchQuotationList();
};
// 报价单弹框分页切换
const quotationPaginationChange = (obj) => {
   quotationPage.current = obj.page;
   quotationPage.size = obj.limit;
   fetchQuotationList();
};
// 选中报价单后回填到台账表单
@@ -1182,6 +1295,7 @@
         addOrUpdateSalesLedger(form.value).then((res) => {
            proxy.$modal.msgSuccess("提交成功");
            closeDia();
            expandedRowKeys.value = [];
            getList();
         });
      }
@@ -1196,6 +1310,12 @@
const productIndex = ref(0);
// 打开产品弹框
const openProductForm = async (type, row, index) => {
   // 编辑时检查产品是否已发货或审核通过
   if (type === "edit" && isProductShipped(row)) {
      proxy.$modal.msgWarning("已发货或审核通过的产品不能编辑");
      return;
   }
   productOperationType.value = type;
   productForm.value = {};
   proxy.resetForm("productFormRef");
@@ -1262,6 +1382,14 @@
      proxy.$modal.msgWarning("请选择数据");
      return;
   }
   // 检查是否有已发货或审核通过的产品
   const shippedProducts = productSelectedRows.value.filter(row => isProductShipped(row));
   if (shippedProducts.length > 0) {
      proxy.$modal.msgWarning("已发货或审核通过的产品不能删除");
      return;
   }
   if (operationType.value === "add") {
      productSelectedRows.value.forEach((selectedRow) => {
         const index = productData.value.findIndex(
@@ -1336,15 +1464,60 @@
         proxy.$modal.msg("已取消");
      });
};
/** 判断单个产品是否已发货(根据shippingStatus判断,已发货或审核通过不可编辑和删除) */
const isProductShipped = (product) => {
   if (!product) return false;
   const status = String(product.shippingStatus || "").trim();
   // 如果发货状态是"已发货"或"审核通过",则不可编辑和删除
   return status === "已发货" || status === "审核通过";
};
/** 判断销售订单下是否存在已发货/发货完成的产品(不可删除) */
const hasShippedProducts = (products) => {
   if (!products || !products.length) return false;
   return products.some((p) => {
      const status = String(p.shippingStatus || "").trim();
      // 有发货日期或车牌号视为已发货
      if (p.shippingDate || p.shippingCarNumber) return true;
      // 已进行发货、发货完成、已发货 均不可删除
      return status === "已进行发货" || status === "发货完成" || status === "已发货";
   });
};
// 删除
const handleDelete = () => {
   let ids = [];
   if (selectedRows.value.length > 0) {
      ids = selectedRows.value.map((item) => item.id);
   } else {
const handleDelete = async () => {
   if (selectedRows.value.length === 0) {
      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);
   // 检查是否有已进行发货或发货完成的销售订单,若有则不允许删除
   const cannotDeleteNames = [];
   for (const row of selectedRows.value) {
      let products = row.children && row.children.length > 0 ? row.children : null;
      if (!products) {
         try {
            const res = await productList({ salesLedgerId: row.id, type: 1 });
            products = res.data || [];
         } catch {
            products = [];
         }
      }
      if (hasShippedProducts(products)) {
         cannotDeleteNames.push(row.salesContractNo || `ID:${row.id}`);
      }
   }
   if (cannotDeleteNames.length > 0) {
      proxy.$modal.msgWarning("已进行发货或发货完成的销售订单不能删除:" + cannotDeleteNames.join("、"));
      return;
   }
   ElMessageBox.confirm("选中的内容将被删除,是否确认删除?", "导出", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
@@ -1558,7 +1731,6 @@
      <div class="print-page">
        <div class="delivery-note">
          <div class="header">
            <div class="company-name">鼎诚瑞实业有限责任公司</div>
            <div class="document-title">零售发货单</div>
          </div>
          
@@ -1570,7 +1742,7 @@
              </div>
              <div>
                <span class="label">客户名称:</span>
                <span class="value">${item.customerName || '张爱有'}</span>
                <span class="value">${item.customerName}</span>
              </div>
            </div>
            <div class="info-row">
@@ -2084,6 +2256,22 @@
   margin-left: 10px;
}
:deep(.yellow) {
  background-color: #FAF0DE;
}
:deep(.pink) {
  background-color: #FAE1DE;
}
:deep(.red) {
  background-color: #FAE1DE;
}
:deep(.purple){
  background-color: #F4DEFA;
}
.table_list {
   margin-top: unset;
}