home.js 2.9 KB

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