MailInfo.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import Main from "../../main/Main";
  2. import ViewObject from "../../main/ViewObject";
  3. import { HttpStateType, ReveData } from "../../util/CHttp";
  4. import GoodItem from "../common/GoodItem";
  5. import Mail from "./Mail";
  6. import MailItem from "./MailItem";
  7. const {ccclass, property} = cc._decorator;
  8. @ccclass
  9. export default class MailInfo extends cc.Component {
  10. @property(cc.Label)
  11. mTitle: cc.Label = null;
  12. @property(cc.Label)
  13. mContent: cc.Label = null;
  14. @property(cc.Node)
  15. mReward: cc.Node = null;
  16. @property(cc.Label)
  17. mTime: cc.Label = null;
  18. @property(cc.Prefab)
  19. mGoodItem: cc.Prefab = null;
  20. @property(cc.Button)
  21. mBTReward: cc.Button = null;
  22. @property(cc.Label)
  23. mBTLable: cc.Label = null;
  24. @property(cc.Node)
  25. mMailYes: cc.Node = null;
  26. @property(cc.Node)
  27. mMailNo: cc.Node = null;
  28. /**
  29. * 邮件内容
  30. */
  31. public mailItem:MailItem;
  32. private mail:Mail
  33. private main:Main
  34. public data:any;
  35. onLoad () {
  36. this.mMailNo.active = true
  37. this.mMailYes.active = false
  38. }
  39. start(){
  40. this.mail = this.node.getComponent(Mail)
  41. this.main = this.mail.main;
  42. }
  43. public setMail(mailItem:MailItem){
  44. this.mMailNo.active = false
  45. this.mMailYes.active = true
  46. this.mailItem = mailItem
  47. this.data = this.mailItem.data
  48. this.flush();
  49. }
  50. public flush(){
  51. this.mBTReward.interactable = !this.data.receive;
  52. if(this.data.receive){
  53. this.mBTLable.string = '已领取';
  54. }else{
  55. this.mBTLable.string = '领取';
  56. }
  57. }
  58. public getMailInfo(){
  59. this.mTitle.string = this.data.title;
  60. let msg = {
  61. mailId:this.data.id
  62. }
  63. this.main.gameHttp.sendJson('email/v1/info',msg,(state,reve:ReveData)=>{
  64. this.main.stopLoad();
  65. if(state == HttpStateType.SUCCESS){
  66. if(reve.retCode == 0){
  67. this.data = reve.data;
  68. this.initData();
  69. }else{
  70. this.main.showTips(reve.message);
  71. }
  72. }else{
  73. this.main.showTips('网络异常');
  74. }
  75. });
  76. }
  77. private initData(){
  78. this.node.getComponent(Mail).mInfoNode.active = true
  79. this.mContent.string = this.data.content;
  80. this.mTime.string = this.data.date+' '+this.data.time;
  81. // "appendix":"[{\"icon\":\"aa\",\"count\":1}]"
  82. this.mReward.destroyAllChildren()
  83. if(this.data.appendix){
  84. let goods = JSON.parse(this.data.appendix);
  85. for (let i = 0; i < goods.length; i++) {
  86. const element = goods[i];
  87. let node = cc.instantiate(this.mGoodItem);
  88. let gl = node.getComponent(GoodItem);
  89. gl.init(this.main,element);
  90. node.parent = this.mReward;
  91. }
  92. }
  93. }
  94. public onclickGet(){
  95. let msg = {
  96. mailId:this.data.id
  97. }
  98. this.main.gameHttp.sendJson('email/v1/receive',msg,(state,reve:ReveData)=>{
  99. this.main.stopLoad();
  100. if(state == HttpStateType.SUCCESS){
  101. if(reve.retCode == 0){
  102. this.data.receive = true;
  103. this.flush();
  104. // this.main.showTips('获得各种奖励..');
  105. this.main.showReward(reve)
  106. this.mailItem.tipsIcon.active = false;
  107. }else{
  108. this.main.showTips(reve.message);
  109. }
  110. }else{
  111. this.main.showTips('网络异常');
  112. }
  113. });
  114. }
  115. }