赵士淞
2023-03-20 c5a26f16570f1ed8e259dffa226c70eaab36f814
eladmin-web-master/src/views/project/projectTask/index.vue
@@ -87,7 +87,7 @@
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" show-summary :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
      <el-table ref="table" v-loading="crud.loading" :summary-method="getSummaries" show-summary :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column show-overflow-tooltip prop="name" label="名称" width="180" />
        <el-table-column show-overflow-tooltip prop="projectName" label="所属项目" width="180">
@@ -249,6 +249,28 @@
        // 项目列表
        this.projectList = res
      })
    },
    // 表格统计
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        // 7/8号单元格
        if (index === 7 || index === 8) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
          }
        }
      })
      return sums
    }
  }
}