var api = require('../../utils/api.js') var global = require('../../utils/config.js') import { getTimestamp } from '../../utils/common' const app = getApp() Page({ data: { first: true, nomorenews: true, departmentName: '', consultFlag: false, options: { autoplay: false, circular: true, interval: 3000, duration: 100, previousMargin: 50, nextMargin: 0, displayMultipleItems: 3, currentSwiper: '', }, options2: { autoplay: false, circular: true, interval: 3000, duration: 100, previousMargin: 50, nextMargin: 0, displayMultipleItems: 3, currentSwiper: '', }, swiperBannerList: [], swiperData: [ { headUrl: '', linkType: 2, name: '222' }, { headUrl: '', linkType: 2, name: '222' } ], fromScan: false, gid: '', nvabarData: { showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示 title: '党群e家', //导航栏 中间的标题 }, height: app.globalData.height * 2 + 20, infoObj: { time: '', title: '', amount: '' }, noticeList: [], innerHtmlStatus: true, visibilityStatus: true, pageNo: 1, pageSize: 10, timestamp: getTimestamp(), newsList: [], issueList: [], projectList: [], colorList: ['#fdf6e3', '#e9ecf5', '#f7eedf', '#efd9cc', '#e1efff'], completeInfoDialogVisible: false, // 是否完善信息 loadMoreVisible: false, loadMoreType: 'loading', sudokuState: { appraiseAvailable: '0', consultAvailable: '0' } }, onShow: function () { if (wx.getStorageSync('token') != '' && wx.getStorageSync('token') != undefined && wx.getStorageSync('token') != null) { if (!this.data.first) { this.getBannerList() this.getFirstInfo() this.getNoticeList() this.setData({ pageNo: 1, newsList: [] }) this.getNewsList(), this.getIndexSudokuState() } } }, onLoad: function (options) { console.log('options:', options) if (options.scene) { this.setData({ gid: decodeURIComponent(options.scene) }) } let that = this setTimeout(function () { that.getUserState() }, 700) }, getBannerList: function () { let that = this api.bannerList('0').then(function (res) { console.log('res==', res.data) that.setData({ swiperBannerList: res.data }) }) }, // 加载新闻列表 getNewsList () { let para = { pageIndex: this.data.pageNo, pageSize: this.data.pageSize, timestamp: getTimestamp() } api.newsList(para).then((res) => { this.setData({ loadMoreType: res.data.length === this.data.pageSize ? 'loading': 'none', newsList: this.data.newsList.concat(res.data) }) }).catch(() => { this.setData({ loadMoreType: 'none', newsList: [] }) }) }, onReachBottom() { this.setData({ loadMoreVisible: true }) if (this.data.loadMoreType === 'loading') { this.setData({ pageNo: this.data.pageNo + 1, pageSize: this.data.pageSize }) this.getNewsList() } }, toDetail(e) { wx.navigateTo({ url: '/subpages/home/pages/newsDetail/newsDetail?id=' + e.currentTarget.dataset.id }) }, getFirstInfo: function () { let that = this api.getFirstInfo().then(function (res) { console.log('infoObj', res.data) if (res.data !== null) { that.setData({ infoObj: res.data }) } console.log('zheli', that.data.infoObj) }) }, getNoticeList: function () { let para = { pageIndex: 1, pageSize: 10, timestamp: getTimestamp() } let that = this api.noticelist(para).then(function (res) { console.log('infoObj', res.data) if (res.data !== null) { that.setData({ noticeList: res.data }) } console.log('zheli', that.data.infoObj) }) }, // 根据微信code查询用户当前状态 getUserState: function () { let that = this wx.login({ success(res) { if (res.code) { let code = res.code api.getToken(code).then(function (res) { let state = res.data.userState console.log(state) console.log('date', Date.parse(new Date())) let date = Date.parse(new Date()) app.globalData.infoCompleted = state wx.removeStorageSync('topGridName') wx.setStorageSync('topGridName', res.data.grid) wx.removeStorageSync('token') wx.setStorageSync('token', res.data.token) that.setData({ departmentName: res.data.grid }) if (state == '0') { if (that.data.gid !== '') { //扫码进来的 // 是否是网格长的情况 if (that.data.gid == 'gridLeader') { // 是网格长,进网格长注册 wx.redirectTo({ url: '/pages/gridLeaderRegister/gridLeaderRegister' }) } else { // 不是网格长,进网格提示页 wx.redirectTo({ url: '/pages/formid/formid?gid=' + that.data.gid }) } } else { // 直接进首页 that.getBannerList() that.getFirstInfo() that.getNoticeList() that.getNewsList() that.getIndexSudokuState() } } else if (state == '4') { //未注册,跳到我要注册页面 if (that.data.gid !== '') { //扫码进来的 // 扫码进来未注册的情况,先进到前置页面获取formid // 是否是网格长的情况 if (that.data.gid == 'gridLeader') { // 是网格长 wx.redirectTo({ url: '/pages/gridLeaderRegister/gridLeaderRegister' }) } else { wx.redirectTo({ url: '/pages/formid/formid?gid=' + that.data.gid }) } } else { // 非扫码进入,通过搜索小程序直接进入的情况 wx.redirectTo({ url: '/pages/toRegister/toRegister' }) // if (app.globalData.tempGridId == '') { // wx.redirectTo({ // todo: // url: '/pages/toRegister/toRegister?code=' + code + '&t=' + date // }) // } else { // wx.redirectTo({ // url: '/pages/formid/formid?gid=' + app.globalData.tempGridId // }) // } } } else { if (that.data.gid !== '') { //扫码进来的 // 是否是网格长的情况 if (that.data.gid == 'gridLeader') { // 是网格长,进网格长注册 wx.redirectTo({ url: '/pages/gridLeaderRegister/gridLeaderRegister' }) } else { // 不是网格长,进网格提示页 wx.redirectTo({ url: '/pages/formid/formid?gid=' + that.data.gid }) } } else { // 直接进首页 that.getBannerList() that.getFirstInfo() that.getNoticeList() that.getNewsList() that.getIndexSudokuState() } } }) } else { console.log('登录失败' + res.errMsg) } } }) }, changeGrid() { wx.navigateTo({ url: '/subpages/changegrid/pages/changeGrid/changeGrid' }) }, swiperChange: function (e) { this.setData({ 'options.currentSwiper': e.detail.current }) }, swiperChange2: function (e) { this.setData({ 'options2.currentSwiper': e.detail.current }) }, // 点击-更多,跳转通知列表 moreNotice() { wx.navigateTo({ url: '/subpages/home/pages/notice/notice' }) }, // 跳转我的消息 toInfoList() { wx.navigateTo({ url: '/subpages/home/pages/info/info' }) }, // 跳转到我要报事 navigateToAddIssue () { if (app.globalData.infoCompleted == 0) { this.setData({ completeInfoDialogVisible: !this.data.completeInfoDialogVisible }) return false } wx.navigateTo({ url: '/subpages/discussion/pages/addIssue/addIssue' }) }, // 跳转到网格专员 navigatetoConsultion() { if (app.globalData.infoCompleted == 0) { this.setData({ completeInfoDialogVisible: !this.data.completeInfoDialogVisible }) return false } wx.navigateTo({ url: '/subpages/home/pages/consultation/consultation' }) }, // 跳转到通知公告 navigateToNotice () { wx.navigateTo({ url: '/subpages/home/pages/notice/notice' }) }, // 跳转到请您监督 navigatetoAppraise () { if (app.globalData.infoCompleted == 0) { this.setData({ completeInfoDialogVisible: !this.data.completeInfoDialogVisible }) return false } const token = wx.getStorageSync('token') wx.navigateTo({ url: `/subpages/home/pages/webview/webview?url=${global.WEBROOT()}&token=${token}` }) }, // 九宫格检查状态 getIndexSudokuState () { api.getIndexSudokuState().then(res => { console.log('九宫格状态', res) let consultAvailable = '0' let appraiseAvailable = '0' if (res.data.length > 0) { res.data.forEach(item => { if (item.name === '咨询' && item.availableFlag === '1') { consultAvailable = '1' } else if (item.name === '干部评价' && item.availableFlag === '1') { appraiseAvailable = '1' } }) } this.setData({ sudokuState: { consultAvailable, appraiseAvailable } }) }).catch(() => { this.setData({ sudokuState: { consultAvailable: '0', appraiseAvailable: '0' } }) }) } })