detail.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. const App = getApp();
  2. // 枚举类:发货方式
  3. import DeliveryTypeEnum from '../../utils/enum/DeliveryType.js';
  4. // 枚举类:支付方式
  5. import PayTypeEnum from '../../utils/enum/order/PayType'
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. // 配送方式
  12. DeliveryTypeEnum,
  13. // 支付方式
  14. PayTypeEnum,
  15. order_id: null,
  16. order: {},
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad(options) {
  22. let _this = this;
  23. _this.data.order_id = options.order_id;
  24. // 获取订单详情
  25. _this.getOrderDetail(options.order_id);
  26. },
  27. /**
  28. * 获取订单详情
  29. */
  30. getOrderDetail(order_id) {
  31. let _this = this;
  32. App._get('user.order/detail', {
  33. order_id
  34. }, result => {
  35. _this.setData(result.data);
  36. });
  37. },
  38. /**
  39. * 跳转到商品详情
  40. */
  41. onTargetGoods(e) {
  42. let goods_id = e.currentTarget.dataset.id;
  43. wx.navigateTo({
  44. url: '../goods/index?goods_id=' + goods_id
  45. });
  46. },
  47. /**
  48. * 取消订单
  49. */
  50. cancelOrder(e) {
  51. let _this = this;
  52. let order_id = _this.data.order_id;
  53. wx.showModal({
  54. title: "提示",
  55. content: "确认取消订单?",
  56. success(o) {
  57. if (o.confirm) {
  58. App._post_form('user.order/cancel', {
  59. order_id
  60. }, result => {
  61. wx.navigateBack();
  62. });
  63. }
  64. }
  65. });
  66. },
  67. /**
  68. * 确认收货
  69. */
  70. receipt(e) {
  71. let _this = this;
  72. let order_id = _this.data.order_id;
  73. wx.showModal({
  74. title: "提示",
  75. content: "确认收到商品?",
  76. success(o) {
  77. if (o.confirm) {
  78. App._post_form('user.order/receipt', {
  79. order_id
  80. }, result => {
  81. _this.getOrderDetail(order_id);
  82. });
  83. }
  84. }
  85. });
  86. },
  87. /**
  88. * 申请售后
  89. */
  90. onApplyRefund(e) {
  91. wx.navigateTo({
  92. url: './refund/apply/apply?order_goods_id=' + e.currentTarget.dataset.id,
  93. })
  94. },
  95. /**
  96. * 跳转到门店详情
  97. */
  98. onTargetShop(e) {
  99. wx.navigateTo({
  100. url: '../shop/detail/index?shop_id=' + e.currentTarget.dataset.id,
  101. })
  102. },
  103. /**
  104. * 点击付款按钮
  105. */
  106. onPayOrder(e) {
  107. let _this = this;
  108. // 显示支付方式弹窗
  109. _this.onTogglePayPopup();
  110. },
  111. /**
  112. * 选择支付方式
  113. */
  114. onSelectPayType(e) {
  115. let _this = this;
  116. // 隐藏支付方式弹窗
  117. _this.onTogglePayPopup();
  118. if (!_this.data.showPayPopup) {
  119. // 发起付款请求
  120. _this.payment(e.currentTarget.dataset.value);
  121. }
  122. },
  123. /**
  124. * 显示/隐藏支付方式弹窗
  125. */
  126. onTogglePayPopup() {
  127. this.setData({
  128. showPayPopup: !this.data.showPayPopup
  129. });
  130. },
  131. /**
  132. * 发起付款请求
  133. */
  134. payment(payType) {
  135. let _this = this,
  136. orderId = _this.data.order_id;
  137. // 显示loading
  138. wx.showLoading({
  139. title: '正在处理...',
  140. });
  141. App._post_form('user.order/pay', {
  142. order_id: orderId,
  143. payType
  144. }, result => {
  145. if (result.code === -10) {
  146. App.showError(result.msg);
  147. return false;
  148. }
  149. // 发起微信支付
  150. if (result.data.pay_type == PayTypeEnum.WECHAT.value) {
  151. App.wxPayment({
  152. payment: result.data.payment,
  153. success() {
  154. _this.getOrderDetail(orderId);
  155. },
  156. fail() {
  157. App.showError(result.msg.error);
  158. },
  159. });
  160. }
  161. // 余额支付
  162. if (result.data.pay_type == PayTypeEnum.BALANCE.value) {
  163. App.showSuccess(result.msg.success, () => {
  164. _this.getOrderDetail(orderId);
  165. });
  166. }
  167. }, null, () => {
  168. wx.hideLoading();
  169. });
  170. },
  171. });