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

414 lines
9.8 KiB

import {
inputSync,
nextTick,
doAfterLogin,
getComponent,
} from "../../../../../utils/tools";
import {
wxRequestPost,
wxRedirectTo,
wxNavigateTo,
} from "../../../../../utils/promise-wx-api";
import words from "../../../../../config/words";
const app = getApp();
let $loading;
let $modal;
const routes = {
demand: "/subpages/points/pages/demand/detail",
event: "/subpages/index/pages/report/detail/index",
ic_event: "",
};
Page({
data: {
words,
resubscribeShow: false,
templateId: "",
customerId: "",
gridId: "",
gridName: "",
// 消息列表
list: {
loading: false,
page: 1,
pageSize: 10,
isNone: false,
state: "",
data: [
// {
// messageContent:
// "哈哈哈哈哈哈哈哈哈哈,哈哈哈哈哈,哈哈哈哈哈哈哈哈哈哈,哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈。哈哈哈哈哈哈哈哈哈哈哈哈,哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈",
// readFlag: "unread",
// id: "62109",
// title: "您有一条xxxx消息",
// createdTime: "2011/11/11 11:11",
// unbold: false
// },
// {
// messageContent:
// "哈哈哈哈哈,哈哈哈哈哈,哈哈哈哈哈哈哈哈哈哈,哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈。哈哈哈哈哈哈哈哈哈哈哈哈",
// readFlag: "read",
// id: "11",
// title: "您有一条xxxx消息",
// createdTime: "2011/11/11 11:11",
// unbold: false
// }
],
},
},
// 初始化组件实例赋值
iniComponentVar() {
$loading = getComponent("#loading");
$modal = getComponent("#modal");
},
async onLoad() {
this.iniComponentVar();
},
async onShow() {
$loading.show();
await doAfterLogin();
const { customerId, gridId, currentGridName } = app.globalData;
this.setData({
customerId,
gridId,
gridName: currentGridName,
});
await this.getApiData();
$loading.hide();
},
onReady() {
this.requestMsg = this.selectComponent("#requestMsg");
},
onReachBottom() {
this.getList();
},
resubscribe(e) {
console.log("eee", e);
this.setData({
resubscribeShow: e.detail.hasShow,
templateId: e.detail.templateId,
});
},
inputSync,
shiftUnbold(e) {
const {
currentTarget: {
dataset: { id },
},
} = e;
console.log("切换展开", id);
const { list } = this.data;
list.data = list.data.map((item) => {
console.log(item.id);
if (item.id == id) {
item.unbold = !item.unbold;
}
return item;
});
this.setData({ list });
},
toInfo(e) {
const {
currentTarget: {
dataset: { id, target },
},
} = e;
console.log("切换阅读", id);
const currItem = this.data.list.data.find((item) => item.id == id);
if (!currItem) return;
if (currItem.messageType && currItem.messageType == "demand") {
wxNavigateTo(routes[currItem.messageType], {
id: target,
showRate: 0,
source: "my",
});
} else if (currItem.messageType && currItem.messageType == "event") {
wxNavigateTo(routes[currItem.messageType], {
eventId: target,
listResource: "my",
});
} else if (currItem.messageType && currItem.messageType == "antiepidemic") {
wxNavigateTo("../fangyi-info/index", {
noticeId: currItem.targetId,
});
} else if (currItem.messageType && currItem.messageType == "ic_event") {
wxNavigateTo("/subpages/mine/pages/myReportEvent/detail/index", {
eventId: currItem.targetId,
// status: 'processing'
});
} else if (currItem.messageType && currItem.messageType == "nucleic") {
wxNavigateTo("/subpages/epidemicmap/pages/index/index", {
type: '1'
});
} else if (currItem.messageType && currItem.messageType == "vaccines") {
wxNavigateTo("/subpages/epidemicmap/pages/index/index", {
type: '2'
});
} else {
wx.setStorageSync("messageInfo", currItem);
wxNavigateTo("../info/index", {});
}
},
// 阅读
async read(e) {
const {
currentTarget: {
dataset: { id, target },
},
} = e;
console.log("切换阅读", id);
const currItem = this.data.list.data.find((item) => item.id == id);
if (!currItem || currItem.readFlag == "read") return;
const {
data: {
data: { code },
},
msg,
} = await wxRequestPost(
"resi/mine/mymessage/readmsg",
{
messageId: id,
},
{
// isMock: true,
isQuiet: true,
}
);
wx.hideLoading();
if (msg === "success" && code === 0) {
const { list } = this.data;
list.data = list.data.map((item) => {
if (item.id == id) {
item.readFlag = "read";
}
return item;
});
this.setData({ list });
if (currItem.messageType) {
if (currItem.messageType == "demand") {
wxNavigateTo(routes[currItem.messageType], {
id: target,
showRate: 0,
source: "my",
});
} else if (currItem.messageType == "event") {
wxNavigateTo(routes[currItem.messageType], {
eventId: target,
listResource: "my",
});
}
// wxNavigateTo(routes[currItem.messageType], {
// id: target,
// showRate: 0,
// source: 'my'
// })
}
}
},
// 删除已读
async readDel() {
const { customerId, gridId, list } = this.data;
const {
data: {
data: { code },
},
msg,
} = await wxRequestPost(
"message/usermessage/delreadmsg",
{
// customerId,
// gridId
},
{
// isMock: true,
isQuiet: false,
}
);
wx.hideLoading();
if (msg == "success" && code == 0) {
list.data = [];
list.page = 1;
list.isNone = false;
list.loading = false;
this.setData({
list,
});
this.getApiData();
// wx.showToast({
// title: words.message.readAllSuccess,
// duration: 1500
// });
}
},
// 阅读全部
async readAll() {
const { customerId, gridId } = this.data;
const {
data: {
data: { code },
},
msg,
} = await wxRequestPost(
"resi/mine/mymessage/readallmsg",
{
customerId,
gridId,
},
{
// isMock: true,
isQuiet: false,
}
);
wx.hideLoading();
if (msg === "success" && code === 0) {
const { list } = this.data;
list.data = list.data.map((item) => {
item.readFlag = "read";
return item;
});
this.setData({ list });
wx.showToast({
title: words.message.readAllSuccess,
duration: 1500,
});
}
},
async getApiData() {
this.getList();
},
// 重置评论列表
resetList() {
let { list } = this.data;
list.data = [];
list.page = 1;
list.isNone = false;
this.setData({ list });
},
// 获取评论列表
async getList() {
const { customerId, gridId, list } = this.data;
// 如果正在加载或没有更多,返回
if (list.loading || list.isNone) return;
list.loading = true;
this.setData({ list });
const {
data: {
data: { code, data },
},
msg,
} = await wxRequestPost(
"resi/mine/mymessage/getmymessage",
{
gridId,
customerId,
pageNo: list.page,
pageSize: list.pageSize,
},
{
// isMock: true
}
);
list.loading = false;
if (msg === "success" && code === 0) {
let newList = data
.map((item) => {
item.unbold = false;
return item;
})
.filter(
(item) => list.data.findIndex((sItem) => sItem.id === item.id) === -1
);
console.log("newList---", newList);
if (list.page == 1) list.data = newList;
else list.data = list.data.concat(newList);
console.log("list.data---", list.data);
list.page = list.page + 1;
if (data.length < list.pageSize) {
list.isNone = true;
}
}
this.setData({ list });
},
handleMsg() {
if (!this.data.resubscribeShow) this.requestMsg.handleMsg();
},
handleRemsg() {
wx.showModal({
title: "提示",
content: "是否激活订阅站内信提醒",
confirmText: "是",
cancelText: "否",
success: async (res) => {
if (res.confirm) this.reSubscribe();
},
fail: (err) => {
console.log("err", err);
wx.showToast(err);
},
});
},
async reSubscribe() {
const { customerId, templateId } = this.data;
const {
data: {
data: { code },
},
msg,
} = await wxRequestPost(
"message/wxmpmessage/activationsubscribe",
{
customerId,
clientType: "resi",
alwaysVisit: "no",
templateId,
},
{
// isMock: true,
isQuiet: false,
}
);
wx.hideLoading();
if (msg === "success" && code === 0) {
wx.showToast({
title: "激活成功",
icon: "none",
duration: 1500,
});
this.requestMsg.initTemplateList();
this.setData({
resubscribeShow: false,
});
}
},
});