diff --git a/src/views/AppHourSale.vue b/src/views/AppHourSale.vue index d17a949..96496dd 100644 --- a/src/views/AppHourSale.vue +++ b/src/views/AppHourSale.vue @@ -5,7 +5,9 @@ export default { data() { return { summary: {}, - tableData: [] + tableData: [], + hourSummary: [], + hourSummaryStyle: {display: 'none'} } }, computed: { @@ -65,7 +67,7 @@ export default { } return {style, value: column.value} }) - } + }, }, methods: { getTableData() { @@ -78,6 +80,49 @@ export default { this.tableData = res.data?.page?.records?.map(e => ({...e, hour: `${`${e.hour - 1}`.padStart(2, '0')}:00-${e.hour.padStart(2, '0')}:00`})) || [] } }) + }, + handleSta({rowIndex}) { + const v = this + const summary = { + compareSaleAmt: 0, compareValidOrderNum: 0, currentSaleAmt: 0, currentValidOrderNum: 0, saleGrowthRate: 0 + } + v.tableData.forEach((e, i) => { + if (i <= rowIndex) { + summary.compareSaleAmt += Number(e.compareSaleAmt || 0) + summary.compareValidOrderNum += Number(e.compareValidOrderNum || 0) + summary.currentSaleAmt += Number(e.currentSaleAmt || 0) + summary.currentValidOrderNum += Number(e.currentValidOrderNum || 0) + summary.saleGrowthRate += Number(e.saleGrowthRate.replace("%", "") || 0) + } + if (i == rowIndex) { + summary.compareSaleAmt = summary.compareSaleAmt.toFixed(2) + summary.compareValidOrderNum = summary.compareValidOrderNum.toFixed(2) + summary.currentSaleAmt = summary.currentSaleAmt.toFixed(2) + summary.currentValidOrderNum = summary.currentValidOrderNum.toFixed(2) + summary.saleGrowthRate = summary.saleGrowthRate.toFixed(2) + "%" + } + }) + this.hourSummary = v.columns.map((column, i) => { + const isNumber = v => /^-?\d+(\.\d+)?%?$/.test(v) + const style = {textAlign: column.align} + if (column.width > 0) { + style.width = `${column.width}px` + } else { + style.flex = 1 + style.minWidth = 0 + } + return { + style, + value: isNumber(summary[column.prop]) ? summary[column.prop] : + i == 0 ? "时段合计" : "" + } + }) + this.hourSummaryStyle.display = "flex" + }, + handleMouseOver(evt) { + const getTop = e => e.offsetParent ? getTop(e.offsetParent) + e.offsetTop : e.offsetTop + const top = getTop(this.$el) + // this.$set(this.hourSummaryStyle, "top", (evt.clientY - top + 10) + "px") } }, watch: { @@ -91,11 +136,14 @@ export default {