difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// --------------------------------------------------------------------
// @author: shiraho@syg.com(必填, 创建模块的人员)
// @description:
//      竖版邮件单个
// <br/>Create: new Date().toISOString()
// --------------------------------------------------------------------
 
var PathTool = require("pathtool");
var TimeTool = require("timetool");
 
var MailCell = cc.Class({
    extends: BasePanel,
    ctor: function () {
        this.prefabPath = PathTool.getPrefabPath("mail", "mail_item");
        this.data = null;
    },
 
 
    initPanel: function () {
        this.main_container = this.root_wnd.getChildByName("main_container");
        this.mail_con = this.main_container.getChildByName("mail_con");
        this.icon = this.mail_con.getChildByName("icon").getComponent(cc.Sprite);
        this.mail_title = this.mail_con.getChildByName("title").getComponent(cc.Label);
        this.time = this.mail_con.getChildByName("time").getComponent(cc.Label);
        this.unread = this.mail_con.getChildByName("unread").getComponent(cc.Label);
        this.unread.string = ("未读")
 
        this.notice_con = this.main_container.getChildByName("notice_con");
        this.notice_title = this.notice_con.getChildByName("title").getComponent(cc.Label);
        this.notice_content = this.notice_con.getChildByName("content").getComponent(cc.Label);
 
        this.onShow()
    },
 
 
    registerEvent: function () {
        if (this.main_container == null) return
        this.main_container.on(cc.Node.EventType.TOUCH_END, function () {
            if (this.data != null && this.callback != null)
                this.callback(this);
        }, this)
 
    },
 
    addCallBack: function (value) {
        this.callback = value
    },
 
    //必要添加的数据传入方法
    setData: function (data) {
        this.data = data;
        this.onShow()
    },
 
    onShow: function () {
        if (this.data == null)
            return
        if (this.root_wnd == null)
            return
        // this.root_wnd.setPosition(this.x, this.y);
        if (this.data.status >= 0) { //邮件
            this.mail_con.active = true;
            this.notice_con.active = false;
            var show_time = TimeTool.getDayOrHour(gcore.SmartSocket.getTime() - this.data.send_time);
            if (show_time) {
                this.time.string = show_time + "前";
            } else {
                this.time.string = "";
            }
            this.changeIcon(this.data.status);
            this.mail_title.string = this.data.subject;
        } else if (this.data.flag >= 0) {  //公告
            this.mail_con.active = false;
            this.notice_con.active = true;
            this.notice_title.string = this.data.title;
            this.notice_content.string = this.data.summary;
            this.setGray(this.data.flag == 1);
        }
    },
 
    //邮件的icon改变
    changeIcon: function (status) {
        if (status != null) {
            if (status == 1) {  //已读
                this.setGray(true);
                if (Utils.getArrLen(this.data.assets) > 0 || Utils.getArrLen(this.data.items) > 0) {
                    this.loadRes(PathTool.getUIIconPath("mail", "mail_icon4"), function (sf_obj) {
                        this.icon.spriteFrame = sf_obj;
                    }.bind(this))
                } else if (Utils.getArrLen(this.data.assets) == 0 || Utils.getArrLen(this.data.items) == 0) {
                    this.loadRes(PathTool.getUIIconPath("mail", "mail_icon3"), function (sf_obj) {
                        this.icon.spriteFrame = sf_obj;
                    }.bind(this))
                }
            } else if (status == 2) {  //领了
                this.setGray(true);
                this.loadRes(PathTool.getUIIconPath("mail", "mail_icon3"), function (sf_obj) {
                    this.icon.spriteFrame = sf_obj;
                }.bind(this))
            } else if (status == 0) {  //未读
                this.setGray(false);
                if (Utils.getArrLen(this.data.assets) > 0 || Utils.getArrLen(this.data.items) > 0) {  //有物品
                    this.loadRes(PathTool.getUIIconPath("mail", "mail_icon2"), function (sf_obj) {
                        this.icon.spriteFrame = sf_obj;
                    }.bind(this))
                } else {
                    this.loadRes(PathTool.getUIIconPath("mail", "mail_icon1"), function (sf_obj) {
                        this.icon.spriteFrame = sf_obj;
                    }.bind(this))
                }
            }
        }
    },
 
    setGray: function (status) {
        if (status) {
            this.root_wnd.opacity = 178;
            this.unread.node.active = false;
        } else {
            this.root_wnd.opacity = 255;
            this.unread.node.active = true;
        }
    },
 
    getData: function () {
        return this.data
    },
 
    updateIconStatus:function(){
        if(this.data == null)return
        var status = this.data.status;
        this.changeIcon(status)
    },
 
    onHide: function () {
 
    },
 
    onDelete: function () {
 
    }
 
});
 
module.exports = MailCell;