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.
441 lines
12 KiB
441 lines
12 KiB
2 years ago
|
import request from "../../config/rerquest";
|
||
|
import { doAfterLogin, loginGrid } from "../../utils/tools";
|
||
|
import { wxGetUserProfile, wxRequestPost } from "@utils/promise-wx-api";
|
||
|
|
||
|
const app = getApp();
|
||
|
|
||
|
Component({
|
||
|
properties: {},
|
||
|
data: {
|
||
|
iniLoaded: false,
|
||
|
|
||
|
isRefresh: false,
|
||
|
associationType: "my-group",
|
||
|
pageSize: 20,
|
||
|
mygroupPageNo: 1,
|
||
|
recommandgroupPageNo: 1,
|
||
|
allPageNo: 1,
|
||
|
myGroupList: [],
|
||
|
myGroupMore: false,
|
||
|
recommandGroupMore: false,
|
||
|
allGroupMore: false,
|
||
|
recommandGroupList: [],
|
||
|
allGroupList: [],
|
||
|
achieveList: [],
|
||
|
nomoreVisible: false,
|
||
|
noDataVisible: true,
|
||
|
loadMoreType: "loading",
|
||
|
loadMoreVisible: false,
|
||
|
showDialog: false,
|
||
|
visible: false,
|
||
|
completeInfoDialogVisible: false,
|
||
|
tabsList: [
|
||
|
{
|
||
|
type: "my-group",
|
||
|
name: "我的小组",
|
||
|
img: "../../assets/images/group/mine.png",
|
||
|
},
|
||
|
{
|
||
|
type: "all-group",
|
||
|
name: "所有小组",
|
||
|
img: "../../assets/images/group/suoyou.png",
|
||
|
},
|
||
|
{
|
||
|
type: "top-group",
|
||
|
name: "小组排名",
|
||
|
img: "../../assets/images/group/grail.png",
|
||
|
},
|
||
|
],
|
||
|
achieveTipsList: [], // 小组成就通告
|
||
|
},
|
||
|
lifetimes: {
|
||
|
ready: async function () {
|
||
|
console.log("ready");
|
||
|
await doAfterLogin();
|
||
|
// await loginGrid()
|
||
|
// this.refreshData();
|
||
|
// 重新执行一次进网格的操作,以获取最新的用户角色
|
||
|
// this.setData({
|
||
|
// iniLoaded: true,
|
||
|
// nomoreVisible: false,
|
||
|
// noDataVisible: true
|
||
|
// })
|
||
|
// this.getMyAssociation()
|
||
|
// this.getCommandAssociation()
|
||
|
|
||
|
// if (this.data.associationType === 'my-group') {
|
||
|
// console.log('my-group')
|
||
|
// if (!app.globalData.previewImage) {
|
||
|
// this.getMyAssociation()
|
||
|
// }
|
||
|
// } else if (this.data.associationType === 'recommand-group') {
|
||
|
// console.log('recommand-group')
|
||
|
// this.getCommandAssociation()
|
||
|
|
||
|
// if (!app.globalData.previewImage) {
|
||
|
// this.getCommandAssociation()
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
app.globalData.previewImage = false;
|
||
|
},
|
||
|
detached: function () {
|
||
|
// this.setData({
|
||
|
// completeInfoDialogVisible: false
|
||
|
// })
|
||
|
},
|
||
|
},
|
||
|
methods: {
|
||
|
refreshData() {
|
||
|
console.log("刷新组首页数据", this.data.isRefresh);
|
||
|
this.selectComponent("#titleList").getInfo();
|
||
|
if (this.data.isRefresh) return;
|
||
|
this.setData({
|
||
|
allPageNo: 1,
|
||
|
mygroupPageNo: 1,
|
||
|
recommandgroupPageNo: 1,
|
||
|
allGroupMore: false,
|
||
|
myGroupMore: false,
|
||
|
recommandGroupMore: false,
|
||
|
isRefresh: true,
|
||
|
});
|
||
|
this.getAchieveTips();
|
||
|
this.getMyAssociation();
|
||
|
this.getCommandAssociation();
|
||
|
this.getAllGroup();
|
||
|
|
||
|
console.log("刷新组数据", this.data.noDataVisible);
|
||
|
},
|
||
|
refreshRecommand() {
|
||
|
this.setData({
|
||
|
recommandgroupPageNo: 1,
|
||
|
recommandGroupMore: false,
|
||
|
isRefresh: true,
|
||
|
});
|
||
|
this.getCommandAssociation();
|
||
|
},
|
||
|
refreshAll() {
|
||
|
this.setData({
|
||
|
allPageNo: 1,
|
||
|
allGroupMore: false,
|
||
|
isRefresh: true,
|
||
|
});
|
||
|
this.getAllGroup();
|
||
|
},
|
||
|
closeDialog() {
|
||
|
this.setData({
|
||
|
visible: false,
|
||
|
});
|
||
|
},
|
||
|
async onReachBottom() {
|
||
|
this.setData({
|
||
|
loadMoreVisible: true,
|
||
|
loadMoreType: "loading",
|
||
|
});
|
||
|
const { myGroupMore, recommandGroupMore, allGroupMore } = this.data;
|
||
|
console.log("allpageno", this.data.allPageNo);
|
||
|
if (this.data.associationType === "my-group") {
|
||
|
console.log(
|
||
|
"onReachBottom my-group",
|
||
|
myGroupMore,
|
||
|
this.data.myGroupList
|
||
|
);
|
||
|
if (myGroupMore) {
|
||
|
this.setData({
|
||
|
loadMoreType: "none",
|
||
|
});
|
||
|
return false;
|
||
|
}
|
||
|
this.data.mygroupPageNo += 1;
|
||
|
this.getMyAssociation();
|
||
|
} else if (this.data.associationType === "all-group") {
|
||
|
if (allGroupMore) {
|
||
|
this.setData({
|
||
|
loadMoreType: "none",
|
||
|
});
|
||
|
return false;
|
||
|
}
|
||
|
this.setData({
|
||
|
allPageNo: this.data.allPageNo + 1,
|
||
|
});
|
||
|
|
||
|
this.getAllGroup();
|
||
|
} else if (this.data.associationType === "top-group") {
|
||
|
const $ele = this.selectComponent("#groupTop");
|
||
|
$ele.handleReachBottom();
|
||
|
}
|
||
|
},
|
||
|
associationChange(e) {
|
||
|
// this.setData({
|
||
|
// nomoreVisible: false,
|
||
|
// noDataVisible: true
|
||
|
// })
|
||
|
const type = e.currentTarget.dataset.type;
|
||
|
// if (type === 'my-group') {
|
||
|
// this.getMyAssociation()
|
||
|
// } else if (type === 'recommand-group') {
|
||
|
// this.getCommandAssociation()
|
||
|
// } else {
|
||
|
// this.getAllGroup()
|
||
|
// }
|
||
|
this.setData({
|
||
|
associationType: type,
|
||
|
});
|
||
|
},
|
||
|
getCommandAssociationData(params: any) {
|
||
|
return request({
|
||
|
method: "POST",
|
||
|
url: "resi/group/group/getrecommendgroup",
|
||
|
options: params,
|
||
|
ifToken: true,
|
||
|
});
|
||
|
},
|
||
|
// 推荐群列表
|
||
|
getCommandAssociation() {
|
||
|
// this.setData({
|
||
|
// loadMoreVisible: false
|
||
|
// })
|
||
|
let params = {
|
||
|
pageNo: this.data.recommandgroupPageNo,
|
||
|
pageSize: this.data.pageSize,
|
||
|
customerId: app.globalData.customerId,
|
||
|
gridId: app.globalData.gridId,
|
||
|
};
|
||
|
let { recommandGroupMore, isRefresh } = this.data;
|
||
|
let list = [];
|
||
|
this.getCommandAssociationData(params)
|
||
|
.then((res) => {
|
||
|
console.log("推荐群列表", res);
|
||
|
if (res.code === 0) {
|
||
|
if (res.data.length === 20) recommandGroupMore = false;
|
||
|
else recommandGroupMore = true;
|
||
|
|
||
|
if (isRefresh) list = [...res.data];
|
||
|
else list = [...this.data.recommandGroupList, ...res.data];
|
||
|
this.setData({
|
||
|
recommandGroupMore,
|
||
|
noDataVisible: false,
|
||
|
recommandGroupList: list,
|
||
|
isRefresh: false,
|
||
|
loadMoreVisible: true,
|
||
|
loadMoreType: "none",
|
||
|
});
|
||
|
}
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
this.setData({
|
||
|
noDataVisible: false,
|
||
|
loadMoreType: "none",
|
||
|
});
|
||
|
console.log(err);
|
||
|
});
|
||
|
},
|
||
|
getMyAssociationData(params: any) {
|
||
|
return request({
|
||
|
method: "POST",
|
||
|
url: "resi/group/group/getmygroupV2",
|
||
|
options: params,
|
||
|
ifToken: true,
|
||
|
});
|
||
|
},
|
||
|
updateWxuserInfoData(params: any) {
|
||
|
return request({
|
||
|
method: "POST",
|
||
|
url: "epmetuser/user/updatewxuserinfo",
|
||
|
options: params,
|
||
|
ifToken: true,
|
||
|
});
|
||
|
},
|
||
|
async getAllGroup() {
|
||
|
this.setData({
|
||
|
// noDataVisible: false,
|
||
|
// loadMoreVisible: this.data.allGroupList.length > 0 ? true : false
|
||
|
});
|
||
|
let { allGroupMore, isRefresh } = this.data;
|
||
|
let list = [];
|
||
|
const {
|
||
|
data: {
|
||
|
data: { code, data },
|
||
|
},
|
||
|
msg,
|
||
|
} = await wxRequestPost(
|
||
|
"resi/group/group/allgrouplist",
|
||
|
{
|
||
|
gridId: app.globalData.gridId,
|
||
|
pageNo: this.data.allPageNo,
|
||
|
pageSize: this.data.pageSize,
|
||
|
},
|
||
|
{
|
||
|
// isMock: true,
|
||
|
// isQuiet: true,
|
||
|
// extraCodes: [8103]
|
||
|
}
|
||
|
);
|
||
|
|
||
|
if (msg === "success") {
|
||
|
if (code === 0) {
|
||
|
// if (data.length) {
|
||
|
if (data.length === 20) allGroupMore = false;
|
||
|
else allGroupMore = true;
|
||
|
if (isRefresh) list = data;
|
||
|
else list = [...this.data.allGroupList, ...data];
|
||
|
this.setData({
|
||
|
allGroupMore,
|
||
|
allGroupList: list,
|
||
|
noDataVisible: false,
|
||
|
loadMoreVisible: true,
|
||
|
isRefresh: false,
|
||
|
loadMoreType: "none",
|
||
|
});
|
||
|
// }
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
async getAchieveTips() {
|
||
|
const {
|
||
|
data: {
|
||
|
data: { code, data },
|
||
|
},
|
||
|
msg,
|
||
|
} = await wxRequestPost(
|
||
|
"resi/group/group/achievement",
|
||
|
{
|
||
|
gridId: app.globalData.gridId,
|
||
|
},
|
||
|
{
|
||
|
// isMock: true,
|
||
|
// isQuiet: true,
|
||
|
// extraCodes: [8103]
|
||
|
}
|
||
|
);
|
||
|
|
||
|
if (msg === "success") {
|
||
|
if (code === 0) {
|
||
|
this.setData({
|
||
|
achieveTipsList: data,
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
handleToGroup(e) {
|
||
|
console.log("reeee", e);
|
||
|
const gid = e.currentTarget.dataset.gid;
|
||
|
wx.navigateTo({
|
||
|
url: "/subpages/group/pages/group/integral/integral?gid=" + gid,
|
||
|
});
|
||
|
},
|
||
|
async createGroup() {
|
||
|
await loginGrid();
|
||
|
console.log(app.globalData.userRoleList);
|
||
|
let userRoleList = app.globalData.userRoleList;
|
||
|
if (
|
||
|
userRoleList.indexOf("warmhearted") >= 0 ||
|
||
|
userRoleList.indexOf("partymember") >= 0
|
||
|
) {
|
||
|
wx.navigateTo({
|
||
|
url: "/pages/group/group/newGroup/newGroup",
|
||
|
});
|
||
|
} else {
|
||
|
this.setData({
|
||
|
visible: true,
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
async confirm() {
|
||
|
const { msg, data } = await wxGetUserProfile({
|
||
|
desc: "用于完善居民信息",
|
||
|
});
|
||
|
if (msg == "success") {
|
||
|
// 同意授权,更新用户信息
|
||
|
console.log(data.avatarUrl);
|
||
|
let that = this;
|
||
|
let params = {
|
||
|
nickName: data.userInfo.nickName,
|
||
|
gender: data.userInfo.gender,
|
||
|
avatarUrl: data.userInfo.avatarUrl,
|
||
|
province: data.userInfo.province,
|
||
|
country: data.userInfo.country,
|
||
|
city: data.userInfo.city,
|
||
|
};
|
||
|
this.updateWxuserInfoData(params).then((res) => {
|
||
|
that.setData({
|
||
|
visible: false,
|
||
|
});
|
||
|
wx.navigateTo({
|
||
|
url: "/subpages/mine/pages/register/communist/index?from=group_createGroup&success=/pages/group/group/newGroup/newGroup",
|
||
|
});
|
||
|
});
|
||
|
console.log("111");
|
||
|
} else {
|
||
|
}
|
||
|
},
|
||
|
async confirm2() {
|
||
|
const { msg, data } = await wxGetUserProfile({
|
||
|
desc: "用于完善居民信息",
|
||
|
});
|
||
|
if (data.userInfo) {
|
||
|
// 同意授权,更新用户信息
|
||
|
console.log(data);
|
||
|
let that = this;
|
||
|
let params = {
|
||
|
nickName: data.userInfo.nickName,
|
||
|
gender: data.userInfo.gender,
|
||
|
avatarUrl: data.userInfo.avatarUrl,
|
||
|
province: data.userInfo.province,
|
||
|
country: data.userInfo.country,
|
||
|
city: data.userInfo.city,
|
||
|
};
|
||
|
this.updateWxuserInfoData(params).then((res) => {
|
||
|
that.setData({
|
||
|
visible: false,
|
||
|
});
|
||
|
wx.navigateTo({
|
||
|
url: "/subpages/mine/pages/register/activist/index?from=group_createGroup&success=/pages/group/group/newGroup/newGroup",
|
||
|
});
|
||
|
});
|
||
|
} else {
|
||
|
}
|
||
|
},
|
||
|
// 我的群列表
|
||
|
getMyAssociation() {
|
||
|
this.setData({
|
||
|
loadMoreVisible: false,
|
||
|
});
|
||
|
let params = {
|
||
|
pageNo: this.data.mygroupPageNo,
|
||
|
pageSize: this.data.pageSize,
|
||
|
customerId: app.globalData.customerId,
|
||
|
gridId: app.globalData.gridId,
|
||
|
};
|
||
|
let { myGroupMore, isRefresh } = this.data;
|
||
|
let list = [];
|
||
|
this.getMyAssociationData(params)
|
||
|
.then((res) => {
|
||
|
console.log("我的群列表", res);
|
||
|
if (res.code === 0) {
|
||
|
if (res.data.length.length === 20) myGroupMore = false;
|
||
|
else myGroupMore = true;
|
||
|
|
||
|
if (isRefresh) list = res.data;
|
||
|
else list = [...this.data.myGroupList, ...res.data];
|
||
|
this.setData({
|
||
|
noDataVisible: false,
|
||
|
myGroupMore,
|
||
|
myGroupList: list,
|
||
|
isRefresh: false,
|
||
|
loadMoreVisible: true,
|
||
|
loadMoreType: "none",
|
||
|
});
|
||
|
}
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
this.setData({
|
||
|
noDataVisible: false,
|
||
|
loadMoreType: "none",
|
||
|
});
|
||
|
console.log(err);
|
||
|
});
|
||
|
},
|
||
|
},
|
||
|
});
|