projects.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. var _request = require('../../utils/request.js')
  2. Page({
  3. data: {
  4. projects_page: 1,
  5. projects_per_page: 5,
  6. projects_more: true,
  7. projects_change: false,
  8. projects: [],
  9. vershow: true,
  10. navData:[],
  11. currentTab: 0,
  12. navScrollLeft: 0,
  13. balance: 0,
  14. todaysend: Date.parse(new Date()) / 1000
  15. },
  16. onLoad: function () {
  17. this.getBalanceInfo()
  18. this.setData({
  19. vershow: getApp().globalData.vershow,
  20. currentTab: 0
  21. // currentTab: getApp().globalData.isshow
  22. })
  23. if (getApp().globalData.isupdate == true) {
  24. this.getType()
  25. }
  26. wx.getSystemInfo({
  27. success: (res) => {
  28. this.setData({
  29. windowWidth: res.windowWidth
  30. })
  31. }
  32. })
  33. },
  34. onShow: function () {
  35. if (getApp().globalData.isshow) {
  36. this.setData({
  37. currentTab: getApp().globalData.isshow,
  38. projects_more: true,
  39. projects_page: 1,
  40. projects_change: true,
  41. })
  42. this.getType()
  43. }
  44. },
  45. onUnload: function () {
  46. getApp().globalData.isshow = ''
  47. // this.setData({
  48. // currentTab: 0,
  49. // })
  50. },
  51. onHide: function () {
  52. getApp().globalData.isshow = ''
  53. // this.setData({
  54. // currentTab: 0,
  55. // })
  56. },
  57. onPullDownRefresh: function () {
  58. this.setData({
  59. projects_more: true,
  60. projects_page: 1,
  61. projects_change: true
  62. })
  63. this.getProjects()
  64. wx.stopPullDownRefresh()
  65. },
  66. onReachBottom: function () {
  67. if (this.data.projects_more) {
  68. var page = this.data.projects_page + 1
  69. this.setData({
  70. projects_page: page
  71. })
  72. this.getProjects()
  73. }
  74. },
  75. getType: function () {
  76. var that = this
  77. var url = 'v1/product/cats'
  78. var params = {}
  79. var success = function (res) {
  80. that.setData({
  81. navData: res.data
  82. })
  83. that.getProjects()
  84. }
  85. _request.$get(url, params, success)
  86. },
  87. getProjects: function () {
  88. var id = this.data.navData[this.data.currentTab].id
  89. if (!this.data.vershow) {
  90. id = 3
  91. }
  92. var that = this
  93. var url = 'v1/cat/' + id + '/products'
  94. var params = {
  95. page: this.data.projects_page,
  96. per_page: this.data.projects_per_page
  97. }
  98. var success = function (res) {
  99. if (that.data.projects_change) {
  100. that.setData({
  101. projects: [],
  102. projects_change: false
  103. })
  104. }
  105. var result = that.data.projects.concat(res.data.list || [])
  106. that.setData({
  107. projects: result
  108. })
  109. var listMore = res.data.list_count > that.data.projects.length
  110. that.setData({
  111. projects_more: listMore
  112. })
  113. }
  114. _request.$get(url, params, success)
  115. },
  116. toProject: function (val) {
  117. var id = val.currentTarget.dataset.val
  118. wx.navigateTo({
  119. url: '/pages/projects/project-detail/project-detail?id=' + id
  120. })
  121. },
  122. switchNav(event){
  123. var cur = event.currentTarget.dataset.current
  124. var singleNavWidth = this.data.windowWidth / 5
  125. this.setData({
  126. navScrollLeft: (cur - 2) * singleNavWidth
  127. })
  128. if (this.data.currentTab == cur) {
  129. return false
  130. } else {
  131. this.setData({
  132. currentTab: cur,
  133. projects_more: true,
  134. projects_page: 1,
  135. projects_change: true
  136. })
  137. this.getProjects()
  138. }
  139. },
  140. getBalanceInfo () {
  141. var that = this
  142. var url = 'v1/user/balance/info'
  143. var params = {
  144. }
  145. var success = function (res) {
  146. var result = res.data.total
  147. that.setData({
  148. balance: result
  149. })
  150. }
  151. _request.$get(url, params, success)
  152. },
  153. onShareAppMessage: function (val) {
  154. return _request.share({
  155. // path: '/pages/start/start?url=pages/projects/projects',
  156. sc: 'xcx_products'
  157. })
  158. }
  159. })