ChangePhone.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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('ChangePhone')
  10. export class ChangePhone extends UIPopup {
  11. readonly viewId = UIViewID.ChangePhone;
  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 cur_phone_code: EditBox = null;
  24. @property(EditBox)
  25. private new_phone: EditBox = null;
  26. @property(EditBox)
  27. private psd: EditBox = null;
  28. @property(EditBox)
  29. private verify_code: EditBox = null;
  30. @property(Label)
  31. private cur_phone: Label = null;
  32. private _cur_phone_code: string = '';
  33. private _new_phone: string = '';
  34. private _psd: string = '';
  35. private _verify_code: string = '';
  36. protected onCreate(): void | Promise<void> {
  37. addBtnClick(this.btn_close, this.onBtnCloseClick, this);
  38. addBtnClick(this.btn_cancel, this.onBtnCloseClick, this);
  39. addBtnClick(this.btn_confirm, this.onBtnConfirmClick, this);
  40. this.cur_phone_code.node.on(EditBox.EventType.TEXT_CHANGED, this.onCurPhoneCodeTextChanged, this);
  41. this.new_phone.node.on(EditBox.EventType.TEXT_CHANGED, this.onNewPhoneTextChanged, this);
  42. this.psd.node.on(EditBox.EventType.TEXT_CHANGED, this.onPsdTextChanged, this);
  43. this.verify_code.node.on(EditBox.EventType.TEXT_CHANGED, this.onVerifyCodeTextChanged, this);
  44. const { Phone } = AppKernel.stores.mainStore.userInfo;
  45. this.cur_phone.string = "Current Phone:" + Phone;
  46. this.select_country.initSelectItems(["+1 United States"], { defaultIndex: 0 });
  47. }
  48. private onBtnCloseClick() {
  49. AppKernel.ui.close(UIViewID.ChangePhone);
  50. }
  51. private async onBtnConfirmClick() {
  52. const old_code = this.cur_phone_code.string;
  53. const phone = this.new_phone.string;
  54. const pwd = this.psd.string;
  55. const new_code = this.verify_code.string;
  56. const isReady = !!old_code && !!phone && !!pwd && !!new_code;
  57. if (!isReady) return;
  58. const res = await AppKernel.stores.mainStore.reqChangePhoneConfirm({
  59. oldCode: old_code,
  60. newPhone: phone,
  61. newCode: new_code,
  62. password: pwd
  63. });
  64. if (res) {
  65. await AppKernel.ui.close(UIViewID.ChangePhone);
  66. AppKernel.ui.toast("Change success");
  67. }
  68. }
  69. private onTextChanged() {
  70. const isReady = !!this._cur_phone_code && !!this._new_phone && !!this._psd && !!this._verify_code;
  71. this.btn_grey.active = !isReady;
  72. this.btn_confirm.active = isReady;
  73. }
  74. private onCurPhoneCodeTextChanged(editBox: EditBox) {
  75. console.log('onCurPhoneCodeTextChanged', editBox.string);
  76. this._cur_phone_code = editBox.string;
  77. this.onTextChanged();
  78. }
  79. private onNewPhoneTextChanged(editBox: EditBox) {
  80. console.log('onNewPhoneTextChanged', editBox.string);
  81. this._new_phone = editBox.string;
  82. this.onTextChanged();
  83. }
  84. private onPsdTextChanged(editBox: EditBox) {
  85. console.log('onPsdTextChanged', editBox.string);
  86. this._psd = editBox.string;
  87. this.onTextChanged();
  88. }
  89. private onVerifyCodeTextChanged(editBox: EditBox) {
  90. console.log('onVerifyCodeTextChanged', editBox.string);
  91. this._verify_code = editBox.string;
  92. this.onTextChanged();
  93. }
  94. }