doum
2026-01-13 f4e09a3f13bbf63b166c3a149497a93a9fd43bc5
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
<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" placeholder="请输入优惠券名称" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <!-- 0商家优惠券 1平台优惠券 -->
      <!-- <el-form-item label="优惠券类型" prop="type">
        <el-select
          v-model="searchForm.type"
          placeholder="请选择优惠券类型"
        >
          <el-option key="0" :value="0" label="商家优惠券"></el-option>
          <el-option key="1" :value="1" label="平台优惠券"></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" v-permissions="['business:coupon:create', 'business:coupon:delete']">
        <li><el-button type="primary" @click="$refs.operaCouponWindow.open('新建平台优惠券', null, 1)" v-permissions="['business:coupon:create']">新建平台优惠券</el-button></li>
        <li><el-button type="primary" @click="$refs.operaCouponWindow.open('新建商家优惠券', null, 0)" v-permissions="['business:coupon:create']">新建商家优惠券</el-button></li>
        <li><el-button @click="deleteByIdInBatch" icon="el-icon-delete" v-permissions="['business:coupon:delete']">删除</el-button></li>
      </ul>
      <el-table
        v-loading="isWorking.search"
        :data="tableData.list"
        stripe
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="name" label="优惠券名称" align="center" min-width="120px">
          <template slot-scope="{row}">
            <el-button type="text" @click="showDetail(row)">{{ row.name }}</el-button>
          </template>
        </el-table-column>
        <el-table-column label="优惠规则" align="center" min-width="100px">
          <template slot-scope="{row}">
            {{ `满${row.limitPrice}减${row.price}` }}
          </template>
        </el-table-column>
        <el-table-column prop="type" label="优惠券类型" align="center" min-width="100px">
          <template slot-scope="{row}">
            {{ row.type==0?'商家优惠券':'平台优惠券' }}
          </template>
        </el-table-column>
        <el-table-column prop="num" label="发放总量" align="center" min-width="100px"></el-table-column>
        <el-table-column  label="已领取" align="center" min-width="100px">
          <template slot-scope="{row}">
            <el-button type="text" @click="showCouponUse(row.id)">{{ row.unused + row.used }}</el-button>
          </template>
        </el-table-column>
        <el-table-column label="剩余数量" align="center" min-width="100px">
          <template slot-scope="{row}">
            {{ row.num - row.unused - row.used }}
          </template>
        </el-table-column>
        <el-table-column prop="used" label="使用数量" align="center" min-width="100px"></el-table-column>
        <el-table-column prop="validDays" label="领取后有效天数" align="center" min-width="110px"></el-table-column>
        <el-table-column prop="startDate" label="开始时间" align="center" min-width="140px"></el-table-column>
        <el-table-column prop="endDate" label="结束时间" align="center" min-width="140px"></el-table-column>
        <el-table-column label="进行状态" align="center" min-width="100px">
          <template slot-scope="{row}">
            {{ row.status==0 ? '未开始' : row.status==1 ? '进行中' : '已结束' }}
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态" align="center" min-width="100px">
          <template slot-scope="{row}">
            <el-switch
              v-model="row.status"
              active-color="#13ce66"
              inactive-color="#999"
              :active-value="0"
              :inactive-value="1"
              @change="statusChange(row)"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column
          v-if="containPermissions(['business:coupon:update', 'business:coupon:delete'])"
          label="操作"
          min-width="120"
          fixed="right"
          align="center" 
        >
          <template slot-scope="{row}">
            <el-button type="text" @click="$refs.operaCouponWindow.open('编辑优惠券', row)" icon="el-icon-edit" v-permissions="['business:coupon:update']">编辑</el-button>
            <el-button type="text" @click="deleteById(row)" icon="el-icon-delete" v-permissions="['business:coupon:delete']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
        :pagination="tableData.pagination"
      >
      </pagination>
    </template>
    <!-- 新建/修改 -->
    <OperaCouponWindow ref="operaCouponWindow" @success="handlePageChange"/>
    <OperaCouponDetail ref="operaCouponDetail" />
    <OperaCouponUsedDetail ref="operaCouponUsedDetail" />
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import OperaCouponWindow from '@/components/business/OperaCouponWindow'
import OperaCouponDetail from '@/components/business/OperaCouponDetail'
import OperaCouponUsedDetail from '@/components/business/OperaCouponUsedDetail'
import { updateStatus } from '@/api/business/coupon'
export default {
  name: 'Coupon',
  extends: BaseTable,
  components: { TableLayout, Pagination, OperaCouponWindow, OperaCouponDetail, OperaCouponUsedDetail },
  data () {
    return {
      // 搜索
      searchForm: {
        name: '',
        type: ''
      }
    }
  },
  created () {
    this.config({
      module: '优惠券信息表',
      api: '/business/coupon',
      'field.id': 'id',
      'field.main': 'id'
    })
    this.search()
  },
  methods: {
    showDetail(row) {
      this.$refs.operaCouponDetail.open('优惠券详情', row)
    },
    showCouponUse(id) {
      
      this.$refs.operaCouponUsedDetail.open('优惠券领取详情', id)
    },
    statusChange(row) {
      updateStatus(row)
        .then(() => {
          this.$tip.success('操作成功')
        })
        .catch(e => {
          this.$tip.error(e)
        })
        .finally(() => {
          this.handlePageChange()
        })
    }
  },
}
</script>