gaoluyang
2025-05-20 7aa0e0f68d2a3d1268a64e49ab47c0c046265e84
src/views/procurementManagement/procurementLedger/index.vue
@@ -2,14 +2,14 @@
  <div class="app-container">
    <div class="search_form">
      <div>
        <span class="search_title">客户名称:</span>
        <span class="search_title">采购合同号:</span>
        <el-input
            v-model="searchForm.customerName"
            v-model="searchForm.purchaseContractNumber"
            style="width: 240px"
            placeholder="请输入"
            @change="handleQuery"
            clearable
            :prefix-icon="Search"
            prefix-icon="Search"
        />
        <el-button type="primary" @click="handleQuery" style="margin-left: 10px">搜索</el-button>
      </div>
@@ -40,20 +40,19 @@
              <el-table-column label="单位" prop="unit" />
              <el-table-column label="数量" prop="quantity" />
              <el-table-column label="税率(%)" prop="taxRate" />
              <el-table-column label="含税单价(元)" prop="taxInclusiveUnitPrice" />
              <el-table-column label="含税总价(元)" prop="taxInclusiveTotalPrice" />
              <el-table-column label="不含税总价(元)" prop="taxExclusiveTotalPrice" />
              <el-table-column label="含税单价(元)" prop="taxInclusiveUnitPrice" :formatter="formattedNumber" />
              <el-table-column label="含税总价(元)" prop="taxInclusiveTotalPrice" :formatter="formattedNumber" />
              <el-table-column label="不含税总价(元)" prop="taxExclusiveTotalPrice" :formatter="formattedNumber" />
            </el-table>
          </template>
        </el-table-column>
        <el-table-column align="center" label="序号" type="index" width="60" />
        <el-table-column label="采购合同号" prop="purchaseContractNumber" show-overflow-tooltip/>
        <el-table-column label="销售合同号" prop="salesContractNo" show-overflow-tooltip/>
        <el-table-column label="客户合同号" prop="customerContractNo" show-overflow-tooltip/>
        <el-table-column label="客户名称" prop="customerName" show-overflow-tooltip/>
        <el-table-column label="业务员" prop="salesman" show-overflow-tooltip/>
        <el-table-column label="供应商名称" prop="supplierName" 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="contractAmount" show-overflow-tooltip :formatter="formattedNumber"/>
        <el-table-column label="录入人" prop="recorderName" 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">
@@ -64,56 +63,48 @@
      <pagination v-show="total > 0" :total="total" layout="total, sizes, prev, pager, next, jumper" :page="page.current"
                  :limit="page.size" @pagination="paginationChange" />
    </div>
    <el-dialog v-model="dialogFormVisible" :title="operationType === 'add' ? '新增销售台账页面' : '编辑销售台账页面'" width="70%" @close="closeDia">
    <el-dialog v-model="dialogFormVisible" :title="operationType === 'add' ? '新增采购台账页面' : '编辑采购台账页面'" width="70%" @close="closeDia">
      <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="销售合同号:" prop="salesContractNo">
              <el-input v-model="form.salesContractNo" placeholder="自动生成" clearable disabled/>
            <el-form-item label="采购合同号:" prop="purchaseContractNumber">
              <el-input v-model="form.purchaseContractNumber" placeholder="请输入" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="业务员:" prop="salesman">
              <el-select v-model="form.salesman" placeholder="请选择" clearable>
                <el-option v-for="item in userList" :key="item.nickName" :label="item.nickName" :value="item.nickName"/>
            <el-form-item label="销售合同号:" prop="salesLedgerId">
              <el-select v-model="form.salesLedgerId" placeholder="请选择" clearable>
                <el-option v-for="item in salesContractList" :key="item.id" :label="item.salesContractNo" :value="item.id"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="客户合同号:" prop="customerContractNo">
              <el-input v-model="form.customerContractNo" placeholder="请输入" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户名称:" prop="customerId">
              <el-select v-model="form.customerId" placeholder="请选择" clearable>
                <el-option v-for="item in customerOption" :key="item.id" :label="item.customerName" :value="item.id">
                  {{item.customerName + '——' + item.taxpayerIdentificationNumber}}
                </el-option>
            <el-form-item label="供应商名称:" prop="supplierId">
              <el-select v-model="form.supplierId" placeholder="请选择" clearable>
                <el-option v-for="item in supplierList" :key="item.id" :label="item.supplierName" :value="item.id"/>
              </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/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="录入人:" prop="entryPerson">
              <el-select v-model="form.entryPerson" placeholder="请选择" clearable>
                <el-option v-for="item in userList" :key="item.nickName" :label="item.nickName" :value="item.nickName"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="录入人:" prop="recorderId">
              <el-select v-model="form.recorderId" placeholder="请选择" clearable disabled>
                <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="录入日期:" prop="entryDate">
              <el-date-picker
                  disabled
                  style="width: 100%"
                  v-model="form.entryDate"
                  value-format="YYYY-MM-DD"
@@ -131,7 +122,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="summarizeProTable">
          <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" />
@@ -139,12 +130,12 @@
          <el-table-column label="单位" prop="unit" />
          <el-table-column label="数量" prop="quantity" />
          <el-table-column label="税率(%)" prop="taxRate" />
          <el-table-column label="含税单价(元)" prop="taxInclusiveUnitPrice" />
          <el-table-column label="含税总价(元)" prop="taxInclusiveTotalPrice" />
          <el-table-column label="不含税总价(元)" prop="taxExclusiveTotalPrice" />
          <el-table-column label="含税单价(元)" prop="taxInclusiveUnitPrice" :formatter="formattedNumber"/>
          <el-table-column label="含税总价(元)" prop="taxInclusiveTotalPrice" :formatter="formattedNumber"/>
          <el-table-column label="不含税总价(元)" prop="taxExclusiveTotalPrice" :formatter="formattedNumber"/>
          <el-table-column fixed="right" label="操作" min-width="60" align="center">
            <template #default="scope">
              <el-button link type="primary" size="small" @click="openProductForm('edit', scope.row);">编辑</el-button>
              <el-button link type="primary" size="small" @click="openProductForm('edit', scope.row, scope.$index);">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
@@ -157,7 +148,7 @@
        </el-row>
        <el-row :gutter="30">
          <el-col :span="24">
            <el-form-item label="附件材料·:" prop="remark">
            <el-form-item label="附件材料:" prop="remark">
              <el-upload
                  v-model:file-list="fileList"
                  :action="upload.url"
@@ -223,7 +214,7 @@
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="含税单价(元):" prop="taxInclusiveUnitPrice">
              <el-input v-model="productForm.taxInclusiveUnitPrice" placeholder="请输入" clearable/>
              <el-input-number v-model="productForm.taxInclusiveUnitPrice" :precision="2" :step="0.1" clearable style="width: 100%"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
@@ -239,12 +230,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-number v-model="productForm.taxInclusiveTotalPrice" :precision="2" :step="0.1" clearable style="width: 100%"/>
            </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-number v-model="productForm.taxExclusiveTotalPrice" :precision="2" :step="0.1" clearable style="width: 100%"/>
            </el-form-item>
          </el-col>
        </el-row>
@@ -277,19 +268,23 @@
import {ElMessageBox } from "element-plus";
import {userListNoPage} from "@/api/system/user.js";
import {
  ledgerList,
  productList,
  customerList,
  addOrUpdateSalesLedger,
  getSalesLedgerWithProducts, delLedger, addOrUpdateSalesLedgerProduct, delProduct, delLedgerFile
  getSalesLedgerWithProducts, addOrUpdateSalesLedgerProduct, delProduct, delLedgerFile
} from "@/api/salesManagement/salesLedger.js";
import {
  addOrEditPurchase,
  delPurchase,
  getSalesNo,
  purchaseList,
  productList, getPurchaseById, getOptions
} from "@/api/procurementManagement/procurementLedger.js";
const { proxy } = getCurrentInstance()
const tableData = ref([])
const productData = ref([])
const selectedRows = ref([])
const productSelectedRows = ref([])
const userList = ref([])
const customerOption = ref([])
const salesContractList = ref([])
const supplierList = ref([])
const tableLoading = ref(false)
const page = reactive({
  current: 1,
@@ -297,38 +292,39 @@
})
const total = ref(0)
const fileList = ref([])
import useUserStore from "@/store/modules/user"
const userStore = useUserStore()
// 用户信息表单弹框数据
const operationType = ref('')
const dialogFormVisible = ref(false)
const data = reactive({
  searchForm: {
    customerName: '',
    purchaseContractNumber: '',
  },
  form: {
    salesContractNo: '',
    salesman: '',
    customerContractNo: '',
    customerId: '',
    purchaseContractNumber: '',
    salesLedgerId: '',
    projectName: '',
    entryPerson: '',
    recorderId: '',
    entryDate: '',
    maintenanceTime: '',
    productData: []
    productData: [],
    supplierName: '',
    supplierId: '',
  },
  rules: {
    salesman: [{ required: true, message: "请选择", trigger: "change" }],
    customerContractNo: [{ required: true, message: "请输入", trigger: "blur" }],
    customerId: [{ required: true, message: "请选择", trigger: "change" }],
    purchaseContractNumber: [{ required: true, message: "请输入", trigger: "blur" }],
    salesLedgerId: [{ required: true, message: "请选择", trigger: "change" }],
    projectName: [{ required: true, message: "请输入", trigger: "blur" }],
    entryPerson: [{ required: true, message: "请选择", trigger: "change" }],
    entryDate: [{ required: true, message: "请选择", trigger: "change" }],
    supplierId: [{ required: true, message: "请输入", trigger: "blur" }],
  }
})
const { searchForm, form, rules } = toRefs(data)
// 产品表单弹框数据
const productFormVisible = ref(false)
const productOperationType = ref('')
const productOperationIndex = ref('')
const currentId = ref('')
const productFormData = reactive({
  productForm: {
@@ -362,6 +358,9 @@
  headers: { Authorization: "Bearer " + getToken() },
})
const formattedNumber = (row, column, cellValue) => {
  return parseFloat(cellValue).toFixed(2);
};
// 查询列表
/** 搜索按钮操作 */
const handleQuery = () => {
@@ -375,13 +374,16 @@
}
const getList = () => {
  tableLoading.value = true
  ledgerList({...searchForm.value, ...page}).then(res => {
  purchaseList({...searchForm.value, ...page}).then(res => {
    tableLoading.value = false
    tableData.value = res.rows
    tableData.value.map(item => {
      item.children = []
    })
    total.value = res.total
    expandedRowKeys.value = []
  }).catch(() => {
    tableLoading.value = false
  })
}
// 表格选择数据
@@ -397,7 +399,7 @@
  if (expandedRows.length > 0) {
    expandedRowKeys.value = []
    try {
      productList({salesLedgerId: row.id}).then(res => {
      productList({salesLedgerId: row.id, type: 2}).then(res => {
        const index = tableData.value.findIndex(item => item.id === row.id);
        if (index > -1) {
          tableData.value[index].children = res.rows;
@@ -413,67 +415,39 @@
}
// 主表合计方法
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']);
};
// 子表合计方法
const summarizeChildrenTable = (param) => {
  const { columns, data } = param;
  const sums = [];
  columns.forEach((column, index) => {
    if (index === 0) {
      sums[index] = '合计';
      return;
    }
    const prop = column.property;
    if (['taxInclusiveUnitPrice', 'taxInclusiveTotalPrice', 'taxExclusiveTotalPrice'].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;
}
const summarizeProTable = (param) => {
  return proxy.summarizeTable(param, ['taxInclusiveUnitPrice', 'taxInclusiveTotalPrice', 'taxExclusiveTotalPrice']);
};
// 打开弹框
const openForm = (type, row) => {
  operationType.value = type
  form.value = {}
  productData.value = []
  fileList.value = []
  userListNoPage().then(res => {
    userList.value = res.data
  })
  customerList().then(res => {
    customerOption.value = res
  getSalesNo().then(res => {
    salesContractList.value = res
  })
  getOptions().then(res => {
    supplierList.value = res.data
  })
  form.value.recorderId = userStore.id
  form.value.entryDate = getCurrentDate();
  if (type === 'edit') {
    currentId.value = row.id;
    getSalesLedgerWithProducts({id: row.id}).then(res => {
    getPurchaseById({id: row.id, type: 2}).then(res => {
      form.value = {...res}
      productData.value = form.value.productData
      fileList.value = form.value.salesLedgerFiles
      if(form.value.salesLedgerFiles) {
        fileList.value = form.value.salesLedgerFiles
      } else {
        fileList.value = []
      }
    })
  }
  dialogFormVisible.value = true
@@ -481,7 +455,7 @@
// 上传前校检
function handleBeforeUpload(file) {
  // 校检文件大小
  if (file.size > 1024 * 1024) {
  if (file.size > 1024 * 1024 * 10) {
    proxy.$modal.msgError('上传文件大小不能超过10MB!')
    return false
  }
@@ -506,11 +480,10 @@
}
// 移除文件
function handleRemove (file) {
  console.log('handleRemove', file)
  console.log('operationType.value', operationType.value)
  console.log('handleRemove', file.id)
  if (operationType.value === 'edit') {
    let ids = []
    ids.push(file.value.id)
    ids.push(file.id)
    delLedgerFile(ids).then(res => {
      proxy.$modal.msgSuccess("删除成功")
    })
@@ -531,7 +504,8 @@
        tempFileIds = fileList.value.map(item => item.tempId)
      }
      form.value.tempFileIds = tempFileIds
      addOrUpdateSalesLedger(form.value).then(res => {
      form.value.type = 2
      addOrEditPurchase(form.value).then(res => {
        proxy.$modal.msgSuccess("提交成功")
        closeDia()
        getList()
@@ -545,8 +519,9 @@
  dialogFormVisible.value = false
}
// 打开产品弹框
const openProductForm = (type, row) => {
const openProductForm = (type, row, index) => {
  productOperationType.value = type
  productOperationIndex.value = index
  productForm.value = {}
  proxy.resetForm("productFormRef")
  if (type === 'edit') {
@@ -561,7 +536,11 @@
      if (operationType.value === "edit") {
        submitProductEdit()
      } else {
        productData.value.push({...productForm.value})
        if (productOperationType.value === 'add') {
          productData.value.push({...productForm.value})
        } else {
          productData.value[productOperationIndex.value] = {...productForm.value}
        }
        closeProductDia()
      }
    }
@@ -569,10 +548,11 @@
}
const submitProductEdit = () => {
  productForm.value.salesLedgerId = currentId.value
  productForm.value.type = 2
  addOrUpdateSalesLedgerProduct(productForm.value).then(res => {
    proxy.$modal.msgSuccess("提交成功")
    closeProductDia()
    getSalesLedgerWithProducts({id: currentId.value}).then(res => {
    getPurchaseById({id: currentId.value, type: 2}).then(res => {
      productData.value = res.productData
    })
  })
@@ -606,7 +586,7 @@
      delProduct(ids).then(res => {
        proxy.$modal.msgSuccess("删除成功")
        closeProductDia()
        getSalesLedgerWithProducts({id: currentId.value}).then(res => {
        getSalesLedgerWithProducts({id: currentId.value, type: 2}).then(res => {
          productData.value = res.productData
        })
      })
@@ -631,7 +611,7 @@
        type: 'warning',
      }
  ).then(() => {
    proxy.download("/sales/ledger/export", {}, '销售台账.xlsx')
    proxy.download("/purchase/ledger/export", {}, '采购台账.xlsx')
  }).catch(() => {
    proxy.$modal.msg("已取消")
  })
@@ -653,7 +633,7 @@
        type: 'warning',
      }
  ).then(() => {
    delLedger(ids).then(res => {
    delPurchase(ids).then(res => {
      proxy.$modal.msgSuccess("删除成功")
      getList()
    })
@@ -661,6 +641,14 @@
    proxy.$modal.msg("已取消")
  })
}
// 获取当前日期并格式化为 YYYY-MM-DD
function getCurrentDate() {
  const today = new Date();
  const year = today.getFullYear();
  const month = String(today.getMonth() + 1).padStart(2, '0'); // 月份从0开始
  const day = String(today.getDate()).padStart(2, '0');
  return `${year}-${month}-${day}`;
}
getList()
</script>