index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <div class="app-container">
  3. <!-- 搜索工作栏 -->
  4. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  5. <el-form-item label="活动名称" prop="name">
  6. <el-input v-model="queryParams.name" placeholder="请输入活动名称" clearable @keyup.enter.native="handleQuery"/>
  7. </el-form-item>
  8. <el-form-item label="活动状态" prop="status">
  9. <el-select v-model="queryParams.status" placeholder="请选择活动状态" clearable size="small">
  10. <el-option v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_ACTIVITY_STATUS)"
  11. :key="dict.value" :label="dict.label" :value="dict.value"/>
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item label="创建时间" prop="createTime">
  15. <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
  16. range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
  17. </el-form-item>
  18. <el-form-item>
  19. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  20. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  21. </el-form-item>
  22. </el-form>
  23. <!-- 操作工具栏 -->
  24. <el-row :gutter="10" class="mb8">
  25. <el-col :span="1.5">
  26. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  27. v-hasPermi="['promotion:discount-activity:create']">新增</el-button>
  28. </el-col>
  29. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  30. </el-row>
  31. <!-- 列表 -->
  32. <el-table v-loading="loading" :data="list">
  33. <el-table-column label="活动名称" align="center" prop="name" />
  34. <el-table-column label="活动时间" align="center" prop="startTime" width="240">
  35. <template slot-scope="scope">
  36. <div>开始:{{ parseTime(scope.row.startTime) }}</div>
  37. <div>结束:{{ parseTime(scope.row.endTime) }}</div>
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="状态" align="center" prop="status">
  41. <template slot-scope="scope">
  42. <dict-tag :type="DICT_TYPE.PROMOTION_ACTIVITY_STATUS" :value="scope.row.status" />
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  46. <template slot-scope="scope">
  47. <span>{{ parseTime(scope.row.createTime) }}</span>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  51. <template slot-scope="scope">
  52. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  53. v-if="scope.row.status !== PromotionActivityStatusEnum.CLOSE.type"
  54. v-hasPermi="['promotion:discount-activity:update']">修改</el-button>
  55. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleClose(scope.row)"
  56. v-if="scope.row.status !== PromotionActivityStatusEnum.CLOSE.type &&
  57. scope.row.status !== PromotionActivityStatusEnum.END.type"
  58. v-hasPermi="['promotion:discount-activity:close']">关闭</el-button>
  59. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  60. v-if="scope.row.status === PromotionActivityStatusEnum.CLOSE.type"
  61. v-hasPermi="['promotion:discount-activity:delete']">删除</el-button>
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. <!-- 分页组件 -->
  66. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  67. @pagination="getList"/>
  68. <!-- 对话框(添加 / 修改) -->
  69. <el-dialog :title="title" :visible.sync="open" width="600px" v-dialogDrag append-to-body>
  70. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  71. <el-form-item label="活动名称" prop="name">
  72. <el-input v-model="form.name" placeholder="请输入活动名称" />
  73. </el-form-item>
  74. <el-form-item label="备注" prop="remark">
  75. <el-input type="textarea" v-model="form.remark" placeholder="请输入备注" />
  76. </el-form-item>
  77. <el-form-item label="活动时间" prop="startAndEndTime">
  78. <el-date-picker clearable v-model="form.startAndEndTime" type="datetimerange" :default-time="['00:00:00', '23:59:59']"
  79. value-format="timestamp" placeholder="选择开始时间" style="width: 480px" />
  80. </el-form-item>
  81. </el-form>
  82. <div slot="footer" class="dialog-footer">
  83. <el-button type="primary" @click="submitForm">确 定</el-button>
  84. <el-button @click="cancel">取 消</el-button>
  85. </div>
  86. </el-dialog>
  87. </div>
  88. </template>
  89. <script>
  90. import { createDiscountActivity, updateDiscountActivity, deleteDiscountActivity, getDiscountActivity, getDiscountActivityPage } from "@/api/mall/promotion/discountActivity";
  91. import {PromotionActivityStatusEnum, PromotionProductScopeEnum} from "@/utils/constants";
  92. import {closeRewardActivity} from "@/api/mall/promotion/rewardActivity";
  93. export default {
  94. name: "DiscountActivity",
  95. components: {
  96. },
  97. data() {
  98. return {
  99. // 遮罩层
  100. loading: true,
  101. // 导出遮罩层
  102. exportLoading: false,
  103. // 显示搜索条件
  104. showSearch: true,
  105. // 总条数
  106. total: 0,
  107. // 限时折扣活动列表
  108. list: [],
  109. // 弹出层名称
  110. title: "",
  111. // 是否显示弹出层
  112. open: false,
  113. // 查询参数
  114. queryParams: {
  115. pageNo: 1,
  116. pageSize: 10,
  117. name: null,
  118. status: null,
  119. createTime: [],
  120. },
  121. // 表单参数
  122. form: {},
  123. // 表单校验
  124. rules: {
  125. name: [{ required: true, message: "活动名称不能为空", trigger: "blur" }],
  126. startAndEndTime: [{ required: true, message: "活动时间不能为空", trigger: "blur" }],
  127. },
  128. // 商品列表
  129. productSpus: [], // TODO 芋艿:需要重新写下
  130. // 如下的变量,主要为了 v-if 判断可以使用到
  131. PromotionProductScopeEnum: PromotionProductScopeEnum,
  132. PromotionActivityStatusEnum: PromotionActivityStatusEnum,
  133. };
  134. },
  135. created() {
  136. this.getList();
  137. },
  138. methods: {
  139. /** 查询列表 */
  140. getList() {
  141. this.loading = true;
  142. // 执行查询
  143. getDiscountActivityPage(this.queryParams).then(response => {
  144. this.list = response.data.list;
  145. this.total = response.data.total;
  146. this.loading = false;
  147. });
  148. },
  149. /** 取消按钮 */
  150. cancel() {
  151. this.open = false;
  152. this.reset();
  153. },
  154. /** 表单重置 */
  155. reset() {
  156. this.form = {
  157. id: undefined,
  158. name: undefined,
  159. startAndEndTime: undefined,
  160. startTime: undefined,
  161. endTime: undefined,
  162. remark: undefined,
  163. };
  164. this.resetForm("form");
  165. },
  166. /** 搜索按钮操作 */
  167. handleQuery() {
  168. this.queryParams.pageNo = 1;
  169. this.getList();
  170. },
  171. /** 重置按钮操作 */
  172. resetQuery() {
  173. this.resetForm("queryForm");
  174. this.handleQuery();
  175. },
  176. /** 新增按钮操作 */
  177. handleAdd() {
  178. this.reset();
  179. this.open = true;
  180. this.title = "添加限时折扣活动";
  181. },
  182. /** 修改按钮操作 */
  183. handleUpdate(row) {
  184. this.reset();
  185. const id = row.id;
  186. getDiscountActivity(id).then(response => {
  187. this.form = response.data;
  188. this.form.startAndEndTime = [response.data.startTime, response.data.endTime];
  189. this.open = true;
  190. this.title = "修改限时折扣活动";
  191. });
  192. },
  193. /** 提交按钮 */
  194. submitForm() {
  195. this.$refs["form"].validate(valid => {
  196. if (!valid) {
  197. return;
  198. }
  199. this.form.startTime = this.form.startAndEndTime[0];
  200. this.form.endTime = this.form.startAndEndTime[1];
  201. // 修改的提交
  202. if (this.form.id != null) {
  203. updateDiscountActivity(this.form).then(response => {
  204. this.$modal.msgSuccess("修改成功");
  205. this.open = false;
  206. this.getList();
  207. });
  208. return;
  209. }
  210. // 添加的提交
  211. createDiscountActivity(this.form).then(response => {
  212. this.$modal.msgSuccess("新增成功");
  213. this.open = false;
  214. this.getList();
  215. });
  216. });
  217. },
  218. /** 删除按钮操作 */
  219. handleDelete(row) {
  220. const id = row.id;
  221. this.$modal.confirm('是否确认删除限时折扣活动编号为"' + id + '"的数据项?').then(function() {
  222. return deleteDiscountActivity(id);
  223. }).then(() => {
  224. this.getList();
  225. this.$modal.msgSuccess("删除成功");
  226. }).catch(() => {});
  227. },
  228. /** 关闭按钮操作 */
  229. handleClose(row) {
  230. const id = row.id;
  231. this.$modal.confirm('是否确认关闭限时折扣活动编号为"' + id + '"的数据项?').then(function() {
  232. return closeRewardActivity(id);
  233. }).then(() => {
  234. this.getList();
  235. this.$modal.msgSuccess("关闭成功");
  236. }).catch(() => {});
  237. }
  238. }
  239. };
  240. </script>