"use strict"; cc._RF.push(module, '16fa9KlLNlE8YMjHHnLxQ64', 'cmp.mail.cell'); // Scripts/mod/mail/cmp/cmp.mail.cell.js "use strict"; // Learn cc.Class: // - https://docs.cocos.com/creator/manual/en/scripting/class.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html var PathTool = require("pathtool"); var TimeTool = require("timetool"); var MailController = require("mail.mod"); var MailEvent = require("mail_event"); var SvcItem = require("nx.fx.sv.expand.item"); cc.Class({ "extends": SvcItem, properties: { //mail mail_con: { "default": null, type: cc.Node }, mail_icons: { "default": [], type: [cc.SpriteFrame] }, icon: { "default": null, type: cc.Sprite }, mail_title: { "default": null, type: cc.Label }, time: { "default": null, type: cc.Label }, unread: { "default": null, type: cc.Label }, red: { "default": null, type: cc.Node }, //notice notice_con: { "default": null, type: cc.Node }, notice_title: { "default": null, type: cc.Label }, notice_content: { "default": null, type: cc.Label }, focus_icon: { "default": null, type: cc.Node } }, // LIFE-CYCLE CALLBACKS: // 数据重置 rebind: function rebind(_idx, _data, _key) { this._super(_idx, _data, _key); // 刷新 this.setData(this.mdata); }, onLoad: function onLoad() { this.ctrl = MailController.getInstance(); }, start: function start() {}, onFocus: function onFocus() { if (!this.focus_icon.active) { this.focus_icon.active = true; } }, outFocus: function outFocus() { if (this.focus_icon.active) { this.focus_icon.active = false; } }, // openInfoView(){ // if(this.callback){ // this.callback(this); // } // }, setData: function setData(data) { if (nx.dt.objEmpty(data)) { return false; } if (this.mdata.status >= 0) { //邮件 this.mail_con.active = true; this.notice_con.active = false; var show_time = TimeTool.getDayOrHour(client.socket.getTime() - this.mdata.send_time); if (show_time) { this.time.string = show_time; } else { this.time.string = ""; } this.changeIcon(this.mdata.status); var str = this.mdata.subject; if (str.length >= 18) { str = str.substring(0, 15) + "..."; } this.mail_title.string = str; } else if (this.mdata.flag >= 0) { //公告 this.mail_con.active = false; this.notice_con.active = true; var _str = this.mdata.title; if (_str.length >= 18) { _str = _str.substring(0, 15) + "..."; } this.notice_title.string = _str; // this.notice_content.string = this.mdata.summary; this.setGray(this.mdata.flag == 1); } }, //邮件的icon改变 changeIcon: function changeIcon(status) { this.red.active = false; this.unread.string = status == 0 ? nx.text.getKey("MailUnread") : nx.text.getKey("MailReal"); if (status == 1) { //已读 this.icon.spriteFrame = this.mail_icons[status]; this.setGray(true); if (this.mdata.is_has == 1) { //有附件 this.icon.spriteFrame = this.mail_icons[3]; } } else if (status == 2) { //领了 this.icon.spriteFrame = this.mail_icons[status]; this.setGray(true); } else if (status == 0) { //未读 this.red.active = true; this.icon.spriteFrame = this.mail_icons[status]; this.setGray(false); if (this.mdata.is_has == 1) { //有附件 this.icon.spriteFrame = this.mail_icons[3]; } } }, setGray: function setGray(status) { if (status) { this.unread.node.active = false; } else { this.unread.node.active = true; } }, getData: function getData() { return this.mdata; }, updateIconStatus: function updateIconStatus() { if (this.mdata == null) return; var status = this.mdata.status; this.changeIcon(status); } // update (dt) {}, }); cc._RF.pop();