BindPhone.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { _decorator, Button, Color, EditBox, instantiate, Label, Node, RichText, Sprite, SpriteFrame, UITransform } from 'cc';
  2. import { UIViewID } from '@scripts/define/UIDefine';
  3. import { UICloseReason } from '@scripts/framework/ui/UILayer';
  4. import { addBtnClick } from '@scripts/utils/UIHelper';
  5. import { AppKernel } from '@scripts/app/AppKernel';
  6. import { SelectBox } from '@scripts/components/selectBox/SelectBox';
  7. import { UIPopup } from '@scripts/framework/ui/UIPopup';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('BindPhone')
  10. export class BindPhone extends UIPopup {
  11. readonly viewId = UIViewID.BindPhone;
  12. @property(SelectBox)
  13. private select_country: SelectBox = null;
  14. @property(Node)
  15. private btn_close: Node = null;
  16. @property(Node)
  17. private btn_cancel: Node = null;
  18. @property(Node)
  19. private btn_confirm: Node = null;
  20. @property(Node)
  21. private btn_grey: Node = null;
  22. @property(EditBox)
  23. private phone: EditBox = null;
  24. @property(EditBox)
  25. private psd: EditBox = null;
  26. @property(EditBox)
  27. private verify_code: EditBox = null;
  28. @property(Label)
  29. private psd_label: Label = null;
  30. private _phone: string = '';
  31. private _psd: string = '';
  32. private _verify_code: string = '';
  33. protected onCreate(): void | Promise<void> {
  34. addBtnClick(this.btn_close, this.onBtnCloseClick, this);
  35. addBtnClick(this.btn_cancel, this.onBtnCloseClick, this);
  36. addBtnClick(this.btn_confirm, this.onBtnConfirmClick, this);
  37. this.phone.node.on(EditBox.EventType.TEXT_CHANGED, this.onPhoneTextChanged, this);
  38. this.psd.node.on(EditBox.EventType.TEXT_CHANGED, this.onPsdTextChanged, this);
  39. this.verify_code.node.on(EditBox.EventType.TEXT_CHANGED, this.onVerifyCodeTextChanged, this);
  40. const { isGuest } = AppKernel.stores.mainStore.userInfo;
  41. const hasPsd = isGuest ? false : true;
  42. this.psd_label.string = hasPsd ? 'Current Password' : 'Set Password';
  43. this.psd.placeholder = hasPsd ? 'Current Password' : 'Set Password';
  44. this.select_country.initSelectItems(["+1 United States"], { defaultIndex: 0 });
  45. }
  46. private onBtnCloseClick() {
  47. AppKernel.ui.close(UIViewID.BindPhone);
  48. }
  49. private async onBtnConfirmClick() {
  50. const phone = this.phone.string;
  51. const pwd = this.psd.string;
  52. const code = this.verify_code.string;
  53. const isReady = !!phone && !!pwd && !!code;
  54. if (!isReady) return;
  55. const res = await AppKernel.stores.mainStore.reqBindPhoneConfirm({
  56. account: phone,
  57. password: pwd,
  58. code: code
  59. });
  60. if (res) {
  61. await AppKernel.ui.close(UIViewID.BindPhone);
  62. AppKernel.ui.toast("Bind success");
  63. }
  64. }
  65. private onTextChanged() {
  66. const isReady = !!this.phone && !!this._psd && !!this._verify_code;
  67. this.btn_grey.active = !isReady;
  68. this.btn_confirm.active = isReady;
  69. }
  70. private onPhoneTextChanged(editBox: EditBox) {
  71. console.log('onPhoneTextChanged', editBox.string);
  72. this._phone = editBox.string;
  73. this.onTextChanged();
  74. }
  75. private onPsdTextChanged(editBox: EditBox) {
  76. console.log('onPsdTextChanged', editBox.string);
  77. this._psd = editBox.string;
  78. this.onTextChanged();
  79. }
  80. private onVerifyCodeTextChanged(editBox: EditBox) {
  81. console.log('onVerifyCodeTextChanged', editBox.string);
  82. this._verify_code = editBox.string;
  83. this.onTextChanged();
  84. }
  85. }