index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. // 主体高度
  10. infoHeight: '',
  11. frameStyle: { useTop: true, name: '个人信息', leftArrow: true, useBar: false },
  12. form: {
  13. },
  14. // index: 0,
  15. // 上传图片
  16. fileList: [],
  17. },
  18. //上传图片
  19. imgUpload: function (e) {
  20. const that = this;
  21. let data = that.data.fileList;
  22. data.push(e.detail)
  23. that.setData({ fileList: data })
  24. },
  25. //删除图片
  26. imgDel: function (e) {
  27. const that = this;
  28. let data = that.data.fileList;
  29. let arr = data.filter((i, index) => index != e.detail.index)
  30. that.setData({ fileList: arr })
  31. },
  32. // //选择
  33. // bindPickerChange: function (e) {
  34. // console.log('picker发送选择改变,携带值为', e.detail.value)
  35. // this.setData({
  36. // index: e.detail.value
  37. // })
  38. // },
  39. back: function () {
  40. wx.navigateBack({ url: '/pages/me/index' })
  41. },
  42. //提交
  43. formSubmit: function (e) {
  44. const value = e.detail.value;
  45. if (!this.WxValidate.checkForm(value)) {
  46. const error = this.WxValidate.errorList[0];
  47. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  48. return false
  49. } else {
  50. value.icon = this.data.fileList;
  51. wx.request({
  52. url: `${app.globalData.publicUrl}/courtAdmin/api/user/${res.data.id}`, //接口地址
  53. method: "post",
  54. data: value,
  55. header: {},
  56. success: res => {
  57. if (res.data.errcode == 0) {
  58. wx.showToast({
  59. title: '保存成功',
  60. icon: 'success',
  61. duration: 2000//延迟两秒
  62. })
  63. } else {
  64. wx.showToast({
  65. title: '保存失败',
  66. icon: 'success',
  67. duration: 2000
  68. })
  69. }
  70. },
  71. })
  72. }
  73. },
  74. /**
  75. * 生命周期函数--监听页面加载
  76. */
  77. onLoad: function (options) {
  78. // 计算高度
  79. this.searchHeight();
  80. // 监听用户是否登录
  81. this.watchLogin();
  82. //验证规则函数
  83. this.initValidate();
  84. },
  85. //验证必填项
  86. initValidate() {
  87. const rules = { phone: { required: true, tel: true }, }
  88. // 验证字段的提示信息,若不传则调用默认的信息
  89. const messages = { phone: { required: '请输入手机号' }, };
  90. this.WxValidate = new WxValidate(rules, messages)
  91. },
  92. // 监听用户是否登录
  93. watchLogin: function () {
  94. const that = this;
  95. wx.getStorage({
  96. key: 'token',
  97. success: res => {
  98. //数据请求
  99. wx.request({
  100. url: `${app.globalData.publicUrl}/courtAdmin/api/user/${res.data.id}`, //接口地址
  101. method: "get",//请求方法
  102. data: {},//请求参数
  103. header: {},
  104. success: res => {
  105. console.log(res);
  106. that.setData({ form: res.data.data })
  107. let icon = res.data.data.icon;
  108. this.setData({ fileList: icon })
  109. },
  110. error: err => {
  111. console.log(err);
  112. }
  113. })
  114. },
  115. fail: res => {
  116. wx.redirectTo({ url: '/pages/login/index', })
  117. }
  118. })
  119. },
  120. // 计算高度
  121. searchHeight: function () {
  122. let frameStyle = this.data.frameStyle;
  123. let client = app.globalData.client;
  124. // 减去状态栏
  125. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  126. // 是否减去底部菜单
  127. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  128. if (infoHeight) this.setData({ infoHeight: infoHeight })
  129. },
  130. /**
  131. * 生命周期函数--监听页面初次渲染完成
  132. */
  133. onReady: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面显示
  137. */
  138. onShow: function () {
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload: function () {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom: function () {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage: function () {
  164. }
  165. })