coupon.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <div class="search">
  3. <Card>
  4. <Row>
  5. <Form ref="searchForm" :model="searchForm" inline :label-width="70" class="search-form">
  6. <Form-item label="活动名称" prop="couponName">
  7. <Input
  8. type="text"
  9. v-model="searchForm.couponName"
  10. placeholder="请输入活动名称"
  11. clearable
  12. style="width: 200px"
  13. />
  14. </Form-item>
  15. <Form-item label="活动状态" prop="promotionStatus">
  16. <Select
  17. v-model="searchForm.promotionStatus"
  18. placeholder="请选择"
  19. clearable
  20. style="width: 200px"
  21. >
  22. <Option value="NEW">未开始</Option>
  23. <Option value="START">已开始/上架</Option>
  24. <Option value="END">已结束/下架</Option>
  25. <Option value="CLOSE">紧急关闭/作废</Option>
  26. </Select>
  27. </Form-item>
  28. <Form-item label="活动时间">
  29. <DatePicker
  30. v-model="selectDate"
  31. type="daterange"
  32. clearable
  33. placeholder="选择起始时间"
  34. style="width: 200px"
  35. ></DatePicker>
  36. </Form-item>
  37. <Button @click="handleSearch" type="primary" icon="ios-search" class="search-btn">搜索</Button>
  38. </Form>
  39. </Row>
  40. <Row class="operation padding-row">
  41. <Button @click="add" type="primary">添加</Button>
  42. <Button @click="delAll">批量下架</Button>
  43. <!-- <Button @click="upAll" >批量上架</Button> -->
  44. </Row>
  45. <Row>
  46. <Table
  47. :loading="loading"
  48. border
  49. :columns="columns"
  50. :data="data"
  51. ref="table"
  52. sortable="custom"
  53. @on-sort-change="changeSort"
  54. @on-selection-change="changeSelect"
  55. >
  56. <template slot-scope="{ row }" slot="action">
  57. <!-- <Button
  58. type="info"
  59. size="small"
  60. style="margin-right: 10px"
  61. @click="receiveInfo(row)"
  62. >查看</Button
  63. > -->
  64. <Button
  65. v-if="row.promotionStatus === 'NEW' || row.promotionStatus === 'CLOSE'"
  66. type="primary"
  67. size="small"
  68. style="margin-right: 10px"
  69. @click="edit(row)"
  70. >编辑
  71. </Button
  72. >
  73. <Button
  74. v-if="row.promotionStatus === 'START' || row.promotionStatus === 'NEW'"
  75. type="error"
  76. size="small"
  77. style="margin-right: 10px"
  78. @click="remove(row)"
  79. >下架
  80. </Button
  81. >
  82. </template>
  83. </Table>
  84. </Row>
  85. <Row type="flex" justify="end" class="page">
  86. <Page
  87. :current="searchForm.pageNumber + 1"
  88. :total="total"
  89. :page-size="searchForm.pageSize"
  90. @on-change="changePage"
  91. @on-page-size-change="changePageSize"
  92. :page-size-opts="[10, 20, 50]"
  93. size="small"
  94. show-total
  95. show-elevator
  96. show-sizer
  97. ></Page>
  98. </Row>
  99. </Card>
  100. </div>
  101. </template>
  102. <script>
  103. import {
  104. getPlatformCouponList,
  105. deletePlatformCoupon,
  106. updatePlatformCouponStatus,
  107. } from "@/api/promotion";
  108. export default {
  109. name: "coupon",
  110. components: {},
  111. data() {
  112. return {
  113. loading: true, // 表单加载状态
  114. modalType: 0, // 添加或编辑标识
  115. modalVisible: false, // 添加或编辑显示
  116. modalTitle: "", // 添加或编辑标题
  117. searchForm: {
  118. // 搜索框初始化对象
  119. pageNumber: 0, // 当前页数
  120. pageSize: 10, // 页面大小
  121. sort: "startTime", // 默认排序字段
  122. order: "desc", // 默认排序方式
  123. },
  124. form: {
  125. // 添加或编辑表单对象初始化数据
  126. promotionName: "",
  127. },
  128. // 表单验证规则
  129. formValidate: {
  130. promotionName: [
  131. {required: true, message: "不能为空", trigger: "blur"},
  132. ],
  133. },
  134. submitLoading: false, // 添加或编辑提交状态
  135. selectList: [], // 多选数据
  136. selectCount: 0, // 多选计数
  137. columns: [
  138. // 表头
  139. {
  140. type: "selection",
  141. width: 60,
  142. align: "center",
  143. fixed: "left",
  144. },
  145. {
  146. title: "活动名称",
  147. key: "promotionName",
  148. minWidth: 120,
  149. fixed: "left",
  150. },
  151. {
  152. title: "优惠券名称",
  153. key: "couponName",
  154. minWidth: 120,
  155. tooltip: true
  156. }, {
  157. title: "面额/折扣",
  158. key: "price",
  159. width: 120,
  160. render: (h, params) => {
  161. if (params.row.price) {
  162. return h(
  163. "div",
  164. this.$options.filters.unitPrice(params.row.price, "¥")
  165. );
  166. } else {
  167. return h("div", params.row.couponDiscount + "折");
  168. }
  169. },
  170. },
  171. {
  172. title: "领取数量/总数量",
  173. key: "publishNum",
  174. render: (h, params) => {
  175. return h(
  176. "div", params.row.receivedNum + "/" + params.row.publishNum)
  177. }
  178. },
  179. {
  180. title: "优惠券类型",
  181. key: "couponType",
  182. width: 120,
  183. render: (h, params) => {
  184. let text = "未知";
  185. if (params.row.couponType === "DISCOUNT") {
  186. text = "打折";
  187. } else if (params.row.couponType === "PRICE") {
  188. text = "减免现金";
  189. }
  190. return h("div", [text]);
  191. },
  192. },
  193. {
  194. title: "品类描述",
  195. key: "scopeType",
  196. width: 100,
  197. render: (h, params) => {
  198. let text = "未知";
  199. if (params.row.scopeType == "ALL") {
  200. text = "全品类";
  201. } else if (params.row.scopeType == "PORTION_GOODS_CATEGORY") {
  202. text = "商品分类";
  203. } else if (params.row.scopeType == "PORTION_SHOP_CATEGORY") {
  204. text = "店铺分类";
  205. } else if (params.row.scopeType == "PORTION_GOODS") {
  206. text = "指定商品";
  207. }
  208. return h("div", [text]);
  209. },
  210. },
  211. {
  212. title: "活动时间",
  213. render: (h, params) => {
  214. return h("div", {
  215. domProps:
  216. {innerHTML: params.row.startTime + "<br/>" + params.row.endTime}
  217. });
  218. },
  219. },
  220. {
  221. title: "状态",
  222. key: "promotionStatus",
  223. fixed: "right",
  224. render: (h, params) => {
  225. let text = "未知",
  226. color = "";
  227. if (params.row.promotionStatus == "NEW") {
  228. text = "未开始";
  229. color = "default";
  230. } else if (params.row.promotionStatus == "START") {
  231. text = "已开始";
  232. color = "green";
  233. } else if (params.row.promotionStatus == "END") {
  234. text = "已结束";
  235. color = "red";
  236. } else if (params.row.promotionStatus == "CLOSE") {
  237. text = "已关闭";
  238. color = "red";
  239. }
  240. return h("div", [
  241. h(
  242. "Tag",
  243. {
  244. props: {
  245. color: color,
  246. },
  247. },
  248. text
  249. ),
  250. ]);
  251. },
  252. },
  253. {
  254. title: "操作",
  255. slot: "action",
  256. align: "center",
  257. fixed: "right",
  258. width: 80
  259. },
  260. ],
  261. data: [], // 表单数据
  262. total: 0, // 表单数据总数
  263. };
  264. },
  265. watch: {
  266. $route(to, from) {
  267. if (to.fullPath == "/promotion/manager-coupon") {
  268. this.init();
  269. }
  270. },
  271. },
  272. methods: {
  273. init() {
  274. this.getDataList();
  275. },
  276. add() {
  277. this.$router.push({name: "add-platform-coupon"});
  278. },
  279. /** 跳转至领取详情页面 */
  280. receiveInfo(v) {
  281. this.$router.push({name: "member-receive-coupon", query: {id: v.id}});
  282. },
  283. info(v) {
  284. this.$router.push({name: "platform-coupon-info", query: {id: v.id}});
  285. },
  286. changePage(v) {
  287. this.searchForm.pageNumber = v - 1;
  288. this.getDataList();
  289. this.clearSelectAll();
  290. },
  291. changePageSize(v) {
  292. this.searchForm.pageSize = v;
  293. this.getDataList();
  294. },
  295. handleSearch() {
  296. this.searchForm.pageNumber = 0;
  297. this.searchForm.pageSize = 10;
  298. this.getDataList();
  299. },
  300. changeSort(e) {
  301. this.searchForm.sort = e.key;
  302. this.searchForm.order = e.order;
  303. if (e.order === "normal") {
  304. this.searchForm.order = "";
  305. }
  306. this.getDataList();
  307. },
  308. clearSelectAll() {
  309. this.$refs.table.selectAll(false);
  310. },
  311. changeSelect(e) {
  312. this.selectList = e;
  313. this.selectCount = e.length;
  314. },
  315. getDataList() {
  316. this.loading = true;
  317. if (this.selectDate && this.selectDate[0] && this.selectDate[1]) {
  318. this.searchForm.startTime = this.selectDate[0].getTime();
  319. this.searchForm.endTime = this.selectDate[1].getTime();
  320. } else {
  321. this.searchForm.startTime = null;
  322. this.searchForm.endTime = null;
  323. }
  324. // 带多条件搜索参数获取表单数据 请自行修改接口
  325. getPlatformCouponList(this.searchForm).then((res) => {
  326. this.loading = false;
  327. if (res.success) {
  328. this.data = res.result.records;
  329. this.total = res.result.total;
  330. }
  331. });
  332. this.total = this.data.length;
  333. this.loading = false;
  334. },
  335. handleSubmit() {
  336. this.$refs.form.validate((valid) => {
  337. if (valid) {
  338. this.submitLoading = true;
  339. if (this.modalType === 0) {
  340. // 添加 避免编辑后传入id等数据 记得删除
  341. delete this.form.id;
  342. this.postRequest("/coupon/insertOrUpdate", this.form).then(
  343. (res) => {
  344. this.submitLoading = false;
  345. if (res.success) {
  346. this.$Message.success("操作成功");
  347. this.getDataList();
  348. this.modalVisible = false;
  349. }
  350. }
  351. );
  352. } else {
  353. // 编辑
  354. this.postRequest("/coupon/insertOrUpdate", this.form).then(
  355. (res) => {
  356. this.submitLoading = false;
  357. if (res.success) {
  358. this.$Message.success("操作成功");
  359. this.getDataList();
  360. this.modalVisible = false;
  361. }
  362. }
  363. );
  364. }
  365. }
  366. });
  367. },
  368. edit(v) {
  369. this.$router.push({name: "edit-platform-coupon", query: {id: v.id}});
  370. },
  371. remove(v) {
  372. this.$Modal.confirm({
  373. title: "确认下架",
  374. // 记得确认修改此处
  375. content: "确认要下架此优惠券么?",
  376. loading: true,
  377. onOk: () => {
  378. // 删除
  379. updatePlatformCouponStatus({couponIds: v.id, promotionStatus: "CLOSE"})
  380. .then((res) => {
  381. this.$Modal.remove();
  382. if (res.success) {
  383. this.$Message.success("优惠券已作废");
  384. this.getDataList();
  385. }
  386. })
  387. .catch(() => {
  388. this.$Modal;
  389. });
  390. },
  391. });
  392. },
  393. delAll() {
  394. if (this.selectCount <= 0) {
  395. this.$Message.warning("您还未选择要下架的优惠券");
  396. return;
  397. }
  398. this.$Modal.confirm({
  399. title: "确认下架",
  400. content: "您确认要下架所选的 " + this.selectCount + " 条数据?",
  401. loading: true,
  402. onOk: () => {
  403. let ids = [];
  404. this.selectList.forEach(function (e) {
  405. ids.push(e.id);
  406. });
  407. let params = {
  408. couponIds: ids.toString(),
  409. promotionStatus: "CLOSE",
  410. };
  411. // 批量删除
  412. updatePlatformCouponStatus(params).then((res) => {
  413. this.$Modal.remove();
  414. if (res.success) {
  415. this.$Message.success("下架成功");
  416. this.clearSelectAll();
  417. this.getDataList();
  418. }
  419. });
  420. },
  421. });
  422. },
  423. upAll() {
  424. if (this.selectCount <= 0) {
  425. this.$Message.warning("请选择要上架的优惠券");
  426. return;
  427. }
  428. this.$Modal.confirm({
  429. title: "确认上架",
  430. content: "您确认要上架所选的 " + this.selectCount + " 条数据?",
  431. loading: true,
  432. onOk: () => {
  433. let ids = [];
  434. this.selectList.forEach(function (e) {
  435. ids.push(e.id);
  436. });
  437. let params = {
  438. couponIds: ids.toString(),
  439. promotionStatus: "START",
  440. };
  441. // 批量上架
  442. updatePlatformCouponStatus(params).then((res) => {
  443. this.$Modal.remove();
  444. if (res.success) {
  445. this.$Message.success("上架成功");
  446. this.clearSelectAll();
  447. this.getDataList();
  448. }
  449. });
  450. },
  451. });
  452. },
  453. },
  454. mounted() {
  455. this.init();
  456. },
  457. };
  458. </script>
  459. <style lang="scss">
  460. @import "@/styles/table-common.scss";
  461. </style>