RedBagCashData.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import { Data } from "../../../mk/data/Data";
  2. import { GameProp } from "../GameData";
  3. /**
  4. * 红包提现数据
  5. * - 跨Index不可提现,提示:请按顺序提现。
  6. * @author 薛鸿潇
  7. */
  8. export class RedBagCashData extends Data {
  9. /**
  10. * 数据初始化
  11. */
  12. public init() {
  13. // 提现进度
  14. // this.cash_bar = gData.gameData.getProp(GameProp.redBag_cash_bar);// 自定义测试数据
  15. this.cash_bar = gData.gameData.gameData.cashIndex;// 服务端数据
  16. // this.initCData();// 假数据列表
  17. // 签到配置表
  18. if (gData.gameData.configs.CashCfg) {
  19. gData.gameData.configs.CashCfg.forEach(item_data => {
  20. for (const key in item_data) {
  21. item_data[key] = parseInt(item_data[key])
  22. }
  23. });
  24. this.c_data = gData.gameData.configs.CashCfg;
  25. this.sortList();
  26. this.init_list = true;
  27. }
  28. }
  29. /** 标志位:初始化列表 */
  30. public init_list: boolean = false;
  31. /** 配置表数据 */
  32. public c_data: Array<CDataType> = [];
  33. private _cash_bar: number = 0;
  34. /** 提现进度 */
  35. set cash_bar(value: number) {
  36. this._cash_bar = value;
  37. this.init_list = true;
  38. }
  39. get cash_bar() {
  40. return this._cash_bar;
  41. }
  42. /**
  43. * 提现操作
  44. */
  45. public cashOP() {
  46. /** 提现档位 */
  47. const cash_index = this.cash_bar;
  48. this.cash_bar++;
  49. gData.gameData.setProp(GameProp.redBag_cash_bar, this.cash_bar);
  50. // 扣除红包
  51. this.sortList();
  52. let item_data = this.getItemDataByIndex(cash_index);
  53. gData.gameData.gameData.redMoney -= item_data.type_value;
  54. // 打开提现到账界面
  55. gData.receiptNotice.receip_rmb = item_data.money;
  56. gData.cashNormal.receip_total_rmb += gData.receiptNotice.receip_rmb;
  57. mk.ui.openPanel('module/receiptNotice/receiptNotice');
  58. }
  59. /**
  60. * 排序
  61. * - 已提条目放最后
  62. */
  63. private sortList() {
  64. const l_count = this.c_data.length;
  65. let index = 0;
  66. for (let i = 0; i < l_count; i++) {
  67. if (this.c_data[index].index <= gData.redBagCash.cash_bar) {
  68. let item_data = this.c_data.splice(index, 1);
  69. this.c_data.push(item_data[0]);
  70. index--;
  71. }
  72. index++;
  73. }
  74. }
  75. /**
  76. * 获取条目,通过index
  77. * @param cash_index 对应id
  78. * @returns
  79. */
  80. public getItemDataByIndex(cash_index: number): CDataType {
  81. const l_count = this.c_data.length;
  82. for (let i = 0; i < l_count; i++) {
  83. if (this.c_data[i].index === cash_index) {
  84. return this.c_data[i]
  85. }
  86. }
  87. }
  88. /** 客户端造的假数据 */
  89. private initCData() {
  90. for (let i = 0; i < 20; i++) {
  91. const id = i + 1;
  92. let obj = {
  93. index: id,
  94. /** 毛币数量? */
  95. money: id,
  96. /** 红包数量 */
  97. type_value: id * 1000,
  98. time: id,
  99. directVideoTime: id,
  100. delayVideoTimes: id,
  101. money_type: id,
  102. num: id,
  103. moneyshow: id,
  104. summoney: id
  105. };
  106. this.c_data.push(obj)
  107. }
  108. this.init_list = true;
  109. }
  110. }
  111. /** 配置表数据内容 */
  112. export type CDataType = {
  113. /** id */
  114. index: number,
  115. /** 毛币数量,单位分 */
  116. money: number,
  117. /** 红包币数量 */
  118. type_value: number,
  119. time: number,
  120. directVideoTime: number,
  121. delayVideoTimes: number,
  122. money_type: number,
  123. num: number,
  124. moneyshow: number,
  125. summoney: number
  126. }