From fe5c9fd1a9d6fc0238633446ee25393d5c771b32 Mon Sep 17 00:00:00 2001 From: zhl Date: Thu, 6 May 2021 20:16:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B4=BB=E5=8A=A8=E5=A5=96?= =?UTF-8?q?=E5=8A=B1=E7=9A=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/activity.ts | 18 ++- src/views/activity/edit.vue | 225 ++++++++++++++++++++++++++++++++- src/views/marketing/coupon.vue | 8 +- 3 files changed, 246 insertions(+), 5 deletions(-) diff --git a/src/api/activity.ts b/src/api/activity.ts index 1dc5fbb..1429cec 100644 --- a/src/api/activity.ts +++ b/src/api/activity.ts @@ -1,6 +1,14 @@ import request from '@/utils/request' +export interface IRewardData { + id?: number, + rank?: number, + rankEnd?: number, + coupon?: string, + count: number +} + export interface IActivityData { _id?: string shop: string @@ -16,7 +24,12 @@ export interface IActivityData { active: number, beginDays?: number[], beginDay?: number, - endDay?: number + endDay?: number, + rewardInfo: IRewardData[] +} + +export const defaultRewardData: IRewardData = { + count: 0 } export const defaultActivityData: IActivityData = { @@ -29,7 +42,8 @@ export const defaultActivityData: IActivityData = { qcount: 0, qtypes: [], repeatType: 0, - shop: '' + shop: '', + rewardInfo: [] } diff --git a/src/views/activity/edit.vue b/src/views/activity/edit.vue index 5b6c585..58782a7 100644 --- a/src/views/activity/edit.vue +++ b/src/views/activity/edit.vue @@ -225,6 +225,57 @@ + + 添加 + + + + + + + + + + @@ -240,7 +291,71 @@ + + + + 第 + + 名至 + + 名 + + + + + + + + + + + + 保存 + + + 取消 + + + + @@ -255,9 +370,17 @@ import RegionPicker from '@/components/RegionPicker/index.vue' import { Form } from 'element-ui' import Tinymce from '@/components/Tinymce/index.vue' import { getShops } from '@/api/shop' -import { defaultActivityData, getActivity, saveActivity } from '@/api/activity' +import { + defaultActivityData, defaultRewardData, + getActivity, + IRewardData, + saveActivity +} from '@/api/activity' import { sec2TimeStr, timeStr2Sec } from '@/utils' import { getAllCategory } from '@/api/question' +import { cloneDeep } from 'lodash' +import { getCoupons } from '@/api/coupon' +import { deleteAdmin } from '@/api/admins' @Component({ name: 'ActivityEditor', @@ -329,6 +452,16 @@ export default class extends Vue { private tempTagView?: ITagView + private dialogType = 'new' + private record: IRewardData = {} + private dialogVisible = false + private modalRules = { + rank: [{ required: true, message: '请输入排名', trigger: 'blur' }, + ], + } + private coupons = [] + + get lang() { return AppModule.language } @@ -493,6 +626,10 @@ export default class extends Vue { @Watch('postForm.shop') private onShopChange() { + if (this.postForm.shop) { + this.getCouponList(this.postForm.shop) + } + if (this.postForm.qtypes?.length > 0) { this.typeSelected = this.postForm.qtypes return @@ -532,7 +669,93 @@ export default class extends Vue { }) } } + // begin of award list + private async getCouponList(shop: string) { + const { data } = await getCoupons({shop}) + this.coupons = data.records + } + private formatCoupon(row: number, column: number, cellValue: string, index: number) { + let result = `未知(${cellValue})` + let data = this.postForm.rewardInfo[index] + for (const dep of this.coupons) { + if (dep._id == cellValue) { + result = dep.name + break + } + } + return `${result} x ${data.count}` + } + private formatRank(row: number, column: number, cellValue: string, index: number) { + let data = this.postForm.rewardInfo[index] + let result = `第 ${data.rank} 名` + if (data.rankEnd) { + result = `第 ${data.rank} 至 ${data.rankEnd} 名` + } + return result + } + private async deleteRank(scope: any) { + const { $index, row } = scope + try { + await this.$confirm('Confirm to remove the record?', 'Warning', { + confirmButtonText: 'Confirm', + cancelButtonText: 'Cancel', + type: 'warning' + }) + this.postForm.rewardInfo.splice($index, 1) + this.$message({ + type: 'success', + message: '删除成功, 请点击保存' + }) + } catch (err) { + } + + } + private handleCreateReward() { + this.record = Object.assign({}, defaultRewardData) + this.record.id = this.postForm.rewardInfo.length + this.dialogType = 'new' + this.dialogVisible = true + } + + private handleEdit(scope: any) { + this.dialogType = 'edit' + this.dialogVisible = true + this.checkStrictly = true + this.record = cloneDeep(scope.row) + } + private closeModal() { + this.dialogVisible = false + this.$refs.modalForm.clearValidate() + } + private saveReward() { + const isEdit = this.dialogType === 'edit' + this.$refs.modalForm.validate(async(valid: boolean) => { + if (!valid) { + this.$message.error('请按要求填写表单') + return false + } + if (isEdit) { + for (let index = 0; index < this.postForm.rewardInfo.length; index++) { + if (this.postForm.rewardInfo[index].id === this.record.id) { + this.postForm.rewardInfo.splice(index, 1, Object.assign({}, this.record)) + break + } + } + } else { + this.postForm.rewardInfo.push(this.record) + } + this.dialogVisible = false + this.$notify({ + title: 'Success', + dangerouslyUseHTMLString: true, + message: ` + 奖励成功保存, 请点击保存 + `, + type: 'success' + }) + }) + } } diff --git a/src/views/marketing/coupon.vue b/src/views/marketing/coupon.vue index 401e0a0..5297aa7 100644 --- a/src/views/marketing/coupon.vue +++ b/src/views/marketing/coupon.vue @@ -158,10 +158,12 @@ export default class extends Vue { private listQuery = { page: 1, limit: 20, - key: '' + key: '', + shop: '' } private filterForm = { - key: '' + key: '', + department: '' } created() { @@ -172,6 +174,7 @@ export default class extends Vue { private async getList() { this.listLoading = true + console.log(this.listQuery) const { data } = await getCoupons(this.listQuery) this.listLoading = false this.list = data.records @@ -198,6 +201,7 @@ export default class extends Vue { private filterData() { this.listQuery.key = this.filterForm.key + this.listQuery.shop = this.filterForm.department this.listQuery.page = 1 this.getList() }