RedBagCash.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import TableView from "../../component/TableView";
  2. const { ccclass, property } = cc._decorator;
  3. /**
  4. * 红包提现界面
  5. * @author 薛鸿潇
  6. */
  7. @ccclass
  8. export default class RedBagCash extends cc.Component {
  9. @property({ displayName: '滚动视图', type: cc.ScrollView })
  10. private sroll_view: cc.ScrollView = null!;
  11. @property({ displayName: '条目容器', type: cc.Node })
  12. private node_content: cc.Node = null!;
  13. @property({ displayName: 'lbl红包数量', type: cc.Label })
  14. private lbl_redbag: cc.Label = null!;
  15. @property({ displayName: 'lbl毛币数量', type: cc.Label })
  16. private lbl_rmb: cc.Label = null!;
  17. private tableview: TableView = null;
  18. onLoad() {
  19. // gData.gameData.gameData.redMoney = 10200;// 测试数据,数据正确后请删除
  20. this.tableview = this.sroll_view.getComponent('TableView');
  21. }
  22. start() {
  23. gData.redBagCash.init_list = true;
  24. // this.initMoney();
  25. // this.initScrollView();
  26. }
  27. update(dt) {
  28. if (gData.redBagCash.init_list) {
  29. this.initScrollView();
  30. this.initMoney();
  31. }
  32. }
  33. lateUpdate() {
  34. gData.redBagCash.init_list = false;
  35. }
  36. /**
  37. * 初始化滚动视图
  38. */
  39. private initScrollView() {
  40. this.sroll_view.node.emit('srollview-init', gData.redBagCash.c_data);
  41. // 条目动画
  42. this.scheduleOnce(() => {
  43. this.itemAnim();
  44. }, 0)
  45. }
  46. private itemAnim() {
  47. let arr_node = this.node_content.children;
  48. const n_count = this.node_content.childrenCount;
  49. const start_pos = new cc.Vec2(0, -this.sroll_view.node.height);
  50. for (let i = 0; i < n_count; i++) {
  51. let node_item = arr_node[i];
  52. const end_pos = node_item.getPosition();
  53. node_item.y = start_pos.y;
  54. this.scheduleOnce(() => {
  55. mk.tween.move(node_item, 0.6, start_pos, end_pos, null, 'backOut');
  56. }, i * 0.1)
  57. }
  58. }
  59. /**
  60. * 初始化货币数量
  61. */
  62. private initMoney() {
  63. this.lbl_redbag.string = `${gData.gameData.gameData.redMoney}`;
  64. let rmb = gData.gameData.gameData.redMoney / 10000;
  65. rmb = rmb > 1 ? Math.floor(rmb) : parseFloat(rmb.toFixed(2));
  66. this.lbl_rmb.string = `${rmb}`;
  67. }
  68. }