index.vue 11 KB

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