index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '基本信息', leftArrow: true, useBar: false },
  10. // 主体高度
  11. infoHeight: '',
  12. form: {}
  13. },
  14. initValidate() {
  15. const rules = { name: { required: true, }, phone: { required: true, tel: true }, email: { required: true, }, address: { required: true, }, dept: { required: true, }, zw: { required: true, }, company: { required: true, } }
  16. // 验证字段的提示信息,若不传则调用默认的信息
  17. const messages = { name: { required: '请输入姓名', }, phone: { required: '请输入电话', }, email: { required: '请输入电子邮箱', }, address: { required: '请输入联系地址', }, dept: { required: '请输入部门', }, zw: { required: '请输入职务', }, company: { required: '请输入工作单位', } };
  18. this.WxValidate = new WxValidate(rules, messages)
  19. },
  20. back: function () {
  21. wx.navigateBack({ url: '/pages/home/index' })
  22. },
  23. // 取消修改
  24. onReset: function () {
  25. this.back()
  26. },
  27. // 提交修改
  28. onSubmit: function (e) {
  29. const params = e.detail.value;
  30. if (!this.WxValidate.checkForm(params)) {
  31. const error = this.WxValidate.errorList[0];
  32. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  33. return false
  34. } else {
  35. console.log(params);
  36. // wx.request({
  37. // url: app.globalData.publicUrl + `/api/hc/user/update/${this.data.form.id}`,
  38. // method: "post",
  39. // data: { ...params },
  40. // header: {},
  41. // success: (res) => {
  42. // if (res.data.errcode == '0') {
  43. // wx.showToast({ title: `信息修改完成`, icon: 'success', duration: 2000 })
  44. // wx.setStorage({ key: "user", data: res.data.data });
  45. // app.globalData.userInfo = res.data.data;
  46. // wx.navigateTo({ url: '/pages/home/index' })
  47. // } else {
  48. // wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 })
  49. // }
  50. // },
  51. // })
  52. }
  53. },
  54. /**
  55. * 生命周期函数--监听页面加载
  56. */
  57. onLoad: function (options) {
  58. //验证规则函数
  59. this.initValidate();
  60. // 监听用户是否登录
  61. this.watchLogin();
  62. // 计算高度
  63. this.searchHeight()
  64. },
  65. // 监听用户是否登录
  66. watchLogin: function () {
  67. wx.getStorage({
  68. key: 'user',
  69. success: res => {
  70. console.log(res);
  71. }
  72. })
  73. },
  74. // 计算高度
  75. searchHeight: function () {
  76. let frameStyle = this.data.frameStyle;
  77. let client = app.globalData.client;
  78. let infoHeight = client.windowHeight;
  79. // 是否去掉状态栏
  80. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  81. // 是否减去底部菜单
  82. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  83. if (infoHeight) this.setData({ infoHeight: infoHeight })
  84. },
  85. /**
  86. * 生命周期函数--监听页面初次渲染完成
  87. */
  88. onReady: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面显示
  92. */
  93. onShow: function () {
  94. },
  95. /**
  96. * 生命周期函数--监听页面隐藏
  97. */
  98. onHide: function () {
  99. },
  100. /**
  101. * 生命周期函数--监听页面卸载
  102. */
  103. onUnload: function () {
  104. },
  105. /**
  106. * 页面相关事件处理函数--监听用户下拉动作
  107. */
  108. onPullDownRefresh: function () {
  109. },
  110. /**
  111. * 页面上拉触底事件的处理函数
  112. */
  113. onReachBottom: function () {
  114. },
  115. /**
  116. * 用户点击右上角分享
  117. */
  118. onShareAppMessage: function () {
  119. }
  120. })