张诺
昨天 b41552e7d56a7068e9080a475baaef9c173f8b7e
src/views/salesManagement/invoiceRegistration/index.vue
@@ -30,7 +30,12 @@
         <div class="flex justify-between">
            <div></div>
            <div>
               <el-button type="primary" @click="openForm" style="margin-bottom: 8px">
               <el-button
                  type="primary"
                  @click="openForm"
                  style="margin-bottom: 8px"
                  :disabled="!canInvoice"
               >
                  开票登记
               </el-button>
            </div>
@@ -111,7 +116,7 @@
            </el-table-column>
            <el-table-column align="center" label="序号" type="index" width="60" />
            <el-table-column
               label="销售合同号"
               label="订单编号"
               prop="salesContractNo"
               show-overflow-tooltip
            />
@@ -179,7 +184,7 @@
         >
            <el-row :gutter="30">
               <el-col :span="12">
                  <el-form-item label="销售合同号:" prop="salesContractNo">
                  <el-form-item label="订单编号:" prop="salesContractNo">
                     <el-input v-model="form.salesContractNo" disabled placeholder="多合同批量处理(具体合同号见产品列表)"></el-input>
                  </el-form-item>
               </el-col>
@@ -296,10 +301,14 @@
               />
               <el-table-column label="本次开票数" prop="currentInvoiceNum" width="180">
                  <template #default="scope">
                     <el-input-number :step="0.1" :min="0" style="width: 100%"
                                              :precision="2"
                                              v-model="scope.row.currentInvoiceNum"
                                              @change="invoiceNumBlur(scope.row)"
                     <el-input-number
                        :step="0.1"
                        :min="0"
                        style="width: 100%"
                        :precision="2"
                        v-model="scope.row.currentInvoiceNum"
                        @change="invoiceNumBlur(scope.row)"
                        :disabled="isProductInvoiceDisabled(scope.row)"
                     ></el-input-number>
                  </template>
               </el-table-column>
@@ -309,10 +318,14 @@
                  width="180"
               >
                  <template #default="scope">
                     <el-input-number :step="0.01" :min="0" style="width: 100%"
                                              :precision="2"
                                              v-model="scope.row.currentInvoiceAmount"
                                              @change="invoiceAmountBlur(scope.row)"
                     <el-input-number
                        :step="0.01"
                        :min="0"
                        style="width: 100%"
                        :precision="2"
                        v-model="scope.row.currentInvoiceAmount"
                        @change="invoiceAmountBlur(scope.row)"
                        :disabled="isProductInvoiceDisabled(scope.row)"
                     ></el-input-number>
                  </template>
               </el-table-column>
@@ -375,7 +388,7 @@
<script setup>
import pagination from "@/components/PIMTable/Pagination.vue";
import FormDialog from '@/components/Dialog/FormDialog.vue';
import { onMounted, ref } from "vue";
import { onMounted, ref, computed } from "vue";
import { Search } from "@element-plus/icons-vue";
import { ElMessageBox } from "element-plus";
// import {userListNoPage} from "@/api/system/user.js";
@@ -439,17 +452,38 @@
const formattedNumber = (row, column, cellValue) => {
   if (cellValue == 0) {
      return parseFloat(cellValue).toFixed(2);
      return parseFloat(cellValue).toFixed(3);
   }
   if (cellValue) {
      return parseFloat(cellValue).toFixed(2);
      return parseFloat(cellValue).toFixed(3);
   } else {
      return cellValue;
   }
};
const formattedInputNumber = (value) => {
   return value ? parseFloat(value).toFixed(2) : 0;
   return value ? parseFloat(value).toFixed(3) : 0;
};
// 判断是否可以开票(基于选中的台账数据)
const canInvoice = computed(() => {
   if (selectedRows.value.length === 0) {
      return false;
   }
   // 检查所有选中的台账,只要有一个未开票金额大于0,就可以开票
   return selectedRows.value.some(row => {
      const noInvoiceAmount = parseFloat(row.noInvoiceAmountTotal || 0);
      return noInvoiceAmount > 0;
   });
});
// 判断单个产品是否可以开票
const isProductInvoiceDisabled = (row) => {
   // 检查未开票金额和未开票数,如果都为0或小于等于0,则禁用
   // 优先使用 tempnoInvoiceAmount 和 tempNoInvoiceNum(初始值),如果没有则使用 noInvoiceAmount 和 originalNoInvoiceNum
   const noInvoiceAmount = parseFloat(row.tempnoInvoiceAmount || row.noInvoiceAmount || 0);
   const noInvoiceNum = parseFloat(row.tempNoInvoiceNum || row.originalNoInvoiceNum || row.noInvoiceNum || 0);
   return noInvoiceAmount <= 0 || noInvoiceNum <= 0;
};
// 查询列表
@@ -505,7 +539,11 @@
      "contractAmount",
      "invoiceTotal",
      "noInvoiceAmountTotal",
   ]);
   ], {
      contractAmount: { decimalPlaces: 3 },
      invoiceTotal: { decimalPlaces: 3 },
      noInvoiceAmountTotal: { decimalPlaces: 3 },
   });
};
// 子表合计方法
const summarizeChildrenTable = (param) => {
@@ -519,7 +557,17 @@
      "noInvoiceNum",
      "noInvoiceAmount",
      "currentInvoiceNum",
   ]);
   ], {
      taxInclusiveUnitPrice: { decimalPlaces: 3 },
      taxInclusiveTotalPrice: { decimalPlaces: 3 },
      taxExclusiveTotalPrice: { decimalPlaces: 3 },
      invoiceNum: { decimalPlaces: 3 },
      invoiceAmount: { decimalPlaces: 3 },
      currentInvoiceAmount: { decimalPlaces: 3 },
      noInvoiceNum: { decimalPlaces: 3 },
      noInvoiceAmount: { decimalPlaces: 3 },
      currentInvoiceNum: { decimalPlaces: 3 },
   });
};
// 打开弹框
const openForm = () => {
@@ -561,7 +609,7 @@
               allProductData.push({
                  ...item,
                  // id: contractId, // 明确设置合同ID
                  salesContractNo: contract.salesContractNo, // 添加销售合同号
                  salesContractNo: contract.salesContractNo, // 添加订单编号
                  customerName: contract.customerName, // 添加客户名称
                  customerContractNo: contract.customerContractNo // 添加客户合同号
               });
@@ -569,15 +617,23 @@
         }
      });
      
      // 设置表单数据(使用第一个合同的基本信息,销售合同号留空)
      // 设置表单数据(使用第一个合同的基本信息,订单编号留空)
      form.value = { ...results[0] };
      form.value.createTime = dayjs().format("YYYY-MM-DD");
      form.value.issueDate = dayjs().format("YYYY-MM-DD");
      form.value.createUer = userStore.nickName;
      form.value.selectedContractIds = selectedRows.value.map(row => row.id); // 存储所有选中的合同ID
      form.value.salesContractNo = ""; // 销售合同号留空,因为会在产品表格中分别显示
      form.value.salesContractNo = ""; // 订单编号留空,因为会在产品表格中分别显示
      
      productData.value = allProductData;
      // 对于不能开票的产品,将开票数和开票金额设置为0
      productData.value.forEach(item => {
         if (isProductInvoiceDisabled(item)) {
            item.currentInvoiceNum = 0;
            item.currentInvoiceAmount = 0;
         }
      });
      
      dialogFormVisible.value = true;
      console.log("productData.value ", productData.value);
@@ -710,7 +766,7 @@
   // 计算本次开票金额
   row.currentInvoiceAmount = (
      row.currentInvoiceNum * row.taxInclusiveUnitPrice
   ).toFixed(2);
   ).toFixed(3);
   // 计算未开票数
   row.noInvoiceNum = (row.originalNoInvoiceNum - row.currentInvoiceNum).toFixed(
      2
@@ -718,7 +774,7 @@
   // 计算未开票金额
   row.noInvoiceAmount = (
      row.tempnoInvoiceAmount - row.currentInvoiceAmount
   ).toFixed(2);
   ).toFixed(3);
};
// 本次开票金额失焦操作
const invoiceAmountBlur = (row) => {
@@ -733,7 +789,7 @@
   // 计算本次开票数
   row.currentInvoiceNum = (
      row.currentInvoiceAmount / row.taxInclusiveUnitPrice
   ).toFixed(2);
   ).toFixed(3);
   console.log("row.currentInvoiceNum ", row.currentInvoiceNum);
   console.log(" row.originalNoInvoiceNum  ", row.originalNoInvoiceNum);
   // 计算未开票数
@@ -743,7 +799,7 @@
   // 计算未开票金额
   row.noInvoiceAmount = (
      row.tempnoInvoiceAmount - row.currentInvoiceAmount
   ).toFixed(2);
   ).toFixed(3);
};
onMounted(() => {