const util = require('../../utils/util.js'); const api = require('../../config/api.js'); const getUserInfo = require('../../utils/getUserInfo').default; const bgImg = require('../../static/images/bgImg') import { Router } from '../../utils/router.js' //获取应用实例 Router({ data: { currentBanner: 0, banners: [], showSearch: false, activeType: -1, header: [], noRecord: '', hideMask: false, keyword: '', url: 'https://www.4dkankan.com/eShopMobile.html?m=', totalPages: 1, currentPage: 1, size: 10, bgImg, loading: false, showClear: false, brandList: [] }, clearKeyword() { this.setData({ keyword: '' }) this.setData({showClear: false}) this.search() }, swiperChange(e) { this.setData({ currentBanner: e.detail.current }) }, onShareAppMessage: function () { return { path: '/pages/index/index' } }, getImgHeight() { const aw = 750 const ah = 480 this.setData({ imgHeight: ah * wx.getSystemInfoSync().windowWidth / aw }) this.navTop = this.data.imgHeight * 0.87 this.bgTop = this.data.imgHeight * 0.6 this.setData({ navTop: this.bgTop }) }, onPageScroll(e) { if (e.scrollTop < 0) return; this.setData({ bgTop: e.scrollTop > this.bgTop ? this.bgTop : e.scrollTop, bgIsTop: e.scrollTop > this.navTop, isFixed: e.scrollTop > this.data.navPosTop }) }, 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') } }, clickSwiper() { wx.navigateTo({ url: this.data.banners[this.data.currentBanner].redirectUrl, }) }, loadMore: function () { if (this.data.currentPage < this.data.totalPages) { console.log(this.data.currentPage + 1) this.getBrandList(this.data.currentPage + 1); } else { return; } }, async getBrandList(page, isSearch = false, refresh = false) { this.setData({ loading: true }) let tempContent = this.data.brandList ? this.data.brandList : []; let { size, keyword, } = this.data console.log('gegeget') util.request(api.getFireList, { pageNum: page, projectSn: keyword, pageSize: size }, 'POST') .then(res => { if (isSearch) { wx.pageScrollTo({ scrollTop: 0 }) this.setData({ brandList: this.formBrandList(res.data.list), currentPage: res.data.curPage, totalPages: res.data.totalPageNum, loading: false, noRecord: false, showSearch: false }); } else if (refresh) { this.setData({ brandList: this.formBrandList(res.data.list), currentPage: res.data.curPage, totalPages: res.data.totalPageNum, loading: false }); } else { this.setData({ brandList: tempContent.concat(this.formBrandList(res.data.list)), currentPage: res.data.curPage, totalPages: res.data.totalPageNum, loading: false }); } }); }, formBrandList(data) { return data.map(item => { let icon = ~item.projectSite.indexOf('非建构筑物') ? '/static/images/fire_other.png' : ~item.projectSite.indexOf('交通工具') ? '/static/images/fire_bus.png' : ~item.projectSite.indexOf('垃圾及废弃物') ? '/static/images/fire_recycle.png' : '/static/images/fire_building.png' return { ...item, icon, createTime: item.createTime.substr(0, 11) } }) }, inputChange: function (e) { let val = e.detail.value this.setData({ keyword: val, noRecord: false }) this.setData({showClear: !!val.length}) 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 () { }, gotoCateg() { wx.navigateTo({ url: '/pages/ncategory/category?id=search', }) }, tapHeaderBar(e) { // let { id } = e.currentTarget.dataset // wx.navigateTo({ // url: '/pages/ncategory/category?id=' + id, // }) let { id } = e.currentTarget.dataset this.setData({ activeType: id, showSearch: false, keyword: '', brandList: [], currentPage: 1 }) this.getBrandList(1) }, tabShow() { this.setData({ showSearch: true }) }, tabHide() { this.setData({ showSearch: false, noRecord: false, keyword: '' }) }, getUserInfo, onLoad: async function (options) { this.setData({ statusBarHeight: wx.getSystemInfoSync().statusBarHeight, isiOS: wx.getSystemInfoSync().system.indexOf('iOS') > -1, }) let navHeight = 0 if (!this.data.isiOS) { navHeight = 48; } else { navHeight = 44; } this.setData({ navHeight: navHeight }) getApp().checkNetStatu(); // this.checkNetStatu() this.setData({ imgServer: util.imgServer }) this.onShow() // wx.setBackgroundColor({ // backgroundColor: '#ff7701' // }) }, async getType() { let items = [{ name: '全部', id: -1 }] this.setData({ header: items }) }, onReady: function () { // 页面渲染完成 }, onShow: function (options) { this.data.brandList = [] 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() // this.options.keyword && this.inputChange({detail: {value: this.options.keyword}}) this.getBrandList(1) this.getType() this.getImgHeight() this.getUserInfo() // 页面显示 }, onHide: function () { // 页面隐藏 }, onUnload: function () { // 页面关闭 }, gotoWV: function (event) { let { id, scene } = event.currentTarget.dataset if (!scene) { return wx.showToast({ icon: 'none', title: '暂无VR数据,无法查看', }) } wx.navigateTo({ url: `/pages/webview/index?id=${id}&scene=${scene}`, // url: `/pages/reserve/reserve?id=${id}` }) }, searchFocus() { wx.navigateTo({ url: '/pages/search/search?keyword=' + this.data.keyword, }) } })