市北党建引领小程序初始化
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.

296 lines
8.4 KiB

2 years ago
2 years ago
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: { // 九宫格显隐状态
consultAvailabel: "0", // 网格力量
appraiseAvailabel: "0", // 请您监督,
2 years ago
talkAndNeedAndPartyAvaliable: "0" // 随时讲、需求清单、党群服务中心
},
completeInfoDialogVisible: false, // 完善信息弹框显隐
gridId: "", // 网格id
departmentName: "", // 所在网格
departmentId: "",//1191534416067149825所在网格id
street: "",//所在街道
isCarryLoad: false,
userId: "",
2 years ago
// userInfo: {
// nickname: "",
// mobile: "",
// faceImg: ""
// },
2 years ago
visible: false,
signMsg: "",
signCode: 0,
isSignUp: 0,
2 years ago
communityId: "", // 社区id
2 years ago
},
2 years ago
2 years ago
async onLoad(options) {
wx.showLoading({
title: "加载中,请稍后",
mask: true
})
this.setData({
statusHeight: app.globalData.deviceInfo.statusHeight,
navigationHeight: app.globalData.deviceInfo.navigationHeight,
})
await this.getUserState()
this.data.isCarryLoad = true
},
onTabItemTap() {
this.getUserState()
},
onShow() {
// 检查版本更新
checkoutVersion()
// this.getFirstInfo()
2 years ago
},
onReachBottom() {
this.setData({
loadMoreVisible: true
})
if (this.data.loadMoreType === "loading") {
this.data.pageNo += 1
// this.getNewsList()
2 years ago
}
},
// 根据微信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)
wx.setStorageSync("userId", res.data.userId)
2 years ago
that.setData({
departmentName: res.data.grid,
departmentId: res.data.gridId,
userId: res.data.userId
})
// that.getComplete()
// that.getUserLoginlog()
if (state == "4") {
2 years ago
// 非扫码进入,通过搜索小程序直接进入的情况
if (wx.getStorageSync("shareObj")) {
const para = JSON.parse(wx.getStorageSync("shareObj"))
app.globalData.tempGridId = "1222489495054602241"
2 years ago
wx.redirectTo({
url: "/pages/formid/formid?gid=1222489495054602241"
2 years ago
})
} else {
wx.redirectTo({
url: "/pages/formid/formid?gid=1222489495054602241"
2 years ago
})
}
} 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)
}
}
})
},
2 years ago
handleXinxin(){
wx.navigateToMiniProgram({
appId: 'wxf09c0e08ffee7711',
path: 'pages/home/home',
2 years ago
envVersion: 'release',
extraData:{},
2 years ago
success(res) {
// 打开成功
}
})
},
2 years ago
// 获取小程序用户登录日志
async getUserLoginlog() {
let data = {
userId: this.data.userId
}
await api.userLoginlog(data)
},
2 years ago
// 获取最新一条消息-主要获取消息未读数
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(() => {
console.log("获取消息列表失败")
})
},
2 years ago
// 获取完整机构
getComplete() {
api.getComplete(this.data.departmentId).then((res) => {
this.setData({
street: res.data.street,
departmentId: res.data.gridId,
communityId: res.data.communityId
})
}).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() {
// timestamp: getTimestamp(),
2 years ago
this.setData({
pageNo: 1,
pageSize: 10,
newsList: [],
loadMoreType: "loading",
loadMoreVisible: false
})
// this.getBannerList()
// this.getIndexSudokuState()
// this.getProjectList()
// this.getInfoList()
// this.getUnreadNum()
// this.getNewsList()
2 years ago
this.getUserInfo()
// this.getAppMenu()
2 years ago
},
// 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)
let userInfoString = JSON.stringify(res.data);
wx.setStorageSync('userInfo', userInfoString);
2 years ago
}).catch(err => {
this.setData({
userInfo: {
faceImg: "",
nickname: "",
partyFlag: "0",
isSignUp: 0
}
})
console.log(err)
})
2 years ago
},
2 years ago
})