index.vue
8.31 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
235
236
<template>
<div class="NCC-common-layout">
<div class="NCC-common-layout-center">
<el-row class="NCC-common-search-box" :gutter="16">
<el-form @submit.native.prevent>
<el-col :span="6">
<el-form-item label="统计月份">
<el-date-picker
v-model="searchForm.statisticsMonth"
type="month"
placeholder="选择月份"
format="yyyy年MM月"
value-format="yyyyMM"
:clearable="false"
@change="handleSearch"
/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="老师姓名">
<el-input v-model="searchForm.teacherName" placeholder="请输入老师姓名" clearable @keyup.enter.native="handleSearch" />
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="门店名称">
<el-input v-model="searchForm.storeName" placeholder="请输入门店名称" clearable @keyup.enter.native="handleSearch" />
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item>
<el-button type="primary" icon="el-icon-search" :loading="loading" @click="handleSearch">查询</el-button>
<el-button icon="el-icon-refresh-right" @click="handleReset">重置</el-button>
</el-form-item>
</el-col>
</el-form>
</el-row>
<div class="NCC-common-layout-main NCC-flex-main">
<div class="NCC-common-head">
<div class="NCC-common-head-left">
<h3 class="NCC-common-head-title">科技部耗卡业绩统计</h3>
</div>
<div class="NCC-common-head-right">
<el-button type="text" icon="el-icon-view" @click="openAllDetail">查看全部明细</el-button>
<el-button type="text" icon="el-icon-download" :loading="exportLoading" @click="handleExportAll">导出明细</el-button>
</div>
</div>
<NCC-table v-loading="loading" :data="tableData" :height="tableHeight">
<el-table-column prop="TeacherName" label="老师姓名" fixed="left" min-width="120" show-overflow-tooltip>
<template slot-scope="scope">
<div class="table-cell-with-icon">
<i class="el-icon-user cell-icon primary"></i>
<span class="cell-text">{{ scope.row.TeacherName || '无' }}</span>
</div>
</template>
</el-table-column>
<el-table-column prop="TotalPerformance" label="总业绩" width="120" align="right">
<template slot-scope="scope">
<span class="amount-text">{{ formatMoney(scope.row.TotalPerformance) }}</span>
</template>
</el-table-column>
<el-table-column prop="OrderCount" label="耗卡品项数" width="110" align="right">
<template slot-scope="scope">{{ scope.row.OrderCount || 0 }}</template>
</el-table-column>
<el-table-column prop="CreateTime" label="创建时间" width="170" align="center">
<template slot-scope="scope">{{ formatDateTime(scope.row.CreateTime) }}</template>
</el-table-column>
<el-table-column label="操作" width="120" fixed="right" align="left">
<template slot-scope="scope">
<el-button type="text" @click="openTeacherDetail(scope.row)">查看明细</el-button>
</template>
</el-table-column>
</NCC-table>
<pagination
v-show="pagination.total > 0"
:total="pagination.total"
:page.sync="pagination.pageIndex"
:limit.sync="pagination.pageSize"
@pagination="handleSearch"
/>
</div>
</div>
<TechConsumeDetailDialog ref="detailDialog" />
</div>
</template>
<script>
import {
getTechConsumePerformanceStatisticsList,
exportTechConsumePerformanceDetail
} from '@/api/extend/statistics'
import TechConsumeDetailDialog from './tech-consume-detail-dialog.vue'
import Pagination from '@/components/Pagination'
export default {
name: 'TechConsumePerformanceStatistics',
components: { TechConsumeDetailDialog, Pagination },
data() {
return {
loading: false,
exportLoading: false,
tableData: [],
tableHeight: 400,
searchForm: {
statisticsMonth: this.getCurrentMonth(),
teacherName: '',
storeName: ''
},
pagination: {
pageIndex: 1,
pageSize: 20,
total: 0
}
}
},
mounted() {
this.calculateTableHeight()
this.handleSearch()
window.addEventListener('resize', this.calculateTableHeight)
},
beforeDestroy() {
window.removeEventListener('resize', this.calculateTableHeight)
},
methods: {
getCurrentMonth() {
const now = new Date()
const year = now.getFullYear()
const month = String(now.getMonth() + 1).padStart(2, '0')
return `${year}${month}`
},
calculateTableHeight() {
this.$nextTick(() => {
const mainEl = this.$el.querySelector('.NCC-common-layout-main')
if (!mainEl) return
const headEl = mainEl.querySelector('.NCC-common-head')
const paginationEl = mainEl.querySelector('.pagination-container')
const headHeight = headEl ? headEl.offsetHeight : 0
const paginationHeight = paginationEl ? paginationEl.offsetHeight : 52
this.tableHeight = Math.max(200, mainEl.clientHeight - headHeight - paginationHeight - 16)
})
},
async handleSearch() {
this.loading = true
try {
const params = {
pageIndex: this.pagination.pageIndex,
pageSize: this.pagination.pageSize,
statisticsMonth: this.searchForm.statisticsMonth,
teacherName: this.searchForm.teacherName,
storeName: this.searchForm.storeName
}
const response = await getTechConsumePerformanceStatisticsList(params)
this.tableData = response.data.list || []
this.pagination.total = response.data.pagination.total || 0
this.calculateTableHeight()
} catch (error) {
this.$message.error('查询失败: ' + error.message)
} finally {
this.loading = false
}
},
handleReset() {
this.searchForm = {
statisticsMonth: this.getCurrentMonth(),
teacherName: '',
storeName: ''
}
this.pagination.pageIndex = 1
this.handleSearch()
},
formatMoney(value) {
if (value === null || value === undefined) return '0.00'
return Number(value).toLocaleString('zh-CN', {
minimumFractionDigits: 2,
maximumFractionDigits: 2
})
},
formatDateTime(value) {
if (!value) return '-'
return new Date(value).toLocaleString('zh-CN')
},
buildDetailQuery(teacherId = '', teacherName = '') {
return {
statisticsMonth: this.searchForm.statisticsMonth,
teacherId,
teacherName: teacherId ? teacherName : this.searchForm.teacherName,
storeName: this.searchForm.storeName
}
},
openTeacherDetail(row) {
if (!this.$refs.detailDialog) return
this.$refs.detailDialog.init(this.buildDetailQuery(row.TeacherId, row.TeacherName))
},
openAllDetail() {
if (!this.searchForm.statisticsMonth) {
this.$message.warning('请先选择统计月份')
return
}
if (!this.$refs.detailDialog) return
this.$refs.detailDialog.init(this.buildDetailQuery())
},
handleExportAll() {
if (!this.searchForm.statisticsMonth) {
this.$message.warning('请先选择统计月份')
return
}
this.exportLoading = true
exportTechConsumePerformanceDetail({
...this.buildDetailQuery(),
pageIndex: 1,
pageSize: 20
}).then(res => {
this.exportLoading = false
if (res.code === 200 && res.data && res.data.url) {
window.open(window.location.origin + res.data.url, '_blank')
this.$message.success('导出成功')
} else {
this.$message.error(res.msg || '导出失败')
}
}).catch(() => {
this.exportLoading = false
this.$message.error('导出失败,请稍后重试')
})
}
}
}
</script>
<style lang="scss" scoped>
.amount-text {
color: #e6a23c;
font-weight: 600;
}
</style>