index.vue
10.8 KB
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
<template>
<el-scrollbar
class="step-box"
ref="stepBox"
v-loading="activityObj.loading"
>
<div class="step-content">
<glsx-combi-form
ref="formRef"
:isEdit="true"
:isBlock="true"
:formObj="configForm"
:formData="formData"
:formRules="rule"
>
<template #merchantId>
<el-select
v-model="configForm.merchantId"
placeholder="请选择"
filterable
remote
:remote-method="remoteMethod"
v-reachbottom="onReachBottom"
@focus="selectFocus"
:loading="loading"
:disabled="disabled"
@change="change"
>
<el-option
v-for="item in merchantObj.data"
:key="item.confId"
:label="item.confName"
:value="item.confId"
></el-option>
<template v-if="merchantObj.nothing">
<div class="select-nothing">到底了!</div>
</template>
</el-select>
</template>
<template #activity>
<div class="tabs flex">
<template v-for="(i, index) in tabsObj.data">
<template>
<el-button
type="text"
@click="changeActivity(index)"
:class="['tab', { active: index == tabsObj.index }]"
:key="index"
:disabled="index == 1 || disabled"
>{{ i }}</el-button>
</template>
</template>
</div>
<div
class="activity-box"
:key="activityObj.key"
>
<template v-if="activityObj.flag">
<template v-if="activityObj.data.length">
<template v-for="(i, index) in activityObj.data">
<template>
<component
:key="index"
:is="
{
0: 'EquityItem',
2: 'CouponItem',
3: 'RedEnvelopeItem'
}[tabsObj.index]
"
:configForm="configForm"
:data="i"
:disabled="disabled"
@choose="choose"
></component>
</template>
</template>
<template v-if="activityObj.nothing">
<div class="nothing-text">
到底了!
</div>
</template>
</template>
<template v-else>
<div class="nothing">
<img src="@/assets/activity-nothing.png" />
<div>暂无内容</div>
</div>
</template>
</template>
</div>
</template>
</glsx-combi-form>
</div>
</el-scrollbar>
</template>
<script type="text/ecmascript-6">
import { getMerchantListMixin } from '@/mixins'
import EquityItem from './EquityItem.vue'
import CouponItem from './CouponItem.vue'
import RedEnvelopeItem from './RedEnvelopeItem.vue'
export default {
name: 'StepOne',
mixins: [getMerchantListMixin],
components: { RedEnvelopeItem, EquityItem, CouponItem },
props: {
disabled: Boolean
},
data () {
return {
configForm: {
name: '',
merchantId: '',
cardTitle: '',
cardCover: '',
activityId: '',
merchantName: ''
},
rule: {
name: [{ required: true, message: '请输入问卷名称', trigger: 'change' }],
merchantId: [{ required: true, message: '请选择所属渠道', trigger: 'change' }],
cardTitle: [{ required: true, message: '请输入卡片标题', trigger: 'change' }],
cardCover: [{ required: true, message: '请上传卡片封面', trigger: 'change' }],
},
formData: [
{
label: '问卷名称',
name: 'name',
type: 'input',
maxlength: 50,
},
{
label: '所属渠道',
type: 'select',
name: 'merchantId',
addHtml: 'merchantId'
},
{
label: '卡片标题',
name: 'cardTitle',
type: 'input',
maxlength: 20,
},
{
label: '卡片封面',
name: 'cardCover',
type: 'upload',
width: '320px',
limitSize: 10,
maxPhotoNum: 1,
suffixSlot: 'cardCover',
beforeLoading: true,
handleUpload: async (e, file, targetItem) => {
try {
const imgFile = e.target.result,
arrBase64 = imgFile.split(',')[1],
str = file.name.split('.'),
base64 = str.at(-1) + '@' + arrBase64,
res = await this.$apis.common.pictureUpload({ file: base64, fileType: 'image' })
if (res) {
this.configForm[targetItem.name] = res
this.formRef().validateField(targetItem.name)
this.$loading().close()
} else throw '上传失败'
} catch (error) {
this.$loading().close()
this.$message(error)
}
}
},
{
label: '关联活动',
addHtml: 'activity'
}
],
tabsObj: {
data: ['权益卡试用', '权益套餐', '商城券', '红包活动'],
index: 0
},
activityObj: {
data: [],
key: Date.now(),
flag: false,
pageNum: 1,
total: 0,
nothing: false,
loading: false
},
merchantObj: {
nothing: false,
data: [],
currentPage: 1,
name: '',
loading: false,
total: 0
}
}
},
watch: {
'disabled' (n) {
this.formData.map(e => {
e.isDisabled = n
})
},
'configForm.merchantId' (n) {
if (!n) this.change()
}
},
mounted () {
this.onActivityReachBottom(this)
this.activityObj.flag = true
},
methods: {
change (id) {
this.clearActivity()
this.configForm.merchantName = ''
this.activityObj = this.$options.data.call(this).activityObj
if (id) {
this.configForm.merchantName = this.merchantObj.data.find(e => e.confId == id).confName
this.getActivityList()
} else this.activityObj.flag = true
},
formRef () {
return this.$refs.formRef.$refs.formRef
},
onActivityReachBottom (_this) {
this.$refs.stepBox.wrap.addEventListener('scroll', function () {
const condition = this.scrollHeight - this.scrollTop <= this.clientHeight,
{ index } = _this.tabsObj,
{ total, pageNum } = _this.activityObj
if (condition) {
if (index == 2) {
if (Math.ceil(total / 100) > pageNum) {
_this.activityObj.pageNum += 1
_this.getActivityList()
} else {
_this.activityObj.nothing = true
_this.activityObj.key = Date.now()
}
console.log(_this.activityObj)
}
}
})
},
changeActivity (index) {
const { merchantId, id } = this.configForm
if (this.tabsObj.index == index) return
if (!merchantId) return this.$message.error('请选择所属渠道')
this.tabsObj.index = index
// this.clearActivity()
this.activityObj = this.$options.data.call(this).activityObj
this.getActivityList()
},
async getActivityList () {
const { index } = this.tabsObj,
{ merchantId } = this.configForm,
{ pageNum } = this.activityObj,
targetApi = {
0: 'getEquityActivityList',
2: 'getMerchantCouponList',
3: 'getActivityRedEnvelopeList'
}[index],
params = {
merchantId
}
try {
if (index == 2) params.pageNum = pageNum
if(index == 3) params.pageSize = 9999
this.activityObj.loading = true
const res = await this.$apis.questionnaire[targetApi](params)
let data = res
if (index == 2) {
data = [...this.activityObj.data, ...res.list]
this.activityObj.total = res.total
}
if(index == 3) data = res.list
this.setActivityData(data)
} catch (error) {
this.setActivityData()
}
},
setActivityData (data = []) {
this.activityObj.data = data
this.activityObj.loading = false
this.activityObj.flag = true
},
choose (e) {
const { index } = this.tabsObj
this.configForm.activityId = e
this.configForm.activityType = e ? index == 0 ? 1 : index : ''
},
clearActivity(){
this.configForm.activityId = ''
this.configForm.activityType = ''
},
},
}
</script>
<style scoped lang="scss">
.step-box {
width: 100%;
height: 100%;
box-sizing: border-box;
/deep/.el-scrollbar__wrap {
&::-webkit-scrollbar {
width: 0;
height: 0;
color: transparent;
}
}
.step-content {
padding-top: 32px;
}
/deep/.el-form-item__content {
width: fit-content;
max-width: calc(100% - 174px);
}
/deep/.activity-img,
/deep/.muti-imgs {
width: 104px;
height: 104px;
background: #0000000a;
border: 1px dashed #00000026;
border-radius: 4px;
input {
margin-top: 0;
}
.img-w-h,
.img-btns {
width: 100%;
height: 100%;
}
}
/deep/.activity-img,
/deep/.muti-imgs {
margin-bottom: 30px;
&::before {
// content: '图片大小10M以内';
content: '\56fe\7247\5927\5c0f\0031\0030M\4ee5\5185';
display: block;
font-size: 14px;
color: #999999;
position: absolute;
left: 0;
line-height: 20px;
bottom: -30px;
width: 200px;
cursor: auto;
}
}
.tabs {
height: 36px;
background: #f8f8f8;
border-radius: 4px;
padding: 0 2px;
width: fit-content;
.tab {
height: 32px;
font-size: 14px;
color: #666666;
padding: 0 16px;
margin: 0;
}
.active {
background: #ffffff;
border-radius: 3px;
font-weight: 500;
color: #5850ff;
}
.is-disabled {
color: #cfcfcf;
}
}
.activity-box {
display: flex;
gap: 16px;
flex-wrap: wrap;
margin-top: 16px;
.nothing {
margin-top: 24px;
font-weight: 500;
font-size: 16px;
color: #666666;
text-align: center;
img {
width: 323px;
height: 92px;
margin-bottom: 16px;
}
}
.nothing-text {
color: #666666;
text-align: center;
font-weight: 500;
font-size: 16px;
width: 100%;
}
}
}
.select-nothing {
font-size: 14px;
padding: 0 20px;
white-space: nowrap;
color: #606266;
height: 34px;
line-height: 34px;
text-align: center;
}
</style>