CntInfo.js 3.5 KB

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