index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. fileList: [],
  14. gender: ['男', '女'],
  15. // objectGender: [{id: 0,name: '男'},{id: 1,name: '女'},],
  16. // index: 0,
  17. },
  18. bindPickerChange: function (e) {
  19. console.log('picker发送选择改变,携带值为', e.detail.value)
  20. this.setData({
  21. index: e.detail.value
  22. })
  23. },
  24. //上传图片
  25. imgUpload: function (e) {
  26. const that = this;
  27. let data = that.data.fileList;
  28. data.push(e.detail)
  29. that.setData({ fileList: data })
  30. },
  31. //删除图片
  32. imgDel: function (e) {
  33. const that = this;
  34. let data = that.data.fileList;
  35. let arr = data.filter((i, index) => index != e.detail.index)
  36. that.setData({ fileList: arr })
  37. },
  38. back: function () {
  39. wx.navigateBack({ url: '/pages/me/index' })
  40. },
  41. //提交
  42. formSubmit: function (e) {
  43. const value = e.detail.value;
  44. if (!this.WxValidate.checkForm(value)) {
  45. const error = this.WxValidate.errorList[0];
  46. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  47. return false
  48. } else {
  49. value.icon = this.data.fileList;
  50. console.log(value);
  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. that.setData({ form: res.data.data })
  106. let icon = res.data.data.icon;
  107. that.setData({ fileList: icon })
  108. },
  109. error: err => {
  110. }
  111. })
  112. },
  113. fail: res => {
  114. wx.redirectTo({ url: '/pages/login/index', })
  115. }
  116. })
  117. },
  118. // 计算高度
  119. searchHeight: function () {
  120. let frameStyle = this.data.frameStyle;
  121. let client = app.globalData.client;
  122. // 减去状态栏
  123. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  124. // 是否减去底部菜单
  125. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  126. if (infoHeight) this.setData({ infoHeight: infoHeight })
  127. },
  128. /**
  129. * 生命周期函数--监听页面初次渲染完成
  130. */
  131. onReady: function () {
  132. },
  133. /**
  134. * 生命周期函数--监听页面显示
  135. */
  136. onShow: function () {
  137. },
  138. /**
  139. * 生命周期函数--监听页面隐藏
  140. */
  141. onHide: function () {
  142. },
  143. /**
  144. * 生命周期函数--监听页面卸载
  145. */
  146. onUnload: function () {
  147. },
  148. /**
  149. * 页面相关事件处理函数--监听用户下拉动作
  150. */
  151. onPullDownRefresh: function () {
  152. },
  153. /**
  154. * 页面上拉触底事件的处理函数
  155. */
  156. onReachBottom: function () {
  157. },
  158. /**
  159. * 用户点击右上角分享
  160. */
  161. onShareAppMessage: function () {
  162. }
  163. })