yangfeng
2023-08-24 4c873da777ea0c6ce0d342ce793fabae89b3f66d
src/components/makepager/CommonFormTableView.vue
@@ -1,13 +1,8 @@
<template>
  <div class="page-view">
    <el-form ref="form" :model="tableList" :show-message="false" label-position="right">
      <el-table
        :data="tableList.tableData"
        :show-summary="showSummary.show"
        :summary-method="getSummaries"
        :span-method="arraySpanMethod"
        style="width: 100%"
      >
      <el-table :data="tableList.tableData" style="width: 100%">
        <el-table-column type="index" label="编号" width="50" align="center"></el-table-column>
        <el-table-column
          v-for="(item, i) in tableList.tableColumn"
          :key="i"
@@ -127,25 +122,9 @@
    </el-form>
    <div v-if="!detailEnter" style="margin: 10px">
      <el-button size="small" type="primary" @click="add">新增</el-button>
      <!-- <el-button size="small" type="primary" disabled>导入明细</el-button> -->
      <el-button size="small" type="primary" @click="empty">清空</el-button>
      <el-button size="small" type="primary" @click="recalculate" :disabled="isRecalculate ? false : true"
        >重算</el-button
      >
    </div>
    <div v-if="showSummary.total || showSummary.refundable" style="height: 42px; line-height: 42px">
      <el-row :gutter="10">
        <el-col v-if="showSummary.total" :span="2" :offset="22">
          <span style="font-weight: bold">合计</span>
          <span style="margin-left: 10px">{{ total }}</span>
        </el-col>
        <el-col v-if="showSummary.refundable" :span="2" :offset="22">
          <span style="font-weight: bold">应退款</span>
          <span style="margin-left: 10px">0.00</span>
        </el-col>
      </el-row>
    </div>
    <!-- 合同订单 -->
    <!-- 产品名称 -->
    <SelectCommonDialog
      v-if="editSelCommonConfig.editVisible"
      :edit-common-config="editSelCommonConfig"
@@ -237,60 +216,6 @@
    handleSelectionChange(val) {
      this.$emit("getSelectArray", val)
    },
    // 行合并
    arraySpanMethod() {
      if (this.showSummary.show) {
        this.$nextTick(() => {
          if (this.$refs.table) {
            var current = this.$refs.table.querySelector(".el-table__footer-wrapper").querySelector(".el-table__footer")
            var cell = current.rows[0].cells
            for (let i = 0; i < this.showSummary.mergeNumber; i++) {
              cell[i].style.display = "none"
            }
            cell[this.showSummary.mergeNumber].classList.remove("is-left")
            cell[this.showSummary.mergeNumber].colSpan = this.showSummary.mergeNumber.toString()
          }
        })
      }
    },
    // 合计
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        // // 更改行名称
        if (index === this.showSummary.mergeNumber) {
          sums[index] = "小计:"
          return
        }
        const title = ["#", "产品名称"]
        // 去除某些不需要计算的数据
        if (title.includes(column.label)) {
          sums[index] = ""
          return
        }
        // 把当前表格数据中同个分类的数据收集起来
        const values = data.map((item) => Number(item[column.property]))
        // 过滤掉
        if (!values.every((value) => Number.isNaN(value))) {
          sums[index] = ` ${values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!Number.isNaN(value)) {
              const num = prev + curr
              return Number(num.toFixed(2))
            } else {
              return Number(prev.toFixed(2))
            }
          }, 0)}`
        } else {
          sums[index] = ""
        }
        if (column.property === "total") {
          this.total = sums[index]
        }
      })
      return sums
    },
    // 数字换行为金额显示格式
    number_format(number, decimals, dec_point, thousands_sep) {
      decimals = 2 //这里默认设置保留两位小数,也可以注释这句采用传入的参数
@@ -332,21 +257,6 @@
    empty() {
      this.isRecalculate = false
      this.$emit("emptyProductClick")
    },
    // 重算
    recalculate() {
      this.$confirm("确定要重算明细所有行?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$emit("recalculateProductClick")
          this.tableList.tableData.map((ite) => {
            ite.total = ite.amount ? ite.amount * ite.price : 1 * ite.price
          })
        })
        .catch(() => {})
    },
    // 选择产品名称相关方法
    querySearchAsync(queryString, cb) {
@@ -406,6 +316,10 @@
        }
      })
      this.$emit("clearupProduct", this.tableList.tableData)
    },
    // 删除
    deleteClient(row) {
      this.$emit("deleteProduct", row)
    }
  }
}