login.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {
  2. getDataSet,
  3. getEventParam,
  4. isMobile,
  5. toast
  6. } from "../../utils/utils";
  7. import User from "../../model/user";
  8. import Route from "../../model/route";
  9. import Api from "../../model/api";
  10. import {logicStatus} from '../../model/enum';
  11. Page({
  12. data: {
  13. formData: {
  14. phone: '',
  15. verify: '',
  16. },
  17. isShowBack: true,
  18. showRegister: false
  19. },
  20. onLoad: function (options) {
  21. this.getRegsiterDisplayStatus();
  22. },
  23. async login(e) {
  24. if (!isMobile(this.data.formData.phone)) {
  25. toast('请输入正确的手机号')
  26. return;
  27. }
  28. if (!this.data.formData.verify.trim()) {
  29. toast('请输入验证码')
  30. return;
  31. }
  32. await User.loginByPhone(this.data.formData);
  33. const eventChannel = this.getOpenerEventChannel()
  34. if (eventChannel.emit) {
  35. eventChannel.emit('login', {
  36. isLogin: true
  37. });
  38. }
  39. wx.navigateBack();
  40. },
  41. register() {
  42. Route.toRegister()
  43. },
  44. async loginByWechat(e) {
  45. await User.loginByWechat();
  46. const eventChannel = this.getOpenerEventChannel()
  47. if (eventChannel.emit) {
  48. eventChannel.emit('login', {
  49. isLogin: true
  50. });
  51. }
  52. wx.navigateBack();
  53. },
  54. onChange(e) {
  55. const field = getDataSet(e, "field");
  56. this.setData({
  57. [field]: getEventParam(e)
  58. })
  59. },
  60. back() {
  61. const eventChannel = this.getOpenerEventChannel()
  62. if (eventChannel.emit) {
  63. eventChannel.emit('login', {
  64. isLogin: false
  65. });
  66. }
  67. wx.navigateBack();
  68. },
  69. async getRegsiterDisplayStatus() {
  70. let {
  71. data
  72. } = await Api.getPulishDict('sys_register_status');
  73. if (data && data.length > 0) {
  74. let status = data[0]['dictValue'];
  75. let showRegister = logicStatus.YES == status;
  76. this.setData({
  77. showRegister
  78. });
  79. }
  80. }
  81. });