var _request = require('../../utils/request.js') Page({ data: { projects_page: 1, projects_per_page: 5, projects_more: true, projects_change: false, projects: [], vershow: true, navData:[], currentTab: 0, navScrollLeft: 0, balance: 0, todaysend: Date.parse(new Date()) / 1000, searchword:'', statusBarHeight:20, navBarHeight:45, windowWidth:375, word:'', price_sort:0, sale_sort:0, selectShow: false,//控制下拉列表的显示隐藏,false隐藏、true显示 selectData: [],//下拉列表的数据 index: 0,//选择的下拉列表下标 zones:[], currentZones:0 }, onLoad: function (options) { const info = wx.getSystemInfoSync(); console.log('info',info); this.setData({ statusBarHeight:info.statusBarHeight }) this.getData() this.getBalanceInfo() this.setData({ vershow: getApp().globalData.vershow, currentTab:options.currentTab ? options.currentTab : 0, searchword:options.searchword ? options.searchword : '' // currentTab: getApp().globalData.isshow }) if (getApp().globalData.isupdate == true) { this.getType() } wx.getSystemInfo({ success: (res) => { this.setData({ windowWidth: res.windowWidth }) } }) }, onShow: function () { if (getApp().globalData.isshow) { this.setData({ currentTab: getApp().globalData.isshow, projects_more: true, projects_page: 1, projects_change: true, }) this.getType() } }, onUnload: function () { getApp().globalData.isshow = '' // this.setData({ // currentTab: 0, // }) }, onHide: function () { getApp().globalData.isshow = '' // this.setData({ // currentTab: 0, // }) }, onPullDownRefresh: function () { this.setData({ projects_more: true, projects_page: 1, projects_change: true }) this.getProjects() wx.stopPullDownRefresh() }, onReachBottom: function () { if (this.data.projects_more) { var page = this.data.projects_page + 1 this.setData({ projects_page: page }) this.getProjects() } }, getData: function () { var that = this var url = 'v1/product/commend_words' var params = {} var success = function (res) { console.log('res',res.data.list); that.setData({ word:res.data.list[0]?res.data.list[0].title:'' }) } _request.$get(url, params, success) }, getType: function () { var that = this var url = 'v1/product/cats' var params = {} var success = function (res) { that.setData({ navData: res.data }) that.getZones() that.getProjects() } _request.$get(url, params, success) }, getZones:function(){ var that = this var url = '/v1/zones' var params = {} var success = function (res) { that.setData({ zones: res.data }) } _request.$get(url, params, success) }, getProjects: function () { var id = this.data.navData[this.data.currentTab].id if (!this.data.vershow) { id = 3 } var that = this var url = 'v1/cat/' + id + '/products' if(that.data.searchword){ var params = { page: this.data.projects_page, per_page: this.data.projects_per_page, words:this.data.searchword, price_sort:this.data.price_sort, sale_sort:this.data.sale_sort, sale_zone: this.data.currentZones } }else{ var params = { page: this.data.projects_page, per_page: this.data.projects_per_page, price_sort:this.data.price_sort, sale_sort:this.data.sale_sort, sale_zone: this.data.currentZones } } var success = function (res) { if (that.data.projects_change) { that.setData({ projects: [], projects_change: false }) } var result = that.data.projects.concat(res.data.list || []) that.setData({ projects: result }) var listMore = res.data.list_count > that.data.projects.length that.setData({ projects_more: listMore }) } _request.$get(url, params, success) }, toProject: function (val) { var id = val.currentTarget.dataset.val wx.navigateTo({ url: '/pages/projects/project-detail/project-detail?id=' + id }) }, switchNav(event){ var cur = event.currentTarget.dataset.current var singleNavWidth = this.data.windowWidth / 5 this.setData({ navScrollLeft: (cur - 2) * singleNavWidth }) if (this.data.currentTab == cur) { return false } else { this.setData({ currentTab: cur, projects_more: true, projects_page: 1, projects_change: true }) this.getProjects() } }, getBalanceInfo () { var that = this var url = 'v1/user/balance/info' var params = { } var success = function (res) { var result = res.data.total that.setData({ balance: result }) } _request.$get(url, params, success) }, onShareAppMessage: function (val) { return _request.share({ // path: '/pages/start/start?url=pages/projects/projects', sc: 'xcx_products' }) }, tosearch: function (val) { var id = val.currentTarget.dataset.val; wx.navigateTo({ url: '/pages/search/search' }) }, sortchangenormal(){ this.setData({ projects_page: 1, projects_per_page: 5, projects_more: true, projects_change: false, projects: [], price_sort:0, sale_sort:0 }) this.getProjects() }, salesort(){ var type = this.data.sale_sort+1; if(type>2) type = 0; this.setData({ projects_page: 1, projects_per_page: 5, projects_more: true, projects_change: false, projects: [], sale_sort:type, }) this.getProjects() }, pricesort(e){ var type = this.data.price_sort+1; if(type>2) type = 0; this.setData({ projects_page: 1, projects_per_page: 5, projects_more: true, projects_change: false, projects: [], price_sort:type, }) this.getProjects() }, // 点击下拉显示框 selectTap() { this.setData({ selectShow: !this.data.selectShow }); }, // 点击下拉列表 optionTap(e) { var cur = e.currentTarget.dataset.current; if (this.data.currentTab == cur) { return false } else { this.setData({ currentTab: cur, projects_more: true, projects_page: 1, projects_change: true, selectShow: !this.data.selectShow, currentZones: 0 }) this.getProjects() } }, closeselect(){ this.setData({ selectShow: false }); }, selectzones(e){ var cur = e.currentTarget.dataset.id; if (this.data.currentZones == cur) { return false } else { this.setData({ currentZones: cur, projects_more: true, projects_page: 1, projects_change: true, projects: [] }) this.getProjects() } } })