changePhone.js 940 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import {getDataSet, getEventParam, isMobile, toast} from "../../utils/utils";
  2. import Api from "../../model/api";
  3. import User from "../../model/user";
  4. Page({
  5. data: {
  6. formData: {
  7. phone: '',
  8. checkNum: '',
  9. }
  10. },
  11. onLoad: function (options) {
  12. },
  13. onChange(e) {
  14. const field = getDataSet(e, "field");
  15. this.setData({
  16. [field]: getEventParam(e)
  17. })
  18. },
  19. async update(e) {
  20. if (!isMobile(this.data.formData.phone)) {
  21. toast('请输入正确的手机号')
  22. return;
  23. }
  24. if (!this.data.formData.checkNum.trim()) {
  25. toast('请输入验证码')
  26. return;
  27. }
  28. await Api.updatePhone(this.data.formData, true)
  29. let user = User.getUserInfoByLocal();
  30. user.phone = this.data.formData.phone;
  31. await User.updateUserInfo(user)
  32. wx.navigateBack();
  33. }
  34. })