coupon.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import request from '@/sheep/request';
  2. import {
  3. t
  4. } from '@/locale';
  5. const CouponApi = {
  6. // 获得优惠劵模板列表
  7. getCouponTemplateListByIds: (ids) => {
  8. return request({
  9. url: '/promotion/coupon-template/list-by-ids',
  10. method: 'GET',
  11. params: { ids },
  12. custom: {
  13. showLoading: false, // 不展示 Loading,避免领取优惠劵时,不成功提示
  14. showError: false,
  15. },
  16. });
  17. },
  18. // 获得优惠劵模版列表
  19. getCouponTemplateList: (spuId, productScope, count) => {
  20. return request({
  21. url: '/promotion/coupon-template/list',
  22. method: 'GET',
  23. params: { spuId, productScope, count },
  24. });
  25. },
  26. // 获得优惠劵模版分页
  27. getCouponTemplatePage: (params) => {
  28. return request({
  29. url: '/promotion/coupon-template/page',
  30. method: 'GET',
  31. params,
  32. });
  33. },
  34. // 获得优惠劵模版
  35. getCouponTemplate: (id) => {
  36. return request({
  37. url: '/promotion/coupon-template/get',
  38. method: 'GET',
  39. params: { id },
  40. });
  41. },
  42. // 我的优惠劵列表
  43. getCouponPage: (params) => {
  44. return request({
  45. url: '/promotion/coupon/page',
  46. method: 'GET',
  47. params,
  48. });
  49. },
  50. // 领取优惠券
  51. takeCoupon: (templateId) => {
  52. return request({
  53. url: '/promotion/coupon/take',
  54. method: 'POST',
  55. data: { templateId },
  56. custom: {
  57. auth: true,
  58. showLoading: true,
  59. loadingMsg: t('common.claiming'),
  60. showSuccess: true,
  61. successMsg: t('common.claim_success'),
  62. },
  63. });
  64. },
  65. // 获得优惠劵
  66. getCoupon: (id) => {
  67. return request({
  68. url: '/promotion/coupon/get',
  69. method: 'GET',
  70. params: { id },
  71. });
  72. },
  73. // 获得未使用的优惠劵数量
  74. getUnusedCouponCount: () => {
  75. return request({
  76. url: '/promotion/coupon/get-unused-count',
  77. method: 'GET',
  78. custom: {
  79. showLoading: false,
  80. auth: true,
  81. },
  82. });
  83. },
  84. // 获得匹配指定商品的优惠劵列表
  85. getMatchCouponList: (price, spuIds, skuIds, categoryIds) => {
  86. return request({
  87. url: '/promotion/coupon/match-list',
  88. method: 'GET',
  89. params: {
  90. price,
  91. spuIds: spuIds.join(','),
  92. skuIds: skuIds.join(','),
  93. categoryIds: categoryIds.join(','),
  94. },
  95. custom: {
  96. showError: false,
  97. showLoading: false, // 避免影响 settlementOrder 结算的结果
  98. },
  99. });
  100. }
  101. };
  102. export default CouponApi;