project-search.js 4.0 KB

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