orderTabs.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // pages/order_tabs/orderTabs.js
  2. const getReq = require('./../../config.js').getReq;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. hasmore:false,
  9. orders:[],
  10. addTimes:[],
  11. curpage:1
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. this.req_datas();
  18. },
  19. req_datas(){
  20. wx.showLoading({
  21. title: '加载中',
  22. });
  23. let self = this;
  24. getReq({
  25. act: 'member_order',
  26. op: 'list',
  27. page: 15,
  28. curpage: this.data.curpage
  29. }, function (res) {
  30. let orders = res.datas.orders;
  31. let addTimes = [];
  32. let hasmore = false;
  33. let curpage = self.data.curpage
  34. for (let item of orders) {
  35. addTimes.push(self.timeFormat(item.order_info.add_time));
  36. }
  37. if (res.datas.mobile_page.hasmore) {
  38. hasmore = true;
  39. curpage = self.data.curpage + 1;
  40. }
  41. else {
  42. hasmore = false;
  43. }
  44. self.setData({
  45. hasmore,
  46. curpage,
  47. orders: self.data.orders.concat(orders),
  48. addTimes: self.data.addTimes.concat(addTimes)
  49. });
  50. wx.hideLoading();
  51. })
  52. },
  53. /**
  54. * 生命周期函数--监听页面初次渲染完成
  55. */
  56. onReady: function () {
  57. },
  58. /**
  59. * 生命周期函数--监听页面显示
  60. */
  61. onShow: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面隐藏
  65. */
  66. onHide: function () {
  67. },
  68. /**
  69. * 生命周期函数--监听页面卸载
  70. */
  71. onUnload: function () {
  72. },
  73. /**
  74. * 页面相关事件处理函数--监听用户下拉动作
  75. */
  76. onPullDownRefresh: function () {
  77. },
  78. /**
  79. * 页面上拉触底事件的处理函数
  80. */
  81. onReachBottom: function () {
  82. this.req_datas();
  83. },
  84. /**
  85. * 用户点击右上角分享
  86. */
  87. onShareAppMessage: function () {
  88. },
  89. timeFormat(time){
  90. let date = new Date(time*1000);
  91. let year = date.getFullYear();
  92. let month = date.getMonth()+1;
  93. let day = date.getDate();
  94. return `${year}-${month}-${day}`;
  95. }
  96. })