index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // index.js
  2. let myPro = require("../../../../utils/wxRequest.js");
  3. let util = require("../../../../utils/util.js");
  4. Page({
  5. data: {
  6. imgUrl: getApp().globalData.imgUrl,
  7. loading: false,
  8. orderInfo: null,
  9. timer: null, // 配送倒计时
  10. count_time: ''
  11. },
  12. onLoad: function (options) {
  13. // Do some initialize when page load.
  14. let that = this;
  15. that.setData({
  16. order_id: options.order_id
  17. });
  18. },
  19. onShow: function () {
  20. // Do something when page show.
  21. let that = this;
  22. // 获取订单信息
  23. that.getOrderDetail();
  24. },
  25. onReady: function () {
  26. // Do something when page ready.
  27. },
  28. onHide: function () {
  29. // Do something when page hide.
  30. },
  31. onUnload: function () {
  32. // Do something when page close.
  33. },
  34. onPullDownRefresh: function () {
  35. // Do something when pull down.
  36. },
  37. onReachBottom: function () {
  38. // Do something when page reach bottom.
  39. },
  40. onPageScroll: function () {
  41. // Do something when page scroll
  42. },
  43. onResize: function () {
  44. // Do something when page resize
  45. },
  46. // 获取订单信息
  47. getOrderDetail(){
  48. let that = this;
  49. let params = {
  50. order_id: that.data.order_id
  51. };
  52. myPro.wxRequest("user/v2/order/detail","GET",params).then(res=>{
  53. that.setData({
  54. orderInfo: res.result
  55. });
  56. // console.log('订单状态',that.data.orderInfo.order_status)
  57. let orderInfo = res.result;
  58. // 当前订单为外卖单且正在配送,开启倒计时
  59. if(orderInfo.fare_type == 0 && orderInfo.order_status == 1 && orderInfo.ship_status == 1){
  60. clearInterval(that.data.timer);
  61. that.data.timer = setInterval(function(){
  62. let ship_at = orderInfo.ship_at;
  63. let shijian = util.daojishi(ship_at,30);
  64. if(shijian['isend']){
  65. clearInterval(that.data.timer);
  66. }else{
  67. that.setData({
  68. count_time: shijian['timeStr']
  69. });
  70. }
  71. },1000)
  72. };
  73. }).catch(err=>{
  74. console.log('报错信息',err);
  75. wx.showToast({
  76. title: err,
  77. icon: "none"
  78. });
  79. })
  80. },
  81. // 再来一单
  82. toGoods(){
  83. let that = this;
  84. wx.reLaunch({
  85. url: '/pages/goods/index'
  86. })
  87. },
  88. // 取消订单
  89. cancleOrder(){
  90. let that = this;
  91. let store = that.data.orderInfo.store;
  92. let orderInfo = that.data.orderInfo;
  93. // 未支付的订单可以取消
  94. if(orderInfo.order_status == 1 && orderInfo.pay_status != 1){
  95. // 取消订单
  96. myPro.wxRequest("user/v2/order/cancelorder","POST",{order_id: orderInfo.id}).then(res=>{
  97. wx.showToast({
  98. title: res.msg,
  99. icon: "none"
  100. });
  101. that.getOrderDetail();
  102. }).catch(err=>{
  103. console.log('报错信息',err);
  104. wx.showToast({
  105. title: err,
  106. icon: "none"
  107. });
  108. });
  109. }else{
  110. wx.showModal({
  111. title: "可联系商家取消",
  112. content: "商家电话"+store.phone,
  113. showCancel: false,
  114. confirmText: "我知道了",
  115. confirmColor: "#000000"
  116. });
  117. }
  118. },
  119. // 收货
  120. receiveOrder(){
  121. let that = this;
  122. let params = {
  123. order_id: that.data.order_id
  124. };
  125. myPro.wxRequest("user/order/commit","POST",params).then(res=>{
  126. wx.showToast({
  127. title: res.msg,
  128. icon: "none"
  129. });
  130. that.getOrderDetail();
  131. }).catch(err=>{
  132. console.log('报错信息',err);
  133. wx.showToast({
  134. title: err,
  135. icon: "none"
  136. });
  137. });
  138. },
  139. // 去支付
  140. goTopay(){
  141. let that = this;
  142. wx.navigateTo({
  143. url: '/pages/pay-order/index?order_id='+that.data.order_id
  144. })
  145. },
  146. // 拨打店铺电话
  147. onMakePhone(){
  148. let that = this;
  149. wx.makePhoneCall({
  150. phoneNumber: that.data.orderInfo.store.phone
  151. });
  152. },
  153. });