index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // pages/login/index.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. nvabarData: {
  9. showCapsule: 0, //是否显示左上角图标,消息中心 1表示显示 0表示不显示
  10. showBack: 1, //返回
  11. title: '登录', //导航栏 中间的标题
  12. // 此页面 页面内容距最顶部的距离
  13. height: app.globalData.height * 2 + 20,
  14. },
  15. user: {},
  16. password:'',
  17. phone:'',
  18. },
  19. formSubmit: function (e) {
  20. console.log('form发生了submit事件,携带数据为:', e.detail.value)
  21. let phone = e.detail.value.phone
  22. let passwd = e.detail.value.password
  23. if (phone) {
  24. if (passwd) {
  25. let pwdRegex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])');
  26. if (passwd.length <8||passwd.length >20||!pwdRegex.test(passwd) ) {
  27. wx.showModal({
  28. title: '提示',
  29. content: '密码格式错误',
  30. confirmText: '确定',
  31. success(res) {
  32. if (res.confirm) {
  33. // console.log('用户点击取消')
  34. } else if (res.cancel) {
  35. // console.log('用户点击取消')
  36. }
  37. }
  38. })
  39. } else {
  40. wx.request({
  41. method: "get",
  42. url: app.globalData.publicUrl + 'api/financial/companyuser',
  43. data: {
  44. phone: e.detail.value.phone
  45. },
  46. success: (e) => {
  47. if (e.data.errcode == 0) {
  48. console.log("login==================>"+e.data.data[0])
  49. // console.log("==================>"+delete e.data.data[0].IDcard)
  50. // if (e.data.data[0].IDcard) {
  51. // delete e.data.data[0].IDcard;
  52. // }
  53. if (e.data.data[0]!=undefined){
  54. delete e.data.data[0].IDcard;
  55. }
  56. if (e.data.data.length>0){
  57. delete e.data.data[0].IDcard;
  58. }
  59. this.setData({
  60. user: e.data.data[0]
  61. })
  62. // console.log('find---user',this.data.user);
  63. wx.request({
  64. method: "POST",
  65. url: app.globalData.publicUrl + 'api/financial/companyuser/login',
  66. data: {
  67. phone: phone,
  68. passwd: passwd
  69. },
  70. success: (e) => {
  71. console.log('success', e);
  72. if (e.data.errcode == 0) {
  73. wx.setStorage({
  74. key: 'user',
  75. data: this.data.user,
  76. })
  77. wx.redirectTo({
  78. url: '/pages/home/index'
  79. })
  80. } else {
  81. wx.showToast({
  82. title: e.data.errmsg,
  83. icon: 'none',
  84. duration: 1500
  85. })
  86. }
  87. }
  88. })
  89. }
  90. }
  91. })
  92. // wx.showToast({
  93. // title: '密码格式不正确,请重新输入',
  94. // icon: 'none',
  95. // duration: 1500
  96. // })
  97. }
  98. } else {
  99. wx.showToast({
  100. title: '密码为空,请重新输入',
  101. icon: 'none',
  102. duration: 1500
  103. })
  104. }
  105. } else {
  106. wx.showToast({
  107. title: '手机号为空,请输入手机号',
  108. icon: 'none',
  109. duration: 1500
  110. })
  111. }
  112. },
  113. // 忘记密码
  114. unBtnPass: function () {
  115. wx.navigateTo({
  116. url: '/pages/unpassword/index'
  117. })
  118. },
  119. // 注冊跳转
  120. registerBtn: function () {
  121. wx.navigateTo({
  122. url: '/pages/register/index'
  123. })
  124. },
  125. // 返回
  126. fanhui() {
  127. wx.redirectTo({
  128. url: '/pages/home/index',
  129. })
  130. },
  131. /**
  132. * 生命周期函数--监听页面加载
  133. */
  134. onLoad: function (options) {
  135. let that = this;
  136. wx.getStorage({
  137. key: 'phone',
  138. success (res) {
  139. console.log(res.data)
  140. that.setData({
  141. phone:res.data
  142. })
  143. }
  144. })
  145. wx.getStorage({
  146. key: 'password',
  147. success (res) {
  148. console.log(res.data)
  149. that.setData({
  150. password:res.data
  151. })
  152. }
  153. })
  154. },
  155. /**
  156. * 生命周期函数--监听页面初次渲染完成
  157. */
  158. onReady: function () {
  159. },
  160. /**
  161. * 生命周期函数--监听页面显示
  162. */
  163. onShow: function () {
  164. },
  165. /**
  166. * 生命周期函数--监听页面隐藏
  167. */
  168. onHide: function () {
  169. },
  170. /**
  171. * 生命周期函数--监听页面卸载
  172. */
  173. onUnload: function () {
  174. },
  175. /**
  176. * 页面相关事件处理函数--监听用户下拉动作
  177. */
  178. onPullDownRefresh: function () {
  179. },
  180. /**
  181. * 页面上拉触底事件的处理函数
  182. */
  183. onReachBottom: function () {
  184. },
  185. /**
  186. * 用户点击右上角分享
  187. */
  188. onShareAppMessage: function () {
  189. }
  190. })