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

153 lines
3.7 KiB

const api = require('../../utils/api')
import regeneratorRuntime from '../../utils/runtime.js'
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
})
},
goToMinapps() {
wx.navigateToMiniProgram({
appId: 'wx9f20a46906ab2c3e',
path: '',
envVersion: 'release',// 打开正式版ß
success(res) {
// 打开成功
console.log('点击允许')
},
fail: function (err) {
console.log(err);
}
})
},
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)
})
},
//下拉刷新
async onPullDownRefresh(){
if (this.data.associationType === 'my-association') {
if (!app.globalData.previewImage) {
await this.getMyAssociation()
}
} else if (this.data.associationType === 'command-association') {
if (!app.globalData.previewImage) {
await this.getCommandAssociation()
}
}
wx.stopPullDownRefresh();
},
})