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

125 lines
3.0 KiB

const api = require("../../utils/api")
const app = getApp()
Page({
data: {
name: "社群",
associationType: "my-association",
userInfo: {
nickname: "",
partyFlag: ""
},
myAssociationList: [],
commandAssociationList: [],
nomoreVisible: false,
noDataVisible: true,
gridName: ""
},
onShow () {
this.setData({
nomoreVisible: false,
noDataVisible: true
})
if (this.data.associationType === "my-association") {
if (!app.globalData.previewImage) {
this.getMyAssociation()
}
} else if (this.data.associationType === "command-association") {
if (!app.globalData.previewImage) {
this.getCommandAssociation()
}
}
app.globalData.previewImage = false
},
onLoad () {
this.getUserInfo()
const gridName = wx.getStorageSync("topGridName")
this.setData({
gridName
})
},
onReachBottom () {
if (!this.data.nomoreVisible) {
this.setData({
nomoreVisible: true
})
}
},
// 我的群 和 推荐群 切换
associationChange (e) {
this.setData({
nomoreVisible: false,
noDataVisible: true
})
const type = e.currentTarget.dataset.type
if (type === "my-association") {
this.getMyAssociation()
this.setData({
associationType: "my-association"
})
} else if (type === "command-association") {
this.getCommandAssociation()
this.setData({
associationType: "command-association"
})
}
},
// 创建群跳转页面
navigateToCreate () {
wx.navigateTo({
url: `/subpages/association/pages/createassociation/createassociation?nickname=${this.data.userInfo.nickname}&partyFlag=${this.data.userInfo.partyFlag}`
})
},
// 获取个人信息
getUserInfo () {
api.getUserInfo().then(res => {
const { nickname, partyFlag } = res.data
app.globalData.userInfo = {
userId: res.data.id,
username: res.data.nickname,
userMobile: res.data.mobile,
partyFlag: res.data.partyFlag
}
this.setData({
userInfo: Object.assign(this.data.userInfo, { nickname, partyFlag: partyFlag})
})
}).catch(err => {
console.log(err)
})
},
// 推荐群列表
getCommandAssociation () {
this.setData({
commandAssociationList: []
})
api.getCommandAssociation().then(res => {
console.log("推荐群列表", res)
this.setData({
commandAssociationList: res.data,
noDataVisible: false
})
}).catch(err => {
this.setData({
noDataVisible: false
})
console.log(err)
})
},
// 我的群列表
getMyAssociation () {
this.setData({
myAssociationList: []
})
api.getMyAssociation().then(res => {
console.log("我的群列表", res)
this.setData({
myAssociationList: res.data,
noDataVisible: false
})
}).catch(err => {
this.setData({
noDataVisible: false
})
console.log(err)
})
}
})