index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // pages/staff/login/index.js
  2. let myPro = require("../../../utils/wxRequest.js");
  3. let util = require("../../../utils/util.js");
  4. var app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. phoneNum:'',
  11. password:'',
  12. showPS:false,
  13. latitude:0,
  14. longitude:0,
  15. },
  16. onPhoneChange(e){
  17. this.setData({
  18. phoneNum:e.detail
  19. })
  20. },
  21. onPasswordChange(e){
  22. this.setData({
  23. password:e.detail
  24. })
  25. },
  26. onClickShowPassword() {
  27. this.setData({
  28. showPS:!this.data.showPS
  29. })
  30. },
  31. loginAction() {
  32. if (this.data.phoneNum === undefined || this.data.phoneNum === null || this.data.phoneNum === '') {
  33. Toast('请输入手机号')
  34. return
  35. }
  36. if (this.data.password === undefined || this.data.password === null || this.data.password === '') {
  37. Toast('请输入密码')
  38. return
  39. }
  40. wx.showLoading({
  41. mask:true
  42. })
  43. var that = this;
  44. var params = {
  45. phone: this.data.phoneNum,
  46. password: this.data.password
  47. }
  48. myPro.wxRequest("staff/login","POST",params).then(res=>{
  49. wx.hideLoading()
  50. var res = res.data;
  51. console.log(res)
  52. if (res.code === 200) {
  53. app.globalData.token = res.result.token
  54. app.globalData.xxInfo = res.result.user
  55. app.globalData.showedWaterDialog = false
  56. wx.setStorage({
  57. key:"xxInfo",
  58. data:res.result.user
  59. })
  60. wx.setStorage({
  61. key:"token",
  62. data:res.result.token
  63. })
  64. wx.setStorage({
  65. key:'staffphone',
  66. data:this.data.phoneNum
  67. });
  68. wx.switchTab({
  69. url: '../index/index'
  70. })
  71. } else {
  72. Toast(res.msg);
  73. }
  74. // wx.reLaunch({
  75. // url: '/pages/index/index'
  76. // });
  77. }).catch(err=>{
  78. console.log('报错信息',err);
  79. wx.showToast({
  80. title: err,
  81. icon: "none"
  82. })
  83. })
  84. // wx.redirectTo({
  85. // url: '../../index/index'
  86. // });
  87. },
  88. /**
  89. * 生命周期函数--监听页面加载
  90. */
  91. onLoad: function (options) {
  92. // wx.hideHomeButton()
  93. },
  94. /**
  95. * 生命周期函数--监听页面初次渲染完成
  96. */
  97. onReady: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面显示
  101. */
  102. onShow: function () {
  103. console.log(wx.getStorageSync('staffphone'))
  104. var that = this;
  105. var staffphone = wx.getStorageSync('staffphone');
  106. if ( staffphone != undefined && staffphone != null ) {
  107. this.setData({
  108. phoneNum:staffphone
  109. })
  110. }
  111. wx.getLocation({
  112. type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  113. success: function (res) {
  114. that.setData({
  115. latitude:res.latitude,
  116. longitude:res.longitude
  117. })
  118. }
  119. })
  120. },
  121. /**
  122. * 生命周期函数--监听页面隐藏
  123. */
  124. onHide: function () {
  125. },
  126. /**
  127. * 生命周期函数--监听页面卸载
  128. */
  129. onUnload: function () {
  130. },
  131. /**
  132. * 页面相关事件处理函数--监听用户下拉动作
  133. */
  134. onPullDownRefresh: function () {
  135. },
  136. /**
  137. * 页面上拉触底事件的处理函数
  138. */
  139. onReachBottom: function () {
  140. },
  141. /**
  142. * 用户点击右上角分享
  143. */
  144. onShareAppMessage: function () {
  145. }
  146. })