index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '', leftArrow: true, useBar: false },
  10. // 主体高度
  11. infoHeight: '',
  12. form: {},
  13. // 用户类别
  14. typeList: [
  15. { label: '0', value: '管理用户' },
  16. { label: '1', value: '团队创建人' },
  17. { label: '2', value: '个人用户' }
  18. ],
  19. },
  20. initValidate() {
  21. const rules = { phone: { required: true, tel: true }, password: { required: true, } }
  22. // 验证字段的提示信息,若不传则调用默认的信息
  23. const messages = { phone: { required: '请输入账号', }, password: { required: '请输入密码', } };
  24. this.WxValidate = new WxValidate(rules, messages)
  25. },
  26. back: function () {
  27. wx.navigateBack({ url: '/pages/login/index' })
  28. },
  29. // 选择用户类别
  30. typeChange: function (e) {
  31. const that = this;
  32. let index = e.detail.value;
  33. let data = that.data.typeList[index];
  34. if (data) that.setData({ 'form.type': data.label });
  35. that.setData({ 'form.type_name': data.value });
  36. },
  37. // 提交登录
  38. onSubmit: function (e) {
  39. const that = this;
  40. const params = e.detail.value;
  41. if (!this.WxValidate.checkForm(params)) {
  42. const error = this.WxValidate.errorList[0];
  43. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  44. return false
  45. } else {
  46. if (params.password !== params.is_password) {
  47. wx.showToast({ title: '密码输入不一致', duration: 2000, icon: 'error', })
  48. } else {
  49. wx.request({
  50. url: `${app.globalData.publicUrl}/courtAdmin/api/user`, //接口地址
  51. method: 'post',
  52. data: params,
  53. success(res) {
  54. if (res.data.errcode == 0) {
  55. wx.showToast({
  56. title: '注册账号成功',
  57. duration: 2000,
  58. icon: 'success',
  59. success: (res) => { that.back() }
  60. })
  61. } else {
  62. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  63. }
  64. }
  65. })
  66. }
  67. }
  68. },
  69. /**
  70. * 生命周期函数--监听页面加载
  71. */
  72. onLoad: function (options) {
  73. //验证规则函数
  74. this.initValidate()
  75. // 计算高度
  76. this.searchHeight()
  77. },
  78. // 计算高度
  79. searchHeight: function () {
  80. let frameStyle = this.data.frameStyle;
  81. let client = app.globalData.client;
  82. let infoHeight = client.windowHeight;
  83. // 是否去掉状态栏
  84. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  85. // 是否减去底部菜单
  86. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  87. if (infoHeight) this.setData({ infoHeight: infoHeight })
  88. },
  89. /**
  90. * 生命周期函数--监听页面初次渲染完成
  91. */
  92. onReady: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面显示
  96. */
  97. onShow: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面隐藏
  101. */
  102. onHide: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面卸载
  106. */
  107. onUnload: function () {
  108. },
  109. /**
  110. * 页面相关事件处理函数--监听用户下拉动作
  111. */
  112. onPullDownRefresh: function () {
  113. },
  114. /**
  115. * 页面上拉触底事件的处理函数
  116. */
  117. onReachBottom: function () {
  118. },
  119. /**
  120. * 用户点击右上角分享
  121. */
  122. onShareAppMessage: function () {
  123. }
  124. })