buhuazhen
6 天以前 168c23ac6a1c021407f905323525c8d411857e57
src/views/salesManagement/salesLedger/index.vue
@@ -6,16 +6,8 @@
          <el-input v-model="searchForm.customerName" placeholder="请输入" clearable prefix-icon="Search"
            @change="handleQuery" />
        </el-form-item>
        <el-form-item label="客户合同号:">
          <el-input v-model="searchForm.customerContractNo" placeholder="请输入" clearable prefix-icon="Search"
            @change="handleQuery" />
        </el-form-item>
        <el-form-item label="销售合同号:">
          <el-input v-model="searchForm.salesContractNo" placeholder="请输入" clearable prefix-icon="Search"
            @change="handleQuery" />
        </el-form-item>
        <el-form-item label="项目名称:">
          <el-input v-model="searchForm.projectName" placeholder="请输入" clearable prefix-icon="Search"
            @change="handleQuery" />
        </el-form-item>
        <el-form-item label="录入日期:">
@@ -41,7 +33,7 @@
        </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">
@@ -61,29 +53,19 @@
                                       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>
                    <el-tag type="success" v-if="scope.row.shippingCarNumber">{{ scope.row.shippingCarNumber }}</el-tag>
                    <el-tag v-else type="info">未发货</el-tag>
                  </div>
                </template>
              </el-table-column>
                     <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>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="数量" prop="quantity" />
                     <el-table-column label="发货状态" width="140" align="center">
                        <template #default="scope">
                           <el-tag :type="getShippingStatusType(scope.row)" size="small">
                              {{ getShippingStatusText(scope.row) }}
                           </el-tag>
                        </template>
                     </el-table-column>
              <el-table-column label="数量" prop ="quantity" />
               <el-table-column label="已发货数量" prop="partSendAmount" >
                  <template #default="scope">
                              {{ scope.row.partSendAmount || 0 }}
                        </template>
                  </el-table-column>
              <el-table-column label="税率(%)" prop="taxRate" />
              <el-table-column label="含税单价(元)" prop="taxInclusiveUnitPrice" :formatter="formattedNumber" />
              <el-table-column label="含税总价(元)" prop="taxInclusiveTotalPrice" :formatter="formattedNumber" />
@@ -94,10 +76,17 @@
                  <el-button 
                    link 
                    type="primary" 
                    size="small"
                    :disabled="scope.row.approveStatus !== 1 || !!scope.row.shippingDate || !!scope.row.shippingCarNumber"
                    size="small"
                    :disabled="!canShip(scope.row)"
                    @click="openDeliveryForm(scope.row)">
                    发货
                  </el-button>
                  <el-button
                    link
                    type="primary"
                    size="small"
                    @click="openDeliveryDetail(scope.row)">
                    详情
                  </el-button>
                </template>
              </el-table-column>
@@ -106,19 +95,19 @@
        </el-table-column>
        <el-table-column align="center" label="序号" type="index" width="60" />
        <el-table-column label="销售合同号" prop="salesContractNo" width="180" show-overflow-tooltip />
        <el-table-column label="客户合同号" prop="customerContractNo" width="180" show-overflow-tooltip />
        <el-table-column label="客户名称" prop="customerName" width="300" show-overflow-tooltip />
        <el-table-column label="业务员" prop="salesman" width="100" show-overflow-tooltip />
        <el-table-column label="项目名称" prop="projectName" width="180" show-overflow-tooltip />
        <el-table-column label="付款方式" prop="paymentMethod" show-overflow-tooltip />
        <el-table-column label="合同金额(元)" prop="contractAmount" width="220" show-overflow-tooltip
          :formatter="formattedNumber" />
        <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 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="操作" min-width="100" 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('edit', scope.row)" :disabled="!scope.row.isEdit">编辑</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>-->
@@ -131,6 +120,14 @@
    <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 v-if="operationType === 'add'" style="margin-bottom: 10px;">
               <el-col :span="24" style="text-align: right;">
                  <el-button type="primary" plain @click="openQuotationDialog">
                     从销售报价导入
                  </el-button>
               </el-col>
            </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="销售合同号:" prop="salesContractNo">
@@ -148,11 +145,6 @@
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="客户合同号:" prop="customerContractNo">
              <el-input v-model="form.customerContractNo" placeholder="请输入" clearable :disabled="operationType === 'view'"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户名称:" prop="customerId">
              <el-select v-model="form.customerId" placeholder="请选择" clearable :disabled="operationType === 'view'">
                <el-option v-for="item in customerOption" :key="item.id" :label="item.customerName" :value="item.id">
@@ -163,20 +155,19 @@
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="项目名称:" prop="projectName">
              <el-input v-model="form.projectName" placeholder="请输入" clearable :disabled="operationType === 'view'" />
            </el-form-item>
          </el-col>
               <!-- <el-col :span="12">
                  <el-form-item label="项目名称:" prop="projectName">
                     <el-input v-model="form.projectName" placeholder="请输入" clearable :disabled="operationType === 'view'" />
                  </el-form-item>
               </el-col> -->
               <el-col :span="12">
                  <el-form-item label="签订日期:" prop="executionDate">
                     <el-date-picker style="width: 100%" v-model="form.executionDate" value-format="YYYY-MM-DD"
                                             format="YYYY-MM-DD" type="date" placeholder="请选择" clearable :disabled="operationType === 'view'" />
                  </el-form-item>
               </el-col>
            </el-row>
        </el-row>
            <el-row :gutter="30">
               <el-col :span="12">
                  <el-form-item label="录入人:" prop="entryPerson">
@@ -195,16 +186,24 @@
                  </el-form-item>
               </el-col>
            </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="交货日期:" prop="deliveryDate">
              <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-form-item label="产品信息:">
                  <el-button v-if="operationType !== 'view'" type="primary" @click="openProductForm('add')">添加</el-button>
                  <el-button v-if="operationType !== 'view'" plain type="danger" @click="deleteProduct" >删除</el-button>
               </el-form-item>
            </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" />
@@ -216,20 +215,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">
@@ -298,6 +299,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>
@@ -356,7 +366,7 @@
                  </el-form-item>
               </el-col>
               <el-col :span="12">
                  <el-form-item label="数量:" prop="quantity">
                  <el-form-item label="数量" prop="quantity">
                     <el-input-number  :step="0.1" :min="0" v-model="productForm.quantity" placeholder="请输入" clearable
                                                :precision="2"
                                                @change="calculateFromQuantity" style="width: 100%" />
@@ -451,7 +461,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>
                     
@@ -460,10 +469,6 @@
                           <div>
                              <span class="label">发货日期:</span>
                              <span class="value">{{ formatDate(item.createTime) }}</span>
                           </div>
                           <div>
                              <span class="label">发货车牌号:</span>
                              <span class="value">{{ item.shippingCarNumber }}</span>
                           </div>
                        </div>
                        <div class="info-row">
@@ -554,19 +559,52 @@
      >
         <el-form :model="deliveryForm" label-width="120px" label-position="top" :rules="deliveryRules" ref="deliveryFormRef">
            <el-row :gutter="30">
               <el-col :span="24">
               <!-- <el-col :span="12">
                  <el-form-item label="发货类型:" prop="type">
                     <el-select
                        v-model="deliveryForm.type"
                        placeholder="请选择发货类型"
                        disabled
                        style="width: 100%"
                     >
                        <el-option label="货车" value="货车" />
                        <el-option label="快递" value="快递" />
                     </el-select>
                  </el-form-item>
               </el-col> -->
      <el-col :span="12">
                  <el-form-item label="待发货数量:" prop="remainAmount">
                     <el-input v-model="deliveryForm.remainAmount" disabled placeholder="请输入待发货数量"></el-input>
                  </el-form-item>
               </el-col>
      <el-col :span="12">
                  <el-form-item label="发货模式:" prop="deliveryMode">
                     <el-select
                        v-model="deliveryForm.deliveryMode"
                        placeholder="请选择发货模式"
            style="width: 100%"
            @change="onDeliveryModeChange"
                     >
                     <el-option label="全部" value="全部" />
                     <el-option label="部分" value="部分" />
                     </el-select>
                  </el-form-item>
               </el-col>
      <el-col :span="12">
        <el-form-item label="发货数量:" prop="partSendAmount">
          <el-input-number
            v-model="deliveryForm.partSendAmount"
            :min="1"
            :max="deliveryForm.remainAmount"
            :precision="0"
            :step="1"
            :disabled="deliveryForm.deliveryMode === '全部'"
            style="width: 100%"
            placeholder="请输入本次发货数量"
          />
        </el-form-item>
      </el-col>
            </el-row>
        <!-- 审批人选择(仿协同审批里的审批人节点选择) -->
        <el-row>
@@ -620,6 +658,48 @@
            </div>
         </template>
      </el-dialog>
      <!-- 发货详情弹框 -->
      <el-dialog
         v-model="deliveryDetailVisible"
         title="发货详情"
         width="80%"
         :close-on-click-modal="false"
         @close="closeDeliveryDetail"
      >
         <el-table
            :data="deliveryDetailTableData"
            border
            stripe
            v-loading="deliveryDetailLoading"
            height="520px"
         >
            <el-table-column align="center" label="序号" type="index" width="60" />
            <el-table-column prop="salesContractNo" label="销售订单" width="180" show-overflow-tooltip />
            <el-table-column prop="shippingNo" label="发货订单号" width="180" show-overflow-tooltip />
            <el-table-column prop="customerName" label="客户名称" min-width="200" show-overflow-tooltip />
            <el-table-column prop="status" label="发货状态" min-width="200" show-overflow-tooltip />
            <el-table-column prop="productName" label="产品名称" min-width="160" show-overflow-tooltip />
            <el-table-column prop="specificationModel" label="规格型号" min-width="160" show-overflow-tooltip />
            <el-table-column prop="type" label="发货类型" width="100" show-overflow-tooltip />
            <el-table-column prop="expressCompany" label="快递公司" width="140" show-overflow-tooltip />
            <el-table-column prop="expressNumber" label="快递单号" width="160" show-overflow-tooltip />
            <el-table-column prop="partSendAmount" label="本次发货数量" width="120" align="center" />
         </el-table>
         <pagination
            v-show="deliveryDetailPage.total > 0"
            :total="deliveryDetailPage.total"
            layout="total, sizes, prev, pager, next, jumper"
            :page="deliveryDetailPage.current"
            :limit="deliveryDetailPage.size"
            @pagination="deliveryDetailPaginationChange"
         />
         <template #footer>
            <div class="dialog-footer">
               <el-button @click="closeDeliveryDetail">关闭</el-button>
            </div>
         </template>
      </el-dialog>
   </div>
</template>
@@ -627,7 +707,7 @@
import { getToken } from "@/utils/auth";
import pagination from "@/components/PIMTable/Pagination.vue";
import {onMounted, ref, getCurrentInstance} from "vue";
import { addShippingInfo } from "@/api/salesManagement/deliveryLedger.js";
import { addShippingInfo, deliveryLedgerListPage } from "@/api/salesManagement/deliveryLedger.js";
import { ElMessageBox, ElMessage } from "element-plus";
import { UploadFilled, Download } from "@element-plus/icons-vue";
import useUserStore from "@/store/modules/user";
@@ -686,6 +766,7 @@
      customerId: "",
      entryPerson: "",
      entryDate: "",
    deliveryDate: "",
      maintenanceTime: "",
      productData: [],
      executionDate: "",
@@ -695,6 +776,7 @@
      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" }],
   },
});
@@ -727,7 +809,6 @@
      taxInclusiveUnitPrice: [
         { required: true, message: "请输入", trigger: "blur" },
      ],
      taxRate: [{ required: true, message: "请选择", trigger: "change" }],
      taxInclusiveTotalPrice: [
         { required: true, message: "请输入", trigger: "blur" },
      ],
@@ -758,22 +839,122 @@
   quotationNo: "",
   customer: "",
});
// 报价单弹框分页
const quotationPage = reactive({
   current: 1,
   size: 10,
   total: 0,
});
const selectedQuotation = ref(null);
// 发货相关
const deliveryFormVisible = ref(false);
const deliveryDetailVisible = ref(false);
const deliveryDetailLoading = ref(false);
const deliveryDetailTableData = ref([]);
const deliveryDetailSalesLedgerId = ref(null);
const deliveryDetailPage = reactive({
   current: 1,
   size: 10,
   total: 0,
});
const currentDeliveryRow = ref(null);
const deliveryFormData = reactive({
  deliveryForm: {
    type: "货车", // 货车, 快递
    type: "快递", // 货车, 快递
    remainAmount: 0,
    deliveryMode: "全部", // 全部 | 部分
    partSendAmount: 0,
  },
  deliveryRules: {
    type: [
      { required: true, message: "请选择发货类型", trigger: "change" }
    ],
    remainAmount: [
      {
        validator: (rule, value, callback) => {
          const remain = Number(value) || 0;
          if (remain <= 0) {
            return callback(new Error("待发货数量需要大于0"));
          }
          return callback();
        },
        trigger: "change",
      }
    ],
    deliveryMode: [
      { required: true, message: "请选择发货模式", trigger: "change" }
    ],
    partSendAmount: [
      {
        validator: (rule, value, callback) => {
          if (deliveryFormData.deliveryForm.deliveryMode !== "部分") {
            return callback();
          }
          const max = Number(deliveryFormData.deliveryForm.remainAmount) || 0;
          const v = Number(value);
          if (!v || v <= 0) {
            return callback(new Error("请输入发货数量"));
          }
          if (v > max) {
            return callback(new Error(`发货数量不能超过待发货数量(${max})`));
          }
          return callback();
        },
        trigger: "change",
      }
    ]
  },
});
const { deliveryForm, deliveryRules } = toRefs(deliveryFormData);
const onDeliveryModeChange = (val) => {
  const remain = Number(deliveryForm.value.remainAmount) || 0;
  if (val === "全部") {
    deliveryForm.value.partSendAmount = remain;
  } else {
    let v = Number(deliveryForm.value.partSendAmount) || 0;
    if (v <= 0 || v > remain) {
      deliveryForm.value.partSendAmount = remain > 0 ? Math.min(1, remain) : 0;
    }
  }
};
const getDeliveryDetailList = () => {
   if (!deliveryDetailSalesLedgerId.value) return;
   deliveryDetailLoading.value = true;
   return deliveryLedgerListPage({
      salesLedgerProductId: deliveryDetailSalesLedgerId.value,
      current: deliveryDetailPage.current,
      size: deliveryDetailPage.size,
   }).then((res) => {
      deliveryDetailTableData.value = res?.data?.records || [];
      deliveryDetailPage.total = res?.data?.total || 0;
   }).finally(() => {
      deliveryDetailLoading.value = false;
   });
};
const deliveryDetailPaginationChange = (obj) => {
   deliveryDetailPage.current = obj.page;
   deliveryDetailPage.size = obj.limit;
   getDeliveryDetailList();
};
const openDeliveryDetail = (row) => {
   deliveryDetailSalesLedgerId.value = row?.id ?? null;
   deliveryDetailPage.current = 1;
   deliveryDetailVisible.value = true;
   getDeliveryDetailList();
};
const closeDeliveryDetail = () => {
   deliveryDetailVisible.value = false;
   deliveryDetailTableData.value = [];
   deliveryDetailSalesLedgerId.value = null;
   deliveryDetailPage.current = 1;
   deliveryDetailPage.total = 0;
};
// 发货审批人节点(仿协同审批 infoFormDia.vue)
const approverNodes = ref([{ id: 1, userId: null }]);
@@ -979,6 +1160,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, [
@@ -1035,6 +1233,8 @@
const openQuotationDialog = async () => {
   if (operationType.value === "view") return;
   quotationDialogVisible.value = true;
   // 打开弹窗时重置分页到第一页
   quotationPage.current = 1;
   // 先确保客户列表已加载,便于后续回填 customerId
   if (!customerOption.value || customerOption.value.length === 0) {
      try {
@@ -1051,14 +1251,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;
   }
@@ -1067,7 +1268,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();
};
// 选中报价单后回填到台账表单
@@ -1076,10 +1285,14 @@
   selectedQuotation.value = row;
   
   // 业务员
   form.value.salesman = row.salesperson || "";
   form.value.salesman = (row.salesperson || "").trim();
   
   // 客户名称 -> customerId
   const customer = (customerOption.value || []).find((c) => c.customerName === row.customer);
   const qCustomerName = String(row.customer || "").trim();
   const customer = (customerOption.value || []).find((c) => {
      const name = String(c.customerName || "").trim();
      return name === qCustomerName || name.includes(qCustomerName) || qCustomerName.includes(name);
   });
   if (customer?.id) {
      form.value.customerId = customer.id;
   } else {
@@ -1184,6 +1397,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");
@@ -1211,6 +1430,8 @@
         // 加载失败时保持可编辑,不中断弹窗
         console.error("加载产品规格型号失败", e);
      }
   } else {
      getProductOptions()
   }
   productFormVisible.value = true;
};
@@ -1218,10 +1439,15 @@
const submitProduct = () => {
   proxy.$refs["productFormRef"].validate((valid) => {
      if (valid) {
         // 如果里面的数据没有taxRate 那就默认带上一个taxRate 为空
         if (!Object.prototype.hasOwnProperty.call(productForm.value, 'taxRate') || productForm.value.taxRate === null || productForm.value.taxRate === undefined) {
            productForm.value.taxRate = 0;
         }
         if (operationType.value === "edit") {
            submitProductEdit();
         } else {
            if(productOperationType.value === "add"){
               productData.value.push({ ...productForm.value });
            }else{
               productData.value[productIndex.value] = { ...productForm.value }
@@ -1248,6 +1474,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(
@@ -1322,15 +1556,55 @@
         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 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: "取消",
@@ -1544,7 +1818,6 @@
      <div class="print-page">
        <div class="delivery-note">
          <div class="header">
            <div class="company-name">鼎诚瑞实业有限责任公司</div>
            <div class="document-title">零售发货单</div>
          </div>
          
@@ -1748,13 +2021,15 @@
   // 计算含税单价 = 含税总价 / 数量
   productForm.value.taxInclusiveUnitPrice = (totalPrice / quantity).toFixed(2);
   
   // 如果有税率,计算不含税总价
   // 有税率则计算不含税总价,否则不含税总价 = 含税总价
   if (productForm.value.taxRate) {
      productForm.value.taxExclusiveTotalPrice =
         proxy.calculateTaxExclusiveTotalPrice(
            totalPrice,
            productForm.value.taxRate
         );
   } else {
      productForm.value.taxExclusiveTotalPrice = totalPrice.toFixed(2);
   }
   
   isCalculating.value = false;
@@ -1762,39 +2037,34 @@
// 根据不含税总价计算含税单价和数量
const calculateFromExclusiveTotalPrice = () => {
   if (!productForm.value.taxRate) {
      proxy.$modal.msgWarning("请先选择税率");
      return;
   }
   if (isCalculating.value) return;
   
   const exclusiveTotalPrice = parseFloat(productForm.value.taxExclusiveTotalPrice);
   const quantity = parseFloat(productForm.value.quantity);
   const taxRate = parseFloat(productForm.value.taxRate);
   
   if (!exclusiveTotalPrice || !quantity || quantity <= 0 || !taxRate) {
   if (!exclusiveTotalPrice || !quantity || quantity <= 0) {
      return;
   }
   
   isCalculating.value = true;
   
   // 先计算含税总价 = 不含税总价 / (1 - 税率/100)
   const taxRateDecimal = taxRate / 100;
   const inclusiveTotalPrice = exclusiveTotalPrice / (1 - taxRateDecimal);
   productForm.value.taxInclusiveTotalPrice = inclusiveTotalPrice.toFixed(2);
   // 计算含税单价 = 含税总价 / 数量
   productForm.value.taxInclusiveUnitPrice = (inclusiveTotalPrice / quantity).toFixed(2);
   if (productForm.value.taxRate) {
      // 有税率:含税总价 = 不含税总价 / (1 - 税率/100)
      const taxRateDecimal = parseFloat(productForm.value.taxRate) / 100;
      const inclusiveTotalPrice = exclusiveTotalPrice / (1 - taxRateDecimal);
      productForm.value.taxInclusiveTotalPrice = inclusiveTotalPrice.toFixed(2);
      productForm.value.taxInclusiveUnitPrice = (inclusiveTotalPrice / quantity).toFixed(2);
   } else {
      // 无税率:含税总价 = 不含税总价
      productForm.value.taxInclusiveTotalPrice = exclusiveTotalPrice.toFixed(2);
      productForm.value.taxInclusiveUnitPrice = (exclusiveTotalPrice / quantity).toFixed(2);
   }
   
   isCalculating.value = false;
};
// 根据数量变化计算总价
const calculateFromQuantity = () => {
   if (!productForm.value.taxRate) {
      proxy.$modal.msgWarning("请先选择税率");
      return;
   }
   if (isCalculating.value) return;
   
   const quantity = parseFloat(productForm.value.quantity);
@@ -1809,13 +2079,15 @@
   // 计算含税总价
   productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(2);
   
   // 如果有税率,计算不含税总价
   // 有税率则计算不含税总价,否则不含税总价 = 含税总价
   if (productForm.value.taxRate) {
      productForm.value.taxExclusiveTotalPrice =
         proxy.calculateTaxExclusiveTotalPrice(
            productForm.value.taxInclusiveTotalPrice,
            productForm.value.taxRate
         );
   } else {
      productForm.value.taxExclusiveTotalPrice = productForm.value.taxInclusiveTotalPrice;
   }
   
   isCalculating.value = false;
@@ -1823,10 +2095,6 @@
// 根据含税单价变化计算总价
const calculateFromUnitPrice = () => {
   if (!productForm.value.taxRate) {
      proxy.$modal.msgWarning("请先选择税率");
      return;
   }
   if (isCalculating.value) return;
   
   const quantity = parseFloat(productForm.value.quantity);
@@ -1841,13 +2109,15 @@
   // 计算含税总价
   productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(2);
   
   // 如果有税率,计算不含税总价
   // 有税率则计算不含税总价,否则不含税总价 = 含税总价
   if (productForm.value.taxRate) {
      productForm.value.taxExclusiveTotalPrice =
         proxy.calculateTaxExclusiveTotalPrice(
            productForm.value.taxInclusiveTotalPrice,
            productForm.value.taxRate
         );
   } else {
      productForm.value.taxExclusiveTotalPrice = productForm.value.taxInclusiveTotalPrice;
   }
   
   isCalculating.value = false;
@@ -1855,30 +2125,93 @@
// 根据税率变化计算不含税总价
const calculateFromTaxRate = () => {
   if (!productForm.value.taxRate) {
      proxy.$modal.msgWarning("请先选择税率");
      return;
   }
   if (isCalculating.value) return;
   
   const inclusiveTotalPrice = parseFloat(productForm.value.taxInclusiveTotalPrice);
   const taxRate = parseFloat(productForm.value.taxRate);
   
   if (!inclusiveTotalPrice || !taxRate) {
   if (!inclusiveTotalPrice) {
      return;
   }
   
   isCalculating.value = true;
   
   // 计算不含税总价
   productForm.value.taxExclusiveTotalPrice =
      proxy.calculateTaxExclusiveTotalPrice(
         inclusiveTotalPrice,
         taxRate
      );
   if (productForm.value.taxRate) {
      // 有税率:重新计算不含税总价
      productForm.value.taxExclusiveTotalPrice =
         proxy.calculateTaxExclusiveTotalPrice(
            inclusiveTotalPrice,
            parseFloat(productForm.value.taxRate)
         );
   } else {
      // 无税率:不含税总价 = 含税总价
      productForm.value.taxExclusiveTotalPrice = inclusiveTotalPrice.toFixed(2);
   }
   
   isCalculating.value = false;
};
/**
 * 获取发货状态文本
 * @param row 行数据
 */
const getShippingStatusText = (row) => {
   const total = Number(row?.quantity || 0);
   const shipped = Number(row?.partSendAmount || 0);
   if (shipped <= 0) {
      return '待发货';
   }
   if (shipped < total) {
      return '发货中';
   }
   if (shipped >= total && total > 0) {
      return '已发货';
   }
   return '待发货';
};
/**
 * 获取发货状态标签类型(颜色)
 * @param row 行数据
 */
const getShippingStatusType = (row) => {
   const total = Number(row?.quantity || 0);
   const shipped = Number(row?.partSendAmount || 0);
   if (shipped <= 0) {
      return 'info';
   }
   if (shipped < total) {
      return 'warning';
   }
   if (shipped >= total && total > 0) {
      return 'success';
   }
   return 'info';
};
const getRemainAmount = (row) => {
   const total = Number(row?.quantity || 0);
   const shipped = Number(row?.partSendAmount || 0);
   return Math.max(0, total - shipped);
};
/**
 * 判断是否可以发货
 * 只有在产品状态是充足,发货状态是待发货和审核拒绝的时候才可以发货
 * @param row 行数据
 */
const canShip = (row) => {
   // 产品状态必须是充足(approveStatus === 1)
   if (row.approveStatus !== 1) {
      return false;
   }
   if (getRemainAmount(row) <= 0) {
      return false;
   }
   return true;
};
/**
 * 下载文件
 *
@@ -1894,20 +2227,23 @@
   });
}
// 打开发货弹框
const openDeliveryForm = (row) => {
   // 校验:只有产品状态为充足且未发货时才能发货
   if (row.approveStatus !== 1) {
      proxy.$modal.msgWarning("产品状态不足,无法发货");
      return;
   }
   if (row.shippingDate || row.shippingCarNumber) {
      proxy.$modal.msgWarning("该产品已发货,无法重复发货");
   // 检查是否可以发货
   if (!canShip(row)) {
      proxy.$modal.msgWarning("只有在产品状态是充足,发货状态是待发货或审核拒绝的时候才可以发货");
      return;
   }
   currentDeliveryRow.value = row;
  const total = Number(row.quantity || 0);
  const shipped = Number(row.partSendAmount || 0);
  const remain = Math.max(0, total - shipped);
  deliveryForm.value = {
    type: "货车",
    type: "快递",
    remainAmount: remain,
    deliveryMode: "全部",
    partSendAmount: remain,
  };
  // 重置审批人节点(默认一个空节点)
  approverNodes.value = [{ id: 1, userId: null }];
@@ -1926,6 +2262,24 @@
        return;
      }
      const approveUserIds = approverNodes.value.map(node => node.userId).join(",");
      const remain = Number(deliveryForm.value.remainAmount) || 0;
      if (remain <= 0) {
        proxy.$modal.msgWarning("待发货数量为0,无法发货");
        return;
      }
      const isAllSend = deliveryForm.value.deliveryMode === "全部" ? 1 : 0;
      let quantityToSend = remain;
      if (isAllSend === 0) {
        quantityToSend = Number(deliveryForm.value.partSendAmount) || 0;
        if (quantityToSend <= 0) {
          proxy.$modal.msgWarning("请输入发货数量");
          return;
        }
        if (quantityToSend > remain) {
          proxy.$modal.msgWarning(`发货数量不能超过待发货数量(${remain})`);
          return;
        }
      }
      // 保存当前展开的行ID,以便发货后重新加载子表格数据
      const currentExpandedKeys = [...expandedRowKeys.value];
      const salesLedgerId = currentDeliveryRow.value.salesLedgerId;
@@ -1933,6 +2287,8 @@
        salesLedgerId: salesLedgerId,
        salesLedgerProductId: currentDeliveryRow.value.id,
        type: deliveryForm.value.type,
        isAllSend,
        partSendAmount: quantityToSend,
            approveUserIds,
      })
        .then(() => {
@@ -1987,6 +2343,22 @@
   margin-left: 10px;
}
::v-deep .yellow {
  background-color: #FAF0DE;
}
::v-deep .pink {
  background-color: #FAE1DE;
}
::v-deep .red {
  background-color: #FAE1DE;
}
::v-deep .purple{
  background-color: #F4DEFA;
}
.table_list {
   margin-top: unset;
}