index.vue 23 KB

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