日照项目的居民端小程序
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.
 
 
 

308 lines
6.7 KiB

import { inputSync, nextTick, doAfterLogin } from "../../../../../utils/tools";
import {
wxShowModal,
wxRequestPost
} from "../../../../../utils/promise-wx-api";
const app = getApp();
const testPic =
"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3015922630,3907554494&fm=26&gp=0.jpg";
// 初始化表单数据
const iniFmData = {
topicId: "",
operateReason: ""
};
Page({
data: {
groupId: "",
firstLoaded: false,
customerId: "",
gridId: "",
gridName: "",
info: {
groupName: "",
leaderFlag: "member" // leader member
},
topics: {
loading: false,
page: 1,
pageSize: 10,
isNone: false,
state: "total", // total approved closed
list: [
// {
// topicId: "1",
// isSelected: false,
// releaseUserHeadPhoto: testPic,
// firstPhoto: testPic,
// releaseUserName: "大王",
// topicContent:
// "哈哈哈哈哈哈哈。哈哈哈哈。。。哈哈哈哈。。哈哈哈哈。。哈哈哈哈。。哈哈哈哈。。哈。。",
// status: "discussing", // discussing closed
// releaseUserFlag: "other", // me other
// releaseTime: "2011-11-11 12:22"
// },
// {
// topicId: "2",
// isSelected: false,
// releaseUserHeadPhoto: testPic,
// firstPhoto: "",
// releaseUserName: "小小王",
// topicContent: "哈哈哈嘻嘻嘻嘻嘻哈。。",
// status: "closed", // discussing closed
// releaseUserFlag: "me", // me other
// releaseTime: "2011-11-11 12:22"
// }
]
},
// 显示更多操作面板
isShowedMoreOperatePanel: false,
// 批量选择中
inBatchSelect: false,
focusedTopicId: "",
topicIds: []
},
async onLoad(query) {
wx.showLoading({
title: "",
mask: true
});
await doAfterLogin();
const { customerId, gridId, currentGridName } = app.globalData;
this.setData({
customerId,
gridId,
gridName: currentGridName
});
const { gid } = query;
this.setData({ groupId: gid });
await this.getApiData();
wx.hideLoading();
},
onReachBottom() {
this.getTopicList();
},
inputSync,
handleTapRootNode() {
this.hideMoreOperatePanel();
},
showMoreOperatePanel() {
this.setData({
isShowedMoreOperatePanel: true
});
},
hideMoreOperatePanel() {
this.setData({
isShowedMoreOperatePanel: false
});
},
startBatchSelect() {
this.setData({
inBatchSelect: true
});
},
endBatchSelect() {
this.setData({
inBatchSelect: false
});
},
// 切换选择话题
shiftSelectTopic(e) {
const {
target: {
dataset: { id }
}
} = e;
let { topicIds } = this.data;
const idIndex = topicIds.indexOf(id);
if (idIndex !== -1) {
topicIds.splice(idIndex, 1);
} else {
topicIds.push(id);
}
console.log(topicIds);
this.setData({
topicIds
});
this.computeTopicIsSelected();
},
// 重新计算是否话题被选中
computeTopicIsSelected() {
let { topics, topicIds } = this.data;
topics.list = topics.list.map(item => {
item.isSelected = topicIds.indexOf(item.topicId) !== -1;
return item;
});
this.setData({ topics });
},
focuseTopic(e) {
const {
target: {
dataset: { id }
}
} = e;
let { focusedTopicId } = this.data;
if (typeof id === "undefined" || id === focusedTopicId) {
focusedTopicId = "";
} else {
focusedTopicId = id;
}
console.log(focusedTopicId);
this.setData({ focusedTopicId });
},
blurTopic() {
this.setData({ focusedTopicId: "" });
},
// 解除屏蔽话题
async relieveShieldTopic() {
const { topicIds } = this.data;
if (topicIds.length === 0) {
return wx.showToast({
title: "请先选择要解除屏蔽的话题",
icon: "none",
duration: 1500
});
}
await wxShowModal({
title: "确定解除屏蔽?"
});
wx.showLoading({
title: "请求中",
mask: true
});
const {
data: {
data: { code, data }
},
msg
} = await wxRequestPost(
"resi/group/topic/cancelhiddentopics",
{
topicIds
},
{
// isMock: true
}
);
wx.hideLoading();
if (msg === "success" && code === 0) {
wx.showToast({
title: "解除屏蔽成功",
duration: 1500
});
let { topics } = this.data;
topics.list = topics.list.filter(item => {
return topicIds.indexOf(item.topicId) === -1;
});
this.setData({ topics, topicIds: [] });
this.endBatchSelect();
}
},
async getApiData() {
this.getTopicList();
await this.getInfo();
},
// 获取小组详情
async getInfo() {
const { groupId } = this.data;
const {
data: {
data: { code, data }
},
msg
} = await wxRequestPost(
"resi/group/group/getgroupsummarize",
{
groupId
},
{
// isMock: true
}
);
if (msg === "success" && code === 0) {
let { info } = this.data;
info.groupName = data.groupName;
info.leaderFlag = data.leaderFlag;
this.setData({ info });
}
},
// 获取评论列表
async getTopicList() {
const { groupId, topics } = this.data;
// 如果正在加载或没有更多,返回
if (topics.loading || topics.isNone) return;
topics.loading = true;
this.setData({ topics });
const {
data: {
data: { code, data }
},
msg
} = await wxRequestPost(
"resi/group/topic/gethiddentopic",
{
groupId,
pageNo: topics.page,
pageSize: topics.pageSize
},
{
// isMock: true
}
);
topics.loading = false;
if (msg === "success" && code === 0) {
let newList = data
.map(item => {
if (!item.releaseUserName) {
item.releaseUserName = "匿名用户";
}
return item;
})
.filter(
item =>
topics.list.findIndex(sItem => sItem.topicId === item.topicId) ===
-1
);
topics.list = topics.list.concat(newList);
topics.page = topics.page + 1;
if (data.length < topics.pageSize) {
topics.isNone = true;
}
}
this.setData({ topics });
}
});