From 9276baaf6664e55e217253caca2151a10640764d Mon Sep 17 00:00:00 2001 From: zzq <a13193816592@163.com> Date: 星期三, 27 九月 2023 11:31:46 +0800 Subject: [PATCH] “报表表格求和” --- src/components/makepager/TableCommonView.vue | 179 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 131 insertions(+), 48 deletions(-) diff --git a/src/components/makepager/TableCommonView.vue b/src/components/makepager/TableCommonView.vue index 7c023f7..2c9631a 100644 --- a/src/components/makepager/TableCommonView.vue +++ b/src/components/makepager/TableCommonView.vue @@ -1,6 +1,6 @@ <!-- eslint-disable vue/no-use-v-if-with-v-for --> <template> - <div class="table-view" v-loading="loading"> + <div :class="{'table-view':true,'table_height':!showSummary}" v-loading="loading"> <el-table ref="table" border @@ -19,9 +19,18 @@ :default-expand-all="tableList.isDefaultExpandAll" :tree-props="{ children: 'child', hasChildren: 'hasChildren' }" :span-method="objectSpanMethod" + :summary-method="getSummaries" + :show-summary="showSummary" > - <el-table-column v-if="tableList.selectBox" type="selection" width="40"> </el-table-column> - <el-table-column v-if="tableList.selectIndex" type="index" label="搴忓彿" width="50"> </el-table-column> + <el-table-column v-if="tableList.selectBox" type="selection" width="40"> + </el-table-column> + <el-table-column + v-if="tableList.selectIndex" + type="index" + label="搴忓彿" + width="50" + > + </el-table-column> <el-table-column v-for="(item, i) in tableList.tableColumn" :key="i" @@ -34,7 +43,9 @@ v-if="item.isShowColumn" > <template slot-scope="scope"> - <span v-if="item.price">{{ "锟�" + number_format(scope.row[item.prop], 2, ".", ",") }}</span> + <span v-if="item.price">{{ + "锟�" + number_format(scope.row[item.prop], 2, ".", ",") + }}</span> <!-- 鐘舵�佹樉绀� --> <div v-else-if="item.status"> <span @@ -43,21 +54,30 @@ greenSlot: scope.row.status == '4', redSlot: scope.row.status == '5', blueSlot: scope.row.status == '3', - graySlot: scope.row.status == '1' + graySlot: scope.row.status == '1', }" >{{ - item.isCallMethod ? item.getCallMethod(scope.row[item.prop], scope.row) : scope.row[item.prop] + item.isCallMethod + ? item.getCallMethod(scope.row[item.prop], scope.row) + : scope.row[item.prop] }}</span > </div> <!-- 璋冪敤鏂规硶鏄剧ず鏂囧瓧 --> <div v-else-if="item.isCallMethod"> - <span>{{ item.getCallMethod(scope.row[item.prop], scope.row) }}</span> + <span>{{ + item.getCallMethod(scope.row[item.prop], scope.row) + }}</span> </div> <!-- 灏忎簬褰撳墠鏃堕棿鏄剧ず涓嶅悓棰滆壊 --> <span v-else-if="item.date" - :style="{ color: new Date().getTime() > new Date(scope.row[item.prop]).getTime() ? '#D23F3A' : '#606266' }" + :style="{ + color: + new Date().getTime() > new Date(scope.row[item.prop]).getTime() + ? '#D23F3A' + : '#606266', + }" >{{ timeAgo(scope.row[item.prop]) }}</span > <div v-else-if="item.conversion"> @@ -70,10 +90,18 @@ >{{ scope.row[item.prop] }}</span > <span v-else-if="item.propType == 'mulitple'"> - {{ scope.row[item.prop][item.propTwo] ? scope.row[item.prop][item.propTwo] : "--" }} + {{ + scope.row[item.prop][item.propTwo] + ? scope.row[item.prop][item.propTwo] + : "--" + }} </span> <span :class="item.className ? item.className : ''" v-else>{{ - scope.row[item.prop] ? scope.row[item.prop] : scope.row[item.prop] === 0 ? scope.row[item.prop] : "--" + scope.row[item.prop] + ? scope.row[item.prop] + : scope.row[item.prop] === 0 + ? scope.row[item.prop] + : "--" }}</span> </template> </el-table-column> @@ -85,15 +113,22 @@ <div class="overSpread1" v-show="iscolopen" @click="onMaskClick"></div> <div v-if="showCheckcol" class="styleBtn"> <i @click="checkcol()" class="label">...</i> - <el-checkbox-group v-model="showcolList" v-show="iscolopen" class="checkbox-group" @change="selCeckBoxList"> - <el-checkbox v-for="item in tableList.allcol" :label="item" :key="item">{{ item }} </el-checkbox> + <el-checkbox-group + v-model="showcolList" + v-show="iscolopen" + class="checkbox-group" + @change="selCeckBoxList" + > + <el-checkbox v-for="item in tableList.allcol" :label="item" :key="item" + >{{ item }} + </el-checkbox> </el-checkbox-group> </div> </div> </template> <script> -import { timeago } from "@/common/config/index" +import { timeago } from "@/common/config/index"; export default { name: "TableCommonView", props: { @@ -106,119 +141,163 @@ showStyle: true, tableInfomation: [], // 鎺ュ彛杩斿洖鏁版嵁 showcol: [], + countcol: [], allcol: [], highlight: false, tableColumn: [ // table琛ㄥ崟 - { label: "", prop: "", min: 200, tooltip: true } - ] - } + { label: "", prop: "", min: 200, tooltip: true }, + ], + }; }, showcol: { typeof: Array, - default: () => [] - } + default: () => [], + }, }, // 鍚堝苟鍗曞厓鏍� rowData: { type: Array, default: () => { - return [] - } + return []; + }, }, // 鍔犺浇鐨刲oading loading: { type: Boolean, - default: false + default: false, }, // 閫変腑鐨勬牱寮� selectClassRow: { type: Object, default: () => { - return {} - } + return {}; + }, }, showCheckcol: { type: Boolean, - default: true + default: true, + }, + showSummary:{ + type:Boolean, + default:false } }, data() { return { iscolopen: false, - showcolList: this.tableList.showcol - } + showcolList: this.tableList.showcol, + }; }, watch: {}, computed: {}, beforeUpdate() {}, methods: { onMaskClick() { - this.iscolopen = false + this.iscolopen = false; }, // 鍚堝苟鍗曞厓鏍� objectSpanMethod({ row, column, rowIndex, columnIndex }) { - row - column + row; + column; if (this.rowData && this.rowData.length > 0) { // 浜у搧BOM 琛ㄦ牸鐗规畩澶勭悊 鍚堝苟鍗曞厓鏍� if (columnIndex < 5 || columnIndex == 9) { - const _row = this.rowData[rowIndex] - const _col = _row > 0 ? 1 : 0 + const _row = this.rowData[rowIndex]; + const _col = _row > 0 ? 1 : 0; return { rowspan: _row, - colspan: _col - } + colspan: _col, + }; } } }, tableRowClick(row) { - this.$emit("tableRowClick", row) + this.$emit("tableRowClick", row); }, handleReserve(row) { - return row._id ? row._id : row.id + return row._id ? row._id : row.id; }, handleSelectionChange(val) { - this.$emit("getSelectArray", val) + this.$emit("getSelectArray", val); }, // 鍏叡璇︽儏 selCommonClick(row) { - this.$emit("selCommonClick", row) + this.$emit("selCommonClick", row); }, // 閫夋嫨鍒� checkcol() { - this.iscolopen = !this.iscolopen + this.iscolopen = !this.iscolopen; }, closeCheckbox() { - let label = document.querySelector(".label") + let label = document.querySelector(".label"); if (label) { - this.iscolopen = false + this.iscolopen = false; } }, selCeckBoxList(val) { - this.$emit("selTableCol", val) + this.$emit("selTableCol", val); }, // 鍗曢�夎鐩稿叧 tableRowClassName({ row }) { if (Object.keys(this.selectClassRow).length > 0) { if (row.id == this.selectClassRow.id) { - return "onSelect" + return "onSelect"; } } - this.$emit("tableRowClassName", row) + this.$emit("tableRowClassName", row); }, timeAgo(val) { - return timeago(val) - } - } -} + return timeago(val); + }, + //姹傚拰 + getSummaries(param) { + if(this.tableList.countcol&&this.tableList.countcol.length>0){ + const { columns, data } = param; + const sums = []; + columns.forEach((column, index) => { + if (index === 0) { + sums[index] = " "; + return; + } + this.tableList.countcol.forEach((countcols,idx) => { + if (column.label === countcols) { + 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); + sums[index] = sums[index].toLocaleString(); + // console.log(sums,"sums") + } else { + sums[index] = ""; + } + } else { + return; + } + }); + }); + return sums; + }else{ + } + }, + + }, +}; </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style lang="scss" scoped> +.table_height{ + height: 100%; +} .table-view { position: relative; - height: 100%; .blue { width: 70px; text-align: center; @@ -296,5 +375,9 @@ border-top-right-radius: 12px; overflow: auto; } + .el-table__body-wrapper{ + // height: ; + } } + </style> -- Gitblit v1.8.0