doum
10 小时以前 e68e324f91d1a4eb2d4c5f07d27ca105a308bc0c
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
<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="couponType">
        <el-select  v-model="searchForm.couponType" clearable  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" icon="el-icon-plus" @click="$refs.operaCouponWindow.open('新建', null, 1)" v-permissions="['business:coupon:create']">新建</el-button></li>
        <li><el-button type="danger" @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"></el-table-column>
        <el-table-column label="类型" align="center" min-width="100px">
          <template slot-scope="{row}">
            <span v-if="row.couponType ===0"> 满减券</span>
            <span v-if="row.couponType ===1"> 折扣券</span>
          </template>
        </el-table-column>
        <el-table-column label="优惠规则" align="center" min-width="150px" show-overflow-tooltip>
          <template slot-scope="{row}">
            <span v-if="row.couponType ===0"> {{ `订单满${row.limitPrice||0}元,减${row.price||0}` }}元</span>
            <span v-if="row.couponType ===1"> {{ `订单满${row.limitPrice||0}元,享${row.price||0}折` }}</span>
          </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.received||0 }}</el-button>
          </template>
        </el-table-column>
        <el-table-column label="剩余数量" align="center" min-width="100px">
          <template slot-scope="{row}">
            {{ (row.num||0) - (row.received||0) }}
          </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="210px">
          <template slot-scope="{row}">
            <span v-if="row.useType ===0"><li> 起:{{ row.startDate}}</li> <li>止:{{row.endDate }}</li></span>
            <span v-if="row.useType ===1"> {{ `领用后${row.validDays||0}天有效` }}</span>
          </template>
        </el-table-column>
        <el-table-column label="适用类型" align="center" min-width="100px">
          <template slot-scope="{row}">
            <span v-if="row.applyType ===0"> 全程通用</span>
            <span v-if="row.applyType ===1"> 按品类</span>
            <span v-if="row.applyType ===2"> 指定商品</span>
          </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"  style="color: red;" @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: '',
        couponType: ''
      }
    }
  },
  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>