Files
kengee-data-screen/src/views/AppHourSale.vue

185 lines
6.4 KiB
Vue
Raw Normal View History

2024-06-30 15:04:47 +08:00
<script>
export default {
name: "AppHourSale",
label: "市场看板-全门店时段销售",
data() {
return {
2024-07-05 17:36:16 +08:00
summary: {},
2024-07-08 01:42:15 +08:00
tableData: [],
hourSummary: [],
hourSummaryStyle: {display: 'none'}
2024-06-30 15:04:47 +08:00
}
},
computed: {
search: v => v.$marketBoard.search,
2024-08-05 03:28:19 +08:00
columns: v => {
let {currentDate, compareDate} = v.search
const {dayjs} = window
currentDate = currentDate ? dayjs(currentDate).format("YYYY-MM-DD") : ""
compareDate = compareDate ? dayjs(compareDate).format("YYYY-MM-DD") : ""
2024-07-05 17:36:16 +08:00
return [
2024-08-05 03:28:19 +08:00
{label: "日期", children: [{label: "时段", width: 100, prop: "hour"}]},
{
label: compareDate, align: 'center', children: [
{label: "销售额", prop: "compareSaleAmt", align: 'center'},
{label: "有效订单数", prop: "compareValidOrderNum", align: 'center'},
]
},
{
label: currentDate, align: 'center', children: [
{label: "销售额", prop: "currentSaleAmt", align: 'center'},
{label: "有效订单数", prop: "currentValidOrderNum", align: 'center'},
]
},
2024-07-05 17:36:16 +08:00
{label: "销售增长率", width: 80, align: 'center', prop: "saleGrowthRate"},
]
},
2024-08-05 03:28:19 +08:00
tableColumns: v => v.columns.map(e => e.children || e).flat(),
2024-07-05 17:36:16 +08:00
tableConfig: v => {
return {
headerBGC: 'rgba(13, 48, 99, 0.6)',
oddRowBGC: window.evenRowBGC(), evenRowBGC: "transparent",
header: v.columns.map(e => e.label), rowNum: 16,
columnWidth: v.columns.map(e => e.width || "0;flex:1;min-width:0;"),
align: v.columns.map(e => e.align || "left"),
data: v.tableData.map(e => v.columns.map(column => e[column.prop])),
}
},
2024-08-05 03:28:19 +08:00
summaryRow: v => v.tableColumns.map((column, i) => {
2024-07-05 17:36:16 +08:00
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(v.summary[column.prop]) ? v.summary[column.prop] :
i == 0 ? v.summary.hour : ""
}
}),
specialRow: v => {
2024-06-30 15:04:47 +08:00
let {currentDate, compareDate} = v.search
const {dayjs} = window
currentDate = currentDate ? dayjs(currentDate).format("YYYY-MM-DD") : ""
compareDate = compareDate ? dayjs(compareDate).format("YYYY-MM-DD") : ""
return [
2024-07-05 17:36:16 +08:00
{value: "日期", width: 100},
{value: compareDate, align: 'center'},
{value: currentDate, align: 'center'},
{width: 80},
].map(column => {
const style = {textAlign: column.align}
if (column.width > 0) {
style.width = `${column.width}px`
} else {
style.flex = 1
style.minWidth = 0
}
return {style, value: column.value}
})
2024-07-08 01:42:15 +08:00
},
2024-06-30 15:04:47 +08:00
},
methods: {
getTableData() {
const {$http, $waitFor} = window
$waitFor($http).then(() => $http.post("/data-boot/la/screen/marketBoard/hourSale", {
...this.search, limit: 999
})).then(res => {
if (res?.data) {
2024-07-05 17:36:16 +08:00
this.summary = res.data.total
2024-08-05 03:28:19 +08:00
this.tableData = res.data?.page?.records?.map(e => ({...e, hour: `${e.hour.padStart(2, '0')}:00-${`${Number(e.hour) + 1}`.padStart(2, '0')}:00`})) || []
2024-06-30 15:04:47 +08:00
}
})
2024-07-08 01:42:15 +08:00
},
2024-08-05 03:28:19 +08:00
handleSta({hour}) {
const rowIndex = this.tableData.findIndex(e => e.hour == hour)
2024-07-08 01:42:15 +08:00
const v = this
const summary = {
compareSaleAmt: 0, compareValidOrderNum: 0, currentSaleAmt: 0, currentValidOrderNum: 0, saleGrowthRate: 0
}
2024-08-05 03:28:19 +08:00
console.log(rowIndex)
2024-07-08 01:42:15 +08:00
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) + "%"
}
})
2024-08-05 03:28:19 +08:00
this.hourSummary = v.tableColumns.map((column, i) => {
2024-07-08 01:42:15 +08:00
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")
2024-06-30 15:04:47 +08:00
}
},
watch: {
search: {
immediate: true, deep: true, handler() {
this.getTableData()
}
}
}
}
</script>
<template>
2024-07-08 01:42:15 +08:00
<section class="AppHourSale" @mousemove="handleMouseOver">
2024-08-05 03:28:19 +08:00
<scroll-table :table-data="tableData" :columns="columns" @click="handleSta" @mouseout.native="hourSummaryStyle={display:'none'}"/>
<!--<dv-scroll-board :config="tableConfig" @mouseover="handleSta" @mouseout.native="hourSummaryStyle={display:'none'}"/>-->
2024-07-08 01:42:15 +08:00
<div class="summary flex hourSummary" :style="hourSummaryStyle">
<div class="item" v-for="(col,i) in hourSummary" :key="i" v-text="col.value" :style="col.style"/>
</div>
2024-07-05 17:36:16 +08:00
<div class="summary flex">
<div class="item" v-for="(col,i) in summaryRow" :key="i" v-text="col.value" :style="col.style"/>
</div>
2024-06-30 15:04:47 +08:00
</section>
</template>
<style>
.AppHourSale {
color: #fff;
box-sizing: border-box;
2024-07-08 01:42:15 +08:00
position: relative;
2024-06-30 15:04:47 +08:00
}
2024-07-08 01:42:15 +08:00
2024-08-05 03:28:19 +08:00
.AppHourSale .dv-scroll-board, .AppHourSale .scrollTable {
height: calc(100% - 60px) !important;
border-color: transparent;
2024-06-30 15:04:47 +08:00
}
2024-07-08 01:42:15 +08:00
.hourSummary {
width: 100%;
background-color: #07193D;
position: absolute;
left: 0;
}
2024-06-30 15:04:47 +08:00
</style>