home.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import {
  2. get,
  3. post
  4. } from '../../utils/http';
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. current: 0,
  11. currentDay: '2021-11-29',
  12. startDay: '1998-04-20',
  13. endDay: '2021-11-29',
  14. homeData: {},
  15. list: [],
  16. total: 0,
  17. page: 1
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. let date = new Date()
  24. let year = date.getFullYear()
  25. let month = date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1
  26. let day = date.getDate() < 10 ? '0'+date.getDate() : date.getDate()
  27. console.log(year,month,day)
  28. this.setData({
  29. currentDay: `${year}-${month}-${day}`,
  30. startDay: '1998-04-20',
  31. endDay: `${year}-${month}-${day}`,
  32. })
  33. this.getHomeData();
  34. this.getOrderList();
  35. },
  36. /**
  37. * 生命周期函数--监听页面初次渲染完成
  38. */
  39. onReady: function () {
  40. },
  41. /**
  42. * 生命周期函数--监听页面显示
  43. */
  44. onShow: function () {
  45. },
  46. /**
  47. * 生命周期函数--监听页面隐藏
  48. */
  49. onHide: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面卸载
  53. */
  54. onUnload: function () {
  55. },
  56. /**
  57. * 页面相关事件处理函数--监听用户下拉动作
  58. */
  59. onPullDownRefresh: function () {
  60. },
  61. /**
  62. * 页面上拉触底事件的处理函数
  63. */
  64. onReachBottom: function () {
  65. if(this.data.page * 10 < this.data.total) {
  66. this.getOrderList(++this.data.page)
  67. }
  68. },
  69. /**
  70. * 用户点击右上角分享
  71. */
  72. onShareAppMessage: function () {
  73. },
  74. /**
  75. * 切换状态
  76. */
  77. onTabsChange(e) {
  78. let current = e.currentTarget.dataset.id
  79. if(current == this.data.current) {
  80. return;
  81. }
  82. this.setData({
  83. current,
  84. page: 1,
  85. },() => {
  86. this.getOrderList(1)
  87. })
  88. },
  89. /**
  90. * 选择时间
  91. */
  92. bindDateChange: function(e) {
  93. console.log('picker发送选择改变,携带值为', e.detail.value)
  94. this.setData({
  95. [e.currentTarget.dataset.date]: e.detail.value,
  96. })
  97. },
  98. /**
  99. * 订单搜索
  100. */
  101. onSearchOrder() {
  102. this.getOrderList();
  103. },
  104. /**
  105. * 获取首页统计数据
  106. */
  107. getHomeData() {
  108. get('api/home',{},(res) => {
  109. this.setData({
  110. homeData: res.data
  111. })
  112. })
  113. },
  114. /**
  115. * 首页订单列表
  116. */
  117. getOrderList(_page) {
  118. let { list,current,page,startDay,endDay } = this.data;
  119. get('api/order/list',{
  120. start_day: startDay,
  121. end_day: endDay,
  122. type: current,
  123. page: _page || page,
  124. limit: 10
  125. },(res) => {
  126. if (_page == 1 || page == 1) {
  127. list = []
  128. this.data.page = 1
  129. }
  130. list.push(...res.data.list)
  131. this.setData({
  132. list,
  133. total: res.data.total,
  134. spinning: false
  135. })
  136. console.log(res)
  137. })
  138. }
  139. })