// 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"); const 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( _idx, _data, _key ) { this._super( _idx, _data, _key ); // 刷新 this.setData(this.mdata) }, onLoad () { this.ctrl = MailController.getInstance(); }, start () { }, onFocus(){ if( !this.focus_icon.active) { this.focus_icon.active = true; } }, outFocus(){ if( this.focus_icon.active ) { this.focus_icon.active = false; } }, // openInfoView(){ // if(this.callback){ // this.callback(this); // } // }, 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 ); let 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; let 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( 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( status ) { if( status ) { this.unread.node.active = false; } else { this.unread.node.active = true; } }, getData: function() { return this.mdata }, updateIconStatus: function() { if( this.mdata == null ) return var status = this.mdata.status; this.changeIcon( status ) }, // update (dt) {}, });