projects.js 4.6 KB

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