Commit 00f90e75d90520e56ac25277e97bad53d1faca36
1 parent
79304b3a
promotion:增加满减送活动的关闭功能
Showing
8 changed files
with
447 additions
and
8 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java
| ... | ... | @@ -30,5 +30,9 @@ public interface ErrorCodeConstants { |
| 30 | 30 | // ========== 满减送活动 1003006000 ========== |
| 31 | 31 | ErrorCode REWARD_ACTIVITY_NOT_EXISTS = new ErrorCode(1003006000, "满减送活动不存在"); |
| 32 | 32 | ErrorCode REWARD_ACTIVITY_SPU_CONFLICTS = new ErrorCode(1003006001, "商品({}) 已经参加满减送活动({})"); |
| 33 | + ErrorCode REWARD_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED = new ErrorCode(1003006002, "满减送活动已关闭,不能修改"); | |
| 34 | + ErrorCode REWARD_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED = new ErrorCode(1003006003, "满减送活动未关闭,不能删除"); | |
| 35 | + ErrorCode REWARD_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED = new ErrorCode(1003006004, "满减送活动已关闭,不能重复关闭"); | |
| 36 | + ErrorCode REWARD_ACTIVITY_CLOSE_FAIL_STATUS_END = new ErrorCode(1003006004, "满减送活动已结束,不能关闭"); | |
| 33 | 37 | |
| 34 | 38 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/reward/RewardActivityController.java
| ... | ... | @@ -45,6 +45,15 @@ public class RewardActivityController { |
| 45 | 45 | return success(true); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | + @PutMapping("/close") | |
| 49 | + @ApiOperation("关闭满减送活动") | |
| 50 | + @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) | |
| 51 | + @PreAuthorize("@ss.hasPermission('promotion:reward-activity:close')") | |
| 52 | + public CommonResult<Boolean> closeRewardActivity(@RequestParam("id") Long id) { | |
| 53 | + rewardActivityService.closeRewardActivity(id); | |
| 54 | + return success(true); | |
| 55 | + } | |
| 56 | + | |
| 48 | 57 | @DeleteMapping("/delete") |
| 49 | 58 | @ApiOperation("删除满减送活动") |
| 50 | 59 | @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class) | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityService.java
| ... | ... | @@ -33,6 +33,13 @@ public interface RewardActivityService { |
| 33 | 33 | void updateRewardActivity(@Valid RewardActivityUpdateReqVO updateReqVO); |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | + * 关闭满减送活动 | |
| 37 | + * | |
| 38 | + * @param id 活动编号 | |
| 39 | + */ | |
| 40 | + void closeRewardActivity(Long id); | |
| 41 | + | |
| 42 | + /** | |
| 36 | 43 | * 删除满减送活动 |
| 37 | 44 | * |
| 38 | 45 | * @param id 编号 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImpl.java
| ... | ... | @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.reward.vo.RewardActivi |
| 8 | 8 | import cn.iocoder.yudao.module.promotion.convert.reward.RewardActivityConvert; |
| 9 | 9 | import cn.iocoder.yudao.module.promotion.dal.dataobject.reward.RewardActivityDO; |
| 10 | 10 | import cn.iocoder.yudao.module.promotion.dal.mysql.reward.RewardActivityMapper; |
| 11 | +import cn.iocoder.yudao.module.promotion.enums.common.PromotionActivityStatusEnum; | |
| 11 | 12 | import cn.iocoder.yudao.module.promotion.util.PromotionUtils; |
| 12 | 13 | import org.springframework.stereotype.Service; |
| 13 | 14 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -19,8 +20,7 @@ import java.util.Map; |
| 19 | 20 | import java.util.Set; |
| 20 | 21 | |
| 21 | 22 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 22 | -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.REWARD_ACTIVITY_NOT_EXISTS; | |
| 23 | -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.REWARD_ACTIVITY_SPU_CONFLICTS; | |
| 23 | +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; | |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * 满减送活动 Service 实现类 |
| ... | ... | @@ -50,7 +50,10 @@ public class RewardActivityServiceImpl implements RewardActivityService { |
| 50 | 50 | @Override |
| 51 | 51 | public void updateRewardActivity(RewardActivityUpdateReqVO updateReqVO) { |
| 52 | 52 | // 校验存在 |
| 53 | - validateRewardActivityExists(updateReqVO.getId()); | |
| 53 | + RewardActivityDO dbRewardActivity = validateRewardActivityExists(updateReqVO.getId()); | |
| 54 | + if (dbRewardActivity.getStatus().equals(PromotionActivityStatusEnum.CLOSE.getStatus())) { // 已关闭的活动,不能修改噢 | |
| 55 | + throw exception(REWARD_ACTIVITY_UPDATE_FAIL_STATUS_CLOSED); | |
| 56 | + } | |
| 54 | 57 | validateRewardActivitySpuConflicts(updateReqVO.getId(), updateReqVO.getProductSpuIds()); |
| 55 | 58 | |
| 56 | 59 | // 更新 |
| ... | ... | @@ -60,17 +63,39 @@ public class RewardActivityServiceImpl implements RewardActivityService { |
| 60 | 63 | } |
| 61 | 64 | |
| 62 | 65 | @Override |
| 66 | + public void closeRewardActivity(Long id) { | |
| 67 | + // 校验存在 | |
| 68 | + RewardActivityDO dbRewardActivity = validateRewardActivityExists(id); | |
| 69 | + if (dbRewardActivity.getStatus().equals(PromotionActivityStatusEnum.CLOSE.getStatus())) { // 已关闭的活动,不能关闭噢 | |
| 70 | + throw exception(REWARD_ACTIVITY_CLOSE_FAIL_STATUS_CLOSED); | |
| 71 | + } | |
| 72 | + if (dbRewardActivity.getStatus().equals(PromotionActivityStatusEnum.END.getStatus())) { // 已关闭的活动,不能关闭噢 | |
| 73 | + throw exception(REWARD_ACTIVITY_CLOSE_FAIL_STATUS_END); | |
| 74 | + } | |
| 75 | + | |
| 76 | + // 更新 | |
| 77 | + RewardActivityDO updateObj = new RewardActivityDO().setId(id).setStatus(PromotionActivityStatusEnum.CLOSE.getStatus()); | |
| 78 | + rewardActivityMapper.updateById(updateObj); | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Override | |
| 63 | 82 | public void deleteRewardActivity(Long id) { |
| 64 | 83 | // 校验存在 |
| 65 | - validateRewardActivityExists(id); | |
| 84 | + RewardActivityDO dbRewardActivity = validateRewardActivityExists(id); | |
| 85 | + if (!dbRewardActivity.getStatus().equals(PromotionActivityStatusEnum.CLOSE.getStatus())) { // 未关闭的活动,不能删除噢 | |
| 86 | + throw exception(REWARD_ACTIVITY_DELETE_FAIL_STATUS_NOT_CLOSED); | |
| 87 | + } | |
| 88 | + | |
| 66 | 89 | // 删除 |
| 67 | 90 | rewardActivityMapper.deleteById(id); |
| 68 | 91 | } |
| 69 | 92 | |
| 70 | - private void validateRewardActivityExists(Long id) { | |
| 71 | - if (rewardActivityMapper.selectById(id) == null) { | |
| 93 | + private RewardActivityDO validateRewardActivityExists(Long id) { | |
| 94 | + RewardActivityDO activity = rewardActivityMapper.selectById(id); | |
| 95 | + if (activity == null) { | |
| 72 | 96 | throw exception(REWARD_ACTIVITY_NOT_EXISTS); |
| 73 | 97 | } |
| 98 | + return activity; | |
| 74 | 99 | } |
| 75 | 100 | |
| 76 | 101 | /** | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/reward/RewardActivityServiceImplTest.java
| ... | ... | @@ -66,7 +66,7 @@ public class RewardActivityServiceImplTest extends BaseDbUnitTest { |
| 66 | 66 | @Test |
| 67 | 67 | public void testUpdateRewardActivity_success() { |
| 68 | 68 | // mock 数据 |
| 69 | - RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class); | |
| 69 | + RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class, o -> o.setStatus(PromotionActivityStatusEnum.WAIT.getStatus())); | |
| 70 | 70 | rewardActivityMapper.insert(dbRewardActivity);// @Sql: 先插入出一条存在的数据 |
| 71 | 71 | // 准备参数 |
| 72 | 72 | RewardActivityUpdateReqVO reqVO = randomPojo(RewardActivityUpdateReqVO.class, o -> { |
| ... | ... | @@ -89,6 +89,21 @@ public class RewardActivityServiceImplTest extends BaseDbUnitTest { |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | @Test |
| 92 | + public void testCloseRewardActivity() { | |
| 93 | + // mock 数据 | |
| 94 | + RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class, o -> o.setStatus(PromotionActivityStatusEnum.WAIT.getStatus())); | |
| 95 | + rewardActivityMapper.insert(dbRewardActivity);// @Sql: 先插入出一条存在的数据 | |
| 96 | + // 准备参数 | |
| 97 | + Long id = dbRewardActivity.getId(); | |
| 98 | + | |
| 99 | + // 调用 | |
| 100 | + rewardActivityService.closeRewardActivity(id); | |
| 101 | + // 校验状态 | |
| 102 | + RewardActivityDO rewardActivity = rewardActivityMapper.selectById(id); | |
| 103 | + assertEquals(rewardActivity.getStatus(), PromotionActivityStatusEnum.CLOSE.getStatus()); | |
| 104 | + } | |
| 105 | + | |
| 106 | + @Test | |
| 92 | 107 | public void testUpdateRewardActivity_notExists() { |
| 93 | 108 | // 准备参数 |
| 94 | 109 | RewardActivityUpdateReqVO reqVO = randomPojo(RewardActivityUpdateReqVO.class); |
| ... | ... | @@ -100,7 +115,7 @@ public class RewardActivityServiceImplTest extends BaseDbUnitTest { |
| 100 | 115 | @Test |
| 101 | 116 | public void testDeleteRewardActivity_success() { |
| 102 | 117 | // mock 数据 |
| 103 | - RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class); | |
| 118 | + RewardActivityDO dbRewardActivity = randomPojo(RewardActivityDO.class, o -> o.setStatus(PromotionActivityStatusEnum.CLOSE.getStatus())); | |
| 104 | 119 | rewardActivityMapper.insert(dbRewardActivity);// @Sql: 先插入出一条存在的数据 |
| 105 | 120 | // 准备参数 |
| 106 | 121 | Long id = dbRewardActivity.getId(); | ... | ... |
yudao-ui-admin/src/api/mall/promotion/rewardActivity.js
0 → 100755
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 创建满减送活动 | |
| 4 | +export function createRewardActivity(data) { | |
| 5 | + return request({ | |
| 6 | + url: '/promotion/reward-activity/create', | |
| 7 | + method: 'post', | |
| 8 | + data: data | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +// 更新满减送活动 | |
| 13 | +export function updateRewardActivity(data) { | |
| 14 | + return request({ | |
| 15 | + url: '/promotion/reward-activity/update', | |
| 16 | + method: 'put', | |
| 17 | + data: data | |
| 18 | + }) | |
| 19 | +} | |
| 20 | + | |
| 21 | +// 关闭满减送活动 | |
| 22 | +export function closeRewardActivity(id) { | |
| 23 | + return request({ | |
| 24 | + url: '/promotion/reward-activity/close?id=' + id, | |
| 25 | + method: 'put' | |
| 26 | + }) | |
| 27 | +} | |
| 28 | + | |
| 29 | +// 删除满减送活动 | |
| 30 | +export function deleteRewardActivity(id) { | |
| 31 | + return request({ | |
| 32 | + url: '/promotion/reward-activity/delete?id=' + id, | |
| 33 | + method: 'delete' | |
| 34 | + }) | |
| 35 | +} | |
| 36 | + | |
| 37 | +// 获得满减送活动 | |
| 38 | +export function getRewardActivity(id) { | |
| 39 | + return request({ | |
| 40 | + url: '/promotion/reward-activity/get?id=' + id, | |
| 41 | + method: 'get' | |
| 42 | + }) | |
| 43 | +} | |
| 44 | + | |
| 45 | +// 获得满减送活动分页 | |
| 46 | +export function getRewardActivityPage(query) { | |
| 47 | + return request({ | |
| 48 | + url: '/promotion/reward-activity/page', | |
| 49 | + method: 'get', | |
| 50 | + params: query | |
| 51 | + }) | |
| 52 | +} | ... | ... |
yudao-ui-admin/src/utils/constants.js
| ... | ... | @@ -292,3 +292,25 @@ export const PromotionConditionTypeEnum = { |
| 292 | 292 | name: '满 N 件' |
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | + | |
| 296 | +/** | |
| 297 | + * 促销活动的状态枚举 | |
| 298 | + */ | |
| 299 | +export const PromotionActivityStatusEnum = { | |
| 300 | + WAIT: { | |
| 301 | + type: 10, | |
| 302 | + name: '未开始' | |
| 303 | + }, | |
| 304 | + RUN: { | |
| 305 | + type: 20, | |
| 306 | + name: '进行中' | |
| 307 | + }, | |
| 308 | + END: { | |
| 309 | + type: 30, | |
| 310 | + name: '已结束' | |
| 311 | + }, | |
| 312 | + CLOSE: { | |
| 313 | + type: 40, | |
| 314 | + name: '已关闭' | |
| 315 | + } | |
| 316 | +} | ... | ... |
yudao-ui-admin/src/views/mall/promotion/rewardActivity/index.vue
0 → 100755
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + | |
| 4 | + <!-- 搜索工作栏 --> | |
| 5 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> | |
| 6 | + <el-form-item label="活动名称" prop="name"> | |
| 7 | + <el-input v-model="queryParams.name" placeholder="请输入活动名称" clearable @keyup.enter.native="handleQuery"/> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="活动状态" prop="status"> | |
| 10 | + <el-select v-model="queryParams.status" placeholder="请选择活动状态" clearable size="small"> | |
| 11 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_ACTIVITY_STATUS)" | |
| 12 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 13 | + </el-select> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item> | |
| 16 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | |
| 17 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | |
| 18 | + </el-form-item> | |
| 19 | + </el-form> | |
| 20 | + | |
| 21 | + <!-- 操作工具栏 --> | |
| 22 | + <el-row :gutter="10" class="mb8"> | |
| 23 | + <el-col :span="1.5"> | |
| 24 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" | |
| 25 | + v-hasPermi="['promotion:reward-activity:create']">新增</el-button> | |
| 26 | + </el-col> | |
| 27 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 28 | + </el-row> | |
| 29 | + | |
| 30 | + <!-- 列表 --> | |
| 31 | + <el-table v-loading="loading" :data="list"> | |
| 32 | + <el-table-column label="活动名称" align="center" prop="name" /> | |
| 33 | + <el-table-column label="活动时间" align="center" prop="startTime" width="240"> | |
| 34 | + <template slot-scope="scope"> | |
| 35 | + <div>开始:{{ parseTime(scope.row.startTime) }}</div> | |
| 36 | + <div>结束:{{ parseTime(scope.row.endTime) }}</div> | |
| 37 | + </template> | |
| 38 | + </el-table-column> | |
| 39 | + <el-table-column label="状态" align="center" prop="status"> | |
| 40 | + <template slot-scope="scope"> | |
| 41 | + <dict-tag :type="DICT_TYPE.PROMOTION_ACTIVITY_STATUS" :value="scope.row.status" /> | |
| 42 | + </template> | |
| 43 | + </el-table-column> | |
| 44 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 45 | + <template slot-scope="scope"> | |
| 46 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 47 | + </template> | |
| 48 | + </el-table-column> | |
| 49 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 50 | + <template slot-scope="scope"> | |
| 51 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" | |
| 52 | + v-if="scope.row.status !== PromotionActivityStatusEnum.CLOSE.type" | |
| 53 | + v-hasPermi="['promotion:reward-activity:update']">修改</el-button> | |
| 54 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleClose(scope.row)" | |
| 55 | + v-if="scope.row.status !== PromotionActivityStatusEnum.CLOSE.type && | |
| 56 | + scope.row.status !== PromotionActivityStatusEnum.END.type" | |
| 57 | + v-hasPermi="['promotion:reward-activity:close']">关闭</el-button> | |
| 58 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 59 | + v-if="scope.row.status === PromotionActivityStatusEnum.CLOSE.type" | |
| 60 | + v-hasPermi="['promotion:reward-activity:delete']">删除</el-button> | |
| 61 | + </template> | |
| 62 | + </el-table-column> | |
| 63 | + </el-table> | |
| 64 | + <!-- 分页组件 --> | |
| 65 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 66 | + @pagination="getList"/> | |
| 67 | + | |
| 68 | + <!-- 对话框(添加 / 修改) --> | |
| 69 | + <el-dialog :title="title" :visible.sync="open" width="600px" v-dialogDrag append-to-body> | |
| 70 | + <el-form ref="form" :model="form" :rules="rules" label-width="80px"> | |
| 71 | + <el-form-item label="活动名称" prop="name"> | |
| 72 | + <el-input v-model="form.name" placeholder="请输入活动名称" /> | |
| 73 | + </el-form-item> | |
| 74 | + <el-form-item label="活动时间" prop="startAndEndTime"> | |
| 75 | + <el-date-picker clearable v-model="form.startAndEndTime" type="datetimerange" :default-time="['00:00:00', '23:59:59']" | |
| 76 | + value-format="timestamp" placeholder="选择开始时间" style="width: 480px" /> | |
| 77 | + </el-form-item> | |
| 78 | + <el-form-item label="条件类型" prop="conditionType"> | |
| 79 | + <el-radio-group v-model="form.conditionType"> | |
| 80 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_CONDITION_TYPE)" | |
| 81 | + :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio> | |
| 82 | + </el-radio-group> | |
| 83 | + </el-form-item> | |
| 84 | + <el-form-item label="优惠设置" prop="conditionType"> | |
| 85 | + <!-- TODO 芋艿:待实现! --> | |
| 86 | + </el-form-item> | |
| 87 | + <el-form-item label="活动商品" prop="productScope"> | |
| 88 | + <el-radio-group v-model="form.productScope"> | |
| 89 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_PRODUCT_SCOPE)" | |
| 90 | + :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio> | |
| 91 | + </el-radio-group> | |
| 92 | + </el-form-item> | |
| 93 | + <el-form-item v-if="form.productScope === PromotionProductScopeEnum.SPU.scope" prop="productSpuIds"> | |
| 94 | + <el-select v-model="form.productSpuIds" placeholder="请选择活动商品" clearable size="small" | |
| 95 | + multiple filterable style="width: 400px"> | |
| 96 | + <el-option v-for="item in productSpus" :key="item.id" :label="item.name" :value="item.id"> | |
| 97 | + <span style="float: left">{{ item.name }}</span> | |
| 98 | + <span style="float: right; color: #8492a6; font-size: 13px">¥{{ (item.minPrice / 100.0).toFixed(2) }}</span> | |
| 99 | + </el-option> | |
| 100 | + </el-select> | |
| 101 | + </el-form-item> | |
| 102 | + <el-form-item label="备注" prop="remark"> | |
| 103 | + <el-input v-model="form.remark" placeholder="请输入备注" /> | |
| 104 | + </el-form-item> | |
| 105 | + </el-form> | |
| 106 | + <div slot="footer" class="dialog-footer"> | |
| 107 | + <el-button type="primary" @click="submitForm">确 定</el-button> | |
| 108 | + <el-button @click="cancel">取 消</el-button> | |
| 109 | + </div> | |
| 110 | + </el-dialog> | |
| 111 | + </div> | |
| 112 | +</template> | |
| 113 | + | |
| 114 | +<script> | |
| 115 | +import { | |
| 116 | + createRewardActivity, | |
| 117 | + updateRewardActivity, | |
| 118 | + deleteRewardActivity, | |
| 119 | + getRewardActivity, | |
| 120 | + getRewardActivityPage, | |
| 121 | + closeRewardActivity | |
| 122 | +} from "@/api/mall/promotion/rewardActivity"; | |
| 123 | +import { | |
| 124 | + PromotionConditionTypeEnum, | |
| 125 | + PromotionProductScopeEnum, | |
| 126 | + PromotionActivityStatusEnum | |
| 127 | +} from "@/utils/constants"; | |
| 128 | +import {getSpuSimpleList} from "@/api/mall/product/spu"; | |
| 129 | + | |
| 130 | +export default { | |
| 131 | + name: "RewardActivity", | |
| 132 | + components: { | |
| 133 | + }, | |
| 134 | + data() { | |
| 135 | + return { | |
| 136 | + // 遮罩层 | |
| 137 | + loading: true, | |
| 138 | + // 导出遮罩层 | |
| 139 | + exportLoading: false, | |
| 140 | + // 显示搜索条件 | |
| 141 | + showSearch: true, | |
| 142 | + // 总条数 | |
| 143 | + total: 0, | |
| 144 | + // 满减送活动列表 | |
| 145 | + list: [], | |
| 146 | + // 弹出层标题 | |
| 147 | + title: "", | |
| 148 | + // 是否显示弹出层 | |
| 149 | + open: false, | |
| 150 | + // 查询参数 | |
| 151 | + queryParams: { | |
| 152 | + pageNo: 1, | |
| 153 | + pageSize: 10, | |
| 154 | + name: null, | |
| 155 | + status: null, | |
| 156 | + }, | |
| 157 | + // 表单参数 | |
| 158 | + form: {}, | |
| 159 | + // 表单校验 | |
| 160 | + rules: { | |
| 161 | + name: [{ required: true, message: "活动名称不能为空", trigger: "blur" }], | |
| 162 | + startAndEndTime: [{ required: true, message: "活动时间不能为空", trigger: "blur" }], | |
| 163 | + conditionType: [{ required: true, message: "条件类型不能为空", trigger: "change" }], | |
| 164 | + productScope: [{ required: true, message: "商品范围不能为空", trigger: "blur" }], | |
| 165 | + productSpuIds: [{ required: true, message: "商品范围不能为空", trigger: "blur" }], | |
| 166 | + }, | |
| 167 | + // 商品列表 | |
| 168 | + productSpus: [], | |
| 169 | + // 如下的变量,主要为了 v-if 判断可以使用到 | |
| 170 | + PromotionProductScopeEnum: PromotionProductScopeEnum, | |
| 171 | + PromotionActivityStatusEnum: PromotionActivityStatusEnum, | |
| 172 | + }; | |
| 173 | + }, | |
| 174 | + created() { | |
| 175 | + this.getList(); | |
| 176 | + // 查询商品列表 | |
| 177 | + getSpuSimpleList().then(response => { | |
| 178 | + this.productSpus = response.data | |
| 179 | + }) | |
| 180 | + }, | |
| 181 | + methods: { | |
| 182 | + /** 查询列表 */ | |
| 183 | + getList() { | |
| 184 | + this.loading = true; | |
| 185 | + // 执行查询 | |
| 186 | + getRewardActivityPage(this.queryParams).then(response => { | |
| 187 | + this.list = response.data.list; | |
| 188 | + this.total = response.data.total; | |
| 189 | + this.loading = false; | |
| 190 | + }); | |
| 191 | + }, | |
| 192 | + /** 取消按钮 */ | |
| 193 | + cancel() { | |
| 194 | + this.open = false; | |
| 195 | + this.reset(); | |
| 196 | + }, | |
| 197 | + /** 表单重置 */ | |
| 198 | + reset() { | |
| 199 | + this.form = { | |
| 200 | + id: undefined, | |
| 201 | + name: undefined, | |
| 202 | + startAndEndTime: undefined, | |
| 203 | + startTime: undefined, | |
| 204 | + endTime: undefined, | |
| 205 | + conditionType: PromotionConditionTypeEnum.PRICE.type, | |
| 206 | + remark: undefined, | |
| 207 | + productScope: PromotionProductScopeEnum.ALL.scope, | |
| 208 | + productSpuIds: undefined, | |
| 209 | + rules: undefined, | |
| 210 | + }; | |
| 211 | + this.resetForm("form"); | |
| 212 | + }, | |
| 213 | + /** 搜索按钮操作 */ | |
| 214 | + handleQuery() { | |
| 215 | + this.queryParams.pageNo = 1; | |
| 216 | + this.getList(); | |
| 217 | + }, | |
| 218 | + /** 重置按钮操作 */ | |
| 219 | + resetQuery() { | |
| 220 | + this.resetForm("queryForm"); | |
| 221 | + this.handleQuery(); | |
| 222 | + }, | |
| 223 | + /** 新增按钮操作 */ | |
| 224 | + handleAdd() { | |
| 225 | + this.reset(); | |
| 226 | + this.open = true; | |
| 227 | + this.title = "添加满减送活动"; | |
| 228 | + }, | |
| 229 | + /** 修改按钮操作 */ | |
| 230 | + handleUpdate(row) { | |
| 231 | + this.reset(); | |
| 232 | + const id = row.id; | |
| 233 | + getRewardActivity(id).then(response => { | |
| 234 | + this.form = response.data; | |
| 235 | + this.form.startAndEndTime = [response.data.startTime, response.data.endTime]; | |
| 236 | + this.open = true; | |
| 237 | + this.title = "修改满减送活动"; | |
| 238 | + }); | |
| 239 | + }, | |
| 240 | + /** 提交按钮 */ | |
| 241 | + submitForm() { | |
| 242 | + this.$refs["form"].validate(valid => { | |
| 243 | + if (!valid) { | |
| 244 | + return; | |
| 245 | + } | |
| 246 | + this.form.startTime = this.form.startAndEndTime[0]; | |
| 247 | + this.form.endTime = this.form.startAndEndTime[1]; | |
| 248 | + // TODO 芋艿:临时实现 | |
| 249 | + this.form.rules = [ | |
| 250 | + { | |
| 251 | + limit: 1, | |
| 252 | + discountPrice: 10, | |
| 253 | + freeDelivery: true, | |
| 254 | + point: 10, | |
| 255 | + couponIds: [10, 20], | |
| 256 | + couponCounts: [1, 2] | |
| 257 | + }, { | |
| 258 | + limit: 2, | |
| 259 | + discountPrice: 20, | |
| 260 | + freeDelivery: false, | |
| 261 | + point: 20, | |
| 262 | + couponIds: [30, 40], | |
| 263 | + couponCounts: [3, 4] | |
| 264 | + } | |
| 265 | + ]; | |
| 266 | + // 修改的提交 | |
| 267 | + if (this.form.id != null) { | |
| 268 | + updateRewardActivity(this.form).then(response => { | |
| 269 | + this.$modal.msgSuccess("修改成功"); | |
| 270 | + this.open = false; | |
| 271 | + this.getList(); | |
| 272 | + }); | |
| 273 | + return; | |
| 274 | + } | |
| 275 | + // 添加的提交 | |
| 276 | + createRewardActivity(this.form).then(response => { | |
| 277 | + this.$modal.msgSuccess("新增成功"); | |
| 278 | + this.open = false; | |
| 279 | + this.getList(); | |
| 280 | + }); | |
| 281 | + }); | |
| 282 | + }, | |
| 283 | + /** 删除按钮操作 */ | |
| 284 | + handleDelete(row) { | |
| 285 | + const id = row.id; | |
| 286 | + this.$modal.confirm('是否确认删除满减送活动编号为"' + id + '"的数据项?').then(function() { | |
| 287 | + return deleteRewardActivity(id); | |
| 288 | + }).then(() => { | |
| 289 | + this.getList(); | |
| 290 | + this.$modal.msgSuccess("删除成功"); | |
| 291 | + }).catch(() => {}); | |
| 292 | + }, | |
| 293 | + /** 关闭按钮操作 */ | |
| 294 | + handleClose(row) { | |
| 295 | + const id = row.id; | |
| 296 | + this.$modal.confirm('是否确认关闭满减送活动编号为"' + id + '"的数据项?').then(function() { | |
| 297 | + return closeRewardActivity(id); | |
| 298 | + }).then(() => { | |
| 299 | + this.getList(); | |
| 300 | + this.$modal.msgSuccess("关闭成功"); | |
| 301 | + }).catch(() => {}); | |
| 302 | + } | |
| 303 | + } | |
| 304 | +}; | |
| 305 | +</script> | ... | ... |