zxl
7 天以前 e8377ebeabf09c9a8d3397274b03dc02945c8dc7
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
<template>
  <div>
    <Card>
      <!-- 搜索表单 -->
      <Form
        ref="searchForm"
        @keydown.enter.native="handleSearch"
        :model="searchForm"
        inline
        :label-width="80"
        class="search-form"
      >
        <FormItem label="用户昵称" prop="nickName">
          <Input
            type="text"
            v-model="searchForm.nickName"
            placeholder="请输入用户昵称"
            clearable
            @on-clear="handleSearch"
            style="width: 180px"
          />
        </FormItem>
        <FormItem label="活动名称" prop="activityName">
          <Input
            type="text"
            v-model="searchForm.activityName"
            placeholder="请输入活动名称"
            clearable
            @on-clear="handleSearch"
            style="width: 180px"
          />
        </FormItem>
        <FormItem label="中奖状态" prop="prizeStatus">
          <Select
            v-model="searchForm.prizeStatus"
            placeholder="请选择中奖状态"
            style="width: 180px"
            clearable
            @on-clear="handleSearch"
            @on-change="handleSearch"
          >
            <Option
              v-for="item in typeSelect"
              :value="item.value"
              :key="item.id"
            >
              {{ item.label }}
            </Option>
          </Select>
        </FormItem>
        <FormItem label="奖品发放状态" prop="distributeStatus">
          <Select
            v-model="searchForm.distributeStatus"
            placeholder="请选择奖品发放状态"
            style="width: 180px"
            clearable
            @on-clear="handleSearch"
            @on-change="handleSearch"
          >
            <Option
              v-for="item in distributeSelect"
              :value="item.value"
              :key="item.id"
            >
              {{ item.label }}
            </Option>
          </Select>
        </FormItem>
        <FormItem label="报名开始时间" prop="time">
          <DatePicker
            v-model="time"
            type="datetimerange"
            placeholder="选择开始时间"
            style="width: 180px"
            @on-clear="handleSearch"
            @on-change="handleSearch"
          ></DatePicker>
        </FormItem>
 
        <Button
          @click="handleSearch"
          type="primary"
          icon="ios-search"
          class="search-btn"
        >搜索</Button>
        <Button
          @click="resetSearch"
          icon="md-refresh"
          style="margin-left: 8px"
        >重置</Button>
        <Button
          @click="queryExport"
          class="search-btn"
          type="primary"
        >导出</Button
        >
      </Form>
 
 
      <!-- 活动表格 -->
      <Table
        :loading="loading"
        border
        :columns="columns"
        :data="data"
        ref="table"
        class="table"
      >
        <!-- 操作按钮插槽 -->
        <template slot-scope="{ row }" slot="action">
          <div class="action-btns">
            <Button
              type="info"
              size="small"
              @click="detail(row)"
            >详情</Button>
          </div>
        </template>
      </Table>
 
      <!-- 分页 -->
      <Row type="flex" justify="end" class="page-footer">
        <Page
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
      <!-- 详情-->
      <Modal
        v-model="infoModalShow"
        title="活动详情"
        @on-cancel="infoModelClose"
        width="800"
        :mask-closable="false"
      >
        <div class="detail-container">
          <Row :gutter="16">
            <Col span="12">
              <div class="detail-item">
                <label>活动名称:</label>
                <span>{{ detailData.activityName }}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>用户昵称:</label>
                <span>{{ detailData.nickName}}</span>
              </div>
            </Col>
            <Col span="12">
              <div class="detail-item">
                <label>奖品内容:</label>
                <span>{{ detailData.prizeContent }}</span>
              </div>
            </Col>
            <Col span="24">
              <div class="detail-item">
                <label>中奖状态:</label>
                <Tag :color="detailData.prizeStatus === 'WIN' ? 'green' : 'red'">
                  {{ detailData.prizeStatus === 'WIN' ? '中奖' : '未中奖' }}
                </Tag>
              </div>
            </Col>
            <Col span="24">
              <div class="detail-item">
                <label>奖品发放:</label>
                <Tag
                  :color="getStatusColor(detailData.distributeStatus)"
                >
                  {{ getStatusText(detailData.distributeStatus) }}
                </Tag>
              </div>
            </Col>
            <Col span="24">
              <div class="detail-item">
                <label>活动封面:</label>
                <div v-if="detailData.activityCoverUrl" class="detail-image">
                  <img
                    :src="detailData.activityCoverUrl" alt="活动封面"
                    class="preview-image-limit"
                  >
                </div>
                <span v-else>-</span>
              </div>
            </Col>
            <Col span="24">
              <div class="detail-item">
                <label>奖品封面:</label>
                <div v-if="detailData.prizeImgUrl" class="detail-image">
                  <img
                    :src="detailData.prizeImgUrl" alt="奖品封面"
                    class="preview-image-limit"
                  >
                </div>
                <span v-else>-</span>
              </div>
            </Col>
 
          </Row>
        </div>
 
      </Modal>
 
    </Card>
  </div>
</template>
 
<script>
import {
  getPage,
  queryExport
} from '@/api/prize-record.js'
 
export default {
  name: "prizeRecord",
 
  data() {
    return {
      infoModalShow:false,
      detailData: {},
      modelShow:false,
      modelTitle:'',
      loading:false,
      columns:[
        {
          title: '用户昵称',
          key: 'nickName',
          minWidth: 100,
        },
        {
          title: '活动名称',
          key: 'prizeActivityName',
          minWidth: 100,
        },
        {
          title: '中奖状态',
          key: 'prizeStatus',
          minWidth: 100,
          render: (h, params) => {
            return h('Tag', {
              props: {
                color: params.row.prizeStatus === 'WIN' ? 'green' : 'red'
              }}, params.row.prizeStatus === 'WIN' ? '中奖' : '未中奖')
          }
        },
        {
          title: '奖品发放状态',
          key: 'distributeStatus',
          minWidth: 100,
          render: (h, params) => {
            // 获取当前状态
            const status = params.row.distributeStatus;
 
            // 根据状态确定颜色和文本
            let color, text;
            switch(status) {
              case 'SUCCESS':
                color = 'green';
                text = '已发放';
                break;
              case 'NOT_WAIT':
                color = 'blue';
                text = '未中奖';
                break;
              case 'FAILED':
                color = 'red';
                text = '发放失败';
                break;
              case 'WAIT':
                color = 'orange';
                text = '待发放';
                break;
              default:
                color = 'default';
                text = '未知状态';
            }
 
            return h('Tag', {
              props: { color }
            }, text);
          }
        },
        {
          title: '抽奖时间',
          key: 'createTime',
          minWidth: 100,
          render: (h, params) => {
            return h('div', [
              h('div', `${this.formatDate(params.row.createTime,'YYYY-MM-DD HH:mm:ss')}`),
            ])
          }
        },
        {
          title: '操作',
          slot: 'action',
          width: 280,
          align: 'center',
          fixed: 'right'
        },
      ],
      data:[],
      total:0,
      time:[],
      searchForm:{
        pageSize:10,
        pageNumber:1,
        nickName:'',
        activityName:'',
        prizeStatus:'',
        distributeStatus:'',
        startTime:'',
        endTime:''
      },
      distributeSelect:[
        {id: 1, value: 'NOT_WAIT', label: '未中奖'},
        {id: 2, value: 'WAIT', label: '待发放'},
        {id: 3, value: 'FAILED', label: '发放失败'},
        {id: 4, value: 'SUCCESS', label: '已发放'},
      ],
      typeSelect:[
        {id: 1, value: 'WIN', label: '中奖'},
        {id: 2, value: 'NOT_WIN', label: '未中奖'}
      ],
      activityCover:null,
 
 
    }
  },
  // 在组件创建前注册
  beforeCreate() {
 
  },
  mounted() {
    this.init();
  },
  methods: {
    formatDate(date, format = 'YYYY-MM-DD HH:mm:ss') {
      if (!date) return '';
 
      const d = new Date(date);
      if (isNaN(d.getTime())) return '';
 
      const padZero = (num) => String(num).padStart(2, '0'); // 更可靠的补零方法
 
      const year = d.getFullYear();
      const month = padZero(d.getMonth() + 1); // 月份 0-11 → +1
      const day = padZero(d.getDate());
      const hours = padZero(d.getHours());
      const minutes = padZero(d.getMinutes());
      const seconds = padZero(d.getSeconds());
      return format
        .replace('YYYY', year)
        .replace('MM', month)
        .replace('DD', day)
        .replace('HH', hours)
        .replace('mm', minutes)
        .replace('ss', seconds);
    },
    queryExport(){
      queryExport(this.searchForm).then(res =>{
        const blob = new Blob([res], {
          type: "application/vnd.ms-excel;charset=utf-8",
        });
        //对于<a>标签,只有 Firefox 和 Chrome(内核) 支持 download 属性
        //IE10以上支持blob但是依然不支持download
        if ("download" in document.createElement("a")) {
          //支持a标签download的浏览器
          const link = document.createElement("a"); //创建a标签
          link.download = "用户抽奖记录.xlsx"; //a标签添加属性
          link.style.display = "none";
          link.href = URL.createObjectURL(blob);
          document.body.appendChild(link);
          link.click(); //执行下载
          URL.revokeObjectURL(link.href); //释放url
          document.body.removeChild(link); //释放标签
        } else {
          navigator.msSaveBlob(blob, fileName);
        }
      })
 
 
    },
    // 获取状态对应的颜色
    getStatusColor(status) {
      // 处理空值情况
      if (!status) return 'default'
 
      // 根据状态返回对应颜色
      switch(status) {
        case 'NOT_WAIT':
          return 'blue'
        case 'WAIT':
          return 'orange'
        case 'FAILED':
          return 'red'
        case 'SUCCESS':
          return 'green'
        // 默认颜色
        default:
          return 'default'
      }
    },
 
    // 获取状态对应的文本
    getStatusText(status) {
      if (!status) return '未知状态'
 
      switch(status) {
        case 'NOT_WAIT':
          return '未中奖'
        case 'WAIT':
          return '待发放'
        case 'FAILED':
          return '发放失败'
        case 'SUCCESS':
          return '已发放'
        // 默认文本
        default:
          return '未知状态'
      }
    },
    // 格式化奖品类型
    replaceText(type) {
      if (type === "coupon") {
        return "优惠券";
      }
      return type; // 如果不是目标词,返回原文本
    },
    resetSearch(){
      this.$refs.searchForm.resetFields()
      this.searchForm.pageNumber = 1
      this.searchForm.startTime = '';
      this.searchForm.endTime = '';
      this.time =[];
      this.getPage()
    },
    infoModelClose(){
      this.infoModalShow = false;
    },
 
    getPage(){
      this.loading = true;
      getPage(this.searchForm).then(res =>{
        this.loading = false;
        if (res.code === 200){
          this.data = res.data;
          this.total = res.total;
        }else {
          this.$Message.error(res.msg)
        }
      })
    },
    detail(row){
      this.infoModalShow = true;
      this.detailData = {...row};
 
 
    },
 
    handleSearch(type,value){
      this.searchForm.startTime = this.formatDate(this.time[0]);
      this.searchForm.endTime = this.formatDate(this.time[1]);
      this.getPage();
    },
 
    // 初始化数据
    init() {
      this.getPage()
    },
    changePage(page){
      this.searchForm.pageNumber = page
      this.getPage()
    },
    changePageSize(pageSize){
      this.searchForm.pageNumber = 1
      this.searchForm.pageSize = pageSize
      this.getPage()
 
    },
 
  },
}
</script>
 
<style lang="scss" scoped>
.search-form {
  padding: 16px;
  background: #f8f8f9;
  border-radius: 4px;
  margin-bottom: 16px;
 
  .ivu-form-item {
    margin-bottom: 16px;
    margin-right: 16px;
  }
 
  .search-btn {
    margin-left: 8px;
  }
}
.table {
  .thumbnail {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: pointer;
    transition: all 0.3s;
 
    &:hover {
      transform: scale(1.05);
      box-shadow: 0 0 8px rgba(0, 0, 0, 0.2);
    }
  }
  .action-btns {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
 
    .ivu-btn {
      margin: 4px;
      font-size: 12px;
      padding: 2px 6px;
      min-width: 60px;
    }
  }
}
.detail-container {
  padding: 16px;
}
 
.detail-item {
  margin-bottom: 16px;
  line-height: 1.5;
}
 
.detail-item label {
  display: inline-block;
  width: 120px;
  font-weight: bold;
  color: #515a6e;
  vertical-align: top;
}
 
.detail-item span {
  display: inline-block;
  max-width: calc(100% - 120px);
}
 
.detail-image {
  display: inline-block;
  margin-top: 8px;
  border: 1px dashed #dcdee2;
  padding: 4px;
  border-radius: 4px;
  background: #f8f8f9;
}
</style>