phone.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import Toast from '@vant/weapp/toast/toast';
  2. const _Http = getApp().globalData.http;
  3. const md5 = require("../../utils/md5");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. isAgree: true,
  10. accountno: "",
  11. password: "",
  12. inputType: "password", //密码输入框类型
  13. memory: true, //记忆
  14. disabled: true, //是否禁用
  15. loading: false, //登陆中
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad(options) {
  21. this.setData({
  22. ...wx.getStorageSync('loginMsg')
  23. })
  24. this.allowOrNot()
  25. },
  26. /* 用户登录 */
  27. userLogin() {
  28. if (this.data.loading || this.data.disabled) return;
  29. if (!this.data.isAgree) return Toast({
  30. message: '请阅读并勾选用户协议',
  31. position: 'bottom'
  32. });
  33. this.setData({
  34. loading: true
  35. })
  36. _Http.login({
  37. "accountno": this.data.accountno,
  38. "password": md5.hexMD5(this.data.password),
  39. "systemclient": "wechatsaletool"
  40. }).then(res => {
  41. console.log("登录", res)
  42. this.setData({
  43. loading: false
  44. })
  45. if (res.msg != '成功') return wx.showToast({
  46. title: res.msg,
  47. icon: "none"
  48. })
  49. wx.setStorageSync('account_list', res.account_list)
  50. wx.setStorageSync('loginMsg', {
  51. accountno: this.data.accountno,
  52. password: (this.data.memory) ? this.data.password : ''
  53. })
  54. if (res.account_list.length == 1) {
  55. wx.setStorageSync('userMsg', res.account_list[0])
  56. wx.switchTab({
  57. url: '/pages/tabbar/home/index'
  58. })
  59. } else {
  60. wx.redirectTo({
  61. url: './selectSite',
  62. })
  63. }
  64. })
  65. },
  66. /* 改变密码输入框类型 */
  67. changePasswordType() {
  68. this.setData({
  69. inputType: this.data.inputType == "text" ? 'password' : 'text'
  70. })
  71. },
  72. /* 授权 */
  73. agreementChange({
  74. detail
  75. }) {
  76. this.setData({
  77. isAgree: detail
  78. })
  79. },
  80. /* 手机号 */
  81. inputPhone(e) {
  82. this.setData({
  83. accountno: e.detail.value.trim()
  84. })
  85. this.allowOrNot()
  86. },
  87. /* 密码 */
  88. inputPassword(e) {
  89. this.setData({
  90. password: e.detail.value.trim()
  91. })
  92. this.allowOrNot()
  93. },
  94. /* 验证是否允许登录 */
  95. allowOrNot() {
  96. this.setData({
  97. disabled: (this.data.accountno.length > 0 && this.data.password.length > 5) ? false : true
  98. })
  99. },
  100. /* 是否记忆密码 */
  101. isMemory() {
  102. this.setData({
  103. memory: !this.data.memory
  104. })
  105. },
  106. /**
  107. * 生命周期函数--监听页面初次渲染完成
  108. */
  109. onReady() {
  110. },
  111. /**
  112. * 生命周期函数--监听页面显示
  113. */
  114. onShow() {
  115. },
  116. /**
  117. * 生命周期函数--监听页面隐藏
  118. */
  119. onHide() {
  120. },
  121. /**
  122. * 生命周期函数--监听页面卸载
  123. */
  124. onUnload() {
  125. },
  126. /**
  127. * 页面相关事件处理函数--监听用户下拉动作
  128. */
  129. onPullDownRefresh() {
  130. },
  131. /**
  132. * 页面上拉触底事件的处理函数
  133. */
  134. onReachBottom() {
  135. },
  136. /**
  137. * 用户点击右上角分享
  138. */
  139. onShareAppMessage() {
  140. }
  141. })