order.js 3.7 KB

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