projects.js 3.9 KB

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