home.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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: `${year}-${month}-${day}`,
  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. let startDay,endDay,currentDay
  86. if(current == this.data.current) {
  87. return;
  88. }
  89. if(current == 0) {
  90. startDay = this.formData(0)
  91. endDay = this.formData(0)
  92. currentDay = this.formData(0)
  93. } else if(current == 1) {
  94. startDay = this.formData(0)
  95. endDay = this.formData(7)
  96. currentDay = this.formData(0)
  97. } else {
  98. startDay = this.formData(-7)
  99. currentDay = this.formData(-7)
  100. endDay = this.formData(0)
  101. }
  102. this.setData({
  103. current,
  104. page: 1,
  105. startDay,endDay,currentDay
  106. },() => {
  107. this.getOrderList(1)
  108. })
  109. },
  110. /**
  111. * 选择时间
  112. */
  113. bindDateChange: function(e) {
  114. console.log('picker发送选择改变,携带值为', e.detail.value)
  115. this.setData({
  116. [e.currentTarget.dataset.date]: e.detail.value,
  117. })
  118. },
  119. /**
  120. * 订单搜索
  121. */
  122. onSearchOrder() {
  123. this.getOrderList();
  124. },
  125. /**
  126. * 获取首页统计数据
  127. */
  128. getHomeData() {
  129. get('api/home',{},(res) => {
  130. this.setData({
  131. homeData: res.data
  132. })
  133. })
  134. },
  135. /**
  136. * 首页订单列表
  137. */
  138. getOrderList(_page) {
  139. let { list,current,page,startDay,endDay } = this.data;
  140. get('api/order/list',{
  141. start_day: startDay,
  142. end_day: endDay,
  143. type: current,
  144. page: _page || page,
  145. limit: 10
  146. },(res) => {
  147. if (_page == 1 || page == 1) {
  148. list = []
  149. this.data.page = 1
  150. }
  151. list.push(...res.data.list)
  152. this.setData({
  153. list,
  154. total: res.data.total,
  155. spinning: false
  156. })
  157. console.log(res)
  158. })
  159. },
  160. /**'
  161. * 格式化时间
  162. */
  163. formData(_day) {
  164. let date = new Date()
  165. date=date.setDate(date.getDate()+_day);
  166. date=new Date(date);
  167. let year = date.getFullYear()
  168. let month = date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1
  169. let day = date.getDate() < 10 ? '0'+date.getDate() : date.getDate()
  170. console.log(year,month,day)
  171. return `${year}-${month}-${day}`;
  172. },
  173. /**
  174. * 跳转客户信息
  175. */
  176. goToClientInfo(e) {
  177. wx.navigateTo({
  178. url: `/pages/clientInfo/clientInfo?userId=${e.currentTarget.dataset.id}`,
  179. })
  180. },
  181. /**
  182. * 跳转客户信息
  183. */
  184. goToFeedback(e) {
  185. let item = e.currentTarget.dataset.item
  186. wx.navigateTo({
  187. url: `/pages/feedback/feedback?orderId=${ item.order_id }&cover=${ item.cover_url }&name=${ item.project_name }`,
  188. })
  189. }
  190. })