"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); var tools_1 = require("../../../../../utils/tools"); var promise_wx_api_1 = require("../../../../../utils/promise-wx-api"); var words_1 = require("../../../../../config/words"); var app = getApp(); var $loading; var $modal; var routes = { demand: "/subpages/points/pages/demand/detail", event: "/subpages/index/pages/report/detail/index", ic_event: "", }; Page({ data: { words: words_1.default, resubscribeShow: false, templateId: "", customerId: "", gridId: "", gridName: "", list: { loading: false, page: 1, pageSize: 10, isNone: false, state: "", data: [], }, }, iniComponentVar: function () { $loading = tools_1.getComponent("#loading"); $modal = tools_1.getComponent("#modal"); }, onLoad: function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { this.iniComponentVar(); return [2]; }); }); }, onShow: function () { return __awaiter(this, void 0, void 0, function () { var _a, customerId, gridId, currentGridName; return __generator(this, function (_b) { switch (_b.label) { case 0: $loading.show(); return [4, tools_1.doAfterLogin()]; case 1: _b.sent(); _a = app.globalData, customerId = _a.customerId, gridId = _a.gridId, currentGridName = _a.currentGridName; this.setData({ customerId: customerId, gridId: gridId, gridName: currentGridName, }); return [4, this.getApiData()]; case 2: _b.sent(); $loading.hide(); return [2]; } }); }); }, onReady: function () { this.requestMsg = this.selectComponent("#requestMsg"); }, onReachBottom: function () { this.getList(); }, resubscribe: function (e) { console.log("eee", e); this.setData({ resubscribeShow: e.detail.hasShow, templateId: e.detail.templateId, }); }, inputSync: tools_1.inputSync, shiftUnbold: function (e) { var id = e.currentTarget.dataset.id; console.log("切换展开", id); var list = this.data.list; list.data = list.data.map(function (item) { console.log(item.id); if (item.id == id) { item.unbold = !item.unbold; } return item; }); this.setData({ list: list }); }, toInfo: function (e) { var _a = e.currentTarget.dataset, id = _a.id, target = _a.target; console.log("切换阅读", id); var currItem = this.data.list.data.find(function (item) { return item.id == id; }); if (!currItem) return; if (currItem.messageType && currItem.messageType == "demand") { promise_wx_api_1.wxNavigateTo(routes[currItem.messageType], { id: target, showRate: 0, source: "my", }); } else if (currItem.messageType && currItem.messageType == "event") { promise_wx_api_1.wxNavigateTo(routes[currItem.messageType], { eventId: target, listResource: "my", }); } else if (currItem.messageType && currItem.messageType == "antiepidemic") { promise_wx_api_1.wxNavigateTo("../fangyi-info/index", { noticeId: currItem.targetId, }); } else if (currItem.messageType && currItem.messageType == "ic_event") { promise_wx_api_1.wxNavigateTo("/subpages/mine/pages/myReportEvent/detail/index", { eventId: currItem.targetId, }); } else if (currItem.messageType && currItem.messageType == "nucleic") { promise_wx_api_1.wxNavigateTo("/subpages/epidemicmap/pages/index/index", { type: '1' }); } else if (currItem.messageType && currItem.messageType == "vaccines") { promise_wx_api_1.wxNavigateTo("/subpages/epidemicmap/pages/index/index", { type: '2' }); } else { wx.setStorageSync("messageInfo", currItem); promise_wx_api_1.wxNavigateTo("../info/index", {}); } }, read: function (e) { return __awaiter(this, void 0, void 0, function () { var _a, id, target, currItem, _b, code, msg, list; return __generator(this, function (_c) { switch (_c.label) { case 0: _a = e.currentTarget.dataset, id = _a.id, target = _a.target; console.log("切换阅读", id); currItem = this.data.list.data.find(function (item) { return item.id == id; }); if (!currItem || currItem.readFlag == "read") return [2]; return [4, promise_wx_api_1.wxRequestPost("resi/mine/mymessage/readmsg", { messageId: id, }, { isQuiet: true, })]; case 1: _b = _c.sent(), code = _b.data.data.code, msg = _b.msg; wx.hideLoading(); if (msg === "success" && code === 0) { list = this.data.list; list.data = list.data.map(function (item) { if (item.id == id) { item.readFlag = "read"; } return item; }); this.setData({ list: list }); if (currItem.messageType) { if (currItem.messageType == "demand") { promise_wx_api_1.wxNavigateTo(routes[currItem.messageType], { id: target, showRate: 0, source: "my", }); } else if (currItem.messageType == "event") { promise_wx_api_1.wxNavigateTo(routes[currItem.messageType], { eventId: target, listResource: "my", }); } } } return [2]; } }); }); }, readDel: function () { return __awaiter(this, void 0, void 0, function () { var _a, customerId, gridId, list, _b, code, msg; return __generator(this, function (_c) { switch (_c.label) { case 0: _a = this.data, customerId = _a.customerId, gridId = _a.gridId, list = _a.list; return [4, promise_wx_api_1.wxRequestPost("message/usermessage/delreadmsg", {}, { isQuiet: false, })]; case 1: _b = _c.sent(), code = _b.data.data.code, msg = _b.msg; wx.hideLoading(); if (msg == "success" && code == 0) { list.data = []; list.page = 1; list.isNone = false; list.loading = false; this.setData({ list: list, }); this.getApiData(); } return [2]; } }); }); }, readAll: function () { return __awaiter(this, void 0, void 0, function () { var _a, customerId, gridId, _b, code, msg, list; return __generator(this, function (_c) { switch (_c.label) { case 0: _a = this.data, customerId = _a.customerId, gridId = _a.gridId; return [4, promise_wx_api_1.wxRequestPost("resi/mine/mymessage/readallmsg", { customerId: customerId, gridId: gridId, }, { isQuiet: false, })]; case 1: _b = _c.sent(), code = _b.data.data.code, msg = _b.msg; wx.hideLoading(); if (msg === "success" && code === 0) { list = this.data.list; list.data = list.data.map(function (item) { item.readFlag = "read"; return item; }); this.setData({ list: list }); wx.showToast({ title: words_1.default.message.readAllSuccess, duration: 1500, }); } return [2]; } }); }); }, getApiData: function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { this.getList(); return [2]; }); }); }, resetList: function () { var list = this.data.list; list.data = []; list.page = 1; list.isNone = false; this.setData({ list: list }); }, getList: function () { return __awaiter(this, void 0, void 0, function () { var _a, customerId, gridId, list, _b, _c, code, data, msg, newList; return __generator(this, function (_d) { switch (_d.label) { case 0: _a = this.data, customerId = _a.customerId, gridId = _a.gridId, list = _a.list; if (list.loading || list.isNone) return [2]; list.loading = true; this.setData({ list: list }); return [4, promise_wx_api_1.wxRequestPost("resi/mine/mymessage/getmymessage", { gridId: gridId, customerId: customerId, pageNo: list.page, pageSize: list.pageSize, }, {})]; case 1: _b = _d.sent(), _c = _b.data.data, code = _c.code, data = _c.data, msg = _b.msg; list.loading = false; if (msg === "success" && code === 0) { newList = data .map(function (item) { item.unbold = false; return item; }) .filter(function (item) { return list.data.findIndex(function (sItem) { return 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: list }); return [2]; } }); }); }, handleMsg: function () { if (!this.data.resubscribeShow) this.requestMsg.handleMsg(); }, handleRemsg: function () { var _this = this; wx.showModal({ title: "提示", content: "是否激活订阅站内信提醒", confirmText: "是", cancelText: "否", success: function (res) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { if (res.confirm) this.reSubscribe(); return [2]; }); }); }, fail: function (err) { console.log("err", err); wx.showToast(err); }, }); }, reSubscribe: function () { return __awaiter(this, void 0, void 0, function () { var _a, customerId, templateId, _b, code, msg; return __generator(this, function (_c) { switch (_c.label) { case 0: _a = this.data, customerId = _a.customerId, templateId = _a.templateId; return [4, promise_wx_api_1.wxRequestPost("message/wxmpmessage/activationsubscribe", { customerId: customerId, clientType: "resi", alwaysVisit: "no", templateId: templateId, }, { isQuiet: false, })]; case 1: _b = _c.sent(), code = _b.data.data.code, msg = _b.msg; wx.hideLoading(); if (msg === "success" && code === 0) { wx.showToast({ title: "激活成功", icon: "none", duration: 1500, }); this.requestMsg.initTemplateList(); this.setData({ resubscribeShow: false, }); } return [2]; } }); }); }, });