index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <div class="app-container">
  3. <!-- 操作工具栏 -->
  4. <el-row :gutter="10" class="mb8">
  5. <el-col :span="1.5">
  6. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  7. v-hasPermi="['promotion:seckill-time:create']">新增秒杀时段</el-button>
  8. </el-col>
  9. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  10. </el-row>
  11. <!-- 列表 -->
  12. <el-table v-loading="loading" :data="list">
  13. <el-table-column label="秒杀时段名称" align="center" prop="name" />
  14. <el-table-column label="开始时间点" align="center" prop="startTime" width="180">
  15. <template v-slot="scope">
  16. <span>{{ scope.row.startTime }}</span>
  17. </template>
  18. </el-table-column>
  19. <el-table-column label="结束时间点" align="center" prop="endTime" width="180">
  20. <template v-slot="scope">
  21. <span>{{ scope.row.endTime }}</span>
  22. </template>
  23. </el-table-column>
  24. <el-table-column label="秒杀活动数量" align="center" prop="seckillActivityCount" />
  25. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  26. <template v-slot="scope">
  27. <span>{{ parseTime(scope.row.createTime) }}</span>
  28. </template>
  29. </el-table-column>
  30. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  31. <template v-slot="scope">
  32. <el-button size="mini" type="text" icon="el-icon-view" @click="handleOpenSeckillActivity(scope.row)">
  33. 查看秒杀活动</el-button>
  34. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  35. v-hasPermi="['promotion:seckill-time:update']">修改</el-button>
  36. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  37. v-hasPermi="['promotion:seckill-time:delete']">删除</el-button>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. <!-- 对话框(添加 / 修改) -->
  42. <el-dialog :title="title" :visible.sync="open" width="600px" v-dialogDrag append-to-body>
  43. <el-form ref="form" :model="form" :rules="rules" label-width="140px">
  44. <el-form-item label="秒杀场次名称" prop="name">
  45. <el-input v-model="form.name" placeholder="请输入秒杀时段名称" clearable />
  46. </el-form-item>
  47. <el-form-item label="秒杀时间段" prop="startAndEndTime">
  48. <el-time-picker is-range v-model="form.startAndEndTime" range-separator="至" start-placeholder="开始时间"
  49. end-placeholder="结束时间" placeholder="选择时间范围" value-format="HH:mm:ss">
  50. </el-time-picker>
  51. </el-form-item>
  52. </el-form>
  53. <div slot="footer" class="dialog-footer">
  54. <el-button type="primary" @click="submitForm">确 定</el-button>
  55. <el-button @click="cancel">取 消</el-button>
  56. </div>
  57. </el-dialog>
  58. </div>
  59. </template>
  60. <script>
  61. import { createSeckillTime, updateSeckillTime, deleteSeckillTime, getSeckillTime, getSeckillTimePage, exportSeckillTimeExcel, getSeckillTimeList } from "@/api/mall/promotion/seckillTime";
  62. import router from "@/router";
  63. import { deepClone } from "@/utils";
  64. export default {
  65. name: "SeckillTime",
  66. components: {
  67. },
  68. data() {
  69. return {
  70. // 遮罩层
  71. loading: true,
  72. // 导出遮罩层
  73. exportLoading: false,
  74. // 显示搜索条件
  75. showSearch: true,
  76. // 总条数
  77. // total: 0,
  78. // 秒杀时段列表
  79. list: [],
  80. // 弹出层标题
  81. title: "",
  82. // 是否显示弹出层
  83. open: false,
  84. // 表单参数
  85. form: {},
  86. // 表单校验
  87. rules: {
  88. name: [{ required: true, message: "秒杀时段名称不能为空", trigger: "blur" }],
  89. startAndEndTime: [{ required: true, message: "秒杀时间段不能为空", trigger: "blur" }],
  90. }
  91. };
  92. },
  93. created() {
  94. this.getList();
  95. },
  96. methods: {
  97. /** 查询列表 */
  98. getList() {
  99. this.loading = true;
  100. // 执行查询
  101. getSeckillTimeList().then(response => {
  102. this.list = response.data;
  103. this.loading = false;
  104. });
  105. },
  106. /** 取消按钮 */
  107. cancel() {
  108. this.open = false;
  109. this.reset();
  110. },
  111. /** 表单重置 */
  112. reset() {
  113. this.form = {
  114. id: undefined,
  115. name: undefined,
  116. startAndEndTime: undefined,
  117. startTime: undefined,
  118. endTime: undefined,
  119. };
  120. this.resetForm("form");
  121. },
  122. /** 搜索按钮操作 */
  123. handleQuery() {
  124. this.getList();
  125. },
  126. /** 重置按钮操作 */
  127. resetQuery() {
  128. this.resetForm("queryForm");
  129. this.handleQuery();
  130. },
  131. /**查看当前秒杀时段的秒杀活动 */
  132. handleOpenSeckillActivity(row) {
  133. router.push({ name: 'SeckillActivity', params: { timeId: row.id } })
  134. },
  135. /** 新增按钮操作 */
  136. handleAdd() {
  137. this.reset();
  138. this.open = true;
  139. this.title = "添加秒杀时段";
  140. },
  141. /** 修改按钮操作 */
  142. handleUpdate(row) {
  143. this.reset();
  144. const id = row.id;
  145. getSeckillTime(id).then(response => {
  146. response.data.startAndEndTime = [response.data.startTime, response.data.endTime]
  147. this.form = response.data;
  148. this.open = true;
  149. this.title = "修改秒杀时段";
  150. });
  151. },
  152. /** 提交按钮 */
  153. submitForm() {
  154. this.$refs["form"].validate(valid => {
  155. console.log(valid, "是否通过");
  156. if (!valid) {
  157. return;
  158. }
  159. // 处理数据
  160. const data = deepClone(this.form);
  161. data.startTime = this.form.startAndEndTime[0];
  162. data.endTime = this.form.startAndEndTime[1];
  163. // 修改的提交
  164. if (this.form.id != null) {
  165. updateSeckillTime(data).then(response => {
  166. this.$modal.msgSuccess("修改成功");
  167. this.open = false;
  168. this.getList();
  169. });
  170. return;
  171. }
  172. // 添加的提交
  173. createSeckillTime(data).then(response => {
  174. this.$modal.msgSuccess("新增成功");
  175. this.open = false;
  176. this.getList();
  177. });
  178. });
  179. },
  180. /** 删除按钮操作 */
  181. handleDelete(row) {
  182. const id = row.id;
  183. this.$modal.confirm('是否确认删除秒杀时段编号为"' + id + '"的数据项?').then(function () {
  184. return deleteSeckillTime(id);
  185. }).then(() => {
  186. this.getList();
  187. this.$modal.msgSuccess("删除成功");
  188. }).catch(() => { });
  189. },
  190. }
  191. };
  192. </script>