index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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" label-width="68px">
  6. <el-form-item label="活动名称" prop="name">
  7. <el-input v-model="queryParams.name" placeholder="请输入活动名称" clearable @keyup.enter.native="handleQuery"/>
  8. </el-form-item>
  9. <el-form-item label="活动状态" prop="status">
  10. <el-select v-model="queryParams.status" placeholder="请选择活动状态" clearable size="small">
  11. <el-option v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_ACTIVITY_STATUS)"
  12. :key="dict.value" :label="dict.label" :value="dict.value"/>
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item>
  16. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  17. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  18. </el-form-item>
  19. </el-form>
  20. <!-- 操作工具栏 -->
  21. <el-row :gutter="10" class="mb8">
  22. <el-col :span="1.5">
  23. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  24. v-hasPermi="['promotion:reward-activity:create']">新增</el-button>
  25. </el-col>
  26. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  27. </el-row>
  28. <!-- 列表 -->
  29. <el-table v-loading="loading" :data="list">
  30. <el-table-column label="活动名称" align="center" prop="name" />
  31. <el-table-column label="活动时间" align="center" prop="startTime" width="240">
  32. <template v-slot="scope">
  33. <div>开始:{{ parseTime(scope.row.startTime) }}</div>
  34. <div>结束:{{ parseTime(scope.row.endTime) }}</div>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="状态" align="center" prop="status">
  38. <template v-slot="scope">
  39. <dict-tag :type="DICT_TYPE.PROMOTION_ACTIVITY_STATUS" :value="scope.row.status" />
  40. </template>
  41. </el-table-column>
  42. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  43. <template v-slot="scope">
  44. <span>{{ parseTime(scope.row.createTime) }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  48. <template v-slot="scope">
  49. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  50. v-if="scope.row.status !== PromotionActivityStatusEnum.CLOSE.type"
  51. v-hasPermi="['promotion:reward-activity:update']">修改</el-button>
  52. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleClose(scope.row)"
  53. v-if="scope.row.status !== PromotionActivityStatusEnum.CLOSE.type &&
  54. scope.row.status !== PromotionActivityStatusEnum.END.type"
  55. v-hasPermi="['promotion:reward-activity:close']">关闭</el-button>
  56. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  57. v-if="scope.row.status === PromotionActivityStatusEnum.CLOSE.type"
  58. v-hasPermi="['promotion:reward-activity:delete']">删除</el-button>
  59. </template>
  60. </el-table-column>
  61. </el-table>
  62. <!-- 分页组件 -->
  63. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  64. @pagination="getList"/>
  65. <!-- 对话框(添加 / 修改) -->
  66. <el-dialog :title="title" :visible.sync="open" width="600px" v-dialogDrag append-to-body>
  67. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  68. <el-form-item label="活动名称" prop="name">
  69. <el-input v-model="form.name" placeholder="请输入活动名称" />
  70. </el-form-item>
  71. <el-form-item label="活动时间" prop="startAndEndTime">
  72. <el-date-picker clearable v-model="form.startAndEndTime" type="datetimerange" :default-time="['00:00:00', '23:59:59']"
  73. value-format="timestamp" placeholder="选择开始时间" style="width: 480px" />
  74. </el-form-item>
  75. <el-form-item label="条件类型" prop="conditionType">
  76. <el-radio-group v-model="form.conditionType">
  77. <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_CONDITION_TYPE)"
  78. :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
  79. </el-radio-group>
  80. </el-form-item>
  81. <el-form-item label="优惠设置" prop="conditionType">
  82. <!-- TODO 芋艿:待实现! -->
  83. </el-form-item>
  84. <el-form-item label="活动商品" prop="productScope">
  85. <el-radio-group v-model="form.productScope">
  86. <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_PRODUCT_SCOPE)"
  87. :key="dict.value" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
  88. </el-radio-group>
  89. </el-form-item>
  90. <el-form-item v-if="form.productScope === PromotionProductScopeEnum.SPU.scope" prop="productSpuIds">
  91. <el-select v-model="form.productSpuIds" placeholder="请选择活动商品" clearable size="small"
  92. multiple filterable style="width: 400px">
  93. <el-option v-for="item in productSpus" :key="item.id" :label="item.name" :value="item.id">
  94. <span style="float: left">{{ item.name }}</span>
  95. <span style="float: right; color: #8492a6; font-size: 13px">¥{{ (item.minPrice / 100.0).toFixed(2) }}</span>
  96. </el-option>
  97. </el-select>
  98. </el-form-item>
  99. <el-form-item label="备注" prop="remark">
  100. <el-input v-model="form.remark" placeholder="请输入备注" />
  101. </el-form-item>
  102. </el-form>
  103. <div slot="footer" class="dialog-footer">
  104. <el-button type="primary" @click="submitForm">确 定</el-button>
  105. <el-button @click="cancel">取 消</el-button>
  106. </div>
  107. </el-dialog>
  108. </div>
  109. </template>
  110. <script>
  111. import {
  112. createRewardActivity,
  113. updateRewardActivity,
  114. deleteRewardActivity,
  115. getRewardActivity,
  116. getRewardActivityPage,
  117. closeRewardActivity
  118. } from "@/api/mall/promotion/rewardActivity";
  119. import {
  120. PromotionConditionTypeEnum,
  121. PromotionProductScopeEnum,
  122. PromotionActivityStatusEnum
  123. } from "@/utils/constants";
  124. import {getSpuSimpleList} from "@/api/mall/product/spu";
  125. export default {
  126. name: "RewardActivity",
  127. components: {
  128. },
  129. data() {
  130. return {
  131. // 遮罩层
  132. loading: true,
  133. // 导出遮罩层
  134. exportLoading: false,
  135. // 显示搜索条件
  136. showSearch: true,
  137. // 总条数
  138. total: 0,
  139. // 满减送活动列表
  140. list: [],
  141. // 弹出层标题
  142. title: "",
  143. // 是否显示弹出层
  144. open: false,
  145. // 查询参数
  146. queryParams: {
  147. pageNo: 1,
  148. pageSize: 10,
  149. name: null,
  150. status: null,
  151. },
  152. // 表单参数
  153. form: {},
  154. // 表单校验
  155. rules: {
  156. name: [{ required: true, message: "活动名称不能为空", trigger: "blur" }],
  157. startAndEndTime: [{ required: true, message: "活动时间不能为空", trigger: "blur" }],
  158. conditionType: [{ required: true, message: "条件类型不能为空", trigger: "change" }],
  159. productScope: [{ required: true, message: "商品范围不能为空", trigger: "blur" }],
  160. productSpuIds: [{ required: true, message: "商品范围不能为空", trigger: "blur" }],
  161. },
  162. // 商品列表
  163. productSpus: [],
  164. // 如下的变量,主要为了 v-if 判断可以使用到
  165. PromotionProductScopeEnum: PromotionProductScopeEnum,
  166. PromotionActivityStatusEnum: PromotionActivityStatusEnum,
  167. };
  168. },
  169. created() {
  170. this.getList();
  171. // 查询商品列表
  172. getSpuSimpleList().then(response => {
  173. this.productSpus = response.data
  174. })
  175. },
  176. methods: {
  177. /** 查询列表 */
  178. getList() {
  179. this.loading = true;
  180. // 执行查询
  181. getRewardActivityPage(this.queryParams).then(response => {
  182. this.list = response.data.list;
  183. this.total = response.data.total;
  184. this.loading = false;
  185. });
  186. },
  187. /** 取消按钮 */
  188. cancel() {
  189. this.open = false;
  190. this.reset();
  191. },
  192. /** 表单重置 */
  193. reset() {
  194. this.form = {
  195. id: undefined,
  196. name: undefined,
  197. startAndEndTime: undefined,
  198. startTime: undefined,
  199. endTime: undefined,
  200. conditionType: PromotionConditionTypeEnum.PRICE.type,
  201. remark: undefined,
  202. productScope: PromotionProductScopeEnum.ALL.scope,
  203. productSpuIds: undefined,
  204. rules: undefined,
  205. };
  206. this.resetForm("form");
  207. },
  208. /** 搜索按钮操作 */
  209. handleQuery() {
  210. this.queryParams.pageNo = 1;
  211. this.getList();
  212. },
  213. /** 重置按钮操作 */
  214. resetQuery() {
  215. this.resetForm("queryForm");
  216. this.handleQuery();
  217. },
  218. /** 新增按钮操作 */
  219. handleAdd() {
  220. this.reset();
  221. this.open = true;
  222. this.title = "添加满减送活动";
  223. },
  224. /** 修改按钮操作 */
  225. handleUpdate(row) {
  226. this.reset();
  227. const id = row.id;
  228. getRewardActivity(id).then(response => {
  229. this.form = response.data;
  230. this.form.startAndEndTime = [response.data.startTime, response.data.endTime];
  231. this.open = true;
  232. this.title = "修改满减送活动";
  233. });
  234. },
  235. /** 提交按钮 */
  236. submitForm() {
  237. this.$refs["form"].validate(valid => {
  238. if (!valid) {
  239. return;
  240. }
  241. this.form.startTime = this.form.startAndEndTime[0];
  242. this.form.endTime = this.form.startAndEndTime[1];
  243. // TODO 芋艿:临时实现
  244. this.form.rules = [
  245. {
  246. limit: 1,
  247. discountPrice: 10,
  248. freeDelivery: true,
  249. point: 10,
  250. couponIds: [10, 20],
  251. couponCounts: [1, 2]
  252. }, {
  253. limit: 2,
  254. discountPrice: 20,
  255. freeDelivery: false,
  256. point: 20,
  257. couponIds: [30, 40],
  258. couponCounts: [3, 4]
  259. }
  260. ];
  261. // 修改的提交
  262. if (this.form.id != null) {
  263. updateRewardActivity(this.form).then(response => {
  264. this.$modal.msgSuccess("修改成功");
  265. this.open = false;
  266. this.getList();
  267. });
  268. return;
  269. }
  270. // 添加的提交
  271. createRewardActivity(this.form).then(response => {
  272. this.$modal.msgSuccess("新增成功");
  273. this.open = false;
  274. this.getList();
  275. });
  276. });
  277. },
  278. /** 删除按钮操作 */
  279. handleDelete(row) {
  280. const id = row.id;
  281. this.$modal.confirm('是否确认删除满减送活动编号为"' + id + '"的数据项?').then(function() {
  282. return deleteRewardActivity(id);
  283. }).then(() => {
  284. this.getList();
  285. this.$modal.msgSuccess("删除成功");
  286. }).catch(() => {});
  287. },
  288. /** 关闭按钮操作 */
  289. handleClose(row) {
  290. const id = row.id;
  291. this.$modal.confirm('是否确认关闭满减送活动编号为"' + id + '"的数据项?').then(function() {
  292. return closeRewardActivity(id);
  293. }).then(() => {
  294. this.getList();
  295. this.$modal.msgSuccess("关闭成功");
  296. }).catch(() => {});
  297. }
  298. }
  299. };
  300. </script>