orderDetail.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. handleOption: {}
  9. },
  10. onLoad: function (options) {
  11. getApp().checkNetStatu();
  12. // 页面初始化 options为页面跳转所带来的参数
  13. this.setData({
  14. orderId: options.id
  15. });
  16. },
  17. gotoLogti: function(e){
  18. let {no,id} = e.currentTarget.dataset
  19. wx.navigateTo({
  20. url: '/pages/logistics/index?no=' + no + '&id=' + id
  21. })
  22. },
  23. gotoGoods(e) {
  24. let {id} = e.currentTarget.dataset
  25. wx.navigateTo({
  26. url: '/pages/goods/goods?id=' + id
  27. })
  28. },
  29. gotoBrand:function(e){
  30. // let {id} = e.currentTarget.dataset
  31. // wx.navigateTo({
  32. // url: '/pages/brandDetail/brandDetail?id=' + id
  33. // })
  34. },
  35. getOrderDetail() {
  36. let that = this;
  37. util.request(api.OrderDetail, {
  38. orderId: that.data.orderId
  39. }).then(function (res) {
  40. if (res.errno === 0) {
  41. that.setData({
  42. orderInfo: res.data.orderInfo,
  43. orderGoods: res.data.orderGoods,
  44. handleOption: res.data.handleOption
  45. });
  46. //that.payTimer();
  47. }
  48. });
  49. },
  50. payTimer() {
  51. let that = this;
  52. let orderInfo = that.data.orderInfo;
  53. setInterval(() => {
  54. orderInfo.add_time -= 1;
  55. that.setData({
  56. orderInfo: orderInfo,
  57. });
  58. }, 1000);
  59. },
  60. cancelOrder(){
  61. let that = this;
  62. let orderInfo = that.data.orderInfo;
  63. var order_status = orderInfo.order_status;
  64. var errorMessage = '';
  65. switch (order_status){
  66. case 300: {
  67. errorMessage = '订单已发货';
  68. break;
  69. }
  70. case 301:{
  71. errorMessage = '订单已收货';
  72. break;
  73. }
  74. case 101:{
  75. errorMessage = '订单已取消';
  76. break;
  77. }
  78. case 102: {
  79. errorMessage = '订单已删除';
  80. break;
  81. }
  82. case 401: {
  83. errorMessage = '订单已退款';
  84. break;
  85. }
  86. case 402: {
  87. errorMessage = '订单已退货';
  88. break;
  89. }
  90. }
  91. if (errorMessage != '') {
  92. util.showErrorToast(errorMessage);
  93. return false;
  94. }
  95. wx.showModal({
  96. title: '',
  97. content: '确定要取消此订单?',
  98. success: function (res) {
  99. if (res.confirm) {
  100. util.request(api.OrderCancel,{
  101. orderId: orderInfo.id
  102. }).then(function (res) {
  103. if (res.errno === 0) {
  104. wx.showModal({
  105. title:'提示',
  106. content: res.errmsg,
  107. showCancel:false,
  108. confirmText:'确定',
  109. success: function (res) {
  110. // util.redirect('/pages/ucenter/order/order');
  111. wx.navigateBack({
  112. url: 'pages/ucenter/order/order?id=-1',
  113. });
  114. }
  115. });
  116. }
  117. });
  118. }
  119. }
  120. });
  121. },
  122. payOrder() {
  123. let that = this;
  124. util.request(api.PayPrepayId, {
  125. orderId: that.data.orderId || 15
  126. }).then(function (res) {
  127. if (res.errno === 0) {
  128. const payParam = res.data;
  129. wx.requestPayment({
  130. 'timeStamp': payParam.timeStamp,
  131. 'nonceStr': payParam.nonceStr,
  132. 'package': payParam.package,
  133. 'signType': payParam.signType,
  134. 'paySign': payParam.paySign,
  135. 'success': function (res) {
  136. console.log(res);
  137. },
  138. 'fail': function (res) {
  139. console.log(res);
  140. }
  141. });
  142. }
  143. });
  144. },
  145. confirmOrder() {
  146. //确认收货
  147. let that = this;
  148. let orderInfo = that.data.orderInfo;
  149. var order_status = orderInfo.order_status;
  150. var errorMessage = '';
  151. switch (order_status) {
  152. // case 300: {
  153. // errorMessage = '订单已发货';
  154. // break;
  155. // }
  156. case 301: {
  157. errorMessage = '订单已收货';
  158. break;
  159. }
  160. case 101: {
  161. errorMessage = '订单已取消';
  162. break;
  163. }
  164. case 102: {
  165. errorMessage = '订单已删除';
  166. break;
  167. }
  168. case 401: {
  169. errorMessage = '订单已退款';
  170. break;
  171. }
  172. case 402: {
  173. errorMessage = '订单已退货';
  174. break;
  175. }
  176. }
  177. if (errorMessage != '') {
  178. util.showErrorToast(errorMessage);
  179. return false;
  180. }
  181. wx.showModal({
  182. title: '',
  183. content: '确定已经收到商品?',
  184. success: function (res) {
  185. if (res.confirm) {
  186. util.request(api.OrderConfirm, {
  187. orderId: orderInfo.id
  188. }).then(function (res) {
  189. if (res.errno === 0) {
  190. wx.showModal({
  191. title: '提示',
  192. content: res.data,
  193. showCancel: false,
  194. confirmText: '确定',
  195. success: function (res) {
  196. // util.redirect('/pages/ucenter/order/order');
  197. wx.navigateBack({
  198. url: 'pages/ucenter/order/order?id=-1',
  199. });
  200. }
  201. });
  202. }
  203. });
  204. }
  205. }
  206. });
  207. },
  208. onReady: function () {
  209. // 页面渲染完成
  210. },
  211. onShow: function () {
  212. this.getOrderDetail();
  213. // 页面显示
  214. },
  215. onHide: function () {
  216. // 页面隐藏
  217. },
  218. onUnload: function () {
  219. // 页面关闭
  220. }
  221. })