orderDetail.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. Page({
  4. data: {
  5. orderId: 0,
  6. orderInfo: {},
  7. orderGoods: [],
  8. expressInfo: {},
  9. flag: false,
  10. handleOption: {}
  11. },
  12. onLoad: function(options) {
  13. // 页面初始化 options为页面跳转所带来的参数
  14. this.setData({
  15. orderId: options.id
  16. });
  17. this.getOrderDetail();
  18. },
  19. onPullDownRefresh() {
  20. wx.showNavigationBarLoading() //在标题栏中显示加载
  21. this.getOrderDetail();
  22. wx.hideNavigationBarLoading() //完成停止加载
  23. wx.stopPullDownRefresh() //停止下拉刷新
  24. },
  25. expandDetail: function() {
  26. let that = this;
  27. this.setData({
  28. flag: !that.data.flag
  29. })
  30. },
  31. getOrderDetail: function() {
  32. wx.showLoading({
  33. title: '加载中',
  34. });
  35. setTimeout(function() {
  36. wx.hideLoading()
  37. }, 2000);
  38. let that = this;
  39. util.request(api.OrderDetail, {
  40. orderId: that.data.orderId
  41. }).then(function(res) {
  42. if (res.errno === 0) {
  43. console.log(res.data);
  44. that.setData({
  45. orderInfo: res.data.orderInfo,
  46. orderGoods: res.data.orderGoods,
  47. handleOption: res.data.orderInfo.handleOption,
  48. expressInfo: res.data.expressInfo
  49. });
  50. }
  51. wx.hideLoading();
  52. });
  53. },
  54. // “去付款”按钮点击效果
  55. payOrder: function() {
  56. let that = this;
  57. util.request(api.OrderPrepay, {
  58. orderId: that.data.orderId
  59. }, 'POST').then(function(res) {
  60. if (res.errno === 0) {
  61. const payParam = res.data;
  62. console.log("支付过程开始");
  63. wx.requestPayment({
  64. 'timeStamp': payParam.timeStamp,
  65. 'nonceStr': payParam.nonceStr,
  66. 'package': payParam.packageValue,
  67. 'signType': payParam.signType,
  68. 'paySign': payParam.paySign,
  69. 'success': function(res) {
  70. console.log("支付过程成功");
  71. util.redirect('/pages/ucenter/order/order');
  72. },
  73. 'fail': function(res) {
  74. console.log("支付过程失败");
  75. util.showErrorToast('支付失败');
  76. },
  77. 'complete': function(res) {
  78. console.log("支付过程结束")
  79. }
  80. });
  81. }
  82. });
  83. },
  84. // “取消订单”点击效果
  85. cancelOrder: function() {
  86. let that = this;
  87. let orderInfo = that.data.orderInfo;
  88. wx.showModal({
  89. title: '',
  90. content: '确定要取消此订单?',
  91. success: function(res) {
  92. if (res.confirm) {
  93. util.request(api.OrderCancel, {
  94. orderId: orderInfo.id
  95. }, 'POST').then(function(res) {
  96. if (res.errno === 0) {
  97. wx.showToast({
  98. title: '取消订单成功'
  99. });
  100. util.redirect('/pages/ucenter/order/order');
  101. } else {
  102. util.showErrorToast(res.errmsg);
  103. }
  104. });
  105. }
  106. }
  107. });
  108. },
  109. // “取消订单并退款”点击效果
  110. refundOrder: function() {
  111. let that = this;
  112. let orderInfo = that.data.orderInfo;
  113. wx.showModal({
  114. title: '',
  115. content: '确定要取消此订单?',
  116. success: function(res) {
  117. if (res.confirm) {
  118. util.request(api.OrderRefund, {
  119. orderId: orderInfo.id
  120. }, 'POST').then(function(res) {
  121. if (res.errno === 0) {
  122. wx.showToast({
  123. title: '取消订单成功'
  124. });
  125. util.redirect('/pages/ucenter/order/order');
  126. } else {
  127. util.showErrorToast(res.errmsg);
  128. }
  129. });
  130. }
  131. }
  132. });
  133. },
  134. // “删除”点击效果
  135. deleteOrder: function() {
  136. let that = this;
  137. let orderInfo = that.data.orderInfo;
  138. wx.showModal({
  139. title: '',
  140. content: '确定要删除此订单?',
  141. success: function(res) {
  142. if (res.confirm) {
  143. util.request(api.OrderDelete, {
  144. orderId: orderInfo.id
  145. }, 'POST').then(function(res) {
  146. if (res.errno === 0) {
  147. wx.showToast({
  148. title: '删除订单成功'
  149. });
  150. util.redirect('/pages/ucenter/order/order');
  151. } else {
  152. util.showErrorToast(res.errmsg);
  153. }
  154. });
  155. }
  156. }
  157. });
  158. },
  159. // “确认收货”点击效果
  160. confirmOrder: function() {
  161. let that = this;
  162. let orderInfo = that.data.orderInfo;
  163. wx.showModal({
  164. title: '',
  165. content: '确认收货?',
  166. success: function(res) {
  167. if (res.confirm) {
  168. util.request(api.OrderConfirm, {
  169. orderId: orderInfo.id
  170. }, 'POST').then(function(res) {
  171. if (res.errno === 0) {
  172. wx.showToast({
  173. title: '确认收货成功!'
  174. });
  175. util.redirect('/pages/ucenter/order/order');
  176. } else {
  177. util.showErrorToast(res.errmsg);
  178. }
  179. });
  180. }
  181. }
  182. });
  183. },
  184. // “申请售后”点击效果
  185. aftersaleOrder: function () {
  186. if(this.data.orderInfo.aftersaleStatus === 0){
  187. util.redirect('/pages/ucenter/aftersale/aftersale?id=' + this.data.orderId );
  188. }
  189. else{
  190. util.redirect('/pages/ucenter/aftersaleDetail/aftersaleDetail?id=' + this.data.orderId);
  191. }
  192. },
  193. onReady: function() {
  194. // 页面渲染完成
  195. },
  196. onShow: function() {
  197. // 页面显示
  198. },
  199. onHide: function() {
  200. // 页面隐藏
  201. },
  202. onUnload: function() {
  203. // 页面关闭
  204. }
  205. })