| | |
| | | // pages/learn/learn.js |
| | | const lawservice = require("../../../service/lawservice") |
| | | const moment = require('../../../utils/moment.min') |
| | | const beLearn = require('../behaviors/beLearn') |
| | | const app = getApp() |
| | | import ListPage from '../../../base/ListPage' |
| | | import b_fetch from '../behaviors/b_fetch' |
| | | import b_openFile from '../behaviors/b_openFile' |
| | | |
| | | Page({ |
| | | behaviors: [beLearn], |
| | | ListPage({ |
| | | behaviors: [b_fetch, b_openFile], |
| | | /** |
| | | * 页面的初始数据 |
| | | */ |
| | |
| | | "name": "在线监测设备" |
| | | } |
| | | ], |
| | | pageList: [ |
| | | |
| | | ], |
| | | banners: [ |
| | | { |
| | | pic: '', |
| | |
| | | fileType: '' |
| | | }, |
| | | ], |
| | | resources: [], |
| | | text2: [{ |
| | | title: "因违章建筑导致执法", |
| | | content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一", |
| | | tags: ['违法搭建', '依法拆除'], |
| | | views: 123, |
| | | time: '2021年3月2日', |
| | | likes: 233 |
| | | }, { |
| | | title: "因违章建筑导致执法", |
| | | content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一", |
| | | tags: ['违法搭建', '依法拆除'], |
| | | views: 123, |
| | | time: '2021年3月2日', |
| | | likes: 233 |
| | | }, { |
| | | title: "因违章建筑导致执法", |
| | | content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一", |
| | | tags: ['违法搭建', '依法拆除'], |
| | | views: 123, |
| | | time: '2021年3月2日', |
| | | likes: 233 |
| | | }, { |
| | | title: "因违章建筑导致执法", |
| | | content: "执法描述:环保主管部门可调阅并作为执法溯源依据之一环保主管部门可调阅并作为执法溯源依据之一", |
| | | tags: ['违法搭建', '依法拆除'], |
| | | views: 123, |
| | | time: '2021年3月2日', |
| | | likes: 233 |
| | | }] |
| | | |
| | | }, |
| | | //计算swiper高度方法(在切换的时候调用) |
| | | tabsHeight(element) { |
| | | let that = this; |
| | | let query = wx.createSelectorQuery(); //必须要先创建一个查询 |
| | | query.select(element).boundingClientRect(function (rect) { |
| | | that.setData({ |
| | | pageheight: rect.height + 'px' |
| | | }); |
| | | }).exec(); |
| | | }, |
| | | swichNav: function (e) { |
| | | var that = this; |
| | | if (this.data.currentTab === e.target.dataset.current) { |
| | | return false; |
| | | } else { |
| | | that.setData({ |
| | | currentTab: e.target.dataset.current, |
| | | navScrollLeft: e.target.dataset.current >= 4 ? ((e.target.dataset.current) * 60) : 0 //判断当前选中的个数是否是第5个 |
| | | }) |
| | | that.tabsHeight('.page' + e.target.dataset.current); //查询哪一个元素 |
| | | } |
| | | }, |
| | | bindChange: function (e) { |
| | | var that = this; |
| | | that.setData({ |
| | | currentTab: e.detail.current, |
| | | navScrollLeft: e.detail.current >= 4 ? ((e.detail.current) * 60) : 0 //判断当前选中的个数是否是第5个 |
| | | }); |
| | | // that.tabsHeight('.page'+e.target.dataset.current); //查询哪一个元素 |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * 生命周期函数--监听页面加载 |
| | | */ |
| | | onLoad: function (options) { |
| | | // this.tabsHeight('.page0'); |
| | | this.getResources() |
| | | this.getResources({}) |
| | | }, |
| | | |
| | | onReachBottom () { |
| | | console.log('onReachBottom'); |
| | | if (this.cPage && this.tPage) { |
| | | if (this.cPage < this.tPage) { |
| | | this.getResources(this.cPage + 1) |
| | | } |
| | | } |
| | | loadComplete() { |
| | | this.getBanner() |
| | | }, |
| | | |
| | | getBanner() { |
| | | let banners = [] |
| | | for (let i = 0; i < 6; i++) { |
| | | const d = this.data.resources[i] |
| | | const results = this.data.results |
| | | const max = results.length > 5 ? 5 : results.length |
| | | for (let i = 0; i < max; i++) { |
| | | const d = this.data.results[i] |
| | | banners.push({ |
| | | pic: d.lrPicurl, |
| | | url: d.lrBodyurl, |
| | |
| | | }) |
| | | }, |
| | | |
| | | getResources(cPage = 1) { |
| | | var that = this |
| | | let user = app.globalData.userInfo |
| | | lawservice.getLawRegulations(user.guid, cPage, {sceneTypeId: user.extension2}, { |
| | | onHead(header) { |
| | | that.cPage = parseInt(header.currentPage) |
| | | that.tPage = parseInt(header.totalPage) |
| | | console.log(`cPage:${that.cPage}, tPage:${that.tPage}`); |
| | | }, |
| | | success(data) { |
| | | let resources = that.data.resources |
| | | data.forEach(d => { |
| | | d.views = parseInt(Math.random() * 1000 + 10) |
| | | d.lrPublishdate = moment(d.lrPublishdate).format('YYYY年MM月DD日') |
| | | }); |
| | | resources = resources.concat(data) |
| | | that.setData({ |
| | | resources |
| | | }) |
| | | if (that.cPage == 1) { |
| | | that.getBanner() |
| | | } |
| | | } |
| | | }, 10) |
| | | }, |
| | | |
| | | openFile(e) { |
| | | var index = e.currentTarget.dataset.index |
| | | let f = this.data.resources[index] |
| | | this.behaviorOpenFile(f) |
| | | }, |
| | | goto: function (e) { |
| | | var url = "" |
| | | var index = e.currentTarget.dataset.index |
| | | switch (index) { |
| | | case '0': |
| | | url = '/pages' |
| | | url = '/pages/m_learn/learfile/learnfile' |
| | | break; |
| | | case '1': |
| | | url = "" |
| | | url = "/pages/m_learn/learncase/learncase" |
| | | break; |
| | | } |
| | | if (url != "") { |