const api = require("../../utils/api") import { getTimestamp } from "../../utils/common" import regeneratorRuntime from "../../utils/runtime.js" const app = getApp() Page({ data: { selectedTabBar: "issue", pageNo: 1, pageSize: 10, timestamp: "", issueList: [], projectList: [], topicList: [], nomoreVisible: false, nomoreStatus: "loading", preloadVisible: true, userInfo: { faceImg: "", nickname: "", partyFlag: "" }, completeInfoDialogVisible: false, showFlagDialogVisible: false, infoCompleted: 0, standardbearerStatus: "" // 亮旗状态 '0'不是党员;'1'党员,首次申请亮旗;'2'已是亮旗党员;'3'党员,亮旗申请未通过 '4'等待审核中 }, onLoad () { this.getUserInfo() this.standardbearerStatus() this.setData({ infoCompleted: app.globalData.infoCompleted }) }, onShow () { if (!app.globalData.previewImage) { this.data.pageNo = 1 this.data.pageSize = 10 this.setData({ nomoreVisible: false, nomoreStatus: "loading", preloadVisible: true }) if (this.data.selectedTabBar === "issue") { this.getIssueList() } else if (this.data.selectedTabBar === "project") { this.getProjectList() } else if (this.data.selectedTabBar === "topic") { this.getTopicList() } } app.globalData.previewImage = false }, // 触底 上拉加载 onReachBottom() { this.setData({ nomoreVisible: true }) if (this.data.selectedTabBar === "topic") { if (this.data.nomoreStatus === "loading") { this.data.pageNo = this.data.pageNo + 1 this.loadMoreTopicList() } else { this.setData({ nomoreVisible: true }) } } else if (this.data.selectedTabBar === "project") { if (this.data.nomoreStatus === "loading") { this.data.pageNo = this.data.pageNo + 1 this.loadMoreProjectList() } else { this.setData({ nomoreVisible: true }) } } }, // tab 切换 chooseTabBar (e) { this.setData({ nomoreVisible: false, nomoreStatus: "loading", preloadVisible: true }) this.data.pageNo = 1 this.data.pageSize = 10 if (e.currentTarget.dataset.type === "issue") { this.getIssueList() } else if (e.currentTarget.dataset.type === "project") { this.data.pageNo = 1 this.data.pageSize = 10 this.getProjectList() } else if (e.currentTarget.dataset.type === "topic") { this.getTopicList() } this.setData({ selectedTabBar: e.currentTarget.dataset.type }) }, // 获取 我的话题列表 getTopicList () { this.setData({ topicList: [] }) const para = { pageIndex: this.data.pageNo, pageSize: this.data.pageSize } api.getMyTopicList(para).then(res => { console.log("我的话题列表", res) this.setData({ topicList: [...res.data], nomoreStatus: res.data.length === 10 ? "loading" : "none", preloadVisible: false }) }).catch(err => { this.setData({ topicList: [], nomoreStatus: "none", preloadVisible: false }) console.log(err) }) }, // 获取 我的话题列表 上拉加载 loadMoreTopicList () { const para = { pageIndex: this.data.pageNo, pageSize: this.data.pageSize } api.getMyTopicList(para).then(res => { console.log("我的话题列表", res) const topicList = [...this.data.topicList, ...res.data] this.setData({ nomoreStatus: res.data.length === 10 ? "loading" : "none", preloadVisible: false, topicList, }) }).catch(err => { this.setData({ topicList: [], nomoreStatus: "none", preloadVisible: false }) console.log(err) }) }, // 获取 我的议题列表 getIssueList () { this.setData({ issueList: [] }) api.getMyIssueList().then(res => { console.log("我的议题列表", res) this.setData({ issueList: [...res.data], nomoreStatus: "none", preloadVisible: false }) }).catch(err => { this.setData({ issueList: [], nomoreStatus: "none", preloadVisible: false }) console.log(err) }) }, // 获取 我的项目列表 getProjectList () { this.setData({ projectList: [] }) this.data.timestamp = getTimestamp() const para = { pageIndex: this.data.pageNo, pageSize: this.data.pageSize, timestamp: this.data.timestamp } api.getMyProjectList(para).then(res => { console.log("我的项目列表", res) this.setData({ projectList: [...res.data], nomoreStatus: res.data.length === 10 ? "loading" : "none", preloadVisible: false }) }).catch(err => { this.setData({ projectList: [], nomoreStatus: "none", preloadVisible: false }) console.log(err) }) }, // 获取 我的项目列表 上拉加载 loadMoreProjectList () { const para = { pageIndex: this.data.pageNo, pageSize: this.data.pageSize, timestamp: this.data.timestamp } api.getMyProjectList(para).then(res => { console.log("我的项目列表", res) const projectList = [...this.data.projectList,...res.data] this.setData({ nomoreStatus: res.data.length === 10 ? "loading" : "none", preloadVisible: false, projectList, }) }).catch(err => { this.setData({ projectList: [], nomoreStatus: "none", preloadVisible: false }) console.log(err) }) }, // 获取用户信息 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) }) }, // 完善信息 navigateToComplete () { wx.navigateTo({ url: "/pages/complete/complete" }) }, // 跳转积分商城 navigateToShopH5() { wx.navigateTo({ url: "/subpages/integralCentre/pages/eshop/eshop" }) }, // 党员亮旗状态查询 standardbearerStatus () { api.standardbearerStatus().then(res => { this.setData({ standardbearerStatus: res.data.status }) console.log("this.data.standardbearerStatus:::", this.data.standardbearerStatus) }).catch(err => { console.log(err) }) }, // 申请亮旗 navigateToShowFlag() { if (this.data.standardbearerStatus === "1" || this.data.standardbearerStatus === "3") { // '1'党员,首次申请亮旗;'3'党员,亮旗申请未通过 wx.showLoading({ title: "正在申请亮旗", }) api.standardbearerApply().then(res => { console.log("申请亮旗", res) wx.hideLoading() this.setData({ showFlagDialogVisible: !this.data.showFlagDialogVisible }) this.standardbearerStatus() }).catch(err => { wx.hideLoading() wx.showToast({ title: "申请亮旗失败", icon: "none", duration: 2000 }) }) } else { wx.showToast({ title: "申请亮旗审核中", icon: "none", duration: 2000 }) } }, // 议题列表 跳转详情 toIssueDetail (e) { const { issueId, state } = e.detail if (state !== "待审核" && state !== "未通过") { wx.navigateTo({ url: `/subpages/discussion/pages/discussionDetail/discussionDetail?type=issue&detailId=${issueId}` }) } else if (state === "待审核" || state === "未通过") { wx.navigateTo({ url: `/subpages/mine/pages/eventDetail/eventDetail?eventId=${issueId}&eventType=${state}` }) } }, // 项目列表 跳转详情 toProjectDetail (e) { const { itemId } = e.detail wx.navigateTo({ url: `/subpages/discussion/pages/discussionDetail/discussionDetail?type=project&detailId=${itemId}` }) }, // 话题列表 跳转详情 toTopicDetail (e) { const { topicId } = e.detail wx.navigateTo({ url: `/subpages/association/pages/topicDetail/topicDetail?detailId=${topicId}` }) }, // 我要报事 addIssue () { if (this.data.infoCompleted == 0) { this.setData({ completeInfoDialogVisible: !this.data.completeInfoDialogVisible }) return false } wx.navigateTo({ url: "/subpages/discussion/pages/addIssue/addIssue" }) }, // 跳转到 邀请记录 navigateToInviteRecord () { wx.navigateTo({ url: "/subpages/mine/pages/inviteRecord/inviteRecord" }) }, // 跳转到 网格管理 navigateToGridManage () { wx.navigateTo({ url: "/subpages/mine/pages/gridManage/gridManage" }) }, //下拉刷新 async onPullDownRefresh(){ console.log("下拉刷新") if (this.data.selectedTabBar === "issue") { await this.getIssueList() } else if (this.data.selectedTabBar === "project") { this.data.pageNo = 1 this.data.pageSize = 10 await this.getProjectList() } else if (this.data.selectedTabBar === "topic") { await this.getTopicList() } wx.stopPullDownRefresh(); }, })