index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. // index: 0,
  14. // 上传图片
  15. fileList: [],
  16. },
  17. afterRead: function (event) {
  18. const { file } = event.detail;
  19. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式app.globalData.fileUrl:
  20. console.log(file);
  21. wx.uploadFile({
  22. url: `${app.globalData.imageUrl}/files/court/elimg/upload`,
  23. filePath: file.url,
  24. name: 'file',
  25. formData: {},
  26. success: (res) => {
  27. console.log(res);
  28. if (res.statusCode == '200') {
  29. let data = [{ name: JSON.parse(res.data).name, url: `${app.globalData.imageUrl}` + JSON.parse(res.data).uri }]
  30. const { fileList = [] } = this.data;
  31. fileList.push({ ...file, url: res.data });
  32. this.setData({ fileList });
  33. } else {
  34. wx.showToast({ title: `${res.data.errmsg}`, icon: 'fail', duration: 2000 })
  35. }
  36. },
  37. });
  38. },
  39. // //选择
  40. // bindPickerChange: function (e) {
  41. // console.log('picker发送选择改变,携带值为', e.detail.value)
  42. // this.setData({
  43. // index: e.detail.value
  44. // })
  45. // },
  46. back: function () {
  47. wx.navigateBack({ url: '/pages/me/index' })
  48. },
  49. /**
  50. * 生命周期函数--监听页面加载
  51. */
  52. onLoad: function (e) {
  53. // 计算高度
  54. this.searchHeight()
  55. const that = this;
  56. // 获取用户信息
  57. wx.getStorage({
  58. key: 'token',
  59. success: function (res) {
  60. wx.request({
  61. url: `${app.globalData.publicUrl}/courtAdmin/api/user`, //接口地址
  62. method: "post",
  63. data: { "id": "", "phone": "", "type": "", "status": "" },
  64. header: {},
  65. success: res => {
  66. that.setData({ form: res.data.data });
  67. console.log(res.data.data);
  68. console.log(res.data.data.id);
  69. },
  70. error: err => {
  71. console.log(err);
  72. }
  73. })
  74. }
  75. })
  76. },
  77. //提交
  78. formSubmit: function (e) {
  79. let value = e.detail.value;
  80. console.log(value);
  81. wx.getStorage({
  82. key: 'token',
  83. success: function (res) {
  84. console.log(res);
  85. wx.request({
  86. url: `${app.globalData.publicUrl}/courtAdmin/api/user`, //接口地址
  87. method: "post",
  88. data: value,
  89. header: {},
  90. success: res => {
  91. wx.showToast({
  92. title: '保存成功',
  93. icon: 'success',
  94. duration: 2000
  95. })
  96. console.log(res);
  97. },
  98. })
  99. }
  100. })
  101. },
  102. // 计算高度
  103. searchHeight: function () {
  104. let frameStyle = this.data.frameStyle;
  105. let client = app.globalData.client;
  106. // 减去状态栏
  107. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  108. // 是否减去底部菜单
  109. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  110. if (infoHeight) this.setData({ infoHeight: infoHeight })
  111. },
  112. /**
  113. * 生命周期函数--监听页面初次渲染完成
  114. */
  115. onReady: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面显示
  119. */
  120. onShow: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面隐藏
  124. */
  125. onHide: function () {
  126. },
  127. /**
  128. * 生命周期函数--监听页面卸载
  129. */
  130. onUnload: function () {
  131. },
  132. /**
  133. * 页面相关事件处理函数--监听用户下拉动作
  134. */
  135. onPullDownRefresh: function () {
  136. },
  137. /**
  138. * 页面上拉触底事件的处理函数
  139. */
  140. onReachBottom: function () {
  141. },
  142. /**
  143. * 用户点击右上角分享
  144. */
  145. onShareAppMessage: function () {
  146. }
  147. })