Skip to content

Commit 27f63dc

Browse files
committed
promotion:完善优惠劵模板的单元测试、禁用功能
1 parent 13c0624 commit 27f63dc

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

src/api/mall/promotion/couponTemplate.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ export function updateCouponTemplate(data) {
1818
})
1919
}
2020

21+
// 更新优惠劵模板的状态
22+
export function updateCouponTemplateStatus(id, status) {
23+
const data = {
24+
id,
25+
status
26+
}
27+
return request({
28+
url: '/promotion/coupon-template/update-status',
29+
method: 'put',
30+
data: data
31+
})
32+
}
33+
2134
// 删除优惠劵模板
2235
export function deleteCouponTemplate(id) {
2336
return request({

src/views/mall/promotion/couponTemplate/index.vue

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<el-table-column label="有效期限" align="center" prop="validityType" width="180" :formatter="validityTypeFormat" />
5353
<el-table-column label="状态" align="center" prop="status">
5454
<template slot-scope="scope">
55-
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
55+
<el-switch v-model="scope.row.status" :active-value="0" :inactive-value="1" @change="handleStatusChange(scope.row)"/>
5656
</template>
5757
</el-table-column>
5858
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
@@ -156,10 +156,23 @@
156156
</template>
157157

158158
<script>
159-
import { createCouponTemplate, updateCouponTemplate, deleteCouponTemplate, getCouponTemplate, getCouponTemplatePage } from "@/api/mall/promotion/couponTemplate";
160-
import { CouponTemplateValidityTypeEnum, PromotionDiscountTypeEnum, PromotionProductScopeEnum} from "@/utils/constants";
159+
import {
160+
createCouponTemplate,
161+
updateCouponTemplate,
162+
deleteCouponTemplate,
163+
getCouponTemplate,
164+
getCouponTemplatePage,
165+
updateCouponTemplateStatus
166+
} from "@/api/mall/promotion/couponTemplate";
167+
import {
168+
CommonStatusEnum,
169+
CouponTemplateValidityTypeEnum,
170+
PromotionDiscountTypeEnum,
171+
PromotionProductScopeEnum
172+
} from "@/utils/constants";
161173
import { getSpuSimpleList } from "@/api/mall/product/spu";
162174
import { parseTime } from "@/utils/ruoyi";
175+
import {changeRoleStatus} from "@/api/system/role";
163176
164177
export default {
165178
name: "CouponTemplate",
@@ -331,6 +344,20 @@ export default {
331344
});
332345
});
333346
},
347+
/** 优惠劵模板状态修改 */
348+
handleStatusChange(row) {
349+
// 此时,row 已经变成目标状态了,所以可以直接提交请求和提示
350+
let text = row.status === CommonStatusEnum.ENABLE ? "启用" : "停用";
351+
this.$modal.confirm('确认要"' + text + '""' + row.name + '"优惠劵吗?').then(function() {
352+
return updateCouponTemplateStatus(row.id, row.status);
353+
}).then(() => {
354+
this.$modal.msgSuccess(text + "成功");
355+
}).catch(function() {
356+
// 异常时,需要将 row.status 状态重置回之前的
357+
row.status = row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE
358+
: CommonStatusEnum.ENABLE;
359+
});
360+
},
334361
/** 删除按钮操作 */
335362
handleDelete(row) {
336363
const id = row.id;

src/views/system/role/index.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
<el-table-column label="显示顺序" prop="sort" width="100" />
5151
<el-table-column label="状态" align="center" width="100">
5252
<template slot-scope="scope">
53-
<el-switch v-model="scope.row.status" :active-value="0" :inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
53+
<el-switch v-model="scope.row.status" :active-value="0" :inactive-value="1" @change="handleStatusChange(scope.row)"/>
5454
</template>
5555
</el-table-column>
5656
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
@@ -167,7 +167,6 @@
167167
import {
168168
addRole,
169169
changeRoleStatus,
170-
dataScope,
171170
delRole,
172171
exportRole,
173172
getRole,

0 commit comments

Comments
 (0)