393 lines
12 KiB
JavaScript
393 lines
12 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'cdcc1o/q79C3rQ5QVTLFu+1', 'mail.mod');
|
|
// Scripts/mod/mail/mail.mod.js
|
|
|
|
"use strict";
|
|
|
|
var _cc$Class;
|
|
// --------------------------------------------------------------------
|
|
// @author: xxx@syg.com(必填, 创建模块的人员)
|
|
// @description:
|
|
// 这里填写详细说明,主要填写该模块的功能简要
|
|
// <br/>Create: 2018-12-08 14:17:36
|
|
// --------------------------------------------------------------------
|
|
var BridgeController = require("bridge.controller");
|
|
// 桥接替换的界面
|
|
var MailEvent = require("mail_event");
|
|
var MailVo = require("mail_vo");
|
|
var NoticeVo = require("notice_vo");
|
|
var MailController = cc.Class((_cc$Class = {
|
|
"extends": BridgeController,
|
|
ctor: function ctor() {},
|
|
// 初始化配置数据
|
|
initConfig: function initConfig() {
|
|
this.mail_list = {}; //所有邮件
|
|
this.notice_list = {}; //所有公告
|
|
this.notice_list = {}; //公告列表
|
|
this.red_status_list = {}; //红点状态
|
|
},
|
|
|
|
// 注册监听事件
|
|
registerEvents: function registerEvents() {},
|
|
// 注册协议接受事件
|
|
registerProtocals: function registerProtocals() {
|
|
var self = this;
|
|
//------邮件-----
|
|
this.RegisterProtocal(10800, this.mailListHandler); //邮件列表
|
|
this.RegisterProtocal(10801, this.getGoodsHandler); //提取单个邮件的附件
|
|
this.RegisterProtocal(10802, this.getAllGoodsHandler); //一键提取附件
|
|
this.RegisterProtocal(10803, this.handle10803); //新邮件推送
|
|
this.RegisterProtocal(10804, this.delMailHandler); //删除没有附件的邮件
|
|
this.RegisterProtocal(10805, this.readMailHandler); //读取邮件
|
|
self.RegisterProtocal(10806, this.on10806); //請求指定的郵件返回
|
|
|
|
self.RegisterProtocal(10950, this.handle10950); //公告
|
|
self.RegisterProtocal(10951, this.handle10951); //刪除通知公告
|
|
self.RegisterProtocal(10952, this.handle10952); //讀取通知公告
|
|
},
|
|
|
|
// 从服务器初始化数据
|
|
reqBaseFromServer: function reqBaseFromServer(_cb) {
|
|
this.reqMailData(_cb);
|
|
},
|
|
reqMailData: function reqMailData(_cb) {
|
|
this.CB10800 = _cb;
|
|
this.SendProtocal(10800, {}, _cb);
|
|
this.sender10950();
|
|
},
|
|
// 打开邮件主界面
|
|
openMailUI: function openMailUI(status) {
|
|
if (status == true) {
|
|
nx.bridge.createPanel("WndMailTest", {});
|
|
} else {
|
|
nx.bridge.closePanel("WndMailTest");
|
|
}
|
|
},
|
|
//打开邮件内容
|
|
openMailInfo: function openMailInfo(bool, data) {
|
|
if (bool == true) {
|
|
this.info_window.setData(data);
|
|
this.info_window.show();
|
|
} else {
|
|
this.info_window.hide();
|
|
}
|
|
},
|
|
// 請求打開單個郵件
|
|
requireMailItem: function requireMailItem(id, srv_id, win, _cb) {
|
|
this.info_window = win;
|
|
var protocal = {};
|
|
protocal.id = id;
|
|
protocal.srv_id = srv_id;
|
|
this.SendProtocal(10806, protocal, _cb);
|
|
},
|
|
on10806: function on10806(data) {
|
|
if (data) {
|
|
// this.openMailInfo(true, data)
|
|
this.openInfoWindow(data);
|
|
}
|
|
},
|
|
//获取邮件信息
|
|
send10800: function send10800() {
|
|
this.SendProtocal(10800, {});
|
|
},
|
|
//初始化邮件列表
|
|
mailListHandler: function mailListHandler(data) {
|
|
this.initMailList(data.mail);
|
|
},
|
|
// --==============================--
|
|
// --desc:初始化公告列表
|
|
// --time:2019-02-15 11:21:44
|
|
// --@data:
|
|
// --@return
|
|
// --==============================--
|
|
handle10950: function handle10950(data) {
|
|
this.initNoticeList(data.board_list, data.type);
|
|
},
|
|
//新增一个邮件
|
|
handle10803: function handle10803(data) {
|
|
this.addMailItem(data.mail);
|
|
},
|
|
//请求删除一个邮件
|
|
deletMailSend: function deletMailSend(ids) {
|
|
var protocal = {};
|
|
protocal.ids = ids;
|
|
this.SendProtocal(10804, protocal);
|
|
},
|
|
//推送删除邮件
|
|
delMailHandler: function delMailHandler(data) {
|
|
nx.tbox(data.msg);
|
|
this.delMailItem(data.ids);
|
|
},
|
|
//读取一个邮件
|
|
read: function read(bid, srv_id, _cb) {
|
|
var protocal = {};
|
|
protocal.id = bid;
|
|
protocal.srv_id = srv_id;
|
|
this.SendProtocal(10805, protocal, _cb);
|
|
},
|
|
//读取一个邮件状态之后
|
|
readMailHandler: function readMailHandler(data) {
|
|
if (data.code == 1) {
|
|
this.readMailItem(data);
|
|
}
|
|
},
|
|
//提取邮件附件
|
|
getGoods: function getGoods(id, srv_id) {
|
|
var protocal = {};
|
|
protocal.id = id;
|
|
protocal.srv_id = srv_id;
|
|
this.SendProtocal(10801, protocal);
|
|
},
|
|
//提取邮件返回
|
|
getGoodsHandler: function getGoodsHandler(data) {
|
|
nx.tbox(data.msg);
|
|
if (data.code == 1) {
|
|
this.getMailGood(data);
|
|
}
|
|
},
|
|
//一键提取邮件
|
|
getAllGoods: function getAllGoods() {
|
|
this.SendProtocal(10802, {});
|
|
},
|
|
//一键提取返回
|
|
getAllGoodsHandler: function getAllGoodsHandler(data) {
|
|
nx.tbox(data.msg);
|
|
if (data.ids == null || Utils.next(data.ids) == null) return;
|
|
this.getAllMailGood(data.ids);
|
|
},
|
|
//获取已经读取过的 且没有附件的邮件,用于一键删除
|
|
getHasReadNonRewardList: function getHasReadNonRewardList() {
|
|
return this.getHasReadNonRewardList();
|
|
},
|
|
getMailInfoView: function getMailInfoView() {
|
|
if (this.mail_info) {
|
|
return this.mail_info;
|
|
}
|
|
return null;
|
|
},
|
|
sender10950: function sender10950() {
|
|
this.SendProtocal(10950, {});
|
|
},
|
|
// --==============================--
|
|
// --desc:服務端通知刪除一個公告
|
|
// --time:2019-02-16 12:40:39
|
|
// --@data:
|
|
// --@return
|
|
// --==============================--
|
|
handle10951: function handle10951(data) {
|
|
this.delNoticeItem(data.id);
|
|
},
|
|
readNotice: function readNotice(id) {
|
|
var protocal = {};
|
|
protocal.id = id;
|
|
this.SendProtocal(10952, protocal);
|
|
},
|
|
// --desc:讀取一個公告
|
|
// --time:2019-02-16 12:42:44
|
|
handle10952: function handle10952(data) {
|
|
nx.dt.strNEmpty(data.msg) ? nx.tbox(data.msg) : "";
|
|
if (data.code == 1) {
|
|
this.readNoticeItem(data.id);
|
|
}
|
|
},
|
|
//////////////////////////////
|
|
//初始化邮件列表
|
|
initMailList: function initMailList(data_list) {
|
|
if (data_list == null || Utils.next(data_list) == null) return;
|
|
for (var i in data_list) {
|
|
var v = data_list[i];
|
|
var key = Utils.getNorKey(v.id, v.srv_id);
|
|
var mail_vo = this.mail_list[key];
|
|
if (mail_vo == null) {
|
|
mail_vo = new MailVo();
|
|
this.mail_list[key] = mail_vo;
|
|
}
|
|
mail_vo.initAttrData(v);
|
|
}
|
|
//初始化红点
|
|
this.checkMailRedSum();
|
|
},
|
|
//设置邮件红点状态
|
|
checkMailRedSum: function checkMailRedSum() {
|
|
var is_new = false;
|
|
for (var k in this.mail_list) {
|
|
if (this.mail_list[k] && this.mail_list[k].status == 0) {
|
|
is_new = true;
|
|
break;
|
|
}
|
|
}
|
|
nx.mTip.openTip("bar.mail.person", is_new);
|
|
},
|
|
//新增邮件 10803
|
|
addMailItem: function addMailItem(data_list) {
|
|
this.initMailList(data_list);
|
|
//新增一个邮件的时候刷新邮件列表
|
|
gcore.GlobalEvent.fire(MailEvent.UPDATE_ITEM);
|
|
},
|
|
//删除没有附件的邮件 10804
|
|
delMailItem: function delMailItem(data_list) {
|
|
if (data_list == null || Utils.next(data_list) == null) return;
|
|
for (var i in data_list) {
|
|
var v = data_list[i];
|
|
if (v) {
|
|
var key = Utils.getNorKey(v.id, v.srv_id);
|
|
// this.mail_list[key] = null;
|
|
delete this.mail_list[key];
|
|
}
|
|
}
|
|
//删除一个邮件的时候刷新邮件列表
|
|
gcore.GlobalEvent.fire(MailEvent.UPDATE_ITEM);
|
|
},
|
|
//读取一封邮件,这个时候需要设置一些状态 10805
|
|
readMailItem: function readMailItem(data) {
|
|
if (data == null) return;
|
|
var key = Utils.getNorKey(data.id, data.srv_id);
|
|
var mail_vo = this.mail_list[key];
|
|
if (mail_vo == null) return;
|
|
mail_vo.setReaded(data.read_time);
|
|
this.checkMailRedSum();
|
|
//读取单封邮件的处理
|
|
gcore.GlobalEvent.fire(MailEvent.READ_MAIL_INFO, key);
|
|
gcore.GlobalEvent.fire(MailEvent.FRESH_ITEM);
|
|
},
|
|
//提取一个邮件附件 10801
|
|
getMailGood: function getMailGood(data) {
|
|
if (data == null) return;
|
|
var key = Utils.getNorKey(data.id, data.srv_id);
|
|
var mail_vo = this.mail_list[key];
|
|
mail_vo.removeAssets();
|
|
this.checkMailRedSum();
|
|
//提取一个邮件的物品
|
|
gcore.GlobalEvent.fire(MailEvent.GET_ITEM_ASSETS, key);
|
|
// gcore.GlobalEvent.fire(MailEvent.UPDATE_ITEM);
|
|
},
|
|
|
|
//一键提取所有邮件 10802
|
|
getAllMailGood: function getAllMailGood(data_list) {
|
|
if (data_list == null || Utils.next(data_list) == null) return;
|
|
for (var i in data_list) {
|
|
var v = data_list[i];
|
|
var key = Utils.getNorKey(v.id, v.srv_id);
|
|
if (this.mail_list[key]) {
|
|
this.mail_list[key].removeAssets(v.read_time);
|
|
}
|
|
}
|
|
this.checkMailRedSum();
|
|
gcore.GlobalEvent.fire(MailEvent.UPDATE_ITEM);
|
|
},
|
|
//获取邮件列表
|
|
getAllMailArray: function getAllMailArray() {
|
|
var temp_list = [];
|
|
for (var k in this.mail_list) {
|
|
var v = this.mail_list[k];
|
|
// if (v.time_out <= client.socket.getTime() && Utils.getArrLen(v.assets) == 0 && Utils.getArrLen(v.items) == 0) {
|
|
|
|
if (v && v.type == 1) {
|
|
temp_list.push(v);
|
|
}
|
|
}
|
|
if (temp_list.length > 0) {
|
|
temp_list.sort(Utils.tableLowerSorter(["status", "is_has"]));
|
|
}
|
|
return temp_list;
|
|
},
|
|
// 获取公告列表
|
|
getNoticeArray: function getNoticeArray() {
|
|
var temp_list = [];
|
|
for (var k in this.mail_list) {
|
|
var v = this.mail_list[k];
|
|
if (v && v.type == 2) {
|
|
temp_list.push(v);
|
|
}
|
|
}
|
|
if (temp_list.length > 0) {
|
|
temp_list.sort(Utils.tableLowerSorter(["status", "is_has"]));
|
|
}
|
|
return temp_list;
|
|
}
|
|
}, _cc$Class["getHasReadNonRewardList"] = function getHasReadNonRewardList() {
|
|
var mail_ids = [];
|
|
for (var i in this.mail_list) {
|
|
var v = this.mail_list[i];
|
|
//删除邮件的已经领取的邮件
|
|
if (v && v.id != null && v.srv_id != null && (v.status == 2 || v.status == 1 && Utils.getArrLen(v.assets) == 0 && Utils.getArrLen(v.items) == 0) && v.type == 1) {
|
|
var mail_data = {};
|
|
mail_data.id = v.id;
|
|
mail_data.srv_id = v.srv_id;
|
|
mail_ids.push(mail_data);
|
|
}
|
|
}
|
|
return mail_ids;
|
|
}, _cc$Class.updateRedStatus = function updateRedStatus(bid, num) {
|
|
var red_num = this.red_status_list[bid];
|
|
if (red_num == num) return;
|
|
this.red_status_list[bid] = num;
|
|
}, _cc$Class.getRedSum = function getRedSum(bid) {
|
|
return this.red_status_list[bid];
|
|
}, _cc$Class.initNoticeList = function initNoticeList(data_list, data_type) {
|
|
if (data_list == null) return;
|
|
for (var i in data_list) {
|
|
var v = data_list[i];
|
|
var notice_vo = this.notice_list[v.id];
|
|
if (notice_vo == null) {
|
|
notice_vo = new NoticeVo();
|
|
this.notice_list[v.id] = notice_vo;
|
|
}
|
|
notice_vo.initAttrData(v);
|
|
}
|
|
// 紅點狀態
|
|
this.checkNoticeRedSum();
|
|
// 這裡包含了更新刪除之類
|
|
gcore.GlobalEvent.fire(MailEvent.UPDATE_NOTICE);
|
|
}, _cc$Class.checkNoticeRedSum = function checkNoticeRedSum() {
|
|
var is_new = false;
|
|
for (var k in this.notice_list) {
|
|
var v = this.notice_list[k];
|
|
if (v && v.flag == 0) {
|
|
is_new = true;
|
|
break;
|
|
}
|
|
}
|
|
nx.mTip.openTip("bar.mail.sys", is_new);
|
|
}, _cc$Class.delNoticeItem = function delNoticeItem(id) {
|
|
if (this.notice_list[id]) {
|
|
this.notice_list[id] = null;
|
|
}
|
|
// 紅點狀態
|
|
this.checkNoticeRedSum();
|
|
// 刪除更新
|
|
gcore.GlobalEvent.fire(MailEvent.UPDATE_NOTICE);
|
|
}, _cc$Class.readNoticeItem = function readNoticeItem(id) {
|
|
var count = 0;
|
|
for (var k in this.notice_list) {
|
|
var v = this.notice_list[k];
|
|
if (v.id != id && v.flag == 0) {
|
|
count++;
|
|
}
|
|
}
|
|
nx.mTip.openTip("bar.mail.sys", count > 0);
|
|
// 紅點狀態
|
|
// this.checkNoticeRedSum();
|
|
// 讀取一封公告
|
|
gcore.GlobalEvent.fire(MailEvent.READ_INFO_NOTICE, id);
|
|
}, _cc$Class["getNoticeArray"] = function getNoticeArray() {
|
|
var temp_list = [];
|
|
for (var k in this.notice_list) {
|
|
temp_list.push(this.notice_list[k]);
|
|
}
|
|
if (temp_list.length > 0) {
|
|
var sort_fun = Utils.tableLowerSorter(["flag"], ["start_time"]);
|
|
temp_list.sort(sort_fun);
|
|
}
|
|
return temp_list;
|
|
}, _cc$Class.getNoticeMessage = function getNoticeMessage(id) {
|
|
if (this.notice_list[id]) {
|
|
return this.notice_list[id];
|
|
}
|
|
return null;
|
|
}, _cc$Class.openInfoWindow = function openInfoWindow(data) {
|
|
gcore.GlobalEvent.fire(MailEvent.OPEN_INFO_WIN, data);
|
|
}, _cc$Class));
|
|
module.exports = MailController;
|
|
|
|
cc._RF.pop(); |