MrShi
90 分钟以前 eb7a808aaf7dd0a6dd2ff70f9ef3f8ce0b1e31d1
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
<template>
  <TableLayout :permissions="['business:coupon:query']">
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" inline>
      <el-form-item label="优惠券名称" prop="name">
        <el-input v-model="searchForm.name" clearable placeholder="请输入优惠券名称" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="searchForm.status" clearable placeholder="请选择状态" @change="search">
          <el-option label="启用" :value="1"></el-option>
          <el-option label="禁用" :value="0"></el-option>
        </el-select>
      </el-form-item>
      <section>
        <el-button type="primary" @click="search">搜索</el-button>
        <el-button @click="reset">重置</el-button>
      </section>
    </el-form>
    <template v-slot:table-wrap>
        <ul class="toolbar">
            <li><el-button type="primary" @click="$refs.operaCouponEdit.open('新增优惠券')" icon="el-icon-plus">新建</el-button></li>
        </ul>
      <el-table
        :height="tableHeightNew"
        v-loading="isWorking.search"
        :data="tableData.list"
        stripe
      >
        <el-table-column prop="name" label="优惠券名称" min-width="120px"></el-table-column>
        <el-table-column label="类型" min-width="100px">
          <template slot-scope="{row}">
            <span v-if="row.type === 0">平台满减券</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column label="优惠规则" min-width="150px">
          <template slot-scope="{row}">
            <span>满{{ ((row.limitPrice || 0) / 100).toFixed(2) }}元减{{ ((row.price || 0) / 100).toFixed(2) }}元</span>
          </template>
        </el-table-column>
        <el-table-column prop="claimCount" label="已领取" min-width="80px"></el-table-column>
        <el-table-column prop="usedCount" label="已使用" min-width="80px"></el-table-column>
        <el-table-column label="限领规则" min-width="120px">
          <template slot-scope="{row}">平台推送后限{{ row.pushDays }}天领取</template>
        </el-table-column>
        <el-table-column label="限用规则" min-width="120px">
          <template slot-scope="{row}">领取后限{{ row.validDays }}天使用</template>
        </el-table-column>
        <el-table-column label="状态" min-width="100px">
          <template slot-scope="{row}">
            <el-switch v-model="row.status" @change="handleStatusChange(row)" active-color="#67c23a" inactive-color="#909399" :active-value="0" :inactive-value="1"></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="180" fixed="right">
          <template slot-scope="{row}">
            <el-button type="text" @click="handleEdit(row)">编辑</el-button>
            <el-button type="text" @click="handleUsageDetail(row)">领用明细</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
        :pagination="tableData.pagination"
      ></pagination>
    </template>
    <OperaCouponEdit ref="operaCouponEdit" @success="search" />
    <OperaCouponUsageDetail ref="operaCouponUsageDetail" />
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import OperaCouponEdit from '@/components/business/OperaCouponEdit'
import OperaCouponUsageDetail from '@/components/business/OperaCouponUsageDetail'
import { fetchList, updateStatus } from '@/api/business/coupon'
 
export default {
  name: 'Coupon',
  extends: BaseTable,
  components: { TableLayout, Pagination, OperaCouponEdit, OperaCouponUsageDetail },
  data () {
    return {
      searchForm: {
        name: '',
        status: ''
      }
    }
  },
  created () {
    this.config({
      api: '/business/coupon',
      'field.id': 'id'
    })
    this.search()
  },
  methods: {
    loadTableData (resolve) {
      this.isWorking.search = true
      fetchList(this.getTableParams())
        .then(data => {
          this.tableData.list = data.list || []
          this.tableData.pagination.total = data.total || 0
          if (resolve) resolve(data)
        })
        .catch(e => {
          this.$tip.apiFailed(e, '加载失败')
        })
        .finally(() => {
          this.isWorking.search = false
        })
    },
    handleEdit (row) {
      this.$refs.operaCouponEdit.open('编辑优惠券', row)
    },
    handleStatusChange (row) {
      updateStatus({ id: row.id, status: row.status })
        .then(res => {
          this.$tip.apiSuccess('状态修改成功')
        })
        .catch(e => {
          row.status = !row.status
          this.$tip.apiFailed(e, '状态修改失败')
        })
    },
    handleUsageDetail (row) {
      this.$refs.operaCouponUsageDetail.open(row)
    }
  }
}
</script>