// -------------------------------------------------------------------- // @author: xxx@syg.com(必填, 创建模块的人员) // @description: // 这里填写详细说明,主要填写该模块的功能简要 //
Create: 2018-12-08 14:17:36 // -------------------------------------------------------------------- const BridgeClass = require( "bridge.class" ); var MailController = require("mail.mod"); var MailEvent = require("mail_event"); var MailVo = require("mail_vo"); var NoticeVo = require("notice_vo"); var MailModel_MAX_COUNT = 50 //最大邮件数量 var MailModel = cc.Class({ extends: BridgeClass, ctor: function () { this.ctrl = MailController.getInstance(); this.initConfig() }, properties: { }, initConfig: function () { this.mail_list = {}; //所有邮件 this.notice_list = {}; //所有公告 this.notice_list = {}; //公告列表 this.red_status_list = {}; //红点状态 }, //初始化邮件列表 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; } } //删除一个邮件的时候刷新邮件列表 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); }, //提取一个邮件附件 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.flag == 0) { is_new = true; break; } } nx.mTip.openTip("bar.mail.sys", is_new); // this.updateRedStatus(2, red_num) }, // --==============================-- // --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){ // 紅點狀態 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 = MailModel;