projects.js 6.9 KB

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