index.vue 23 KB

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