const api = require('../../../../utils/understandJs') const app = getApp() Page({ /** * 页面的初始数据 */ data: { pageIndex: 1, pageSize: 10, modulelist: [], //module 接口 noticelist: [], //notice 接口 newsCategoryList: [], //type-8 tab list nodata: false, loadMoreType: 'none', loadMoreVisible: false, isLoadMore: false, //是否显示load-more组件 swiperBannerList: [], indicatorDots: false, //指示点 autoplay: true, //true,//自动播放 circular: true, //衔接滑动 interval: 5000, //自动播放间隔时长(ms) duration: 500, //幻灯片切换时长(ms) currentSwiper: 0, showTitle: true, //视频标题 moduleInfo: {}, //pid, bannerflag, categorycode, modulestyle, categoryname preloadVisible: true, //type-8 预加载 lastPlayVideo: '', //正在播放的视频 completeInfoDialogVisible: false, //完善信息 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.data.moduleInfo = { ...options } this.setData({ moduleInfo: this.data.moduleInfo }) wx.setNavigationBarTitle({ title: options.categoryname }) if (options.bannerflag == '1') { this.getBannerList(options.categorycode) } if (this.getModuleStyleType() == 'notice_list') { this.setData({ isLoadMore: true }) this.getNoticelist() } else if (this.getModuleStyleType() == 'module_list') { this.getModuleCategory() } else if (options.modulestyle == '4') { wx.navigateTo({ url: `../noticeDetail/noticeDetail?pid=${this.data.moduleInfo.pid}&bannerflag=${this.data.moduleInfo.bannerflag}&categorycode=${this.data.moduleInfo.categorycode}&modulestyle=${this.data.moduleInfo.modulestyle}&categoryname=${this.data.moduleInfo.categoryname}` }) } else if (this.getModuleStyleType() == 'notice_tab_list') { this.getModuleCategoryList().then(() => { this.getNoticelist(this.data.newsCategoryList[0].value) }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { this.setData({ loadMoreVisible: true }) if (this.data.loadMoreType === 'loading') { this.setData({ pageIndex: this.data.pageIndex + 1, pageSize: this.data.pageSize, }) if (this.getModuleStyleType() == 'notice_list') { this.getNoticelist() } else if (this.getModuleStyleType() == 'module_list') { this.getModuleCategory() }else if (this.getModuleStyleType() == 'notice_tab_list') { this.getNoticelist(this.data.newsCategoryList[0].value) } } }, //modulestyle 调用模式 getModuleStyleType () { let moduleStyle = this.data.moduleInfo.modulestyle if (moduleStyle == '1' || moduleStyle == '3' || moduleStyle == '5' || moduleStyle == '6' || moduleStyle == '7' || moduleStyle == '9') { return 'notice_list' } else if (moduleStyle == '2') { return 'module_list' } else if (moduleStyle == '8') { return 'notice_tab_list' } return 'notice_list' }, //获取模块列表 getModuleCategory() { let params = { pageIndex: this.data.pageIndex, pageSize: this.data.pageSize, pid: this.data.moduleInfo.pid } api.moduleCategory(params).then(res => { this.setData({ modulelist: this.data.modulelist.concat(res.data), loadMoreType: res.data.length === this.data.pageSize ? 'loading' : 'none', loadMoreVisible: res.data.length === this.data.pageSize ? false : true }) if (this.data.modulelist.length == 0) { this.setData({ nodata: true, loadMoreType: 'none', loadMoreVisible: false, }) } }).catch(err => { this.setData({ modulelist: [], nodata: true, loadMoreType: 'none', loadMoreVisible: false, }) console.log(err) }) }, //获取通知列表 getNoticelist(categoryCode='') { let that = this let params = { pageIndex: that.data.pageIndex, pageSize: that.data.pageSize, noticeCategory: categoryCode == '' ? that.data.moduleInfo.categorycode : categoryCode } api.noticelist(params).then(res => { let list = [ ...res.data ] if (that.data.moduleInfo.modulestyle == '7') { list = [] res.data.forEach(item => { if (item.noticeVideoUrl) { item.showTitle = true list.push(item) } }) } console.log(list) that.setData({ noticelist: that.data.noticelist.concat(list), loadMoreType: res.data.length === that.data.pageSize ? 'loading' : 'none', loadMoreVisible: res.data.length === that.data.pageSize ? false : true, preloadVisible: false }) if (that.data.noticelist.length == 0) { that.setData({ nodata: true, loadMoreType: 'none', loadMoreVisible: false, }) } }).catch(err => { that.setData({ noticelist: [], nodata: true, loadMoreType: 'none', loadMoreVisible: false, preloadVisible: false }) console.log(err) }) }, // 获取type-8 分类列表 getModuleCategoryList () { let params = { pageIndex: this.data.pageIndex, pageSize: this.data.pageSize, pid: this.data.moduleInfo.pid } return new Promise((resolve, reject) => { api.moduleCategory(params).then(res => { console.log('获取分类列表', res) // const newsCategoryList = [{ // value: 'all', // select: true, // label: '全部' // }] const newsCategoryList = [] res.data.forEach(item => { newsCategoryList.push({ value: item.categoryCode, select: false, label: item.categoryName }) }) newsCategoryList[0].select = true this.setData({ newsCategoryList }) resolve(true) }).catch(err => { console.log(err) reject(false) }) }) }, //获取视频banner列表 getBannerList: function(bannerNum) { let that = this api.bannerList(bannerNum).then(function(res) { // console.log('res==', res.data) that.setData({ swiperBannerList: res.data }) }) }, swiperChange: function(e) { wx.createVideoContext('video'+this.data.currentSwiper).pause() this.setData({ currentSwiper: e.detail.current, autoplay: true }) }, bindplay() { this.setData({ autoplay: false }) wx.getNetworkType({ success (res) { const networkType = res.networkType if (res.networkType != 'wifi') { wx.showToast({ title: '当前为非WI-FI环境,请注意流量消耗', icon: 'none', duration: 3000 }) } } }) }, bindended() { this.setData({ autoplay: true }) }, bindcontrolstoggle(e) { this.setData({ showTitle: e.detail.show }) }, videoitemplay (e) { wx.createVideoContext(this.data.lastPlayVideo).pause() this.setData({ lastPlayVideo: e.currentTarget.id }) wx.getNetworkType({ success (res) { const networkType = res.networkType if (res.networkType != 'wifi') { wx.showToast({ title: '当前为非WI-FI环境,请注意流量消耗', icon: 'none', duration: 3000 }) } } }) }, videoitemtoggle (e) { this.data.noticelist[e.currentTarget.dataset.index].showTitle = e.detail.show this.setData({ noticelist: this.data.noticelist }) }, /** * module 跳转模块页面 */ navigateToType (e) { const info = e.currentTarget.dataset.info if (info.moduleStyle) { wx.navigateTo({ url: `./moduleList?pid=${info.id}&bannerflag=${info.bannerFlag}&categorycode=${info.categoryCode}&modulestyle=${info.moduleStyle}&categoryname=${info.categoryName}` }) } else { wx.showToast({ title: '该模块未选择展示形式', icon: 'none', duration: 2000 }) } }, //notice 跳转详情页面 toDetail(e){ const info = e.currentTarget.dataset wx.navigateTo({ url: `../noticeDetail/noticeDetail?id=${info.id}&title=${this.data.moduleInfo.categoryname}` }) }, //type-8 tab切换回调函数 newsCategoryCallback (e) { // if (e.detail.newsCategoryId === 'all') { // this.data.newsCategoryId = '' // } else { // this.data.newsCategoryId = e.detail.newsCategoryId // } this.setData({ pageIndex: 1, noticelist: [], loadMoreType: 'none', loadMoreVisible: false, preloadVisible: true, nodata: false }) this.getNoticelist(e.detail.newsCategoryId) }, //type-2 锦水清风-我要举报 toReportIssue (e) { if (this.verifyCompleteInfo()) { return false } if (e.currentTarget.dataset.code == 'notice_jsqf_wyjb') { wx.navigateTo({ url: "/subpages/oneKeyService/pages/reportIssue/reportIssue" }) } else { wx.showToast({ title: '暂未开放', icon: 'none', duration: 2000 }) } }, //type-9 拨打电话 mobile(e) { wx.showModal({ title: '拨打电话', content: `您确定拨打${e.currentTarget.dataset.mobile}`, cancelColor: '#29B9A5', confirmColor: '#29B9A5', success: (res) => { if (res.confirm) { console.log('用户点击确定') wx.makePhoneCall({ phoneNumber: e.currentTarget.dataset.mobile }) } else if (res.cancel) { console.log('用户点击取消') } } }) }, // 检查 是否完善信息 verifyCompleteInfo () { if (app.globalData.infoCompleted == 0) { this.setData({ completeInfoDialogVisible: !this.data.completeInfoDialogVisible }) return true } else { return false } }, })