index.vue
9.82 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<template>
<div>
<el-container>
<el-header>
<div class="app-container">
<el-button type="primary" @click="handleCreate()">创建</el-button>
<el-button type="primary" @click="exportTO()">导出</el-button>
</div>
</el-header>
<el-main>
<div class="app-container">
<el-table
v-loading="loading"
:data="qrcodelist"
style="width: 100%">
<el-table-column prop="sceneStr" label="场景">
</el-table-column>
<el-table-column prop="ticket" label="二维码">
<template slot-scope="scope">
<el-image style="width:60px;" :src="ticket+scope.row.ticket"></el-image>
</template>
</el-table-column>
<el-table-column prop="subCount" label="订阅数量">
</el-table-column>
<el-table-column prop="unsubCount" label="取消订阅数量">
</el-table-column>
<el-table-column label="操作">
<template slot-scope="scope">
<el-link type="primary" icon="el-icon-edit" @click="handleEdit(scope.$index, scope.row)">修改</el-link>
<el-link type="primary" @click="handleDetail(scope.$index, scope.row)">详情<i
class="el-icon-view el-icon--right"></i></el-link>
</template>
</el-table-column>
</el-table>
</div>
</el-main>
<el-footer>
</el-footer>
<el-dialog title="场景二维码新建/保存"
:visible.sync="dialogFormVisible"
>
<el-form :model="editForm" label-width="80px">
<el-form-item label="场景名:">
<el-input v-model="editForm.sceneStr"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">取 消</el-button>
<el-button type="primary" @click="qrCodeSave()">确 定</el-button>
</div>
</el-dialog>
<el-dialog title="详情"
:visible.sync="dialogDetailVisible"
>
<el-header>
<el-date-picker
clearable
v-model="value"
type="daterange"
align="right"
unlink-panels
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="timestamp"
@change="chooseTime"
:picker-options="pickerOptions">
</el-date-picker>
<el-link @click="oneWeek" type="primary">最近一周</el-link>
<el-link @click="oneMonth" type="primary">最近一个月</el-link>
<el-link @click="threeMonth" type="primary">最近三个月</el-link>
<el-button type="primary" @click="exportExcel">导出</el-button>
</el-header>
<el-main>
<div>
<el-table
v-loading="subloading"
:data="sublist">
<el-table-column prop="openid" label="openid">
</el-table-column>
<el-table-column prop="subscribe" label="事件操作">
<template slot-scope="scope">
<el-tag type="info" v-show="scope.row.subscribe===0">取消订阅</el-tag>
<el-tag type="success" v-show="scope.row.subscribe===1">订阅</el-tag>
</template>
</el-table-column>
<el-table-column prop="createTime" label="时间">
<template slot-scope="scope">
{{timestampToTime(scope.row)}}
</template>
</el-table-column>
</el-table>
</div>
</el-main>
<el-footer>
<div class="block" style="text-align:right;">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page.sync="tableForm.page"
:page-size="tableForm.size"
layout="total,prev, pager, next, jumper"
:total="total">
</el-pagination>
</div>
</el-footer>
</el-dialog>
</el-container>
</div>
</template>
<script>
import {request} from '@/api/fetch-api';
import api from '@/api/api.js'
let urls = {
qrlist: "/aiwanpaiapi/tianbao/qr/code/list",
sublist: "/aiwanpaiapi/tianbao/subscribe/list",
export2: "/aiwanpaiapi/tianbao/subscribe/export2",
export3: "/aiwanpaiapi/tianbao/subscribe/export3",
save: "/aiwanpaiapi/tianbao/qr/code/save"
};
export default {
data() {
return {
ticket: 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=',
qrcodelist: [],
sublist: [],
qrcode: {},
editForm: {},
loading: true,
subloading: true,
total: 0,
tableForm: {
qrCodeCode: '',
start: '',
end: '',
page: 1,
size: 10
},
value: [],
dialogFormVisible: false,
dialogDetailVisible: false,
pickerOptions: {
shortcuts: [{
text: '最近一周',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一个月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近三个月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
picker.$emit('pick', [start, end]);
}
}]
},
}
},
methods: {
initQrCodeList() {
request.get(urls.qrlist, {}).then(response => {
this.qrcodelist = response.content;
this.loading = false
});
},
subscribeByQrCodeCode() {
console.log("tableForm===", this.tableForm)
request.get(urls.sublist, this.tableForm).then(response => {
this.sublist = response.content.list;
this.total = response.content.total;
this.subloading = false;
});
},
/*导出部分*/
exportExcel() {
console.log("start", this.tableForm.start);
console.log("end", this.tableForm.end);
let url = request.build(urls.export3, this.tableForm);
window.open(url);
},
/*创建场景二维码*/
handleCreate() {
this.dialogFormVisible = true;
this.editForm = {}
},
/*导出场景*/
exportTO() {
let url = request.build(urls.export2);
window.open(url);
},
qrCodeSave() {
request.post(urls.save, this.editForm).then(response => {
this.dialogFormVisible = false;
this.initQrCodeList();
if (response.content === "error") {
this.$message.error("身份错误")
} else {
this.$message.success("保存成功");
}
}).catch(() => {
this.$message.error("保存失败")
});
},
/*弹出修改窗口*/
handleEdit(index, row) {
this.dialogFormVisible = true;
this.editForm = row;
},
/*详情窗口*/
handleDetail(index, row) {
this.dialogDetailVisible = true;
this.tableForm.qrCodeCode = row.qrCodeCode;
console.log("tableForm.qeCodecode", this.tableForm.qrCodeCode);
this.oneWeek();
//this.subscribeByQrCodeCode();
},
/*分页*/
handleSizeChange(val) {
console.log(`每页 ${val} 条`);
this.tableForm.size = val;
this.subscribeByQrCodeCode()
},
handleCurrentChange(val) {
console.log(`当前页: ${val}`);
this.tableForm.page = val;
this.subscribeByQrCodeCode()
},
/*时间戳转时间*/
timestampToTime(row) {
var date = new Date(row.createTime * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
var Y = date.getFullYear() + '-';
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
var D = date.getDate() + ' ';
var h = date.getHours() + ':';
var m = date.getMinutes() + ':';
var s = date.getSeconds();
return Y + M + D + h + m + s
},
/*改变时间*/
chooseTime(time) {
console.log("time", time)
if (time != null) {
this.tableForm.start = Math.round(time[0] / 1000).toString();
this.tableForm.end = Math.round(time[1] / 1000).toString();
} else {
this.tableForm.start = '';
this.tableForm.end = '';
}
this.subscribeByQrCodeCode();
},
/*一周*/
period(lastDay) {
let now = new Date();
this.tableForm.end = Math.round((now.getTime()) / 1000).toString();
let seventDay = Math.round((now.getTime() - lastDay * 24 * 60 * 60 * 1000) / 1000).toString();
this.tableForm.start = seventDay;
this.value=[];
this.value.push(new Date(now.getTime() - lastDay * 24 * 60 * 60 * 1000));
this.value.push(now);
},
/*最近一周*/
oneWeek() {
this.period(7);
this.subscribeByQrCodeCode();
},
oneMonth() {
this.period(30);
this.subscribeByQrCodeCode();
},
threeMonth() {
this.period(90);
this.subscribeByQrCodeCode();
},
},
created() {
this.initQrCodeList()
}
}
</script>
<style scoped>
</style>