You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
427 lines
12 KiB
427 lines
12 KiB
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'
|
|
import regeneratorRuntime from '../../utils/runtime.js'
|
|
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: '', // 所在网格
|
|
departmentId: '',//1191534416067149825所在网格id
|
|
street: '',//所在街道
|
|
isCarryLoad: false,
|
|
userId: "",
|
|
userInfo: {
|
|
nickname: '',
|
|
mobile: '',
|
|
faceImg: ''
|
|
},
|
|
},
|
|
async onLoad(options) {
|
|
wx.showLoading({
|
|
title: '加载中,请稍后',
|
|
mask: true
|
|
})
|
|
if (options.shareType) {
|
|
const para = {
|
|
shareType: options.shareType,
|
|
detailId: options.detailId,
|
|
infoCompleted: options.infoCompleted ? options.infoCompleted : '',
|
|
type: options.detailType ? options.detailType : '',
|
|
showClassify: options.showClassify ? options.showClassify : '',
|
|
nowGridId: options.nowGridId ? options.nowGridId : ''
|
|
}
|
|
wx.setStorageSync("shareObj", JSON.stringify(para))
|
|
}
|
|
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,
|
|
})
|
|
}
|
|
|
|
// 切换网格的时候,更换网格id
|
|
if (options.departmentId) {
|
|
this.setData({
|
|
departmentId: options.departmentId
|
|
})
|
|
}
|
|
await this.getUserState()
|
|
this.data.isCarryLoad = true
|
|
|
|
},
|
|
onTabItemTap() {
|
|
this.getUserState()
|
|
},
|
|
onShow() {
|
|
// 检查版本更新
|
|
checkoutVersion()
|
|
this.getFirstInfo()
|
|
},
|
|
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 => {
|
|
wx.hideLoading()
|
|
const state = res.data.userState
|
|
app.globalData.infoCompleted = state
|
|
wx.setStorageSync('topGridName', res.data.grid)
|
|
wx.setStorageSync('gridId', res.data.gridId) //当前网格id,新闻、议题、项目分享时用
|
|
wx.setStorageSync('token', res.data.token)
|
|
that.setData({
|
|
departmentName: res.data.grid,
|
|
departmentId: res.data.gridId,
|
|
userId: res.data.userId
|
|
})
|
|
that.getComplete()
|
|
that.getUserLoginlog()
|
|
// 扫码进入
|
|
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') {
|
|
// 非扫码进入,通过搜索小程序直接进入的情况
|
|
if (wx.getStorageSync("shareObj")) {
|
|
const para = JSON.parse(wx.getStorageSync("shareObj"))
|
|
wx.redirectTo({
|
|
url: "/pages/formid/formid?gid=" + para.nowGridId
|
|
})
|
|
} else {
|
|
wx.redirectTo({
|
|
url: '/pages/toRegister/toRegister'
|
|
})
|
|
}
|
|
} else {
|
|
if (wx.getStorageSync("shareObj")) {
|
|
const para = JSON.parse(wx.getStorageSync("shareObj"))
|
|
if (para.shareType === 'newsDetail') {
|
|
wx.navigateTo({
|
|
url: `/subpages/home/pages/newsDetail/newsDetail?id=${para.detailId}`
|
|
})
|
|
} else if (para.shareType === 'discussionDetail') {
|
|
wx.navigateTo({
|
|
url: `/subpages/discussion/pages/discussionDetail/discussionDetail?detailId=${para.detailId}&type=${para.type}&showClassify=${para.showClassify}`
|
|
})
|
|
}
|
|
wx.removeStorageSync("shareObj")
|
|
}
|
|
that.initLoad()
|
|
}
|
|
}
|
|
})
|
|
} else {
|
|
console.log('登录失败' + res.errMsg)
|
|
}
|
|
}
|
|
})
|
|
},
|
|
// 获取小程序用户登录日志
|
|
async getUserLoginlog() {
|
|
let data = {
|
|
userId: this.data.userId
|
|
}
|
|
let res = await api.userLoginlog(data)
|
|
},
|
|
// 获取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
|
|
}
|
|
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'
|
|
}
|
|
})
|
|
})
|
|
},
|
|
// 跳转到我要报事
|
|
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'
|
|
})
|
|
},
|
|
// 获取完整机构
|
|
getComplete() {
|
|
api.getComplete(this.data.departmentId).then((res) => {
|
|
this.setData({
|
|
street: res.data.street,
|
|
departmentId: res.data.gridId
|
|
})
|
|
}).catch((err) => {
|
|
console.log(err)
|
|
})
|
|
},
|
|
// 跳转到请您监督
|
|
navigatetoAppraise() {
|
|
if (app.globalData.infoCompleted == 0) {
|
|
this.setData({
|
|
completeInfoDialogVisible: !this.data.completeInfoDialogVisible
|
|
})
|
|
return false
|
|
}
|
|
const token = wx.getStorageSync('token')
|
|
// https://lyljdgs.qingdaoshibei.cn/app/mobileapp/mszj/index.aspx?deptName=延安路街道&gridId=123467521122
|
|
wx.navigateTo({
|
|
url: `/subpages/home/pages/webview/webview?url=${global.WEBROOT()}&token=${token}&deptName=${this.data.street}&gridId=${this.data.departmentId}`
|
|
})
|
|
},
|
|
// 初始化加载
|
|
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()
|
|
this.getUserInfo()
|
|
},
|
|
onShow() {
|
|
this.getUnreadNum()
|
|
},
|
|
// 切换网格,跳转到网格列表
|
|
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}`
|
|
})
|
|
}
|
|
},
|
|
getFirstInfo() {
|
|
api.getFirstInfo().then((res) => {
|
|
console.log('infoObj', res.data)
|
|
})
|
|
},
|
|
//下拉刷新
|
|
async onPullDownRefresh() {
|
|
await this.initLoad()
|
|
wx.stopPullDownRefresh();
|
|
},
|
|
// 获取用户信息
|
|
getUserInfo() {
|
|
api.getUserInfo().then(res => {
|
|
console.log('用户信息', res)
|
|
const userInfo = {}
|
|
for (const key in this.data.userInfo) {
|
|
userInfo[key] = res.data[key]
|
|
}
|
|
this.setData({
|
|
userInfo
|
|
})
|
|
}).catch(err => {
|
|
this.setData({
|
|
userInfo: {
|
|
faceImg: '',
|
|
nickname: '',
|
|
partyFlag: '0'
|
|
}
|
|
})
|
|
console.log(err)
|
|
})
|
|
},
|
|
})
|
|
|
|
|