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 }, onLoad: function () { this.getBalanceInfo() this.setData({ vershow: getApp().globalData.vershow, currentTab: 0 // 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() } }, getType: function () { var that = this var url = 'v1/product/cats' var params = {} var success = function (res) { that.setData({ navData: res.data }) that.getProjects() } _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' var params = { page: this.data.projects_page, per_page: this.data.projects_per_page } 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' }) } })