Commit ea2a57f0a00b8a592cb8fa430c7c8cdd32a5e93b
1 parent
83ee1c61
修改秒杀时段id
Showing
8 changed files
with
514 additions
and
5 deletions
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/SeckillActivityController.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity; |
| 2 | 2 | |
| 3 | 3 | import org.springframework.web.bind.annotation.*; |
| 4 | + | |
| 4 | 5 | import javax.annotation.Resource; |
| 6 | + | |
| 5 | 7 | import org.springframework.validation.annotation.Validated; |
| 6 | 8 | import org.springframework.security.access.prepost.PreAuthorize; |
| 7 | 9 | import io.swagger.annotations.*; |
| ... | ... | @@ -14,11 +16,13 @@ import java.io.IOException; |
| 14 | 16 | |
| 15 | 17 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 16 | 18 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 19 | + | |
| 17 | 20 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 18 | 21 | |
| 19 | 22 | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| 20 | 23 | |
| 21 | 24 | import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; |
| 25 | + | |
| 22 | 26 | import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; |
| 23 | 27 | |
| 24 | 28 | import cn.iocoder.yudao.module.promotion.controller.admin.seckillactivity.vo.*; |
| ... | ... | @@ -65,6 +69,9 @@ public class SeckillActivityController { |
| 65 | 69 | @PreAuthorize("@ss.hasPermission('promotion:seckill-activity:query')") |
| 66 | 70 | public CommonResult<SeckillActivityRespVO> getSeckillActivity(@RequestParam("id") Long id) { |
| 67 | 71 | SeckillActivityDO seckillActivity = seckillActivityService.getSeckillActivity(id); |
| 72 | + if (seckillActivity == null) { | |
| 73 | + return success(null); | |
| 74 | + } | |
| 68 | 75 | return success(SeckillActivityConvert.INSTANCE.convert(seckillActivity)); |
| 69 | 76 | } |
| 70 | 77 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityCreateReqVO.java
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityExportReqVO.java
| ... | ... | @@ -19,7 +19,7 @@ public class SeckillActivityExportReqVO { |
| 19 | 19 | private Integer status; |
| 20 | 20 | |
| 21 | 21 | @ApiModelProperty(value = "秒杀时段id") |
| 22 | - private Long timeId; | |
| 22 | + private String timeId; | |
| 23 | 23 | |
| 24 | 24 | @ApiModelProperty(value = "创建时间") |
| 25 | 25 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityPageReqVO.java
| ... | ... | @@ -21,7 +21,7 @@ public class SeckillActivityPageReqVO extends PageParam { |
| 21 | 21 | private Integer status; |
| 22 | 22 | |
| 23 | 23 | @ApiModelProperty(value = "秒杀时段id") |
| 24 | - private Long timeId; | |
| 24 | + private String timeId; | |
| 25 | 25 | |
| 26 | 26 | @ApiModelProperty(value = "创建时间") |
| 27 | 27 | @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityRespVO.java
| ... | ... | @@ -4,6 +4,8 @@ import lombok.*; |
| 4 | 4 | import java.util.*; |
| 5 | 5 | import io.swagger.annotations.*; |
| 6 | 6 | |
| 7 | +import javax.validation.constraints.NotNull; | |
| 8 | + | |
| 7 | 9 | @ApiModel("管理后台 - 秒杀活动 Response VO") |
| 8 | 10 | @Data |
| 9 | 11 | @EqualsAndHashCode(callSuper = true) |
| ... | ... | @@ -22,4 +24,7 @@ public class SeckillActivityRespVO extends SeckillActivityBaseVO { |
| 22 | 24 | @ApiModelProperty(value = "创建时间", required = true) |
| 23 | 25 | private Date createTime; |
| 24 | 26 | |
| 27 | + @ApiModelProperty(value = "秒杀时段id", required = true) | |
| 28 | + private String timeId; | |
| 29 | + | |
| 25 | 30 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/seckillactivity/vo/SeckillActivityUpdateReqVO.java
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckillactivity/SeckillActivityDO.java
yudao-ui-admin/src/views/promotion/seckillActivity/index.vue
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + | |
| 4 | + <!-- 搜索工作栏 --> | |
| 5 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" | |
| 6 | + label-width="68px"> | |
| 7 | + <el-form-item label="活动名称" prop="name"> | |
| 8 | + <el-input v-model="queryParams.name" placeholder="请输入秒杀活动名称" clearable | |
| 9 | + @keyup.enter.native="handleQuery" /> | |
| 10 | + </el-form-item> | |
| 11 | + <el-form-item label="活动状态" prop="status"> | |
| 12 | + <el-select v-model="queryParams.status" placeholder="请选择活动状态" clearable size="small"> | |
| 13 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_ACTIVITY_STATUS)" :key="dict.value" | |
| 14 | + :label="dict.label" :value="dict.value" /> | |
| 15 | + </el-select> | |
| 16 | + </el-form-item> | |
| 17 | + <el-form-item label="参与场次" prop="timeId"> | |
| 18 | + <el-select v-model="queryParams.timeId" placeholder="请选择参与场次" clearable size="small"> | |
| 19 | + <el-option v-for="item in seckillTimeList" :key="item.id" :label="item.name" :value="item.id" /> | |
| 20 | + </el-select> | |
| 21 | + <!-- <el-option v-for="seckill in seckillTimeList" :key="seckill.id" :lable="seckill.name" :value="seckill.id" /> --> | |
| 22 | + <!-- <el-input v-model="queryParams.timeId" placeholder="请输入秒杀时段id" clearable @keyup.enter.native="handleQuery" /> --> | |
| 23 | + </el-form-item> | |
| 24 | + <el-form-item label="创建时间" prop="createTime"> | |
| 25 | + <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" | |
| 26 | + type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" | |
| 27 | + :default-time="['00:00:00', '23:59:59']" /> | |
| 28 | + </el-form-item> | |
| 29 | + <el-form-item> | |
| 30 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | |
| 31 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | |
| 32 | + </el-form-item> | |
| 33 | + </el-form> | |
| 34 | + | |
| 35 | + <!-- 操作工具栏 --> | |
| 36 | + <el-row :gutter="10" class="mb8"> | |
| 37 | + <el-col :span="1.5"> | |
| 38 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" | |
| 39 | + v-hasPermi="['promotion:seckill-activity:create']">新增秒杀活动</el-button> | |
| 40 | + </el-col> | |
| 41 | + <el-col :span="1.5"> | |
| 42 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" | |
| 43 | + :loading="exportLoading" v-hasPermi="['promotion:seckill-activity:export']">导出</el-button> | |
| 44 | + </el-col> | |
| 45 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 46 | + </el-row> | |
| 47 | + | |
| 48 | + <!-- 列表 --> | |
| 49 | + <el-table v-loading="loading" :data="list"> | |
| 50 | + <el-table-column label="活动名称" align="center" prop="name" /> | |
| 51 | + <el-table-column label="活动状态" align="center" prop="status"> | |
| 52 | + <template slot-scope="scope"> | |
| 53 | + <dict-tag :type="DICT_TYPE.PROMOTION_ACTIVITY_STATUS" :value="scope.row.status" /> | |
| 54 | + </template> | |
| 55 | + </el-table-column> | |
| 56 | + <el-table-column label="参与场次" prop="timeId" width="250"> | |
| 57 | + <template slot-scope="scope"> | |
| 58 | + <span v-for="item in seckillTimeList" :key="item.id" | |
| 59 | + v-if="scope.row.timeId.indexOf(item.id) !== -1"> | |
| 60 | + <el-tag style="margin:4px;" size="small">{{ item.name }}</el-tag> | |
| 61 | + </span> | |
| 62 | + </template> | |
| 63 | + </el-table-column> | |
| 64 | + <el-table-column label="活动开始时间" align="center" prop="startTime" width="190"> | |
| 65 | + <template slot-scope="scope"> | |
| 66 | + <span>{{ "开始: " + parseTime(scope.row.startTime) }}</span> | |
| 67 | + <span>{{ "结束: " + parseTime(scope.row.endTime) }}</span> | |
| 68 | + </template> | |
| 69 | + </el-table-column> | |
| 70 | + | |
| 71 | + <el-table-column label="付款订单数" align="center" prop="orderCount" /> | |
| 72 | + <el-table-column label="付款人数" align="center" prop="userCount" /> | |
| 73 | + <el-table-column label="订单实付金额" align="center"> | |
| 74 | + <template slot-scope="scope"> | |
| 75 | + ¥{{ (scope.row.totalPrice / 100.0).toFixed(2) }} | |
| 76 | + </template> | |
| 77 | + </el-table-column> | |
| 78 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 79 | + <template slot-scope="scope"> | |
| 80 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 81 | + </template> | |
| 82 | + </el-table-column> | |
| 83 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 84 | + <template slot-scope="scope"> | |
| 85 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" | |
| 86 | + v-hasPermi="['promotion:seckill-activity:update']">修改</el-button> | |
| 87 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 88 | + v-hasPermi="['promotion:seckill-activity:delete']">删除</el-button> | |
| 89 | + </template> | |
| 90 | + </el-table-column> | |
| 91 | + </el-table> | |
| 92 | + <!-- 分页组件 --> | |
| 93 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 94 | + @pagination="getList" /> | |
| 95 | + | |
| 96 | + <!-- 对话框(添加 / 修改) --> | |
| 97 | + <el-dialog :title="title" :visible.sync="open" width="1200px" v-dialogDrag append-to-body> | |
| 98 | + <el-form ref="form" :model="form" :rules="rules" label-width="80px"> | |
| 99 | + <el-form-item label="活动名称" prop="name"> | |
| 100 | + <el-input v-model="form.name" placeholder="请输入秒杀活动名称" /> | |
| 101 | + </el-form-item> | |
| 102 | + <!-- <el-form-item label="活动状态" prop="status"> | |
| 103 | + <el-radio-group v-model="form.status"> | |
| 104 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_ACTIVITY_STATUS)" | |
| 105 | + :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio> | |
| 106 | + </el-radio-group> | |
| 107 | + </el-form-item> --> | |
| 108 | + | |
| 109 | + <el-form-item label="活动时间" prop="startAndEndTime"> | |
| 110 | + <el-date-picker clearable v-model="form.startAndEndTime" type="datetimerange" | |
| 111 | + value-format="timestamp" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" | |
| 112 | + style="width: 1080px" /> | |
| 113 | + </el-form-item> | |
| 114 | + <!-- | |
| 115 | + <el-form-item label="活动结束时间" prop="endTime"> | |
| 116 | + <el-date-picker clearable v-model="form.endTime" type="date" value-format="timestamp" placeholder="选择活动结束时间" /> | |
| 117 | + </el-form-item> --> | |
| 118 | + | |
| 119 | + <el-form-item label="排序" prop="sort"> | |
| 120 | + <el-input-number v-model="form.sort" controls-position="right" :min="0" :max="10000"> | |
| 121 | + </el-input-number> | |
| 122 | + </el-form-item> | |
| 123 | + | |
| 124 | + <!-- <el-form-item label="秒杀时段id" prop="timeId"> | |
| 125 | + <el-input v-model="form.timeId" placeholder="请输入秒杀时段id" /> | |
| 126 | + </el-form-item> | |
| 127 | + <el-form-item label="订单实付金额(分)" prop="totalPrice"> | |
| 128 | + <el-input v-model="form.totalPrice" placeholder="请输入订单实付金额(分)" /> | |
| 129 | + </el-form-item> --> | |
| 130 | + | |
| 131 | + <el-form-item label="备注" prop="remark"> | |
| 132 | + <el-input type="textarea" v-model="form.remark" placeholder="请输入备注" /> | |
| 133 | + </el-form-item> | |
| 134 | + <el-form-item label="场次选择"> | |
| 135 | + <el-select v-model="form.timeIds" placeholder="请选择参与场次" clearable size="small" multiple filterable | |
| 136 | + style="width: 880px"> | |
| 137 | + <el-option v-for="item in seckillTimeList" :key="item.id" :label="item.name" :value="item.id"> | |
| 138 | + <span style="float: left">{{ item.name + ': { ' }} {{ item.startTime }} -- {{ item.endTime + | |
| 139 | + ' }' | |
| 140 | + }}</span> | |
| 141 | + <span style="float: right; color: #8492a6; font-size: 13px"></span> | |
| 142 | + </el-option> | |
| 143 | + </el-select> | |
| 144 | + </el-form-item> | |
| 145 | + | |
| 146 | + <el-form-item label="商品选择"> | |
| 147 | + <el-select v-model="form.skuIds" placeholder="请选择活动商品" clearable size="small" multiple filterable | |
| 148 | + style="width: 880px" @change="changeFormSku"> | |
| 149 | + <el-option v-for="item in productSkus" :key="item.id" :label="item.spuName + ' ' + item.name" | |
| 150 | + :value="item.id"> | |
| 151 | + <span style="float: left">{{ item.spuName }} {{ item.name }}</span> | |
| 152 | + <span style="float: right; color: #8492a6; font-size: 13px">¥{{ (item.price / | |
| 153 | + 100.0).toFixed(2) | |
| 154 | + }}</span> | |
| 155 | + </el-option> | |
| 156 | + </el-select> | |
| 157 | + | |
| 158 | + <el-row> | |
| 159 | + <el-button type="primary" size="mini" @click="batchEditProduct('limitBuyCount')">限购</el-button> | |
| 160 | + <el-button type="primary" size="mini" @click="batchEditProduct('seckillPrice')">秒杀价</el-button> | |
| 161 | + <el-button type="primary" size="mini" @click="batchEditProduct('seckillStock')">秒杀库存</el-button> | |
| 162 | + </el-row> | |
| 163 | + | |
| 164 | + <el-table v-loading="loading" ref="productsTable" :data="form.products"> | |
| 165 | + <el-table-column type="selection" width="55"> | |
| 166 | + </el-table-column> | |
| 167 | + <el-table-column label="商品名称" align="center" width="200"> | |
| 168 | + <template slot-scope="scope"> | |
| 169 | + {{ scope.row.spuName }} {{ scope.row.name }} | |
| 170 | + </template> | |
| 171 | + </el-table-column> | |
| 172 | + <el-table-column label="商品价格" align="center" prop="price"> | |
| 173 | + <template slot-scope="scope"> | |
| 174 | + ¥{{ (scope.row.price / 100.0).toFixed(2) }} | |
| 175 | + </template> | |
| 176 | + </el-table-column> | |
| 177 | + <el-table-column label="库存" align="center" prop="productStock" /> | |
| 178 | + <el-table-column label="限购(0为不限购)" align="center" width="150"> | |
| 179 | + <template slot-scope="scope"> | |
| 180 | + <el-input-number v-model="scope.row.limitBuyCount" size="mini" controls-position="right" | |
| 181 | + :min="0" :max="10000"> | |
| 182 | + </el-input-number> | |
| 183 | + </template> | |
| 184 | + </el-table-column> | |
| 185 | + | |
| 186 | + <el-table-column label="秒杀价(元)" align="center" width="150"> | |
| 187 | + <template slot-scope="scope"> | |
| 188 | + <el-input-number v-model="scope.row.seckillPrice" size="mini" controls-position="right" | |
| 189 | + :precision="2" :min="0" :max="10000"> | |
| 190 | + </el-input-number> | |
| 191 | + </template> | |
| 192 | + </el-table-column> | |
| 193 | + | |
| 194 | + <el-table-column label="秒杀库存" align="center" width="150"> | |
| 195 | + <template slot-scope="scope"> | |
| 196 | + <el-input-number v-model="scope.row.seckillStock" size="mini" controls-position="right" | |
| 197 | + :min="0" :max="10000"> | |
| 198 | + </el-input-number> | |
| 199 | + </template> | |
| 200 | + </el-table-column> | |
| 201 | + | |
| 202 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 203 | + <template slot-scope="scope"> | |
| 204 | + <el-button size="mini" type="text" icon="el-icon-delete" | |
| 205 | + @click="removeFormSku(scope.row.skuId)">删除 | |
| 206 | + </el-button> | |
| 207 | + </template> | |
| 208 | + </el-table-column> | |
| 209 | + </el-table> | |
| 210 | + </el-form-item> | |
| 211 | + | |
| 212 | + | |
| 213 | + </el-form> | |
| 214 | + <div slot="footer" class="dialog-footer"> | |
| 215 | + <el-button type="primary" @click="submitForm">确 定</el-button> | |
| 216 | + <el-button @click="cancel">取 消</el-button> | |
| 217 | + </div> | |
| 218 | + </el-dialog> | |
| 219 | + </div> | |
| 220 | +</template> | |
| 221 | + | |
| 222 | +<script> | |
| 223 | +import { getSkuOptionList } from "@/api/mall/product/sku"; | |
| 224 | +import { createSeckillActivity, updateSeckillActivity, deleteSeckillActivity, getSeckillActivity, getSeckillActivityPage, exportSeckillActivityExcel } from "@/api/promotion/seckillActivity"; | |
| 225 | +import { getSeckillTimeList } from "@/api/promotion/seckillTime"; | |
| 226 | +import router from '@/router'; | |
| 227 | +import { PromotionDiscountTypeEnum } from "@/utils/constants"; | |
| 228 | + | |
| 229 | +export default { | |
| 230 | + name: "SeckillActivity", | |
| 231 | + components: { | |
| 232 | + }, | |
| 233 | + data() { | |
| 234 | + return { | |
| 235 | + // 遮罩层 | |
| 236 | + loading: true, | |
| 237 | + // 导出遮罩层 | |
| 238 | + exportLoading: false, | |
| 239 | + // 显示搜索条件 | |
| 240 | + showSearch: true, | |
| 241 | + // 总条数 | |
| 242 | + total: 0, | |
| 243 | + // 秒杀活动列表 | |
| 244 | + list: [], | |
| 245 | + // 秒杀场次列表 | |
| 246 | + seckillTimeList: [], | |
| 247 | + // 弹出层标题 | |
| 248 | + title: "", | |
| 249 | + // 是否显示弹出层 | |
| 250 | + open: false, | |
| 251 | + // 查询参数 | |
| 252 | + queryParams: { | |
| 253 | + pageNo: 1, | |
| 254 | + pageSize: 10, | |
| 255 | + name: null, | |
| 256 | + status: null, | |
| 257 | + timeId: null, | |
| 258 | + createTime: [], | |
| 259 | + }, | |
| 260 | + // 表单参数 | |
| 261 | + form: { | |
| 262 | + skuIds: [], // 选中的 SKU | |
| 263 | + products: [], // 商品信息 | |
| 264 | + timeIds: [], //选中的秒杀场次id | |
| 265 | + }, | |
| 266 | + // 商品 SKU 列表 | |
| 267 | + productSkus: [], | |
| 268 | + // 表单校验 | |
| 269 | + rules: { | |
| 270 | + name: [{ required: true, message: "秒杀活动名称不能为空", trigger: "blur" }], | |
| 271 | + status: [{ required: true, message: "活动状态不能为空", trigger: "blur" }], | |
| 272 | + startAndEndTime: [{ required: true, message: "活动时间不能为空", trigger: "blur" }], | |
| 273 | + endTime: [{ required: true, message: "活动结束时间不能为空", trigger: "blur" }], | |
| 274 | + sort: [{ required: true, message: "排序不能为空", trigger: "blur" }], | |
| 275 | + timeIds: [{ required: true, message: "秒杀场次不能为空", trigger: "blur" }], | |
| 276 | + totalPrice: [{ required: true, message: "订单实付金额,单位:分不能为空", trigger: "blur" }], | |
| 277 | + } | |
| 278 | + }; | |
| 279 | + }, | |
| 280 | + created() { | |
| 281 | + this.getList(); | |
| 282 | + }, | |
| 283 | + methods: { | |
| 284 | + /** 查询列表 */ | |
| 285 | + getList() { | |
| 286 | + this.loading = true; | |
| 287 | + // 执行查询 | |
| 288 | + getSeckillActivityPage(this.queryParams).then(response => { | |
| 289 | + this.list = response.data.list; | |
| 290 | + console.log(response, "查询返回的秒杀活动列表"); | |
| 291 | + this.total = response.data.total; | |
| 292 | + this.loading = false; | |
| 293 | + }); | |
| 294 | + // 获得 SKU 商品列表 | |
| 295 | + getSkuOptionList().then(response => { | |
| 296 | + this.productSkus = response.data; | |
| 297 | + }); | |
| 298 | + // 获取参与场次列表 | |
| 299 | + getSeckillTimeList().then(response => { | |
| 300 | + this.seckillTimeList = response.data; | |
| 301 | + console.log(this.seckillTimeList, "最终获取的参与场次列表"); | |
| 302 | + }); | |
| 303 | + }, | |
| 304 | + /** 取消按钮 */ | |
| 305 | + cancel() { | |
| 306 | + this.open = false; | |
| 307 | + this.reset(); | |
| 308 | + }, | |
| 309 | + /** 表单重置 */ | |
| 310 | + reset() { | |
| 311 | + this.form = { | |
| 312 | + id: undefined, | |
| 313 | + name: undefined, | |
| 314 | + status: undefined, | |
| 315 | + remark: undefined, | |
| 316 | + startTime: undefined, | |
| 317 | + endTime: undefined, | |
| 318 | + sort: undefined, | |
| 319 | + timeId: undefined, | |
| 320 | + totalPrice: undefined, | |
| 321 | + skuIds: [], | |
| 322 | + products: [], | |
| 323 | + }; | |
| 324 | + this.resetForm("form"); | |
| 325 | + }, | |
| 326 | + /** 搜索按钮操作 */ | |
| 327 | + handleQuery() { | |
| 328 | + this.queryParams.pageNo = 1; | |
| 329 | + this.getList(); | |
| 330 | + }, | |
| 331 | + /** 重置按钮操作 */ | |
| 332 | + resetQuery() { | |
| 333 | + this.resetForm("queryForm"); | |
| 334 | + this.handleQuery(); | |
| 335 | + }, | |
| 336 | + /** 新增按钮操作 */ | |
| 337 | + handleAdd() { | |
| 338 | + this.reset(); | |
| 339 | + this.open = true; | |
| 340 | + this.title = "添加秒杀活动"; | |
| 341 | + }, | |
| 342 | + /** 修改按钮操作 */ | |
| 343 | + handleUpdate(row) { | |
| 344 | + console.log(row, "当前行数据"); | |
| 345 | + this.reset(); | |
| 346 | + const id = row.id; | |
| 347 | + getSeckillActivity(id).then(response => { | |
| 348 | + this.form = response.data; | |
| 349 | + this.open = true; | |
| 350 | + this.title = "修改秒杀活动"; | |
| 351 | + }); | |
| 352 | + }, | |
| 353 | + /** 提交按钮 */ | |
| 354 | + submitForm() { | |
| 355 | + this.$refs["form"].validate(valid => { | |
| 356 | + if (!valid) { | |
| 357 | + return; | |
| 358 | + } | |
| 359 | + // 处理数据 | |
| 360 | + const data = deepClone(this.form); | |
| 361 | + data.startTime = this.form.startAndEndTime[0]; | |
| 362 | + data.endTime = this.form.startAndEndTime[1]; | |
| 363 | + // 修改的提交 | |
| 364 | + if (this.form.id != null) { | |
| 365 | + updateSeckillActivity(data).then(response => { | |
| 366 | + this.$modal.msgSuccess("修改成功"); | |
| 367 | + this.open = false; | |
| 368 | + this.getList(); | |
| 369 | + }); | |
| 370 | + return; | |
| 371 | + } | |
| 372 | + // 添加的提交 | |
| 373 | + createSeckillActivity(data).then(response => { | |
| 374 | + this.$modal.msgSuccess("新增成功"); | |
| 375 | + this.open = false; | |
| 376 | + this.getList(); | |
| 377 | + }); | |
| 378 | + }); | |
| 379 | + }, | |
| 380 | + /** 删除按钮操作 */ | |
| 381 | + handleDelete(row) { | |
| 382 | + const id = row.id; | |
| 383 | + this.$modal.confirm('是否确认删除秒杀活动编号为"' + id + '"的数据项?').then(function () { | |
| 384 | + return deleteSeckillActivity(id); | |
| 385 | + }).then(() => { | |
| 386 | + this.getList(); | |
| 387 | + this.$modal.msgSuccess("删除成功"); | |
| 388 | + }).catch(() => { }); | |
| 389 | + }, | |
| 390 | + /** 导出按钮操作 */ | |
| 391 | + handleExport() { | |
| 392 | + // 处理查询参数 | |
| 393 | + let params = { ...this.queryParams }; | |
| 394 | + params.pageNo = undefined; | |
| 395 | + params.pageSize = undefined; | |
| 396 | + this.$modal.confirm('是否确认导出所有秒杀活动数据项?').then(() => { | |
| 397 | + this.exportLoading = true; | |
| 398 | + return exportSeckillActivityExcel(params); | |
| 399 | + }).then(response => { | |
| 400 | + this.$download.excel(response, '秒杀活动.xls'); | |
| 401 | + this.exportLoading = false; | |
| 402 | + }).catch(() => { }); | |
| 403 | + }, | |
| 404 | + /** 批量修改商品秒杀价,秒杀库存,每人限购数量 */ | |
| 405 | + batchEditProduct(editType) { | |
| 406 | + const selectProducts = this.$refs.productsTable.selection; | |
| 407 | + if (selectProducts.length === 0) { | |
| 408 | + this.$modal.msgError("请选择需要修改的商品"); | |
| 409 | + return; | |
| 410 | + } | |
| 411 | + let promptTitle = '请输入'; | |
| 412 | + let regularPattern = /^[\s\S]*.*[^\s][\s\S]*$/; // 判断非空,且非空格 | |
| 413 | + //限购数 | |
| 414 | + if (editType === 'limitBuyCount') { | |
| 415 | + promptTitle = '限购数'; | |
| 416 | + regularPattern = /^[0-9]*$/; //数字 | |
| 417 | + } | |
| 418 | + //秒杀价 | |
| 419 | + if (editType === 'seckillPrice') { | |
| 420 | + promptTitle = '秒杀价(元)'; | |
| 421 | + regularPattern = /^[0-9]+(\.[0-9]{1,2})?$/; // 有一位或两位小数的正数 | |
| 422 | + } | |
| 423 | + //秒杀库存 | |
| 424 | + if (editType === 'seckillStock') { | |
| 425 | + promptTitle = '秒杀库存'; | |
| 426 | + regularPattern = /^[0-9]*$/; //数字 | |
| 427 | + } | |
| 428 | + | |
| 429 | + this.$prompt(promptTitle, '提示', { | |
| 430 | + confirmButtonText: '保存', | |
| 431 | + cancelButtonText: '取消', | |
| 432 | + inputPattern: regularPattern, | |
| 433 | + inputErrorMessage: promptTitle + '格式不正确' | |
| 434 | + }).then(({ value }) => { | |
| 435 | + if (editType === 'limitBuyCount') { | |
| 436 | + selectProducts.forEach((item) => { | |
| 437 | + item.limitBuyCount = value; | |
| 438 | + }) | |
| 439 | + } | |
| 440 | + if (editType === 'seckillPrice') { | |
| 441 | + selectProducts.forEach((item) => { | |
| 442 | + item.seckillPrice = value; | |
| 443 | + }) | |
| 444 | + } | |
| 445 | + if (editType === 'seckillStock') { | |
| 446 | + selectProducts.forEach((item) => { | |
| 447 | + item.seckillStock = value; | |
| 448 | + }) | |
| 449 | + } | |
| 450 | + }).catch(); | |
| 451 | + }, | |
| 452 | + /** 当 Form 的 SKU 发生变化时 */ | |
| 453 | + changeFormSku(skuIds) { | |
| 454 | + // 处理【新增】 | |
| 455 | + skuIds.forEach(skuId => { | |
| 456 | + // 获得对应的 SKU 信息 | |
| 457 | + const sku = this.productSkus.find(item => item.id === skuId); | |
| 458 | + if (!sku) { | |
| 459 | + return; | |
| 460 | + } | |
| 461 | + // 判断已存在,直接跳过 | |
| 462 | + console.log(this.form, "当前form") | |
| 463 | + const product = this.form.products.find(item => item.skuId === skuId); | |
| 464 | + if (product) { | |
| 465 | + return; | |
| 466 | + } | |
| 467 | + this.form.products.push({ | |
| 468 | + skuId: sku.id, | |
| 469 | + name: sku.name, | |
| 470 | + price: sku.price, | |
| 471 | + productStock: sku.stock, | |
| 472 | + spuId: sku.spuId, | |
| 473 | + spuName: sku.spuName, | |
| 474 | + limitBuyCount: 1, | |
| 475 | + seckillStock: sku.stock, | |
| 476 | + seckillPrice: sku.price, | |
| 477 | + }); | |
| 478 | + }); | |
| 479 | + // 处理【移除】 | |
| 480 | + this.form.products.map((product, index) => { | |
| 481 | + if (!skuIds.includes(product.skuId)) { | |
| 482 | + this.form.products.splice(index, 1); | |
| 483 | + } | |
| 484 | + }); | |
| 485 | + }, | |
| 486 | + /** 移除 Form 的 SKU */ | |
| 487 | + removeFormSku(skuId) { | |
| 488 | + this.form.skuIds.map((id, index) => { | |
| 489 | + if (skuId === id) { | |
| 490 | + this.form.skuIds.splice(index, 1); | |
| 491 | + } | |
| 492 | + }); | |
| 493 | + this.changeFormSku(this.form.skuIds); | |
| 494 | + }, | |
| 495 | + } | |
| 496 | +}; | |
| 497 | +</script> | ... | ... |