index.vue 23 KB

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