Files
fc/dev/project/assets/Scripts/mod/mail/cmp/cmp.mail.info.js
T

261 lines
7.9 KiB
JavaScript
Raw Normal View History

2026-05-23 22:10:14 +08:00
// --------------------------------------------------------------------
// @author: shiraho@syg.com(必填, 创建模块的人员)
// @description:
// 竖版邮件/公告详情
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
var PathTool = require( "pathtool" );
var TimeTool = require( "timetool" );
var MailController = require( "mail.mod" );
var MailEvent = require( "mail_event" );
const ItemLay = require("cmp.common.itemlayout");
cc.Class({
extends: cc.Component,
properties: {
title:{
default:null,
type:cc.Label
},
time:{
default:null,
type:cc.Label
},
list:{
default:null,
type:ItemLay
},
// icon:{
// default:null,
// type:cc.Sprite
// },
content:{
default:null,
type:cc.RichText
},
youxiao:{
default:null,
type:cc.Label
},
goods_container:{
default:null,
type:cc.Node
},
goods_scroll_content:{
default:null,
type:cc.Node
},
btn_get:{
default:null,
type:cc.Node
},
btn_delete:{
default:null,
type:cc.Node
},
// goods_list : []
},
// LIFE-CYCLE CALLBACKS:
onLoad () {
this.ctrl = MailController.getInstance();
if(this.get_item_assets == null){
this.get_item_assets = gcore.GlobalEvent.bind( MailEvent.GET_ITEM_ASSETS, ( key )=> {
if( this.data ) {
var item_key = Utils.getNorKey( this.data.id || 0, this.data.srv_id || "" );
if( key == item_key ) {
this.removeAsset( key );
}
}
} )
}
},
start () {
},
//必要添加的数据传入方法
setData: function( data ) {
this.data = data;
var str2 = data.content;
if( nx.dt.strNEmpty( data.content ) ) {
str2 = str2.replace( /&lt/g, "<" );
str2 = str2.replace( /&gt/g, ">" );
str2 = str2.replace( /&#039/g, "'" );
str2 = str2.replace( /&quot/g, '"' );
str2 = StringUtil.parseStr( str2 ).string
}
// var color = game.configs.color_data.data_color16[ 58 ];
//特殊符号处理^
let new_msg = null;
if(str2 && str2.indexOf("^")!=-1){
let arr = str2.split("^");
for(let i=0;i<arr.length;i++){
let cfg = gitemdata(arr[i]);
if(cfg){
arr[i] = cfg.name;
}
}
new_msg = arr.join("");
}else{
new_msg = str2;
}
this.content.string = new_msg;
this.list.rebuild([]);
if( data.status != null ) {
let str = data.subject;
if(str.length >= 18){
str = str.substring(0,15) + "...";
}
this.title.string = str;
this.time.active = true;
this.youxiao.active = true;
if( data.assets && data.items ) {
if( Utils.getArrLen( data.assets ) > 0 || Utils.getArrLen( data.items ) > 0 && data.type == 1 ) {
this.changeButtonStatus( true );
this.goods_container.active = true;
this.createGoodsList();
} else if( Utils.getArrLen( data.assets ) <= 0 || Utils.getArrLen( data.items ) <= 0 && data.type == 1 ) {
this.changeButtonStatus( false );
this.goods_container.active = false;
} else {
this.btn_get.active = false;
this.btn_delete.active = false;
this.goods_container.active = false;
}
}
// var show_time = TimeTool.getDayOrHour( client.socket.getTime() - this.data.send_time );
// if( show_time != null ) {
// this.time.string = show_time;
// } else {
// this.time.string = "";
// }
var show_time2 = TimeTool.getDayOrHour( data.time_out - client.socket.getTime() );
if( show_time2 != null ) {
this.youxiao.string = nx.text.getKey("MailLimitTime") + show_time2;
} else {
this.youxiao.string = "";
}
// this.changeIcon( data.status );
this.ctrl.read( data.id, data.srv_id);
} else if( data.flag != null ) {
let str = data.title;
if(str.length >= 18){
str = str.substring(0,15) + "...";
}
this.title.string = str;
this.btn_get.active = false;
this.btn_delete.active = false;
this.goods_container.active = false;
this.time.active = false;
this.youxiao.active = false;
// this.changeIcon( data.flag );
// this.ctrl.readNotice( data.id );
}
},
resetData(){
this.list.rebuild([]);
this.title.string = "";
this.content.string = "";
this.btn_get.active = false;
this.btn_delete.active = false;
this.goods_container.active = false;
this.time.active = false;
this.youxiao.active = false;
},
removeAsset: function() {
this.list.rebuild([]);
this.goods_container.active = false;
this.data.assets = {};
this.data.status = 2;
this.data.items = {};
// this.changeIcon( this.data.status );
this.changeButtonStatus( false );
},
createGoodsList: function() {
if( this.data.status == 2 ) { //领了的就不创建了
this.list.rebuild([]);
return
}
let list = [];
var show_list = [];
for( var k in this.data.assets ) {
var v = this.data.assets[ k ];
if( nx.dt.objClone( Utils.getItemConfig( v.label || v.base_id ) ).id != null )
show_list.push( this.data.assets[ k ] );
}
for( var k in this.data.items ) {
var v = this.data.items[ k ];
if( nx.dt.objClone( Utils.getItemConfig( v.label || v.base_id ) ).id != null )
show_list.push( this.data.items[ k ] );
}
for(let i in show_list){
var v = show_list[i];
let real = {};
real.id = v.label || v.base_id;
real.num = v.val || v.quantity;
list.push(real)
}
this.list.rebuild(list);
},
changeButtonStatus: function( status ) {
this.btn_get.active = status;
this.btn_delete.active = !status;
},
changeIcon: function( status ) {
// const icon = ( status == 0 ) ? "mail_2" : "mail_3";
// nx.gui.setAtlasFrame( this.icon, "", "uiRes/mods/mail/mail/" + icon );
},
touchGet(){
if( !this.data || !this.data.assets || !this.data.items ) {
return;
}
if( Utils.getArrLen( this.data.assets ) > 0 ||
Utils.getArrLen( this.data.items ) > 0 && this.data.type == 1 ) {
this.ctrl.getGoods( this.data.id, this.data.srv_id );
}
},
touchDel(){
if( !this.data || !this.data.assets || !this.data.items ) {
return;
}
if( Utils.getArrLen( this.data.assets ) <= 0 ||
Utils.getArrLen( this.data.items ) <= 0 && this.data.type == 1 ) {
var ids = [ { id: this.data.id, srv_id: this.data.srv_id } ];
this.ctrl.deletMailSend( ids );
}
},
onDestroy(){
if(this.get_item_assets){
gcore.GlobalEvent.unbind(this.get_item_assets);
this.get_item_assets = null;
}
}
// update (dt) {},
});