ZN
8 天以前 3db4630f6bf34bc8857600ca6a0078eb43a21d1e
src/views/salesManagement/salesLedger/index.vue
@@ -10,10 +10,6 @@
          <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="录入日期:">
          <el-date-picker v-model="searchForm.entryDate" value-format="YYYY-MM-DD" format="YYYY-MM-DD" type="daterange"
            placeholder="请选择" clearable @change="changeDaterange" />
@@ -64,28 +60,8 @@
                           </el-tag>
                        </template>
                     </el-table-column>
                     <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="数量" prop ="quantity" />
               <el-table-column label="已发货数量" prop="partSendAmount" />
              <el-table-column label="税率(%)" prop="taxRate" />
              <el-table-column label="含税单价(元)" prop="taxInclusiveUnitPrice" :formatter="formattedNumber" />
              <el-table-column label="含税总价(元)" prop="taxInclusiveTotalPrice" :formatter="formattedNumber" />
@@ -101,6 +77,13 @@
                    @click="openDeliveryForm(scope.row)">
                    发货
                  </el-button>
                  <el-button
                    link
                    type="primary"
                    size="small"
                    @click="openDeliveryDetail(scope.row)">
                    详情
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
@@ -110,8 +93,7 @@
        <el-table-column label="销售合同号" prop="salesContractNo" 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 />
@@ -169,25 +151,19 @@
              </el-select>
            </el-form-item>
          </el-col>
               <el-col :span="12">
               <!-- <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-row>
        <el-row :gutter="30">
               </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-col :span="12">
                  <el-form-item label="付款方式">
                     <el-input v-model="form.paymentMethod" 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">
@@ -208,14 +184,14 @@
            </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="交货日期:" prop="entryDate">
            <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>
@@ -386,7 +362,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%" />
@@ -490,10 +466,6 @@
                              <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">
                           <div>
@@ -583,19 +555,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="待发货数量:">
                     <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>
@@ -649,6 +654,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>
@@ -656,7 +703,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";
@@ -758,7 +805,6 @@
      taxInclusiveUnitPrice: [
         { required: true, message: "请输入", trigger: "blur" },
      ],
      taxRate: [{ required: true, message: "请选择", trigger: "change" }],
      taxInclusiveTotalPrice: [
         { required: true, message: "请输入", trigger: "blur" },
      ],
@@ -799,18 +845,100 @@
// 发货相关
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" }
    ],
    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({
      salesLedgerId: 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?.salesLedgerId ?? 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 }]);
@@ -1295,10 +1423,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 }
@@ -1872,13 +2005,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;
@@ -1886,39 +2021,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);
@@ -1933,13 +2063,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;
@@ -1947,10 +2079,6 @@
// 根据含税单价变化计算总价
const calculateFromUnitPrice = () => {
   if (!productForm.value.taxRate) {
      proxy.$modal.msgWarning("请先选择税率");
      return;
   }
   if (isCalculating.value) return;
   
   const quantity = parseFloat(productForm.value.quantity);
@@ -1965,13 +2093,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;
@@ -1979,27 +2109,27 @@
// 根据税率变化计算不含税总价
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;
};
@@ -2065,6 +2195,12 @@
   return typeTextMap[statusStr] || 'info';
};
const getRemainAmount = (row) => {
   const total = Number(row?.quantity || 0);
   const shipped = Number(row?.partSendAmount || 0);
   return Math.max(0, total - shipped);
};
/**
 * 判断是否可以发货
 * 只有在产品状态是充足,发货状态是待发货和审核拒绝的时候才可以发货
@@ -2075,18 +2211,13 @@
   if (row.approveStatus !== 1) {
      return false;
   }
   // 获取发货状态
   const shippingStatus = row.shippingStatus;
   // 如果已发货(有发货日期或车牌号),不能再次发货
   if (row.shippingDate || row.shippingCarNumber) {
   if (getRemainAmount(row) <= 0) {
      return false;
   }
   // 发货状态必须是"待发货"或"审核拒绝"
   const statusStr = shippingStatus ? String(shippingStatus).trim() : '';
   return statusStr === '待发货' || statusStr === '审核拒绝';
   return true;
};
/**
@@ -2104,6 +2235,7 @@
   });
}
// 打开发货弹框
const openDeliveryForm = (row) => {
   // 检查是否可以发货
@@ -2111,10 +2243,15 @@
      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 }];
@@ -2133,6 +2270,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;
@@ -2140,6 +2295,8 @@
        salesLedgerId: salesLedgerId,
        salesLedgerProductId: currentDeliveryRow.value.id,
        type: deliveryForm.value.type,
        isAllSend,
        partSendAmount: quantityToSend,
            approveUserIds,
      })
        .then(() => {