yyb
昨天 3a48d44d1eb5340c7caf2b010e1e9f081955d56c
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>
@@ -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";
@@ -450,6 +463,27 @@
const formattedInputNumber = (value) => {
   return value ? parseFloat(value).toFixed(2) : 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;
};
// 查询列表
@@ -555,12 +589,12 @@
      const allProductData = [];
      results.forEach((result, index) => {
         const contract = selectedRows.value[index];
         const contractId = contract.id;
         // const contractId = contract.id;
         if (result.productData) {
            result.productData.forEach(item => {
               allProductData.push({
                  ...item,
                  id: contractId, // 明确设置合同ID
                  // id: contractId, // 明确设置合同ID
                  salesContractNo: contract.salesContractNo, // 添加销售合同号
                  customerName: contract.customerName, // 添加客户名称
                  customerContractNo: contract.customerContractNo // 添加客户合同号
@@ -578,6 +612,14 @@
      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);
@@ -699,51 +741,78 @@
};
//本次开票失焦操作
const getInvoiceCalcUnitPrice = (row) => {
   const baseNoInvoiceNum = parseFloat(
      row.tempNoInvoiceNum ?? row.originalNoInvoiceNum ?? row.noInvoiceNum ?? 0
   );
   const baseNoInvoiceAmount = parseFloat(
      row.tempnoInvoiceAmount ?? row.noInvoiceAmount ?? row.taxInclusiveTotalPrice ?? 0
   );
   if (!baseNoInvoiceNum) {
      return 0;
   }
   return baseNoInvoiceAmount / baseNoInvoiceNum;
};
const invoiceNumBlur = (row) => {
   if (!row.currentInvoiceNum) {
      row.currentInvoiceNum = 0;
   }
   if (row.currentInvoiceNum > row.tempNoInvoiceNum) {
   const baseNoInvoiceNum = parseFloat(
      row.tempNoInvoiceNum ?? row.originalNoInvoiceNum ?? row.noInvoiceNum ?? 0
   );
   const baseNoInvoiceAmount = parseFloat(
      row.tempnoInvoiceAmount ?? row.noInvoiceAmount ?? row.taxInclusiveTotalPrice ?? 0
   );
   const unitPrice = getInvoiceCalcUnitPrice(row);
   if (!unitPrice) {
      row.currentInvoiceAmount = 0;
      row.noInvoiceNum = Number(baseNoInvoiceNum).toFixed(2);
      row.noInvoiceAmount = Number(baseNoInvoiceAmount).toFixed(2);
      return;
   }
   if (row.currentInvoiceNum > baseNoInvoiceNum) {
      proxy.$modal.msgWarning("本次开票数不得大于未开票数");
      row.currentInvoiceNum = 0;
   }
   // 计算本次开票金额
   row.currentInvoiceAmount = (
      row.currentInvoiceNum * row.taxInclusiveUnitPrice
   ).toFixed(2);
   row.currentInvoiceAmount = (row.currentInvoiceNum * unitPrice).toFixed(2);
   // 计算未开票数
   row.noInvoiceNum = (row.originalNoInvoiceNum - row.currentInvoiceNum).toFixed(
      2
   );
   row.noInvoiceNum = (baseNoInvoiceNum - row.currentInvoiceNum).toFixed(2);
   // 计算未开票金额
   row.noInvoiceAmount = (
      row.tempnoInvoiceAmount - row.currentInvoiceAmount
   ).toFixed(2);
   row.noInvoiceAmount = (row.noInvoiceNum * unitPrice).toFixed(2);
};
// 本次开票金额失焦操作
const invoiceAmountBlur = (row) => {
   if (!row.currentInvoiceAmount) {
      row.currentInvoiceAmount = 0;
   }
   const baseNoInvoiceNum = parseFloat(
      row.tempNoInvoiceNum ?? row.originalNoInvoiceNum ?? row.noInvoiceNum ?? 0
   );
   const baseNoInvoiceAmount = parseFloat(
      row.tempnoInvoiceAmount ?? row.noInvoiceAmount ?? row.taxInclusiveTotalPrice ?? 0
   );
   const unitPrice = getInvoiceCalcUnitPrice(row);
   if (!unitPrice) {
      row.currentInvoiceNum = 0;
      row.noInvoiceNum = Number(baseNoInvoiceNum).toFixed(2);
      row.noInvoiceAmount = Number(baseNoInvoiceAmount).toFixed(2);
      return;
   }
   // 计算是否超过开票总金额
   if (row.currentInvoiceAmount > row.tempnoInvoiceAmount) {
   if (row.currentInvoiceAmount > baseNoInvoiceAmount) {
      proxy.$modal.msgWarning("本次开票金额不得大于未开票金额");
      row.currentInvoiceAmount = 0;
   }
   // 计算本次开票数
   row.currentInvoiceNum = (
      row.currentInvoiceAmount / row.taxInclusiveUnitPrice
   ).toFixed(2);
   row.currentInvoiceNum = (row.currentInvoiceAmount / unitPrice).toFixed(2);
   console.log("row.currentInvoiceNum ", row.currentInvoiceNum);
   console.log(" row.originalNoInvoiceNum  ", row.originalNoInvoiceNum);
   // 计算未开票数
   row.noInvoiceNum = (row.originalNoInvoiceNum - row.currentInvoiceNum).toFixed(
      2
   );
   row.noInvoiceNum = (baseNoInvoiceNum - row.currentInvoiceNum).toFixed(2);
   // 计算未开票金额
   row.noInvoiceAmount = (
      row.tempnoInvoiceAmount - row.currentInvoiceAmount
   ).toFixed(2);
   row.noInvoiceAmount = (row.noInvoiceNum * unitPrice).toFixed(2);
};
onMounted(() => {