detail.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. info: { id: '1234567', name: '测试人员', phone: '12345678901', email: '123456@qq.com', address: '1', dept: '1', zw: '1', company: '1', type: '0', type_name: '超级管理员' },
  13. form: {},
  14. // 用户类别
  15. typeList: [
  16. { value: '0', label: '超级管理员' },
  17. { value: '1', label: '科室人员' },
  18. { value: '2', label: '办公室人员' },
  19. { value: '3', label: '采购部门' },
  20. { value: '4', label: '入库管理部门' },
  21. { value: '5', label: '财务部门' },
  22. { value: '6', label: '供货单位' },]
  23. },
  24. initValidate() {
  25. 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, } }
  26. // 验证字段的提示信息,若不传则调用默认的信息
  27. const messages = { type_name: { required: '请选择用户类别', }, name: { required: '请输入姓名', }, phone: { required: '请输入电话', }, email: { required: '请输入电子邮箱', }, address: { required: '请输入联系地址', }, dept: { required: '请输入部门', }, zw: { required: '请输入职务', }, company: { required: '请输入工作单位', } };
  28. this.WxValidate = new WxValidate(rules, messages)
  29. },
  30. back: function () {
  31. wx.navigateBack({ url: '/pages/home/index' })
  32. },
  33. // 选择用户类别
  34. typeChange: function (e) {
  35. let { value } = e.detail;
  36. let data = this.data.typeList[value];
  37. this.setData({ 'form.type': data.value })
  38. this.setData({ 'form.type_name': data.label })
  39. },
  40. // 取消修改
  41. onReset: function () {
  42. this.back()
  43. },
  44. // 提交修改
  45. onSubmit: function (e) {
  46. console.log(e.detail.value)
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad: function (options) {
  52. if (options.id) {
  53. this.setData({ 'form': this.data.info })
  54. }
  55. //验证规则函数
  56. this.initValidate();
  57. // 计算高度
  58. this.searchHeight()
  59. },
  60. // 计算高度
  61. searchHeight: function () {
  62. let frameStyle = this.data.frameStyle;
  63. let client = app.globalData.client;
  64. let infoHeight = client.windowHeight;
  65. // 是否去掉状态栏
  66. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  67. // 是否减去底部菜单
  68. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  69. if (infoHeight) this.setData({ infoHeight: infoHeight })
  70. },
  71. /**
  72. * 生命周期函数--监听页面初次渲染完成
  73. */
  74. onReady: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面显示
  78. */
  79. onShow: function () {
  80. },
  81. /**
  82. * 生命周期函数--监听页面隐藏
  83. */
  84. onHide: function () {
  85. },
  86. /**
  87. * 生命周期函数--监听页面卸载
  88. */
  89. onUnload: function () {
  90. },
  91. /**
  92. * 页面相关事件处理函数--监听用户下拉动作
  93. */
  94. onPullDownRefresh: function () {
  95. },
  96. /**
  97. * 页面上拉触底事件的处理函数
  98. */
  99. onReachBottom: function () {
  100. },
  101. /**
  102. * 用户点击右上角分享
  103. */
  104. onShareAppMessage: function () {
  105. }
  106. })