|
|
|
const app = getApp()
|
|
|
|
const api = require('../../utils/api')
|
|
|
|
const homeApi = require('../../utils/home')
|
|
|
|
const global = require('../../utils/config')
|
|
|
|
import { getTimestamp } from '../../utils/common'
|
|
|
|
import checkoutVersion from '../../utils/checkVersion'
|
|
|
|
Page({
|
|
|
|
data: {
|
|
|
|
statusHeight: 0, // 自定义头部状态栏高度
|
|
|
|
navigationHeight: 0, // 自定义头部导航栏高度
|
|
|
|
bannerList: [], // banner列表
|
|
|
|
newsList: [], // 新闻列表
|
|
|
|
projectList: [], // 项目列表
|
|
|
|
infoList: [], // 消息列表
|
|
|
|
unReadNum: 0, // 未读数量
|
|
|
|
loadMoreType: 'none',
|
|
|
|
loadMoreVisible: false,
|
|
|
|
pageNo: 1, // 新闻列表-分页页码
|
|
|
|
pageSize: 10, // 新闻列表-分页页长
|
|
|
|
timestamp: '', // 时间戳
|
|
|
|
sudokuState: { // 九宫格显隐状态
|
|
|
|
consultAvailable: '0', // 网格专员
|
|
|
|
appraiseAvailable: '0' // 请您监督
|
|
|
|
},
|
|
|
|
completeInfoDialogVisible: false, // 完善信息弹框显隐
|
|
|
|
gridId: '', // 网格id
|
|
|
|
departmentName: '', // 所在网格
|
|
|
|
isCarryLoad: false
|
|
|
|
},
|
|
|
|
onLoad (options) {
|
|
|
|
if (options.scene) {
|
|
|
|
this.setData({
|
|
|
|
statusHeight: app.globalData.deviceInfo.statusHeight,
|
|
|
|
navigationHeight: app.globalData.deviceInfo.navigationHeight,
|
|
|
|
gridId: options.scene
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.setData({
|
|
|
|
statusHeight: app.globalData.deviceInfo.statusHeight,
|
|
|
|
navigationHeight: app.globalData.deviceInfo.navigationHeight,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
this.getUserState()
|
|
|
|
this.data.isCarryLoad = true
|
|
|
|
},
|
|
|
|
onTabItemTap () {
|
|
|
|
this.getUserState()
|
|
|
|
},
|
|
|
|
onShow () {
|
|
|
|
// 检查版本更新
|
|
|
|
checkoutVersion()
|
|
|
|
},
|
|
|
|
onReachBottom () {
|
|
|
|
this.setData({
|
|
|
|
loadMoreVisible: true
|
|
|
|
})
|
|
|
|
if (this.data.loadMoreType === 'loading') {
|
|
|
|
this.data.pageNo += 1
|
|
|
|
this.getNewsList()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 根据微信code查询用户当前状态
|
|
|
|
getUserState () {
|
|
|
|
let that = this
|
|
|
|
wx.login({
|
|
|
|
success(res) {
|
|
|
|
if (res.code) {
|
|
|
|
let code = res.code
|
|
|
|
api.getToken(code).then(res => {
|
|
|
|
const state = res.data.userState
|
|
|
|
app.globalData.infoCompleted = state
|
|
|
|
wx.setStorageSync('topGridName', res.data.grid)
|
|
|
|
wx.setStorageSync('token', res.data.token)
|
|
|
|
that.setData({
|
|
|
|
departmentName: res.data.grid
|
|
|
|
})
|
|
|
|
// 扫码进入
|
|
|
|
if(that.data.gridId !== '') {
|
|
|
|
// 扫的是网格长码
|
|
|
|
if (that.data.gridId == 'gridLeader') {
|
|
|
|
wx.redirectTo({
|
|
|
|
url: '/pages/gridLeaderRegister/gridLeaderRegister'
|
|
|
|
})
|
|
|
|
// 扫的是网格码
|
|
|
|
} else {
|
|
|
|
wx.redirectTo({
|
|
|
|
url: '/pages/formid/formid?gid=' + that.data.gridId
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (state == '4') {
|
|
|
|
// 非扫码进入,通过搜索小程序直接进入的情况
|
|
|
|
wx.redirectTo({
|
|
|
|
url: '/pages/toRegister/toRegister'
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
that.initLoad()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
console.log('登录失败' + res.errMsg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取banner列表
|
|
|
|
getBannerList () {
|
|
|
|
api.bannerList('0').then(res => {
|
|
|
|
console.log('首页banner列表', res)
|
|
|
|
this.setData({
|
|
|
|
bannerList: res.data
|
|
|
|
})
|
|
|
|
}).catch(() => {
|
|
|
|
console.log('获取banner列表失败')
|
|
|
|
this.setData({
|
|
|
|
bannerList: []
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取新闻列表
|
|
|
|
getNewsList () {
|
|
|
|
let para = {
|
|
|
|
pageIndex: this.data.pageNo,
|
|
|
|
pageSize: this.data.pageSize,
|
|
|
|
timestamp: this.data.timestamp,
|
|
|
|
categoryCode:""
|
|
|
|
}
|
|
|
|
api.newsList(para).then((res) => {
|
|
|
|
console.log('首页新闻列表', res)
|
|
|
|
this.setData({
|
|
|
|
loadMoreType: res.data.length === this.data.pageSize ? 'loading': 'none',
|
|
|
|
newsList: this.data.newsList.concat(res.data)
|
|
|
|
})
|
|
|
|
}).catch(() => {
|
|
|
|
console.log('首页新闻列表获取失败')
|
|
|
|
this.setData({
|
|
|
|
loadMoreType: 'none',
|
|
|
|
newsList: []
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取项目列表
|
|
|
|
getProjectList () {
|
|
|
|
const para = {
|
|
|
|
pageIndex: 1,
|
|
|
|
pageSize: 10,
|
|
|
|
timestamp: this.data.timestamp,
|
|
|
|
searchContent: '',
|
|
|
|
firstCategoryCode: ''
|
|
|
|
}
|
|
|
|
api.getProjectList(para).then(res => {
|
|
|
|
console.log('项目列表', res)
|
|
|
|
this.setData({
|
|
|
|
projectList: res.data,
|
|
|
|
})
|
|
|
|
}).catch(() => {
|
|
|
|
console.log('获取项目列表失败', res)
|
|
|
|
this.setData({
|
|
|
|
projectList: []
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取最新一条消息-主要获取消息未读数
|
|
|
|
getUnreadNum () {
|
|
|
|
api.getFirstInfo().then(res => {
|
|
|
|
console.log('获取消息未读数', res)
|
|
|
|
this.setData({
|
|
|
|
unReadNum: res.data.amount
|
|
|
|
})
|
|
|
|
}).catch(() => {
|
|
|
|
console.log('获取消息未读数失败')
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 获取消息列表
|
|
|
|
getInfoList() {
|
|
|
|
let para = {
|
|
|
|
pageIndex: 1,
|
|
|
|
pageSize: 10,
|
|
|
|
timestamp: this.data.timestamp
|
|
|
|
}
|
|
|
|
homeApi.getInfoList(para).then(res => {
|
|
|
|
console.log('消息列表', res)
|
|
|
|
this.setData({
|
|
|
|
infoList: res.data
|
|
|
|
})
|
|
|
|
}).catch((err) => {
|
|
|
|
console.log('获取消息列表失败')
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 九宫格检查状态
|
|
|
|
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(() => {
|
|
|
|
console.log('获取九宫格状态失败')
|
|
|
|
this.setData({
|
|
|
|
sudokuState: {
|
|
|
|
consultAvailable: '0',
|
|
|
|
appraiseAvailable: '0'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 跳转到互帮互助
|
|
|
|
navigateToHeart () {
|
|
|
|
if (app.globalData.infoCompleted == 0) {
|
|
|
|
this.setData({
|
|
|
|
completeInfoDialogVisible: !this.data.completeInfoDialogVisible
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
wx.navigateTo({
|
|
|
|
url: '/pages/heart/heart'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 跳转到左邻右舍
|
|
|
|
navigateToAssociation() {
|
|
|
|
if (app.globalData.infoCompleted == 0) {
|
|
|
|
this.setData({
|
|
|
|
completeInfoDialogVisible: !this.data.completeInfoDialogVisible
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
wx.switchTab({
|
|
|
|
url: '/pages/association/association',
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 跳转到有么说么
|
|
|
|
navigateToDiscussion () {
|
|
|
|
wx.switchTab({
|
|
|
|
url: '/pages/discussion/discussion'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 跳转到物业服务
|
|
|
|
navigateToProperty () {
|
|
|
|
// if (app.globalData.infoCompleted == 0) {
|
|
|
|
// this.setData({
|
|
|
|
// completeInfoDialogVisible: !this.data.completeInfoDialogVisible
|
|
|
|
// })
|
|
|
|
// return false
|
|
|
|
// }
|
|
|
|
wx.switchTab({
|
|
|
|
url: '/pages/property/property'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
navigateToSafe(){
|
|
|
|
wx.navigateTo({
|
|
|
|
url: '/subpages/safety/pages/index/index',
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 初始化加载
|
|
|
|
initLoad () {
|
|
|
|
this.setData({
|
|
|
|
pageNo: 1,
|
|
|
|
pageSize: 10,
|
|
|
|
timestamp: getTimestamp(),
|
|
|
|
newsList: [],
|
|
|
|
loadMoreType: 'loading',
|
|
|
|
loadMoreVisible: false
|
|
|
|
})
|
|
|
|
this.getBannerList()
|
|
|
|
this.getIndexSudokuState()
|
|
|
|
this.getProjectList()
|
|
|
|
this.getInfoList()
|
|
|
|
this.getUnreadNum()
|
|
|
|
this.getNewsList()
|
|
|
|
},
|
|
|
|
// 切换网格,跳转到网格列表
|
|
|
|
changeGrid() {
|
|
|
|
wx.navigateTo({ url: '/subpages/changegrid/pages/changeGrid/changeGrid' })
|
|
|
|
},
|
|
|
|
// 跳转到新闻详情
|
|
|
|
navigatetoNewsDetail (e) {
|
|
|
|
wx.navigateTo({ url: `/subpages/home/pages/newsDetail/newsDetail?id=${e.detail.newsId}` })
|
|
|
|
},
|
|
|
|
// 跳转到 项目详情
|
|
|
|
navigatetoItemDetail (e) {
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `/subpages/discussion/pages/discussionDetail/discussionDetail?type=project&detailId=${e.detail.itemId}&showClassify=show`
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 跳转到消息列表
|
|
|
|
navigateToInfoList () {
|
|
|
|
wx.navigateTo({ url: '/subpages/home/pages/info/info' })
|
|
|
|
},
|
|
|
|
// 跳转到banner详情
|
|
|
|
navigatetoBannerDetail (e) {
|
|
|
|
const { id, url, newsFlag } = e.detail
|
|
|
|
if (newsFlag == '0') {
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `/subpages/home/pages/webview/webview?url=${url}`
|
|
|
|
})
|
|
|
|
} else if (newsFlag == '1') {
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `/subpages/home/pages/newsDetail/newsDetail?id=${id}`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
//政策法规
|
|
|
|
navigateToPolicy(){
|
|
|
|
wx.navigateTo({
|
|
|
|
url: '/subpages/home/pages/notice/notice'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
//社区教育
|
|
|
|
navigateToEducation(){
|
|
|
|
wx.navigateTo({
|
|
|
|
url: '/subpages/education/pages/index/index'
|
|
|
|
})
|
|
|
|
},
|
|
|
|
navigateToSynthetical(){
|
|
|
|
wx.navigateTo({
|
|
|
|
url: '/subpages/education/pages/healthyLife/healthyLife?page=zhfw'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|