projects.js 7.9 KB

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