| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- 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:''
- },
- onLoad: function (options) {
- console.log('onload-options',options.searchword);
- this.getBalanceInfo()
- this.setData({
- vershow: getApp().globalData.vershow,
- // currentTab:options.currentTab ? options.currentTab : 0,
- searchword:options.words ? options.words : ''
- // 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'
- if(that.data.searchword){
- var params = {
- // page: this.data.projects_page,
- // per_page: this.data.projects_per_page,
- words:that.data.searchword
- }
- }else{
- var params = {
- page: this.data.projects_page,
- per_page: this.data.projects_per_page
- }
- }
-
- console.log('searchword',that.data.searchword)
-
- 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'
- })
- }
- })
|