detail.js 3.9 KB

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