478 lines
15 KiB
JavaScript
478 lines
15 KiB
JavaScript
// --------------------------------------------------------------------
|
|
// @author: xxx@syg.com(必填, 创建模块的人员)
|
|
// @description:
|
|
// 这里填写详细说明,主要填写该模块的功能简要
|
|
// <br/>Create: 2018-12-08 14:17:36
|
|
// --------------------------------------------------------------------
|
|
const BridgeController = require( "bridge.controller" );
|
|
// 桥接替换的界面
|
|
const MailEvent = require("mail_event");
|
|
const MailVo = require("mail_vo");
|
|
const NoticeVo = require("notice_vo");
|
|
|
|
var MailController = cc.Class({
|
|
extends: BridgeController,
|
|
ctor: function () {
|
|
},
|
|
|
|
// 初始化配置数据
|
|
initConfig: function () {
|
|
this.mail_list = {}; //所有邮件
|
|
this.notice_list = {}; //所有公告
|
|
this.notice_list = {}; //公告列表
|
|
this.red_status_list = {}; //红点状态
|
|
},
|
|
|
|
// 注册监听事件
|
|
registerEvents: function () {
|
|
},
|
|
|
|
// 注册协议接受事件
|
|
registerProtocals: function () {
|
|
let 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( _cb ) {
|
|
this.reqMailData( _cb );
|
|
},
|
|
|
|
reqMailData( _cb ){
|
|
this.CB10800 = _cb;
|
|
this.SendProtocal( 10800, {}, _cb );
|
|
this.sender10950();
|
|
},
|
|
|
|
// 打开邮件主界面
|
|
openMailUI: function (status) {
|
|
|
|
if (status == true) {
|
|
nx.bridge.createPanel("WndMailTest",{});
|
|
} else {
|
|
nx.bridge.closePanel("WndMailTest");
|
|
}
|
|
},
|
|
|
|
//打开邮件内容
|
|
openMailInfo: function (bool, data) {
|
|
if (bool == true) {
|
|
this.info_window.setData(data);
|
|
this.info_window.show();
|
|
} else {
|
|
this.info_window.hide();
|
|
}
|
|
},
|
|
|
|
// 請求打開單個郵件
|
|
requireMailItem(id, srv_id,win,_cb){
|
|
this.info_window = win;
|
|
let protocal = {}
|
|
protocal.id = id
|
|
protocal.srv_id = srv_id
|
|
this.SendProtocal(10806, protocal,_cb)
|
|
},
|
|
|
|
on10806(data){
|
|
if (data) {
|
|
// this.openMailInfo(true, data)
|
|
this.openInfoWindow(data)
|
|
}
|
|
},
|
|
|
|
//获取邮件信息
|
|
send10800: function () {
|
|
this.SendProtocal(10800, {});
|
|
},
|
|
|
|
//初始化邮件列表
|
|
mailListHandler: function (data) {
|
|
this.initMailList(data.mail)
|
|
},
|
|
|
|
// --==============================--
|
|
// --desc:初始化公告列表
|
|
// --time:2019-02-15 11:21:44
|
|
// --@data:
|
|
// --@return
|
|
// --==============================--
|
|
handle10950(data){
|
|
this.initNoticeList(data.board_list, data.type)
|
|
},
|
|
|
|
//新增一个邮件
|
|
handle10803:function(data){
|
|
this.addMailItem(data.mail);
|
|
},
|
|
|
|
//请求删除一个邮件
|
|
deletMailSend:function(ids){
|
|
var protocal = {};
|
|
protocal.ids = ids;
|
|
this.SendProtocal(10804,protocal);
|
|
},
|
|
|
|
//推送删除邮件
|
|
delMailHandler:function(data){
|
|
nx.tbox(data.msg);
|
|
this.delMailItem(data.ids);
|
|
},
|
|
|
|
//读取一个邮件
|
|
read:function(bid,srv_id,_cb){
|
|
var protocal = {};
|
|
protocal.id = bid;
|
|
protocal.srv_id = srv_id;
|
|
this.SendProtocal(10805,protocal,_cb);
|
|
},
|
|
|
|
//读取一个邮件状态之后
|
|
readMailHandler:function(data){
|
|
if(data.code == 1){
|
|
this.readMailItem(data)
|
|
}
|
|
},
|
|
|
|
//提取邮件附件
|
|
getGoods:function(id,srv_id){
|
|
var protocal = {};
|
|
protocal.id = id;
|
|
protocal.srv_id = srv_id;
|
|
this.SendProtocal(10801,protocal)
|
|
},
|
|
|
|
//提取邮件返回
|
|
getGoodsHandler:function(data){
|
|
nx.tbox(data.msg);
|
|
if(data.code == 1){
|
|
this.getMailGood(data)
|
|
}
|
|
},
|
|
|
|
//一键提取邮件
|
|
getAllGoods:function(){
|
|
this.SendProtocal(10802,{})
|
|
},
|
|
|
|
//一键提取返回
|
|
getAllGoodsHandler:function(data){
|
|
nx.tbox(data.msg);
|
|
if(data.ids == null || Utils.next(data.ids) == null)return
|
|
this.getAllMailGood(data.ids);
|
|
},
|
|
|
|
//获取已经读取过的 且没有附件的邮件,用于一键删除
|
|
getHasReadNonRewardList:function(){
|
|
return this.getHasReadNonRewardList();
|
|
},
|
|
|
|
getMailInfoView:function(){
|
|
if(this.mail_info){
|
|
return this.mail_info
|
|
}
|
|
return null
|
|
},
|
|
|
|
sender10950(){
|
|
this.SendProtocal(10950,{})
|
|
},
|
|
|
|
// --==============================--
|
|
// --desc:服務端通知刪除一個公告
|
|
// --time:2019-02-16 12:40:39
|
|
// --@data:
|
|
// --@return
|
|
// --==============================--
|
|
handle10951(data){
|
|
this.delNoticeItem(data.id)
|
|
},
|
|
|
|
readNotice(id){
|
|
let protocal ={}
|
|
protocal.id = id
|
|
this.SendProtocal(10952,protocal)
|
|
},
|
|
|
|
// --desc:讀取一個公告
|
|
// --time:2019-02-16 12:42:44
|
|
|
|
handle10952( data ){
|
|
|
|
nx.dt.strNEmpty( data.msg ) ? nx.tbox(data.msg) : "";
|
|
if (data.code == 1) {
|
|
this.readNoticeItem(data.id);
|
|
}
|
|
},
|
|
|
|
//////////////////////////////
|
|
//初始化邮件列表
|
|
initMailList: function (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 () {
|
|
let 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 (data_list) {
|
|
this.initMailList(data_list);
|
|
//新增一个邮件的时候刷新邮件列表
|
|
gcore.GlobalEvent.fire(MailEvent.UPDATE_ITEM);
|
|
},
|
|
|
|
//删除没有附件的邮件 10804
|
|
delMailItem: function (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 (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 (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 (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 () {
|
|
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 () {
|
|
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
|
|
},
|
|
|
|
//获取已读且已经领取的邮件
|
|
getHasReadNonRewardList: function () {
|
|
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
|
|
},
|
|
|
|
//更新红点状态
|
|
updateRedStatus: function (bid, num) {
|
|
var red_num = this.red_status_list[bid];
|
|
if (red_num == num) return
|
|
this.red_status_list[bid] = num;
|
|
},
|
|
|
|
getRedSum: function (bid) {
|
|
return this.red_status_list[bid]
|
|
},
|
|
|
|
// --==============================--
|
|
// --desc:初始化公告列表
|
|
// --time:2019-02-15 11:40:59
|
|
// --@data_list:
|
|
// --@data_type:類型(0:全部 1:更新或新增)
|
|
// --@return
|
|
// --==============================--
|
|
initNoticeList(data_list, data_type){
|
|
if (data_list == null) return;
|
|
for (let i in data_list) {
|
|
let v = data_list[i];
|
|
let 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)
|
|
},
|
|
|
|
// --==============================--
|
|
// --desc:公告紅點
|
|
// --time:2019-02-16 12:52:49
|
|
// --@return
|
|
// --==============================--
|
|
checkNoticeRedSum(){
|
|
let is_new = false;
|
|
for (let k in this.notice_list) {
|
|
let v = this.notice_list[k];
|
|
if ( v && v.flag == 0) {
|
|
is_new = true;
|
|
break;
|
|
}
|
|
}
|
|
nx.mTip.openTip("bar.mail.sys", is_new);
|
|
},
|
|
|
|
// --==============================--
|
|
// --desc:通知刪除一個公告
|
|
// --time:2019-02-16 12:42:11
|
|
// --@id:
|
|
// --@return
|
|
// --==============================--
|
|
delNoticeItem(id){
|
|
if (this.notice_list[id]) {
|
|
this.notice_list[id] = null;
|
|
}
|
|
// 紅點狀態
|
|
this.checkNoticeRedSum()
|
|
// 刪除更新
|
|
gcore.GlobalEvent.fire(MailEvent.UPDATE_NOTICE)
|
|
},
|
|
|
|
// --==============================--
|
|
// --desc:通知讀取一個公告
|
|
// --time:2019-02-16 12:43:16
|
|
// --@id:
|
|
// --@return
|
|
// --==============================--
|
|
readNoticeItem(id){
|
|
|
|
let count = 0;
|
|
for (let k in this.notice_list) {
|
|
let 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);
|
|
},
|
|
|
|
// --==============================--
|
|
// --desc:獲取公告列表(主要用於排序)
|
|
// --time:2019-02-16 12:46:34
|
|
// --@return
|
|
// --==============================--
|
|
getNoticeArray(){
|
|
let temp_list = []
|
|
for (let k in this.notice_list) {
|
|
temp_list.push(this.notice_list[k]);
|
|
}
|
|
if (temp_list.length > 0) {
|
|
let sort_fun = Utils.tableLowerSorter(["flag"], ["start_time"])
|
|
temp_list.sort(sort_fun)
|
|
}
|
|
return temp_list;
|
|
},
|
|
//為了更快獲取公告的信息
|
|
getNoticeMessage(id){
|
|
if (this.notice_list[id]) {
|
|
return this.notice_list[id]
|
|
}
|
|
return null;
|
|
},
|
|
|
|
//更新info界面
|
|
openInfoWindow(data){
|
|
gcore.GlobalEvent.fire(MailEvent.OPEN_INFO_WIN,data);
|
|
}
|
|
//////////////////////////////
|
|
});
|
|
|
|
module.exports = MailController; |