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

226 lines
6.6 KiB

const app = getApp()
const api = require("../../utils/api")
const homeApi = require("../../utils/home")
const global = require("../../utils/config")
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: { // 九宫格显隐状态
consultAvailabel: "0", // 网格力量
appraiseAvailabel: "0", // 请您监督,
talkAndNeedAndPartyAvaliable: "0" // 随时讲、需求清单、党群服务中心
},
completeInfoDialogVisible: false, // 完善信息弹框显隐
gridId: "", // 网格id
departmentName: "", // 所在网格
departmentId: "", //1191534416067149825所在网格id
street: "", //所在街道
isCarryLoad: false,
userId: "",
// userInfo: {
// nickname: "",
// mobile: "",
// faceImg: ""
// },
visible: false,
signMsg: "",
signCode: 0,
isSignUp: 0,
communityId: "", // 社区id
},
onLoad() {
this.initLoad();
this.setData({
statusHeight: app.globalData.deviceInfo.statusHeight,
navigationHeight: app.globalData.deviceInfo.navigationHeight,
});
// 检查版本更新
checkoutVersion();
this.data.isCarryLoad = true;
},
onShow() {},
onHide() {
let token = wx.getStorageSync("token")
if (!token) {
wx.reLaunch({
url: '/pages/login/login'
})
}
},
onReachBottom() {
this.setData({
loadMoreVisible: true
});
if (this.data.loadMoreType === "loading") {
this.data.pageNo += 1
}
},
handleXinxin() {
wx.navigateToMiniProgram({
appId: 'wxf09c0e08ffee7711',
path: 'pages/home/home',
envVersion: 'release',
extraData: {},
success(res) {
// 打开成功
}
})
},
// 获取小程序用户登录日志
async getUserLoginlog() {
let data = {
userId: this.data.userId
}
await api.userLoginlog(data)
},
// 获取最新一条消息-主要获取消息未读数
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("获取消息列表失败")
})
},
// 获取完整机构
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() {
this.setData({
pageNo: 1,
pageSize: 10,
newsList: [],
loadMoreType: "loading",
loadMoreVisible: false
})
this.getUserInfo()
},
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 => {
let userInfoString = JSON.stringify(res.data);
wx.setStorageSync('userInfo', userInfoString);
}).catch(err => {
this.setData({
userInfo: {
faceImg: "",
nickname: "",
partyFlag: "0",
isSignUp: 0
}
})
wx.reLaunch({
url: '/pages/login/login'
})
})
}
})