123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- const util = require('../../utils/util.js');
- const api = require('../../config/api.js');
- const user = require('../../services/user.js');
- import header from './data'
- import { Router } from '../../utils/router.js'
- //获取应用实例
- Router({
- data: {
- showSearch: false,
- activeType:-1,
- header: header,
- noRecord:'',
- hideMask: false,
- inputShowed: false,
- keyword:'',
- url:'https://www.4dkankan.com/eShopMobile.html?m=',
- totalPages: 1,
- currentPage: 1,
- size: 10,
- loading: false,
- brandList:[]
- },
- onShareAppMessage: function () {
- return {
- path: '/pages/index/index'
- }
- },
- onPullDownRefresh(){
- this.setData({
- brandList: this.data.brandList.slice(0,10),
- currentPage: 1
- });
- this.getBrandList(1,false,true);
- getApp().onPullDownRefresh()
- },
- onReachBottom() {
- if (!this.data.loading) {
- this.loadMore();
- console.log('reach down')
- }
- },
- loadMore: function () {
- if (this.data.currentPage<this.data.totalPages) {
- console.log(this.data.currentPage + 1)
- this.getBrandList(this.data.currentPage + 1);
- } else {
- return;
- }
- },
- getBrandList(page,isSearch=false,refresh=false){
-
- this.setData({
- loading: true
- })
- let tempContent = this.data.brandList ?
- this.data.brandList :
- [];
- let { activeType, size, keyword,} = this.data
-
- util.request(api.IndexList, { type: activeType, page, name:keyword, size })
- .then(res=> {
- if (isSearch){
- // if (res.data.data.length <= 0) {
- // this.setData({
- // noRecord: true
- // });
- // }
- // else {
- wx.pageScrollTo({
- scrollTop: 0
- })
- this.setData({
- brandList: res.data.data,
- currentPage: res.data.currentPage,
- totalPages: res.data.totalPages,
- loading: false,
- noRecord: false,
- showSearch: false
- });
- // }
- }
- else if(refresh){
- this.setData({
- brandList: res.data.data,
- currentPage: res.data.currentPage,
- totalPages: res.data.totalPages,
- loading: false
- });
- }
- else {
- this.setData({
- brandList: tempContent.concat(res.data.data),
- currentPage: res.data.currentPage,
- totalPages: res.data.totalPages,
- loading: false
- });
- }
-
- });
- },
- inputChange: function (e) {
- let val = e.detail.value
- this.setData({
- keyword:val,
- noRecord: false
- })
- this.search()
- },
- handleScroll(ev) {
- this.setData({isFixed: ev.detail.isFixed})
- },
- search:function(){
- let {keyword} = this.data
-
- this.getBrandList(1, true)
- // if (this.brandList.length <= 0) {
- // this.setData({
- // noRecord: true
- // })
- // }
- // else {
- // this.setData({
- // activeType: -1,
- // noRecord: false,
- // showSearch: false
- // })
- // }
- },
- inputFocus: function () {
- },
- tapHeaderBar(e){
- let { id } = e.currentTarget.dataset
- this.setData({
- activeType: id,
- showSearch: false,
- keyword: '',
- brandList: [],
- currentPage: 1
- })
- wx.pageScrollTo({
- duration: 0,
- scrollTop: 0
- })
- this.getBrandList(1)
- },
- tabShow(){
- this.setData({
- showSearch: true
- })
- },
- tabHide() {
- this.setData({
- showSearch: false,
- noRecord:false,
- keyword:''
- })
- },
-
- onLoad: async function (options) {
- getApp().checkNetStatu();
- // this.checkNetStatu()
- this.setData({
- imgServer: util.imgServer
- })
- if (options.id !== 'search') {
- this.setData({activeType: options.id})
- } else {
- this.setData({inputShowed: true})
- }
- this.getBrandList(1)
- },
- onReady: function () {
- // 页面渲染完成
- },
- onShow: function (options) {
- if (global.type) {
- this.tapHeaderBar({
- currentTarget: {
- dataset: this.data.header[0]
- }
- })
- global.type = null
- }
- if(typeof this.getTabBar === 'function' && this.getTabBar()){
- this.getTabBar().setData({
- selected:0
- })
- }
- getApp().updateCardCount()
- // 页面显示
- },
- onHide: function () {
- // 页面隐藏
- },
- onUnload: function () {
- // 页面关闭
- },
- gotoWV: function (event){
- let { id } = event.currentTarget.dataset
-
- wx.navigateTo({
- url: `/pages/webview/index?id=${id}`,
- // url: `/pages/share/share?id=${id}`,
- })
- }
- })
|