repeatCustomerStore.vue
5.57 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
<template>
<div class="repeat-customer-container" v-loading="loading">
<div class="analysis-date-condition">
<div class="condition-item-option">
<el-date-picker
class="date-input analysis-date-input times-box"
v-model="customTime"
value-format="yyyy-MM-dd"
align="right"
type="daterange"
size="mini"
:picker-options="pickerOptions1"
range-separator="-"
:start-placeholder="$t('table.startTime')"
:end-placeholder="$t('table.endTime')">
</el-date-picker>
</div>
<div class="condition-item btn-condition-item">
<el-button type="primary" class="primary-btn analysis-collapse-btn" size="samll" @click="clickHandle">{{$t('button.confirm')}}</el-button>
<el-button type="primary" class="primary-btn analysis-collapse-btn" size="samll" @click="downloadHandle">{{$t('allPages.loadData')}}</el-button>
</div>
</div>
<el-table :data="tableData" class="asis-table baseasis-table" :max-height="tableHeight">
<el-table-column prop="orderNum" align="center" label="序号"></el-table-column>
<el-table-column prop="mallId" align="center" label="门店ID"></el-table-column>
<el-table-column prop="name" align="center" label="门店名称" show-overflow-tooltip></el-table-column>
<el-table-column prop="countdate" align="center" label="日期" :formatter="dateFormatter"></el-table-column>
<el-table-column prop="count" align="center" label="多次到店人数"></el-table-column>
</el-table>
<el-pagination
class="page-wrapper"
background
tooltip-effect="light"
:current-page="currentPage"
:page-sizes="[10, 20, 50, 100]"
:page-size="pageSize"
@size-change="sizeChange"
@current-change="currentChange"
layout="sizes, prev, pager, next, slot, jumper"
:total="total">
<span class="slot-pagination-ele slot-ele-total">{{$t('table.pageHead')}} {{ total }} {{$t('table.pageTail')}}</span>
</el-pagination>
</div>
</template>
<script>
export default {
data() {
return {
pickerOptions1: {
disabledDate(time) {
return time.getTime() > Date.now()
}
},
customTime: [],
loading: false,
allData: [],
tableData: [],
downloadData: [],
currentPage: 1,
pageSize: 10,
total: 0
}
},
computed: {
tableHeight() {
// 浏览器内部高度 - 条件容器高 - 页码容器 - 底部距离
return window.innerHeight - 54 - 58 - 40
}
},
watch: {
},
created() {
this.customTime = [
this.dayReduce(new Date(), 7),
dateUnit.dateFormat(new Date(), 'yyyy-MM-dd')
]
},
mounted() {
// this.getData()
},
methods: {
getData() {
let { customTime } = this
, props = ['mallId', 'name', 'countdate', 'count']
this.currentPage = 1
this.total = 0
this.tableData = []
this.downloadData = []
this.$api.analysisReport.historyArrival({
startDate: customTime[0],
endDate: customTime[1]
})
.then(res => {
let result = res.data
if (result.msg_code === 200) {
if (!result.data.length) return
let resultData = result.data.map(item => {
return this.sortProp(props, item)
})
this.allData = resultData.map((item, index) => {
this.downloadData.push(Object.values(item))
return {
...item,
orderNum: ++index
}
})
this.total = resultData.length
this.tableData = this.pagination()
}
else {
this.$message({
message: result.msg_info,
type: 'error'
})
}
this.loading = false
})
.catch(error => {
this.loading = false
this.$message({
message: error,
type: 'error'
})
})
},
sortProp(props, sortObj) {
let obj = {}
props.forEach(k => {
obj[k] = sortObj[k]
})
return obj
},
clickHandle() {
this.loading = true
this.getData()
},
pagination() {
let
{ currentPage, pageSize, allData } = this
, offset = (currentPage - 1) * pageSize
return (offset + pageSize >= allData.length)
? this.allData.slice(offset, allData.length)
: this.allData.slice(offset, offset + pageSize)
},
currentChange(val) {
if (this.currentPage != val) {
this.currentPage = val
this.tableData = this.pagination()
}
},
sizeChange(val) {
this.pageSize = val
this.tableData = this.pagination()
},
dateFormatter(row, column, cellValue) {
return cellValue.replace(/^(\d{4})-(\d{2})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})$/, '$1-$2-$3')
},
downloadHandle() {
import('@/utils/Export2Excel').then(excel => {
excel.export_json_to_excel({
header: ['门店ID', '门店名称', '日期', '多次到店人数'],
data: this.downloadData,
filename: '多次到店人数报表',
autoWidth: true,
bookType: 'xlsx'
})
})
}
}
}
</script>
<style scoped>
.repeat-customer-container {
width: 100%;
}
.repeat-customer-container .analysis-date-condition {
padding: 15px 0;
margin: 0 auto;
background: #fff;
box-sizing: border-box;
overflow: hidden;
}
.repeat-customer-container .condition-item-option {
float: left;
width: 50%;
text-align: right;
}
.repeat-customer-container .page-wrapper {
padding-top: 20px;
}
</style>