orderDetail.js 5.5 KB

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