const app = getApp() const api = require("../../utils/api") const homeApi = require("../../utils/home") const global = require("../../utils/config") 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", // 请您监督, 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 }, 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() }, 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) wx.setStorageSync("userId", res.data.userId) that.setData({ departmentName: res.data.grid, departmentId: res.data.gridId, userId: res.data.userId }) // that.getComplete() // that.getUserLoginlog() if (state == "4") { // 非扫码进入,通过搜索小程序直接进入的情况 if (wx.getStorageSync("shareObj")) { const para = JSON.parse(wx.getStorageSync("shareObj")) app.globalData.tempGridId = "1222489495054602241" wx.redirectTo({ url: "/pages/formid/formid?gid=1222489495054602241" }) } else { wx.redirectTo({ url: "/pages/formid/formid?gid=1222489495054602241" }) } } 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) } } }) }, 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() { // timestamp: getTimestamp(), this.setData({ pageNo: 1, pageSize: 10, newsList: [], loadMoreType: "loading", loadMoreVisible: false }) // this.getBannerList() // this.getIndexSudokuState() // this.getProjectList() // this.getInfoList() // this.getUnreadNum() // this.getNewsList() this.getUserInfo() // this.getAppMenu() }, // 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 => { let userInfoString = JSON.stringify(res.data); wx.setStorageSync('userInfo', userInfoString); }).catch(err => { this.setData({ userInfo: { faceImg: "", nickname: "", partyFlag: "0", isSignUp: 0 } }) console.log(err) }) } })