mailbox_read_item.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { _decorator, Color, Component, Label, Node, Sprite, SpriteFrame, UITransform } from 'cc';
  2. import { mail_item_data } from '../../data';
  3. import { base_ui } from '../../fw/base_ui';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('mailbox_read_item')
  6. export class mailbox_read_item extends base_ui {
  7. @property(Node) lab_title:Node = null
  8. @property(Node) lab_time:Node = null
  9. @property(Node) lab_read_status:Node = null
  10. @property(Node) img_read_dot:Node = null
  11. @property(SpriteFrame) sf_read:SpriteFrame = null
  12. @property(SpriteFrame) sf_unread:SpriteFrame = null
  13. private read_color:Color = new Color().fromHEX("#7a8594")
  14. private unread_color:Color = new Color().fromHEX("#000000")
  15. private m_data:mail_item_data = null
  16. private m_click_cb = null
  17. start() {
  18. this.onButtonListen(this.node, ()=>{
  19. if(this.m_click_cb) {
  20. this.m_click_cb(this)
  21. }
  22. })
  23. }
  24. initView(data:mail_item_data, click_cb) {
  25. this.setData(data)
  26. this.m_click_cb = click_cb
  27. }
  28. public setData(data:mail_item_data) {
  29. this.m_data = data
  30. this.lab_title.getComponent(Label).string = this.m_data.title
  31. this.lab_time.getComponent(Label).string = this.m_data.create_at
  32. if(this.m_data.state==1) {
  33. this.node.getComponent(Sprite).spriteFrame = this.sf_read
  34. this.lab_title.getComponent(Label).color = this.read_color
  35. this.lab_time.getComponent(Label).color = this.read_color
  36. this.lab_read_status.getComponent(Label).color = this.read_color
  37. this.lab_read_status.getComponent(Label).string = '已读'
  38. this.img_read_dot.active = false
  39. } else {
  40. this.node.getComponent(Sprite).spriteFrame = this.sf_unread
  41. this.lab_title.getComponent(Label).color = this.unread_color
  42. this.lab_time.getComponent(Label).color = this.unread_color
  43. this.lab_read_status.getComponent(Label).color = new Color().fromHEX("#008614")
  44. this.lab_read_status.getComponent(Label).string = '未读'
  45. this.img_read_dot.active = true
  46. }
  47. }
  48. public getData():mail_item_data {
  49. return this.m_data
  50. }
  51. }