orderList.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. var http = require('../../utils/http.js');
  2. var config = require('../../utils/config.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. list: [],
  9. current: 1,
  10. pages: 0,
  11. sts: 0
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function(options) {
  17. if (options.sts) {
  18. this.setData({
  19. sts: options.sts
  20. });
  21. this.loadOrderData(options.sts, 1);
  22. } else {
  23. this.loadOrderData(0, 1);
  24. }
  25. },
  26. /**
  27. * 加载订单数据
  28. */
  29. loadOrderData: function(sts, current) {
  30. var ths = this;
  31. wx.showLoading();
  32. //加载订单列表
  33. var params = {
  34. url: "/p/myOrder/myOrder",
  35. method: "GET",
  36. data: {
  37. current: current,
  38. size: 10,
  39. status: sts,
  40. },
  41. callBack: function(res) {
  42. //console.log(res);
  43. var list = [];
  44. if (res.current == 1) {
  45. list = res.records;
  46. } else {
  47. list = ths.data.list;
  48. Array.prototype.push.apply(list, res.records);
  49. }
  50. ths.setData({
  51. list: list,
  52. pages: res.pages,
  53. current: res.current
  54. });
  55. wx.hideLoading();
  56. }
  57. };
  58. http.request(params);
  59. },
  60. /**
  61. * 状态点击事件
  62. */
  63. onStsTap: function(e) {
  64. var sts = e.currentTarget.dataset.sts;
  65. this.setData({
  66. sts: sts
  67. });
  68. this.loadOrderData(sts, 1);
  69. },
  70. /**
  71. * 生命周期函数--监听页面初次渲染完成
  72. */
  73. onReady: function() {
  74. },
  75. /**
  76. * 生命周期函数--监听页面显示
  77. */
  78. onShow: function() {
  79. },
  80. /**
  81. * 生命周期函数--监听页面隐藏
  82. */
  83. onHide: function() {
  84. },
  85. /**
  86. * 生命周期函数--监听页面卸载
  87. */
  88. onUnload: function() {
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh: function() {
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. */
  98. onReachBottom: function() {
  99. if (this.data.current < this.data.pages) {
  100. this.loadOrderData(this.data.sts, this.data.current + 1);
  101. }
  102. },
  103. /**
  104. * 用户点击右上角分享
  105. */
  106. onShareAppMessage: function() {
  107. },
  108. /**
  109. * 查看物流
  110. */
  111. toDeliveryPage: function(e) {
  112. wx.navigateTo({
  113. url: '/pages/express-delivery/express-delivery?orderNum=' + e.currentTarget.dataset.ordernum
  114. })
  115. },
  116. /**
  117. * 取消订单
  118. */
  119. onCancelOrder: function(e) {
  120. var ordernum = e.currentTarget.dataset.ordernum;
  121. var ths = this;
  122. wx.showModal({
  123. title: '',
  124. content: '要取消此订单?',
  125. confirmColor: "#3e62ad",
  126. cancelColor: "#3e62ad",
  127. cancelText: '否',
  128. confirmText: '是',
  129. success(res) {
  130. if (res.confirm) {
  131. wx.showLoading({
  132. mask: true
  133. });
  134. var params = {
  135. url: "/p/myOrder/cancel/" + ordernum,
  136. method: "PUT",
  137. data: {},
  138. callBack: function(res) {
  139. //console.log(res);
  140. ths.loadOrderData(ths.data.sts, 1);
  141. wx.hideLoading();
  142. }
  143. };
  144. http.request(params);
  145. } else if (res.cancel) {
  146. //console.log('用户点击取消')
  147. }
  148. }
  149. })
  150. },
  151. /**
  152. * 付款
  153. */
  154. onPayAgain: function(e) {
  155. wx.showLoading({
  156. mask: true
  157. });
  158. var params = {
  159. url: "/p/order/pay",
  160. method: "POST",
  161. data: {
  162. payType: 1,
  163. orderNumbers: e.currentTarget.dataset.ordernum
  164. },
  165. callBack: res => {
  166. //console.log(res);
  167. wx.hideLoading();
  168. wx.requestPayment({
  169. timeStamp: res.timeStamp,
  170. nonceStr: res.nonceStr,
  171. package: res.packageValue,
  172. signType: res.signType,
  173. paySign: res.paySign,
  174. success: function() {
  175. wx.navigateTo({
  176. url: '/pages/pay-result/pay-result?sts=1&orderNumbers=' + e.currentTarget.dataset.ordernum,
  177. })
  178. },
  179. fail: function(err) {
  180. //console.log("支付失败");
  181. }
  182. })
  183. }
  184. };
  185. http.request(params);
  186. },
  187. /**
  188. * 查看订单详情
  189. */
  190. toOrderDetailPage: function(e) {
  191. wx.navigateTo({
  192. url: '/pages/order-detail/order-detail?orderNum=' + e.currentTarget.dataset.ordernum,
  193. })
  194. },
  195. /**
  196. * 确认收货
  197. */
  198. onConfirmReceive: function(e) {
  199. var ths = this;
  200. wx.showModal({
  201. title: '',
  202. content: '我已收到货?',
  203. confirmColor: "#eb2444",
  204. success(res) {
  205. if (res.confirm) {
  206. wx.showLoading({
  207. mask: true
  208. });
  209. var params = {
  210. url: "/p/myOrder/receipt/" + e.currentTarget.dataset.ordernum,
  211. method: "PUT",
  212. data: {},
  213. callBack: function(res) {
  214. //console.log(res);
  215. ths.loadOrderData(ths.data.sts, 1);
  216. wx.hideLoading();
  217. }
  218. };
  219. http.request(params);
  220. } else if (res.cancel) {
  221. //console.log('用户点击取消')
  222. }
  223. }
  224. })
  225. },
  226. //删除已完成||已取消的订单
  227. delOrderList: function(e) {
  228. var ths = this
  229. wx.showModal({
  230. title: '',
  231. content: '确定要删除此订单吗?',
  232. confirmColor: "#eb2444",
  233. success(res) {
  234. if (res.confirm) {
  235. var ordernum = e.currentTarget.dataset.ordernum;
  236. wx.showLoading();
  237. var params = {
  238. url: "/p/myOrder/" + ordernum,
  239. method: "DELETE",
  240. data: {},
  241. callBack: function(res) {
  242. ths.loadOrderData(ths.data.sts, 1);
  243. wx.hideLoading();
  244. }
  245. }
  246. http.request(params);
  247. } else if (res.cancel) {
  248. console.log('用户点击取消')
  249. }
  250. }
  251. })
  252. }
  253. })