RedBagCashData.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 async cashOP() {
  46. /** 提现档位 */
  47. const cash_index = this.cash_bar;
  48. let data = { index: cash_index };
  49. let response = await mk.http.sendData('cashUsual', data);
  50. if (response.errcode != 0) {
  51. mk.tip.pop(response.errmsg);
  52. return;
  53. }
  54. this.cash_bar++;
  55. // gData.gameData.setProp(GameProp.redBag_cash_bar, this.cash_bar);
  56. gData.gameData.gameData.cashIndex++;
  57. // 扣除红包
  58. this.sortList();
  59. let item_data = this.getItemDataByIndex(cash_index);
  60. gData.gameData.gameData.redMoney -= item_data.type_value;
  61. // 打开提现到账界面
  62. gData.receiptNotice.receip_rmb = item_data.money;
  63. gData.cashNormal.receip_total_rmb += gData.receiptNotice.receip_rmb;
  64. mk.ui.openPanel('module/receiptNotice/receiptNotice');
  65. }
  66. /**
  67. * 排序
  68. * - 已提条目放最后
  69. */
  70. private sortList() {
  71. const l_count = this.c_data.length;
  72. let index = 0;
  73. for (let i = 0; i < l_count; i++) {
  74. if (this.c_data[index].index <= gData.redBagCash.cash_bar) {
  75. let item_data = this.c_data.splice(index, 1);
  76. this.c_data.push(item_data[0]);
  77. index--;
  78. }
  79. index++;
  80. }
  81. }
  82. /**
  83. * 获取条目,通过index
  84. * @param cash_index 对应id
  85. * @returns
  86. */
  87. public getItemDataByIndex(cash_index: number): CDataType {
  88. const l_count = this.c_data.length;
  89. for (let i = 0; i < l_count; i++) {
  90. if (this.c_data[i].index === cash_index) {
  91. return this.c_data[i]
  92. }
  93. }
  94. }
  95. /** 客户端造的假数据 */
  96. private initCData() {
  97. for (let i = 0; i < 20; i++) {
  98. const id = i + 1;
  99. let obj = {
  100. index: id,
  101. /** 毛币数量? */
  102. money: id,
  103. /** 红包数量 */
  104. type_value: id * 1000,
  105. time: id,
  106. directVideoTime: id,
  107. delayVideoTimes: id,
  108. money_type: id,
  109. num: id,
  110. moneyshow: id,
  111. summoney: id
  112. };
  113. this.c_data.push(obj)
  114. }
  115. this.init_list = true;
  116. }
  117. }
  118. /** 配置表数据内容 */
  119. export type CDataType = {
  120. /** id */
  121. index: number,
  122. /** 毛币数量,单位分 */
  123. money: number,
  124. /** 红包币数量 */
  125. type_value: number,
  126. time: number,
  127. directVideoTime: number,
  128. delayVideoTimes: number,
  129. money_type: number,
  130. num: number,
  131. moneyshow: number,
  132. summoney: number
  133. }