cloudroam
2024-09-14 7f177f5915a1dbdf8ad6cd840b4d7408b9f3598f
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
<template>
  <el-bus-crud v-bind="tableConfig" />
</template>
 
<script>
import InputSelect from '@/components/input-select'
import {
  couponForm,
  couponSearchForm,
  getActivityEffectiveTime,
  getActivityReceiveTime,
  couponColumn,
} from '@/utils/coupon-form'
export default {
  data() {
    return {
      tableConfig: {
        url: 'flower/api/v2/coupon/avtivy/page',
        newUrl: 'flower/api/v2/coupon/avtivy',
        viewUrl: 'flower/api/v2/coupon/avtivy',
        viewOnPath: true,
        editUrl: 'flower/api/v2/coupon/avtivy',
        editMethodType: 'put',
        editOnPath: true,
        deleteUrl: 'flower/api/v2/coupon/avtivy',
        deleteMethodType: 'delete',
        deleteOnPath: true,
        canEdit: (row) => row.status === 'inactive' || row.status === 'expired',
        canDelete: (row) =>
          row.status === 'inactive' || row.status === 'expired',
        operationAttrs: {
          width: 180,
          fixed: 'right',
        },
        onResetView: (row) => {
          this.$router.push(`${this.$route.path}/${row.id}`)
        },
        beforeOpen: (row, isNew) => {
          if (!isNew) {
            row.usageTypeStr = getActivityEffectiveTime(row)
            row.getStartDateStr = getActivityReceiveTime(row)
          }
        },
        columns: [
          ...couponColumn(),
          {
            label: '领取时间',
            formatter: getActivityReceiveTime,
            minWidth: 320,
          },
          {
            label: '有效期',
            formatter: getActivityEffectiveTime,
            minWidth: 320,
          },
          { label: '领取渠道', prop: 'getTypeName', minWidth: 120 },
          { label: '已领取总数', prop: 'getNum', minWidth: 150 },
          { label: '剩余未领取总数', prop: 'unGetNum', minWidth: 150 },
          { label: '状态', prop: 'statusName', minWidth: 120 },
          { label: '领取渠道', prop: 'getTypeName', minWidth: 120 },
          { label: '操作人', prop: 'createByName', minWidth: 120 },
        ],
        // 页面上要到分,后端要传到秒
        beforeConfirm: (data) => {
          if (data.getStartDate) {
            data.getStartDate = this.$elBusUtil.formatDate(
              data.getStartDate,
              'YYYY-MM-DD HH:mm:ss'
            )
          }
          if (data.getEndDate) {
            data.getEndDate = this.$elBusUtil.formatDate(
              data.getEndDate,
              'YYYY-MM-DD HH:mm:ss'
            )
          }
          if (data.usageStartDate) {
            data.usageStartDate = this.$elBusUtil.formatDate(
              data.usageStartDate,
              'YYYY-MM-DD HH:mm:ss'
            )
          }
          if (data.usageEndDate) {
            data.usageEndDate = this.$elBusUtil.formatDate(
              data.usageEndDate,
              'YYYY-MM-DD HH:mm:ss'
            )
          }
        },
        searchForm: [
          {
            type: 'row',
            items: [...couponSearchForm(),
              {
                label: '领取渠道:',
                id: 'getType',
                type: 'bus-select-dict',
                el: {
                  code: 'COUPON_GET_TYPE',
                  style: 'width:100%',
                },
              },
            ],
          },
 
        ],
        form: [
          ...couponForm(),
          {
            label: '领取渠道:',
            id: 'getType',
            type: 'bus-select-dict',
            el: {
              code: 'COUPON_GET_TYPE',
              style: 'width:100%',
            },
            str: true,
            strKey: 'getTypeName',
            rules: { required: true, message: '请选择领取渠道' },
          },
          {
            label: '领取时间:',
            id: 'getStartDate',
            component: 'el-bus-date-range',
            el: {
              type: 'datetime',
              format: 'yyyy-MM-dd HH:mm',
              valueFormat: 'yyyy-MM-dd HH:mm',
            },
            str: true,
            commonRules: true,
            commonFormat: true,
            commonFormatProps: ['getStartDate', 'getEndDate'],
          },
          {
            label: '使用时间:',
            id: 'usageType',
            type: 'bus-select-dict',
            el: {
              code: 'COUPON_USAGE_TYPE',
              style: 'width:100%',
            },
            str: true,
            rules: { required: true, message: '请选择使用时间' },
            on: {
              change: (e, updateForm) => {
                updateForm({
                  usageStartDate: null,
                  usageEndDate: null,
                  usageTimeNum: undefined,
                  usageTimeType: null,
                })
              },
            },
          },
          {
            label: '使用固定时间:',
            id: 'usageStartDate',
            component: 'el-bus-date-range',
            el: {
              type: 'datetime',
              format: 'yyyy-MM-dd HH:mm',
              valueFormat: 'yyyy-MM-dd HH:mm',
            },
            commonRules: true,
            commonFormat: true,
            commonFormatProps: ['usageStartDate', 'usageEndDate'],
            hidden: (row, item, mode) =>
              row.usageType !== 'fixed' || mode === 'view',
          },
          {
            label: '领取后有效时间:',
            id: 'usageTimeNum',
            component: InputSelect,
            commonRules: true,
            commonFormat: true,
            commonFormatProps: ['usageTimeNum', 'usageTimeType'],
            el: {
              inputAttrs: {
                min: 1,
                max: 99999999,
                precision: 0,
                controls: false,
              },
              selectAttrs: {
                code: 'COUPON_USAGE_TIME_TYPE',
              },
            },
            hidden: (row, item, mode) =>
              row.usageType !== 'get_after_time' || mode === 'view',
          },
          {
            label: '发放数量:',
            id: 'couponAmount',
            type: 'input-number',
            el: {
              precision: 0,
              min: 1,
              max: 99999999,
              controls: false,
            },
            unit: '张',
            rules: {
              required: true,
              message: '请输入发放数量',
              trigger: 'blur',
            },
          },
          {
            label: '每人限领:',
            id: 'getLimit',
            type: 'input-number',
            el: {
              precision: 0,
              min: 1,
              max: 99999999,
              controls: false,
            },
            unit: '张',
            rules: {
              required: true,
              message: '请输入每人限领',
              trigger: 'blur',
            },
          },
        ],
        extraButtons: [
          {
            text: '发布',
            show: (row) =>
              row.status === 'inactive' || row.status === 'expired',
            atClick: async (row) => {
              try {
                await this.$elBusUtil.confirm('确定要发布吗?')
                const { code } = await this.$elBusHttp.request(
                  `flower/api/v2/coupon/avtivy/active/${row.id}`,
                  { method: 'put' }
                )
                if (code === 0) {
                  this.$message.success('发布成功')
                }
              } catch (e) {
                return false
              }
            },
          },
          {
            text: '下架',
            show: (row) => row.status === 'active',
            atClick: async (row) => {
              try {
                await this.$elBusUtil.confirm('确定要下架吗?')
                const { code } = await this.$elBusHttp.request(
                  `flower/api/v2/coupon/avtivy/expire/${row.id}`,
                  { method: 'put' }
                )
                if (code === 0) {
                  this.$message.success('下架成功')
                }
              } catch (e) {
                return false
              }
            },
          },
        ],
      },
    }
  },
  head() {
    return {
      title: '活动优惠券',
    }
  },
}
</script>