chenrui
2025-06-04 b497a0b35c09e6b53324c14b7697c1e9e0ed36a9
src/views/salesManagement/salesLedger/index.vue
@@ -53,7 +53,7 @@
        <el-table-column label="业务员" prop="salesman" show-overflow-tooltip/>
        <el-table-column label="项目名称" prop="projectName" show-overflow-tooltip/>
        <el-table-column label="合同金额(元)" prop="contractAmount" show-overflow-tooltip/>
        <el-table-column label="录入人" prop="entryPerson" show-overflow-tooltip/>
        <el-table-column label="录入人" prop="entryPersonName" show-overflow-tooltip/>
        <el-table-column label="录入日期" prop="entryDate" show-overflow-tooltip/>
        <el-table-column fixed="right" label="操作" min-width="60" align="center">
          <template #default="scope">
@@ -104,7 +104,7 @@
          </el-col>
          <el-col :span="12">
            <el-form-item label="录入人:" prop="entryPerson">
              <el-select v-model="form.entryPerson" placeholder="请选择" clearable @change="changs">
              <el-select v-model="form.entryPerson" placeholder="请选择" clearable @change="changs" disabled>
                <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId"/>
              </el-select>
            </el-form-item>
@@ -132,7 +132,7 @@
            <el-button plain type="danger" @click="deleteProduct">删除</el-button>
          </el-form-item>
        </el-row>
        <el-table :data="productData" border @selection-change="productSelected">
        <el-table :data="productData" border @selection-change="productSelected"   show-summary :summary-method="summarizeMainTable">
          <el-table-column align="center" type="selection" width="55" />
          <el-table-column align="center" label="序号" type="index" width="60" />
          <el-table-column label="产品大类" prop="productCategory" />
@@ -190,7 +190,11 @@
      </template>
    </el-dialog>
    <el-dialog v-model="productFormVisible" :title="productOperationType === 'add' ? '新增产品' : '编辑产品'" width="40%" @close="closeProductDia">
      <el-form :model="productForm" label-width="140px" label-position="top" :rules="productRules" ref="productFormRef">
      <el-form :model="productForm"
               label-width="140px"
               label-position="top"
               :rules="productRules"
               ref="productFormRef">
        <el-row :gutter="30">
          <el-col :span="24">
            <el-form-item label="产品大类:" prop="productCategory">
@@ -227,19 +231,19 @@
          </el-col>
          <el-col :span="12">
            <el-form-item label="数量:" prop="quantity">
              <el-input v-model="productForm.quantity" placeholder="请输入" clearable/>
              <el-input v-model="productForm.quantity" placeholder="请输入" clearable @change="mathNum" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="含税单价(元):" prop="taxInclusiveUnitPrice">
              <el-input v-model="productForm.taxInclusiveUnitPrice" placeholder="请输入" clearable/>
              <el-input v-model="productForm.taxInclusiveUnitPrice" placeholder="请输入" clearable @change="mathNum" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="税率(%):" prop="taxRate">
              <el-select v-model="productForm.taxRate" placeholder="请选择" clearable>
              <el-select v-model="productForm.taxRate" placeholder="请选择" clearable  @change="mathNum">
                <el-option label="1" value="1"/>
                <el-option label="6" value="6"/>
                <el-option label="13" value="13"/>
@@ -250,12 +254,12 @@
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="含税总价(元):" prop="taxInclusiveTotalPrice">
              <el-input v-model="productForm.taxInclusiveTotalPrice" placeholder="请输入" clearable/>
              <el-input v-model="productForm.taxInclusiveTotalPrice" placeholder="请输入" clearable disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="不含税总价(元):" prop="taxExclusiveTotalPrice">
              <el-input v-model="productForm.taxExclusiveTotalPrice" placeholder="请输入" clearable/>
              <el-input v-model="productForm.taxExclusiveTotalPrice" placeholder="请输入" clearable disabled />
            </el-form-item>
          </el-col>
        </el-row>
@@ -284,7 +288,6 @@
import { getToken } from "@/utils/auth"
import pagination from '@/components/PIMTable/Pagination.vue'
import { ref } from 'vue'
import {Search} from "@element-plus/icons-vue";
import {ElMessageBox } from "element-plus";
import useUserStore from '@/store/modules/user'
import {userListNoPage} from "@/api/system/user.js";
@@ -447,13 +450,16 @@
    if (children && children.length > 0) {
      newItem.children = convertIdToValue(children);
    }
    return newItem;
  });
}
// 表格选择数据
const handleSelectionChange = (selection) => {
  selectedRows.value = selection
  // 过滤掉子数据
  selectedRows.value = selection.filter(item => item.children !== undefined);
  console.log('selection',selectedRows.value)
}
const productSelected = (selectedRows) => {
  productSelectedRows.value = selectedRows
@@ -467,7 +473,7 @@
      productList({salesLedgerId: row.id, type: 1}).then(res => {
      const index = tableData.value.findIndex(item => item.id === row.id);
      if (index > -1) {
        tableData.value[index].children = res.rows;
        tableData.value[index].children = res;
      }
      expandedRowKeys.value.push(row.id)
    })
@@ -480,26 +486,7 @@
}
// 主表合计方法
const summarizeMainTable = (param) => {
  const { columns, data } = param;
  const sums = [];
  columns.forEach((column, index) => {
    if (index === 0) {
      sums[index] = '合计';
      return;
    }
    const prop = column.property;
    if (['contractAmount'].includes(prop)) {
      const values = data.map(item => Number(item[prop]));
      if (!values.every(value => isNaN(value))) {
        sums[index] = values.reduce((acc, val) => (!isNaN(val) ? acc + val : acc), 0);
      } else {
        sums[index] = '';
      }
    } else {
      sums[index] = '';
    }
  })
  return sums;
  return proxy.summarizeTable(param, ['contractAmount','taxInclusiveTotalPrice','taxExclusiveTotalPrice']);
};
// 子表合计方法
const summarizeChildrenTable = (param) => {
@@ -534,6 +521,7 @@
  customerList().then(res => {
    customerOption.value = res
  })
  form.value.entryPerson = userStore.id
  if (type === 'edit') {
    currentId.value = row.id;
    getSalesLedgerWithProducts({id: row.id, type: 1}).then(res => {
@@ -689,7 +677,7 @@
    }).catch(() => {
      proxy.$modal.msg("已取消")
    })
  }
}
// 关闭产品弹框
@@ -745,12 +733,25 @@
  const day = String(today.getDate()).padStart(2, '0');
  return `${year}-${month}-${day}`;
}
const mathNum = (val) => {
  productForm.value.taxExclusiveTotalPrice = proxy.calculateTaxExclusiveTotalPrice(val, productForm.value.taxRate)
const mathNum = () => {
  console.log('productForm.value',productForm.value)
  if(!productForm.value.taxInclusiveUnitPrice){
    return
  }
  if(!productForm.value.quantity){
    return
  }
  // 含税总价计算
  productForm.value.taxInclusiveTotalPrice = proxy.calculateTaxIncludeTotalPrice(productForm.value.taxInclusiveUnitPrice, productForm.value.quantity)
  if(productForm.value.taxRate){
    // 不含税总价计算
    productForm.value.taxExclusiveTotalPrice = proxy.calculateTaxExclusiveTotalPrice(productForm.value.taxInclusiveTotalPrice, productForm.value.taxRate)
  }
}
getList()
</script>
<style scoped lang="scss">
</style>
</style>