CntInfo.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. return;
  55. }
  56. if (this.isOutCnt) {
  57. console.warn("点击提现过快!");
  58. return;
  59. }
  60. this.isOutCnt = true;
  61. GlobalD.GameData.onCntWithdraw(this.inputInviteValue, (data) => {
  62. this.isOutCnt = false;
  63. const [err, tx] = data;
  64. if (err === null) {
  65. console.log(tx) //String|null 交易唯一哈市
  66. GlobalD.GameData.onCntCanWithdrawBalance((data) => {
  67. console.log("站内收益余额:", GlobalD.GameData.CNTDrawBalance);
  68. //更新数据
  69. this.setInfo();
  70. });
  71. //更新钱包余额,
  72. GlobalD.dapp.cntBalance().then((cntBalance) => {
  73. // console.log("更新cnt:" + cntBalance) // string, 精度18,需要自行处理省略几位小数
  74. GlobalD.GameData.SetCNT(cntBalance);
  75. });
  76. //更新日志数据
  77. cc.find("GameNode/ManageDapp").getComponent("ManageDapp").onUpdateCntList();
  78. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "成功提现!", 1);
  79. } else {
  80. GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), err, 2);
  81. }
  82. });
  83. }
  84. });