order.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import request from '@/sheep/request';
  2. const OrderApi = {
  3. // 计算订单信息
  4. settlementOrder: (data) => {
  5. const data2 = {
  6. ...data,
  7. };
  8. // 移除多余字段
  9. if (!(data.couponId > 0)) {
  10. delete data2.couponId;
  11. }
  12. if (!(data.addressId > 0)) {
  13. delete data2.addressId;
  14. }
  15. if (!(data.combinationActivityId) > 0) {
  16. delete data2.combinationActivityId;
  17. }
  18. if (!(data.combinationHeadId > 0)) {
  19. delete data2.combinationHeadId;
  20. }
  21. if (!(data.seckillActivityId > 0)) {
  22. delete data2.seckillActivityId;
  23. }
  24. // 解决 SpringMVC 接受 List<Item> 参数的问题
  25. delete data2.items;
  26. for (let i = 0; i < data.items.length; i++) {
  27. data2[encodeURIComponent('items[' + i + '' + '].skuId')] = data.items[i].skuId + '';
  28. data2[encodeURIComponent('items[' + i + '' + '].count')] = data.items[i].count + '';
  29. if (data.items[i].cartId) {
  30. data2[encodeURIComponent('items[' + i + '' + '].cartId')] = data.items[i].cartId + '';
  31. }
  32. }
  33. const queryString = Object.keys(data2)
  34. .map((key) => key + '=' + data2[key])
  35. .join('&');
  36. return request({
  37. url: `/trade/order/settlement?${queryString}`,
  38. method: 'GET',
  39. custom: {
  40. showError: true,
  41. showLoading: true,
  42. },
  43. });
  44. },
  45. // 创建订单
  46. createOrder: (data) => {
  47. return request({
  48. url: `/trade/order/create`,
  49. method: 'POST',
  50. data,
  51. });
  52. },
  53. // 获得订单
  54. getOrder: (id) => {
  55. return request({
  56. url: `/trade/order/get-detail`,
  57. method: 'GET',
  58. params: {
  59. id,
  60. },
  61. custom: {
  62. showLoading: false,
  63. },
  64. });
  65. },
  66. // 订单列表
  67. getOrderPage: (params) => {
  68. return request({
  69. url: '/trade/order/page',
  70. method: 'GET',
  71. params,
  72. custom: {
  73. showLoading: false,
  74. },
  75. });
  76. },
  77. // 确认收货
  78. receiveOrder: (id) => {
  79. return request({
  80. url: `/trade/order/receive`,
  81. method: 'PUT',
  82. params: {
  83. id,
  84. },
  85. });
  86. },
  87. // 取消订单
  88. cancelOrder: (id) => {
  89. return request({
  90. url: `/trade/order/cancel`,
  91. method: 'DELETE',
  92. params: {
  93. id,
  94. },
  95. });
  96. },
  97. // 删除订单
  98. deleteOrder: (id) => {
  99. return request({
  100. url: `/trade/order/delete`,
  101. method: 'DELETE',
  102. params: {
  103. id,
  104. },
  105. });
  106. },
  107. // 获得交易订单的物流轨迹
  108. getOrderExpressTrackList: (id) => {
  109. return request({
  110. url: `/trade/order/get-express-track-list`,
  111. method: 'GET',
  112. params: {
  113. id,
  114. },
  115. });
  116. },
  117. // 获得交易订单数量
  118. getOrderCount: () => {
  119. return request({
  120. url: '/trade/order/get-count',
  121. method: 'GET',
  122. custom: {
  123. showLoading: false,
  124. auth: true,
  125. },
  126. });
  127. },
  128. // 创建单个评论
  129. createOrderItemComment: (data) => {
  130. return request({
  131. url: `/trade/order/item/create-comment`,
  132. method: 'POST',
  133. data,
  134. });
  135. },
  136. };
  137. export default OrderApi;