锦水居民端小程序
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.

317 lines
7.8 KiB

6 years ago
const api = require('../../utils/api')
5 years ago
import {
getTimestamp
} from '../../utils/common'
6 years ago
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: '',
points:0,
grade:0
6 years ago
},
completeInfoDialogVisible: false,
infoCompleted: 0
},
5 years ago
onLoad() {
6 years ago
this.getUserInfo()
this.setData({
infoCompleted: app.globalData.infoCompleted
})
},
5 years ago
onShow() {
6 years ago
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()
5 years ago
} else if (this.data.selectedTabBar === 'topic') {
6 years ago
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 切换
5 years ago
chooseTabBar(e) {
6 years ago
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()
5 years ago
}
6 years ago
this.setData({
selectedTabBar: e.currentTarget.dataset.type
})
},
// 获取 我的话题列表
5 years ago
getTopicList() {
6 years ago
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)
})
},
// 获取 我的话题列表 上拉加载
5 years ago
loadMoreTopicList() {
6 years ago
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)
})
},
// 获取 我的议题列表
5 years ago
getIssueList() {
6 years ago
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)
})
},
// 获取 我的项目列表
5 years ago
getProjectList() {
6 years ago
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)
})
},
// 获取 我的项目列表 上拉加载
5 years ago
loadMoreProjectList() {
6 years ago
const para = {
pageIndex: this.data.pageNo,
pageSize: this.data.pageSize,
timestamp: this.data.timestamp
}
api.getMyProjectList(para).then(res => {
console.log('我的项目列表', res)
5 years ago
const projectList = [...this.data.projectList, ...res.data]
6 years ago
this.setData({
nomoreStatus: res.data.length === 10 ? 'loading' : 'none',
preloadVisible: false,
projectList,
})
}).catch(err => {
this.setData({
projectList: [],
nomoreStatus: 'none',
preloadVisible: false
})
console.log(err)
})
},
// 获取用户信息
5 years ago
getUserInfo() {
6 years ago
api.getUserInfo().then(res => {
console.log('用户信息', res)
const userInfo = {}
5 years ago
for (const key in this.data.userInfo) {
6 years ago
userInfo[key] = res.data[key]
}
this.setData({
userInfo
})
}).catch(err => {
this.setData({
userInfo: {
faceImg: '',
nickname: '',
partyFlag: '0',
points:0,
grade:0
6 years ago
}
})
console.log(err)
})
},
// 完善信息
5 years ago
navigateToComplete() {
6 years ago
wx.navigateTo({
url: '/pages/complete/complete'
})
},
// 议题列表 跳转详情
5 years ago
toIssueDetail(e) {
const {
issueId,
state
} = e.detail
6 years ago
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}`
})
}
},
// 项目列表 跳转详情
5 years ago
toProjectDetail(e) {
const {
itemId
} = e.detail
6 years ago
wx.navigateTo({
url: `/subpages/discussion/pages/discussionDetail/discussionDetail?type=project&detailId=${itemId}`
})
},
// 话题列表 跳转详情
5 years ago
toTopicDetail(e) {
const {
topicId
} = e.detail
6 years ago
wx.navigateTo({
url: `/subpages/association/pages/topicDetail/topicDetail?detailId=${topicId}`
})
},
// 我有事说
5 years ago
addIssue() {
6 years ago
if (this.data.infoCompleted == 0) {
this.setData({
completeInfoDialogVisible: !this.data.completeInfoDialogVisible
})
return false
}
wx.navigateTo({
url: '/subpages/discussion/pages/addIssue/addIssue'
})
},
// 跳转到 邀请记录
5 years ago
navigateToInviteRecord() {
6 years ago
wx.navigateTo({
url: '/subpages/mine/pages/inviteRecord/inviteRecord'
})
},
// 跳转到 网格管理
5 years ago
navigateToGridManage() {
6 years ago
wx.navigateTo({
url: '/subpages/mine/pages/gridManage/gridManage'
})
5 years ago
},
//跳转到积分中心
navigateToIntegralCentre(e) {
console.log(':::::'+e.currentTarget.dataset.points)
5 years ago
wx.navigateTo({
url: `/subpages/integralCentre/pages/index/index?points=` + e.currentTarget.dataset.points
5 years ago
})
6 years ago
}
})