CntInfo.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. amountValue: {
  5. default: null,
  6. type: cc.Label,
  7. serializable: true,
  8. },
  9. inputContainer: {
  10. default: null,
  11. type: cc.Node,
  12. serializable: true,
  13. },
  14. inputInviteValue: {
  15. default: 1,
  16. visible: false
  17. },
  18. isOutCnt: false,
  19. },
  20. inputValue(value, e) {
  21. var numberTemp = new RegExp("^[A-Za-z0-9]+$");
  22. if (numberTemp.test(value)) {
  23. if (Number(value) >= 1) {
  24. this.inputInviteValue = Number(value);
  25. } else {
  26. this.inputInviteValue = 1;
  27. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  28. }
  29. } else {
  30. this.inputInviteValue = 1;
  31. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  32. console.log("请输入整数的倍数", this.inputInviteValue);
  33. }
  34. },
  35. setInfo() {
  36. this.amountValue.string = Math.floor( GlobalD.GameData.CNTDrawBalance * 100) / 100;
  37. },
  38. onclose() {
  39. this.node.active = false;
  40. },
  41. onPanelCntWithdraw() {
  42. //todo 判断一下amount
  43. console.log(this.inputInviteValue,GlobalD.GameData.CNTDrawBalance);
  44. if (this.inputInviteValue > GlobalD.GameData.CNTDrawBalance) {
  45. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "提现的cnt不足!", 2, () => {
  46. console.log("finish toast!");
  47. });
  48. return;
  49. }
  50. if (this.isOutCnt) {
  51. console.warn("点击提现过快!");
  52. return;
  53. }
  54. this.isOutCnt = true;
  55. GlobalD.GameData.onCntWithdraw(this.inputInviteValue, (data) => {
  56. this.isOutCnt = false;
  57. const [err, tx] = data;
  58. if (err === null) {
  59. console.log(tx) //String|null 交易唯一哈市
  60. GlobalD.GameData.onCntCanWithdrawBalance((data) => {
  61. console.log("站内收益余额:",GlobalD.GameData.CNTDrawBalance);
  62. //更新数据
  63. this.setInfo();
  64. });
  65. //更新钱包余额,
  66. GlobalD.dapp.cntBalance().then((cntBalance) => {
  67. // console.log("更新cnt:" + cntBalance) // string, 精度18,需要自行处理省略几位小数
  68. GlobalD.GameData.SetCNT(cntBalance);
  69. });
  70. //更新日志数据
  71. cc.find("GameNode/ManageDapp").getComponent("ManageDapp").onUpdateCntList();
  72. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "成功提现!", 1, () => {
  73. console.log("finish toast!");
  74. });
  75. } else {
  76. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), err, 2, () => {
  77. console.log("finish toast!");
  78. });
  79. }
  80. });
  81. }
  82. });