projects.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. price_sort:0,
  21. sale_sort:0,
  22. selectShow: false,//控制下拉列表的显示隐藏,false隐藏、true显示
  23. selectData: [],//下拉列表的数据
  24. index: 0,//选择的下拉列表下标
  25. },
  26. onLoad: function (options) {
  27. const info = wx.getSystemInfoSync();
  28. console.log('info',info);
  29. this.setData({
  30. statusBarHeight:info.statusBarHeight
  31. })
  32. this.getData()
  33. this.getBalanceInfo()
  34. this.setData({
  35. vershow: getApp().globalData.vershow,
  36. currentTab:options.currentTab ? options.currentTab : 0,
  37. searchword:options.searchword ? options.searchword : ''
  38. // currentTab: getApp().globalData.isshow
  39. })
  40. if (getApp().globalData.isupdate == true) {
  41. this.getType()
  42. }
  43. wx.getSystemInfo({
  44. success: (res) => {
  45. this.setData({
  46. windowWidth: res.windowWidth
  47. })
  48. }
  49. })
  50. },
  51. onShow: function () {
  52. if (getApp().globalData.isshow) {
  53. this.setData({
  54. currentTab: getApp().globalData.isshow,
  55. projects_more: true,
  56. projects_page: 1,
  57. projects_change: true,
  58. })
  59. this.getType()
  60. }
  61. },
  62. onUnload: function () {
  63. getApp().globalData.isshow = ''
  64. // this.setData({
  65. // currentTab: 0,
  66. // })
  67. },
  68. onHide: function () {
  69. getApp().globalData.isshow = ''
  70. // this.setData({
  71. // currentTab: 0,
  72. // })
  73. },
  74. onPullDownRefresh: function () {
  75. this.setData({
  76. projects_more: true,
  77. projects_page: 1,
  78. projects_change: true
  79. })
  80. this.getProjects()
  81. wx.stopPullDownRefresh()
  82. },
  83. onReachBottom: function () {
  84. if (this.data.projects_more) {
  85. var page = this.data.projects_page + 1
  86. this.setData({
  87. projects_page: page
  88. })
  89. this.getProjects()
  90. }
  91. },
  92. getData: function () {
  93. var that = this
  94. var url = 'v1/product/commend_words'
  95. var params = {}
  96. var success = function (res) {
  97. console.log('res',res.data.list);
  98. that.setData({
  99. word:res.data.list[0].title
  100. })
  101. }
  102. _request.$get(url, params, success)
  103. },
  104. getType: function () {
  105. var that = this
  106. var url = 'v1/product/cats'
  107. var params = {}
  108. var success = function (res) {
  109. that.setData({
  110. navData: res.data
  111. })
  112. that.getProjects()
  113. }
  114. _request.$get(url, params, success)
  115. },
  116. getProjects: function () {
  117. var id = this.data.navData[this.data.currentTab].id
  118. if (!this.data.vershow) {
  119. id = 3
  120. }
  121. var that = this
  122. var url = 'v1/cat/' + id + '/products'
  123. if(that.data.searchword){
  124. var params = {
  125. page: this.data.projects_page,
  126. per_page: this.data.projects_per_page,
  127. words:this.data.searchword,
  128. price_sort:this.data.price_sort,
  129. sale_sort:this.data.sale_sort
  130. }
  131. }else{
  132. var params = {
  133. page: this.data.projects_page,
  134. per_page: this.data.projects_per_page,
  135. price_sort:this.data.price_sort,
  136. sale_sort:this.data.sale_sort
  137. }
  138. }
  139. var success = function (res) {
  140. if (that.data.projects_change) {
  141. that.setData({
  142. projects: [],
  143. projects_change: false
  144. })
  145. }
  146. var result = that.data.projects.concat(res.data.list || [])
  147. that.setData({
  148. projects: result
  149. })
  150. var listMore = res.data.list_count > that.data.projects.length
  151. that.setData({
  152. projects_more: listMore
  153. })
  154. }
  155. _request.$get(url, params, success)
  156. },
  157. toProject: function (val) {
  158. var id = val.currentTarget.dataset.val
  159. wx.navigateTo({
  160. url: '/pages/projects/project-detail/project-detail?id=' + id
  161. })
  162. },
  163. switchNav(event){
  164. var cur = event.currentTarget.dataset.current
  165. var singleNavWidth = this.data.windowWidth / 5
  166. this.setData({
  167. navScrollLeft: (cur - 2) * singleNavWidth
  168. })
  169. if (this.data.currentTab == cur) {
  170. return false
  171. } else {
  172. this.setData({
  173. currentTab: cur,
  174. projects_more: true,
  175. projects_page: 1,
  176. projects_change: true
  177. })
  178. this.getProjects()
  179. }
  180. },
  181. getBalanceInfo () {
  182. var that = this
  183. var url = 'v1/user/balance/info'
  184. var params = {
  185. }
  186. var success = function (res) {
  187. var result = res.data.total
  188. that.setData({
  189. balance: result
  190. })
  191. }
  192. _request.$get(url, params, success)
  193. },
  194. onShareAppMessage: function (val) {
  195. return _request.share({
  196. // path: '/pages/start/start?url=pages/projects/projects',
  197. sc: 'xcx_products'
  198. })
  199. },
  200. tosearch: function (val) {
  201. var id = val.currentTarget.dataset.val;
  202. wx.navigateTo({
  203. url: '/pages/search/search'
  204. })
  205. },
  206. sortchangenormal(){
  207. this.setData({
  208. projects_page: 1,
  209. projects_per_page: 5,
  210. projects_more: true,
  211. projects_change: false,
  212. projects: [],
  213. price_sort:0,
  214. sale_sort:0
  215. })
  216. this.getProjects()
  217. },
  218. salesort(){
  219. var type = this.data.sale_sort+1;
  220. if(type>2) type = 0;
  221. this.setData({
  222. projects_page: 1,
  223. projects_per_page: 5,
  224. projects_more: true,
  225. projects_change: false,
  226. projects: [],
  227. sale_sort:type,
  228. })
  229. this.getProjects()
  230. },
  231. pricesort(e){
  232. var type = this.data.price_sort+1;
  233. if(type>2) type = 0;
  234. this.setData({
  235. projects_page: 1,
  236. projects_per_page: 5,
  237. projects_more: true,
  238. projects_change: false,
  239. projects: [],
  240. price_sort:type,
  241. })
  242. this.getProjects()
  243. },
  244. // 点击下拉显示框
  245. selectTap() {
  246. this.setData({
  247. selectShow: !this.data.selectShow
  248. });
  249. },
  250. // 点击下拉列表
  251. optionTap(e) {
  252. var cur = e.currentTarget.dataset.current;
  253. if (this.data.currentTab == cur) {
  254. return false
  255. } else {
  256. this.setData({
  257. currentTab: cur,
  258. projects_more: true,
  259. projects_page: 1,
  260. projects_change: true,
  261. selectShow: !this.data.selectShow,
  262. })
  263. this.getProjects()
  264. }
  265. },
  266. closeselect(){
  267. this.setData({
  268. selectShow: false
  269. });
  270. }
  271. })