index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. var app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. parameter: {
  8. 'navbar': '1',
  9. 'return': '1',
  10. 'title': '订单详情',
  11. 'color': true,
  12. 'class': '0'
  13. // 'class': '2' 顶部为灰色
  14. },
  15. order_id:'',
  16. evaluate:0,
  17. cartInfo:[],//购物车产品
  18. orderInfo:{},//订单详情
  19. isGoodsReturn:false,//是否为退款订单
  20. status:{},//订单底部按钮状态
  21. isClose:false,
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. if (options.order_id) this.setData({ order_id: options.order_id});
  28. if (options.isReturen){
  29. this.setData({ 'parameter.class': '2', isGoodsReturn:true });
  30. this.selectComponent('#navbar').setClass();
  31. }
  32. },
  33. /**
  34. * 登录授权回调
  35. *
  36. */
  37. onLoadFun:function(){
  38. this.getOrderInfo();
  39. },
  40. /**
  41. * 获取订单详细信息
  42. *
  43. */
  44. getOrderInfo:function(){
  45. var that=this;
  46. wx.showLoading({ title: "正在加载中" });
  47. app.baseGet(app.U({ c: 'user_api', a:'get_order',q:{uni:this.data.order_id}}),function(res){
  48. var _type=res.data._status._type;
  49. wx.hideLoading();
  50. that.setData({ orderInfo: res.data, cartInfo: res.data.cartInfo, evaluate: _type==3 ? 3: 0});
  51. that.getOrderStatus();
  52. },function(res){
  53. wx.hideLoading();
  54. app.Tips({title:res.msg},'/pages/order_list/index');
  55. },true)
  56. },
  57. /**
  58. *
  59. * 剪切订单号
  60. */
  61. copy:function(){
  62. var that=this;
  63. wx.setClipboardData({data: this.data.orderInfo.order_id});
  64. },
  65. /**
  66. * 打电话
  67. */
  68. goTel:function(){
  69. wx.makePhoneCall({
  70. phoneNumber: this.data.orderInfo.delivery_id
  71. })
  72. },
  73. /**
  74. * 设置底部按钮
  75. *
  76. */
  77. getOrderStatus:function(){
  78. var orderInfo = this.data.orderInfo || {}, _status = orderInfo._status || { _type:0},status={};
  79. var type = parseInt(_status._type), combination_id = orderInfo.combination_id || 0, delivery_type = orderInfo.delivery_type,
  80. seckill_id = orderInfo.seckill_id ? parseInt(orderInfo.seckill_id) : 0,
  81. bargain_id=orderInfo.bargain_id ? parseInt(orderInfo.bargain_id) : 0,
  82. combination_id = orderInfo.combination_id ? parseInt(orderInfo.combination_id) : 0;
  83. status={
  84. type: type,
  85. class_status:0
  86. };
  87. if (type == 1 && combination_id >0) status.class_status = 1;//查看拼团
  88. if (type == 2 && delivery_type == 'express') status.class_status = 2;//查看物流
  89. if (type == 2) status.class_status = 3;//确认收货
  90. if (type == 4 || type == 0) status.class_status = 4;//删除订单
  91. if (!seckill_id && !bargain_id && !combination_id && (type == 3 || type == 4)) status.class_status = 5;//再次购买
  92. this.setData({ status: status});
  93. },
  94. /**
  95. * 去拼团详情
  96. *
  97. */
  98. goJoinPink:function(){
  99. wx.navigateTo({
  100. url: '/pages/activity/goods_combination_status/index?id=' + this.data.orderInfo.pink_id,
  101. });
  102. },
  103. /**
  104. * 立即付款
  105. *
  106. */
  107. checkPay:function(){
  108. var that=this;
  109. wx.showActionSheet({
  110. itemList: ['微信支付', '余额支付'],
  111. success(res) {
  112. var paytype = res.tapIndex ? 'yue' :'weixin';
  113. wx.showLoading({ title: '支付中' });
  114. app.baseGet(app.U({ c: 'auth_api', a: 'pay_order', q: { uni: that.data.orderInfo.order_id, paytype: paytype}}),function(res){
  115. if (paytype == 'weixin' && res.data.result){
  116. var jsConfig = res.data.result.jsConfig;
  117. wx.requestPayment({
  118. timeStamp: jsConfig.timestamp,
  119. nonceStr: jsConfig.nonceStr,
  120. package: jsConfig.package,
  121. signType: jsConfig.signType,
  122. paySign: jsConfig.paySign,
  123. success: function (res) {
  124. wx.hideLoading();
  125. return app.Tips({ title: '支付成功', icon:'success'},function(){
  126. that.getOrderInfo();
  127. });
  128. },
  129. fail: function (e) {
  130. wx.hideLoading();
  131. return app.Tips({ title: '取消支付' });
  132. },
  133. complete: function (e) {
  134. wx.hideLoading();
  135. if (res.errMsg == 'requestPayment:cancel') return app.Tips({ title: '取消支付' });
  136. },
  137. });
  138. } else if (paytype =='yue'){
  139. wx.hideLoading();
  140. return app.Tips({title:res.msg,icon:'success'},function(){
  141. that.getOrderInfo();
  142. });
  143. }
  144. });
  145. }
  146. })
  147. },
  148. /**
  149. * 再此购买
  150. *
  151. */
  152. goOrderConfirm:function(){
  153. var that=this;
  154. app.baseGet(app.U({ c: 'auth_api', a:'again_order',q:{uni:that.data.orderInfo.order_id}}),function(res){
  155. return wx.navigateTo({ url:'/pages/order_confirm/index?cartId='+res.data});
  156. });
  157. },
  158. confirmOrder:function(){
  159. var that=this;
  160. wx.showModal({
  161. title: '确认收货',
  162. content: '为保障权益,请收到货确认无误后,再确认收货',
  163. success: function (res) {
  164. if (res.confirm) {
  165. app.baseGet(app.U({ c: 'user_api', a:'user_take_order',q:{uni:that.data.order_id}}),function(res){
  166. return app.Tips({title:'操作成功',icon:'success'},function(){
  167. that.getOrderInfo();
  168. });
  169. });
  170. }
  171. }
  172. })
  173. },
  174. /**
  175. *
  176. * 删除订单
  177. */
  178. delOrder:function(){
  179. var that=this;
  180. app.baseGet(app.U({ c: 'user_api', a:'user_remove_order',q:{uni:this.data.order_id}}),function(res){
  181. return app.Tips({title:'删除成功',icon:'success'},{tab:3,url:1});
  182. });
  183. },
  184. /**
  185. * 生命周期函数--监听页面显示
  186. */
  187. onShow: function () {
  188. if (app.globalData.isLog && this.data.isClose) {
  189. this.getOrderInfo();
  190. }
  191. },
  192. /**
  193. * 生命周期函数--监听页面隐藏
  194. */
  195. onHide: function () {
  196. this.setData({ isClose: true });
  197. },
  198. })