3f535f30
杨鑫
'初始'
|
142
143
144
145
146
147
148
149
150
151
152
|
<el-pagination
:current-page="proOption.page"
:page-sizes="[10, 20, 50, 100]"
:page-size="proOption.pageSize"
background
small
layout="total, sizes, prev, pager, next, jumper"
:total="total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
|
3f535f30
杨鑫
'初始'
|
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
|
data() {
return {
// 新增
getRowKeys(row) {
return row.productId
},
addForm: new InitCouponForm(),
proOption: {
page: 1,
pageSize: 10
},
dateInfo: [],
idList: [],
isThreshold: true,
total: 0,
tableData: [],
currentType: '1',
shopCouponId: '', // 优惠券ID
couponRules: {
couponName: [
{ required: true, message: '请输入优惠券名称', trigger: 'blur' }
],
couponContent: [{ required: true, message: '请输入优惠金额' }],
dateInfo: [{ type: 'date', required: true, message: '请选择时间' }],
number: [{ required: true, message: '请输入发放数量', trigger: 'blur' }]
},
multipleSelection: [],
roleList: [],
isVisible: false // 选择商品弹窗
}
},
watch: {
couponId: {
handler(nVal, oVal) {
this.shopCouponId = nVal
console.log('this.shopCouponId', this.shopCouponId)
if (!nVal) {
this.addForm = new InitCouponForm()
} else {
this.getCouponInfo()
}
this.$nextTick(() => {
console.log('multipleTable', this.$refs.multipleTable)
})
}
}
},
mounted() {
console.log('mounted-------')
this.shopCouponId = this.couponId
if (this.shopCouponId) {
this.getCouponInfo()
}
},
methods: {
resetData() {
if (this.$refs.multipleTable) {
this.$refs.multipleTable.clearSelection()
this.idList = []
}
},
proving1(e) {
var keynum = window.event ? e.keyCode : e.which // 获取键盘码
// var keychar = String.fromCharCode(keynum) // 获取键盘码对应的字符
if (
e.key
.replace(/[^\d^\.]+/g, '')
.replace('.', '$#$')
.replace(/\./g, '')
.replace('$#$', '.') === '' &&
keynum !== 8
) {
this.$message.warning('禁止输入中文或空')
e.target.value = ' '
}
},
addCouponFn(ruleForm) {
this.$refs[ruleForm].validate(valid => {
if (valid) {
if (this.addForm.timeType === '1' && this.dateInfo.length === 0) {
this.$message({
message: '请选择用券时间开始和结束日期',
type: 'warning'
})
return false
}
if (this.addForm.timeType === '2' && this.addForm.effectiveDay === null) {
this.$message({
message: '请填写领券多久内可以使用时间',
type: 'warning'
})
return false
}
if (this.addForm.receiveType === ' 2' && this.addForm.frequency === null) {
this.$message({
message: '请填写每人限领次数',
type: 'warning'
})
return false
}
if (this.addForm.couponType === '2') {
var regExp = /^([1-9]{1})(.\d{1})?$/
if (!regExp.test(this.addForm.couponContent)) {
this.$message({
message: '格式输入不正确',
type: 'warning'
})
return false
}
}
if ([2, 3].includes(parseInt(this.addForm.applyType))) {
if (!this.addForm.ids || !this.addForm.ids.length || this.addForm.ids.length === 0) {
this.$message({
message: '请选择指定商品',
type: 'warning'
})
return false
}
}
this.addForm.effectiveStart = this.dateInfo[0]
this.addForm.effectiveEnd = this.dateInfo[1]
if (this.shopCouponId) {
updateCoupon(this.addForm).then(res => {
if (res.code === '') {
this.$message.success('修改成功')
this.addForm = new InitCouponForm()
this.$emit('reset')
} else {
this.$message.error(res.message)
}
})
} else {
addCoupon(this.addForm).then(res => {
if (res.code === '') {
this.$message.success('提交成功')
this.addForm = new InitCouponForm()
this.$emit('reset')
} else {
this.$message.error(res.message)
}
})
}
} else {
console.log('error submit!!')
return false
}
})
},
handleSizeChange(val) {
this.proOption.pageSize = val
this.getProList()
},
handleCurrentChange(val) {
this.proOption.page = val
this.getProList()
},
// 选择商品
chooseProduct(type) {
this.isVisible = true
if (this.currentType !== type) {
this.idList = []
if (this.multipleSelection.length !== 0) {
this.$refs.multipleTable.clearSelection()
}
}
this.currentType = type
this.getProList()
},
getProList() {
getProducts(this.proOption).then(res => {
if (res.code === '') {
this.tableData = res.data.list
this.total = res.data.total
// 点击编辑时回显表格勾选
if (this.shopCouponId) {
for (let i = 0; i < this.tableData.length; i++) {
if (this.idList.includes(this.tableData[i].productId)) {
this.$refs.multipleTable.toggleRowSelection(this.tableData[i])
}
}
}
}
})
},
// 选中商品
handleSelectionChange(val) {
this.multipleSelection = val
},
// 保存选择商品ID
saveIdList() {
const idList = []
this.multipleSelection.forEach(i => {
idList.push(i.productId)
})
this.idList = idList
console.log('idList.length', idList.length)
this.addForm.ids = idList
this.addForm.applyType = this.currentType
this.isVisible = false
},
// 取消选择
closeSelect() {
this.isVisible = false
},
// 跳转优惠券列表
goToCoupon() {
this.$emit('reset')
},
async getCouponInfo() {
const res = await couponDetail({ shopCouponId: this.shopCouponId })
this.addForm = res.data
this.addForm.applyType = res.data.applyType.toString()
this.addForm.couponContent = res.data.couponContent
this.addForm.couponName = res.data.couponName
this.addForm.couponType = res.data.couponType.toString()
this.addForm.effectiveDay = res.data.effectiveDay
this.addForm.effectiveStart = res.data.effectiveStart
this.addForm.effectiveEnd = res.data.effectiveEnd
this.addForm.frequency = res.data.frequency
this.addForm.ids = res.data.ids
this.addForm.ifAdd = res.data.ifAdd.toString()
this.addForm.number = res.data.number
this.addForm.receiveType = res.data.receiveType.toString()
this.addForm.remark = res.data.remark
this.addForm.shopCouponId = res.data.shopCouponId
this.addForm.threshold = res.data.threshold.toString()
this.addForm.timeType = res.data.timeType.toString()
this.dateInfo = [this.addForm.effectiveStart, this.addForm.effectiveEnd]
if (this.addForm.applyType === '2') {
this.addForm.products.forEach(item => {
this.idList.push(item.productId)
})
} else if (this.addForm.applyType === '3') {
this.addForm.excludeIds.forEach(item => {
this.idList.push(item)
})
} else {
this.idList = []
}
this.currentType = res.data.applyType.toString()
},
changeThreshold(val) { // 输入框值改变
if (val) {
this.addForm.threshold = 0
}
},
}
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
@import url("../../../styles/elDialog.scss");
.addCoupon {
background: #FFFFFF;
.dialog-footer {
|