projects.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. }
  145. }else{
  146. var params = {
  147. page: this.data.projects_page,
  148. per_page: this.data.projects_per_page,
  149. price_sort:this.data.price_sort,
  150. sale_sort:this.data.sale_sort
  151. }
  152. }
  153. if(this.data.currentZones != 0){
  154. params['sale_sort'] = this.data.currentZones
  155. }
  156. var success = function (res) {
  157. if (that.data.projects_change) {
  158. that.setData({
  159. projects: [],
  160. projects_change: false
  161. })
  162. }
  163. var result = that.data.projects.concat(res.data.list || [])
  164. that.setData({
  165. projects: result
  166. })
  167. var listMore = res.data.list_count > that.data.projects.length
  168. that.setData({
  169. projects_more: listMore
  170. })
  171. }
  172. _request.$get(url, params, success)
  173. },
  174. toProject: function (val) {
  175. var id = val.currentTarget.dataset.val
  176. wx.navigateTo({
  177. url: '/pages/projects/project-detail/project-detail?id=' + id
  178. })
  179. },
  180. switchNav(event){
  181. var cur = event.currentTarget.dataset.current
  182. var singleNavWidth = this.data.windowWidth / 5
  183. this.setData({
  184. navScrollLeft: (cur - 2) * singleNavWidth
  185. })
  186. if (this.data.currentTab == cur) {
  187. return false
  188. } else {
  189. this.setData({
  190. currentTab: cur,
  191. projects_more: true,
  192. projects_page: 1,
  193. projects_change: true
  194. })
  195. this.getProjects()
  196. }
  197. },
  198. getBalanceInfo () {
  199. var that = this
  200. var url = 'v1/user/balance/info'
  201. var params = {
  202. }
  203. var success = function (res) {
  204. var result = res.data.total
  205. that.setData({
  206. balance: result
  207. })
  208. }
  209. _request.$get(url, params, success)
  210. },
  211. onShareAppMessage: function (val) {
  212. return _request.share({
  213. // path: '/pages/start/start?url=pages/projects/projects',
  214. sc: 'xcx_products'
  215. })
  216. },
  217. tosearch: function (val) {
  218. var id = val.currentTarget.dataset.val;
  219. wx.navigateTo({
  220. url: '/pages/search/search'
  221. })
  222. },
  223. sortchangenormal(){
  224. this.setData({
  225. projects_page: 1,
  226. projects_per_page: 5,
  227. projects_more: true,
  228. projects_change: false,
  229. projects: [],
  230. price_sort:0,
  231. sale_sort:0
  232. })
  233. this.getProjects()
  234. },
  235. salesort(){
  236. var type = this.data.sale_sort+1;
  237. if(type>2) type = 0;
  238. this.setData({
  239. projects_page: 1,
  240. projects_per_page: 5,
  241. projects_more: true,
  242. projects_change: false,
  243. projects: [],
  244. sale_sort:type,
  245. })
  246. this.getProjects()
  247. },
  248. pricesort(e){
  249. var type = this.data.price_sort+1;
  250. if(type>2) type = 0;
  251. this.setData({
  252. projects_page: 1,
  253. projects_per_page: 5,
  254. projects_more: true,
  255. projects_change: false,
  256. projects: [],
  257. price_sort:type,
  258. })
  259. this.getProjects()
  260. },
  261. // 点击下拉显示框
  262. selectTap() {
  263. this.setData({
  264. selectShow: !this.data.selectShow
  265. });
  266. },
  267. // 点击下拉列表
  268. optionTap(e) {
  269. var cur = e.currentTarget.dataset.current;
  270. if (this.data.currentTab == cur) {
  271. return false
  272. } else {
  273. this.setData({
  274. currentTab: cur,
  275. projects_more: true,
  276. projects_page: 1,
  277. projects_change: true,
  278. selectShow: !this.data.selectShow,
  279. currentZones: 0
  280. })
  281. this.getProjects()
  282. }
  283. },
  284. closeselect(){
  285. this.setData({
  286. selectShow: false
  287. });
  288. },
  289. selectzones(e){
  290. var cur = e.currentTarget.dataset.id;
  291. if (this.data.currentZones == cur) {
  292. return false
  293. } else {
  294. this.setData({
  295. currentZones: cur,
  296. projects_more: true,
  297. projects_page: 1,
  298. projects_change: true,
  299. projects: []
  300. })
  301. this.getProjects()
  302. }
  303. }
  304. })