RedBagCashData.ts 3.9 KB

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