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.
440 lines
9.8 KiB
440 lines
9.8 KiB
import { inputSync, doAfterLogin } from "@utils/tools";
|
|
import { 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: "",
|
|
};
|
|
const iniCloseFmData = {
|
|
topicId: "",
|
|
operateReason: "",
|
|
closedStatus: "",
|
|
};
|
|
|
|
Page({
|
|
data: {
|
|
groupId: "",
|
|
|
|
firstLoaded: false,
|
|
|
|
customerId: "",
|
|
gridId: "",
|
|
gridName: "",
|
|
|
|
info: {
|
|
groupName: "",
|
|
leaderFlag: "member", // leader member
|
|
},
|
|
|
|
topics: {
|
|
loading: false,
|
|
page: 1,
|
|
pageSize: 10,
|
|
isNone: false,
|
|
state: "", // discussing closed
|
|
list: [
|
|
// {
|
|
// topicId: "1",
|
|
// releaseUserHeadPhoto: testPic,
|
|
// firstPhoto: testPic,
|
|
// releaseUserName: "大王",
|
|
// topicContent:
|
|
// "哈哈哈哈哈哈哈。哈哈哈哈。。。哈哈哈哈。。哈哈哈哈。。哈哈哈哈。。哈哈哈哈。。哈。。",
|
|
// status: "discussing", // discussing closed
|
|
// releaseUserFlag: "other", // me other
|
|
// releaseTime: "2011-11-11 12:22"
|
|
// },
|
|
// {
|
|
// topicId: "2",
|
|
// releaseUserHeadPhoto: testPic,
|
|
// firstPhoto: "",
|
|
// releaseUserName: "小小王",
|
|
// topicContent: "哈哈哈嘻嘻嘻嘻嘻哈。。",
|
|
// status: "closed", // discussing closed
|
|
// releaseUserFlag: "me", // me other
|
|
// releaseTime: "2011-11-11 12:22"
|
|
// }
|
|
],
|
|
},
|
|
|
|
isShowedFiltrateListPanle: false,
|
|
|
|
focusedTopicId: "",
|
|
resolved: true, //关闭话题radio
|
|
showedCloseTopicPanel: false,
|
|
showedShieldTopicPanel: false,
|
|
fmData: {
|
|
...iniFmData,
|
|
},
|
|
closeFmData: {
|
|
...iniCloseFmData,
|
|
},
|
|
},
|
|
|
|
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();
|
|
},
|
|
|
|
read(e) {
|
|
const {
|
|
target: {
|
|
dataset: { id },
|
|
},
|
|
} = e;
|
|
let {
|
|
topics: { list },
|
|
} = this.data;
|
|
list.forEach((item) => {
|
|
if (item.id === id) {
|
|
item.readOrUnRead = "read";
|
|
}
|
|
});
|
|
this.setData({
|
|
"topics.list": list,
|
|
});
|
|
},
|
|
|
|
async handleTapUnreadHint(e) {
|
|
const {
|
|
target: {
|
|
dataset: { id, type },
|
|
},
|
|
} = e;
|
|
const { unReadCount } = await this.selectComponent("#viewUnread").show({
|
|
id,
|
|
type,
|
|
});
|
|
const {
|
|
topics: { list },
|
|
} = this.data;
|
|
list.forEach((item) => {
|
|
if (item.id === id) {
|
|
item.unReadCount = unReadCount;
|
|
}
|
|
});
|
|
this.setData({
|
|
"topics.list": list,
|
|
});
|
|
},
|
|
|
|
inputSync,
|
|
|
|
showFiltrateListPanel() {
|
|
this.setData({
|
|
isShowedFiltrateListPanle: true,
|
|
});
|
|
},
|
|
hideFiltrateListPanel() {
|
|
this.setData({
|
|
isShowedFiltrateListPanle: false,
|
|
});
|
|
},
|
|
|
|
filtrateList(e) {
|
|
const {
|
|
target: {
|
|
dataset: { state },
|
|
},
|
|
} = e;
|
|
const { topics } = this.data;
|
|
if (topics.state !== state) {
|
|
topics.state = state;
|
|
this.setData({ topics });
|
|
this.refreshTopicList();
|
|
}
|
|
},
|
|
|
|
handleTapRootNode() {
|
|
this.hideFiltrateListPanel();
|
|
},
|
|
|
|
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: "" });
|
|
},
|
|
|
|
// 屏蔽话题
|
|
shieldTopic() {
|
|
let { fmData, focusedTopicId, showedShieldTopicPanel } = this.data;
|
|
fmData.topicId = focusedTopicId;
|
|
showedShieldTopicPanel = true;
|
|
this.setData({
|
|
fmData,
|
|
showedShieldTopicPanel,
|
|
});
|
|
},
|
|
// 确认屏蔽
|
|
async confirmShieldTopic() {
|
|
const { fmData } = this.data;
|
|
if (fmData.operateReason === "") {
|
|
return wx.showToast({
|
|
title: "屏蔽理由不能为空。",
|
|
icon: "none",
|
|
duration: 1500,
|
|
});
|
|
}
|
|
|
|
wx.showLoading({
|
|
title: "请求中",
|
|
mask: true,
|
|
});
|
|
const {
|
|
data: {
|
|
data: { code, data },
|
|
},
|
|
msg,
|
|
} = await wxRequestPost("resi/group/topic/hidetopic", fmData, {
|
|
// 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 item.id !== fmData.topicId;
|
|
});
|
|
this.setData({ topics });
|
|
this.cancelShieldTopic();
|
|
} else {
|
|
console.log("屏蔽失败。", data);
|
|
wx.showToast({
|
|
title: "网络错误",
|
|
icon: "none",
|
|
duration: 1500,
|
|
});
|
|
}
|
|
},
|
|
// 取消屏蔽
|
|
cancelShieldTopic() {
|
|
this.setData({
|
|
showedShieldTopicPanel: false,
|
|
fmData: {
|
|
...iniFmData,
|
|
},
|
|
});
|
|
this.blurTopic();
|
|
},
|
|
|
|
// 关闭话题
|
|
closeTopic() {
|
|
let { closeFmData, focusedTopicId, showedCloseTopicPanel } = this.data;
|
|
closeFmData.topicId = focusedTopicId;
|
|
showedCloseTopicPanel = true;
|
|
this.setData({
|
|
closeFmData,
|
|
showedCloseTopicPanel,
|
|
resolved: true,
|
|
});
|
|
},
|
|
// 确认关闭话题
|
|
async confirmCloseTopic() {
|
|
const { closeFmData } = this.data;
|
|
if (closeFmData.operateReason === "") {
|
|
return wx.showToast({
|
|
title: "关闭理由不能为空。",
|
|
icon: "none",
|
|
duration: 1500,
|
|
});
|
|
}
|
|
closeFmData.closedStatus = this.data.resolved ? "resolved" : "unresolved";
|
|
wx.showLoading({
|
|
title: "请求中",
|
|
mask: true,
|
|
});
|
|
const {
|
|
data: {
|
|
data: { code, data },
|
|
},
|
|
msg,
|
|
} = await wxRequestPost("resi/group/topic/closetopic", closeFmData, {
|
|
// isMock: true
|
|
});
|
|
wx.hideLoading();
|
|
|
|
if (msg === "success" && code === 0) {
|
|
wx.showToast({
|
|
title: "关闭话题成功。",
|
|
duration: 1500,
|
|
});
|
|
let { topics } = this.data;
|
|
topics.list = topics.list.map((item) => {
|
|
if (item.id === closeFmData.topicId) {
|
|
item.status = "closed";
|
|
}
|
|
return item;
|
|
});
|
|
this.setData({ topics });
|
|
this.cancelCloseTopic();
|
|
}
|
|
},
|
|
// 取消关闭话题
|
|
cancelCloseTopic() {
|
|
this.setData({
|
|
showedCloseTopicPanel: false,
|
|
closeFmData: {
|
|
...iniCloseFmData,
|
|
},
|
|
});
|
|
this.blurTopic();
|
|
},
|
|
|
|
closeRadioChange(e) {
|
|
let { value } = e.detail;
|
|
if (value === "resolved") {
|
|
this.setData({ resolved: true });
|
|
} else {
|
|
this.setData({ resolved: false });
|
|
}
|
|
},
|
|
|
|
translateTopic(e) {
|
|
console.log(e.currentTarget.dataset.topicid);
|
|
let topicId = e.currentTarget.dataset.topicid;
|
|
wx.navigateTo({
|
|
url: `../topicToDiscussion/index?topicid=${topicId}`,
|
|
});
|
|
},
|
|
|
|
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 });
|
|
}
|
|
},
|
|
|
|
// 刷新评论列表
|
|
refreshTopicList() {
|
|
this.resetTopicList();
|
|
this.getTopicList();
|
|
},
|
|
|
|
// 重置评论列表
|
|
resetTopicList() {
|
|
let { topics } = this.data;
|
|
topics.list = [];
|
|
topics.page = 1;
|
|
topics.isNone = false;
|
|
this.setData({ topics });
|
|
},
|
|
|
|
// 获取评论列表
|
|
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/getpasttopiclistv2",
|
|
{
|
|
groupId,
|
|
status: topics.state,
|
|
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.id === item.id) ===
|
|
-1
|
|
);
|
|
topics.list = topics.list.concat(newList);
|
|
topics.page = topics.page + 1;
|
|
if (data.length < topics.pageSize) {
|
|
topics.isNone = true;
|
|
}
|
|
}
|
|
|
|
this.setData({ topics });
|
|
},
|
|
});
|
|
|