AreaStatisticsComp.vue
7.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<template>
<view class="h-c-container">
<CardNvue :auto-height="true" card-padding="20rpx 28rpx 28rpx">
<template #content>
<view class="table">
<IndicatorsFilterTitleVue :title="t('PreMenu.regionalStatistics')" :options="indicatorsList" :options-props="indicatorsOptions"
@change="handleCurrentKeyChange" />
<view class="table-head" style="margin-top: 20rpx;">
<view class="table-head-item">
<text class="table-head-item-text">{{ t('table.areaName') }}</text>
</view>
<view class="table-head-item">
<text class="table-head-item-text">{{ t('table.value') }}</text>
</view>
<l-popover placement="bottom" v-if="hasPreviers">
<view class="table-head-item" style="display: flex;flex-direction: row;">
<text class="table-head-item-text">{{ t('DateType.lastWeekDay') }}</text>
<uv-icon name="info-circle" size="28rpx" style="margin-left: 8rpx;" color="#90949D"></uv-icon>
</view>
<template #content>
<view style="width: 400rpx;">
<uv-text
:text="`${t('DateType.lastWeekDay')}:${previers.startDate} ${t('maintenance.common.splitDate')} ${previers.endDate}`"
color="#387CF5" size="24rpx"></uv-text>
</view>
</template>
</l-popover>
<view class="table-head-item last-table" v-if="hasPreviers">
<text class="table-head-item-text">{{ t('echarts.growthRate') }}</text>
</view>
</view>
<view class="table-body" v-if="tableList.length>0">
<view class="table-body-item" v-for="(item,index) in tableList" :key="index">
<view class="table-body-item-value table-body-item-name">
<uv-text class="table-body-item-value-text" align="center" color="#202328" size="26rpx" :lines="1"
:text="item.gateName"></uv-text>
</view>
<view class="table-body-item-value">
<text class="table-body-item-value-text">{{formateVal(item?.[currentKey])}}</text>
</view>
<view class="table-body-item-value" v-if="hasPreviers">
<text class="table-body-item-value-text">{{formateVal(previersList[index]?.[currentKey])}}</text>
</view>
<view class="table-body-item-value" v-if="hasPreviers">
<uv-icon
:name="calRateAndFlag(item?.[currentKey],previersList[index]?.[currentKey])?.flag === '1'?'arrow-up-fill':'arrow-down-fill'"
v-if="calRateAndFlag(item?.[currentKey],previersList[index]?.[currentKey])?.flag !== '2'"
:color="['#00B274','#ff3000'][calRateAndFlag(item?.[currentKey],previersList[index]?.[currentKey])?.flag || 2]"
size="16rpx" style="margin-top: 4rpx;margin-right: 6rpx;" />
<text class="table-body-item-value-text"
:class="['decrease','increase','normal'][calRateAndFlag(item?.[currentKey],previersList[index]?.[currentKey])?.flag || 1]">
{{ calRateAndFlag(item?.[currentKey],previersList[index]?.[currentKey])?.rate }}</text>
</view>
</view>
</view>
<view class="p-empty" v-else style="margin-top: 40rpx;">
<image class="p-empty-img" src="/static/common/empty.png" mode=""></image>
<text class="p-empty-text chart-text">{{ t('maintenance.monitor.project.empty.text') }}</text>
</view>
</view>
</template>
</CardNvue>
</view>
</template>
<script setup>
import {
ref,
onMounted,
computed
} from 'vue'
import {
formatSeconds,
calculatePreviousPeriod
} from '@/utils'
import {
getUserIndicatorIndexApi,
getAreaAnalysisStatisApi
} from '@/api'
import {
t
} from '@/plugins/index.js'
import PageOptions from '@/components/PageOptions.vue'
import CardNvue from '@/pages/flow/components/Card.nvue'
import CustomNavBar from '@/components/CustomNav.nvue'
import LPopover from '@/uni_modules/lime-popover/components/l-popover/l-popover.vue'
import IndicatorsFilterTitleVue from '@/components/IndicatorsFilterTitle.vue'
// 格式化数值
const formateVal = (val) => {
if (currentKey.value?.endsWith('Time')) {
return formatSeconds(val)
}
return val
}
// 计算增长率及颜色
const calRateAndFlag = (fir, last) => {
// 测试说:需要与pc保持一致,因此都设置为0
// fir有值 last 无值 +100%
// fir无值 last 有值 -100%
// fir无值 last 无值 0%
if (!fir && !last) {
return {
rate: '0%',
flag: '2'
}
} else if (fir && !last) {
return {
// rate: '+100%',
rate: '0%',
flag: '2'
}
} else if (!fir && last) {
return {
// rate: '-100%',
rate: '0%',
flag: '2'
}
}
const rate = ((fir - last) / last * 100).toFixed(2)
if (rate > 0) {
return {
rate: `+${rate}%`,
flag: '1'
}
} else {
return {
rate: `${rate}%`,
flag: '0'
}
}
}
/********** 列表展示 *********/
const initData = (val) => {
params.value = val
if (!!currentKey.value) {
getTableList()
} else {
initIndicatorList()
}
}
// 存在上周期数据
const hasPreviers = computed(() => {
return ['yearMonth', 'year', 'week', 'date'].includes(params.value.type)
})
const tableList = ref([])
const previersList = ref([])
const params = ref({})
const previers = ref({})
const getTableList = async () => {
try {
const {
data
} = await getAreaAnalysisStatisApi({
mallId: params.value.storeId,
startDate: params.value.startDate,
endDate: params.value.endDate
})
tableList.value = data || []
// 如果有上周期数据,则获取上周期数据
if (hasPreviers.value) {
previers.value = calculatePreviousPeriod(params.value)
const {
startDate,
endDate
} = previers.value
const {
data: previersData
} = await getAreaAnalysisStatisApi({
mallId: params.value.storeId,
startDate,
endDate
})
previersList.value = previersData || []
}
} catch (e) {
console.log(e);
}
}
/********** 指标相关 *********/
const indicatorsOptions = {
label: 'indexName',
value: 'indexKey'
}
// onMounted(() => {
// flag.value = true
// })
const handleCurrentKeyChange = (e) => {
currentKey.value = e
}
const currentKey = ref('')
const indicatorsList = ref([])
const initIndicatorList = async () => {
try {
const {
data
} = await getUserIndicatorIndexApi({
id: params.value.storeId
})
indicatorsList.value = data?.filter(item => item.status === 1) || []
currentKey.value = data.length > 0 ? data[0].indexKey : ''
params.value.currentKey = currentKey.value
getTableList()
} catch (e) {
console.log(e);
}
}
defineExpose({
initData
})
</script>
<style lang="scss" scoped>
@import '@/styles/table.scss';
.table-body-item-value-text.increase {
color: #FF3000;
}
.table-body-item-value-text.decrease {
color: #00B274;
}
</style>