detail.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. // 详细信息
  13. id: '',
  14. form: {},
  15. },
  16. initValidate() {
  17. const rules = { code: { required: true, }, name: { required: true } }
  18. // 验证字段的提示信息,若不传则调用默认的信息
  19. const messages = { code: { required: '请输入类型类别', }, name: { required: '请输入类别名称', } };
  20. this.WxValidate = new WxValidate(rules, messages)
  21. },
  22. back: function () {
  23. wx.navigateBack({ url: '/pages/type/index' })
  24. },
  25. // 取消保存
  26. onReset: function (e) {
  27. this.back()
  28. },
  29. // 提交保存
  30. onSubmit: function (e) {
  31. const params = e.detail.value;
  32. if (!this.WxValidate.checkForm(params)) {
  33. const error = this.WxValidate.errorList[0];
  34. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  35. return false
  36. } else {
  37. console.log(params);
  38. }
  39. },
  40. /**
  41. * 生命周期函数--监听页面加载
  42. */
  43. onLoad: function (options) {
  44. //验证规则函数
  45. this.initValidate();
  46. if (options.id) this.setData({ id: options.id })
  47. // 监听用户是否登录
  48. this.watchLogin();
  49. // 计算高度
  50. this.searchHeight()
  51. },
  52. // 监听用户是否登录
  53. watchLogin: function () {
  54. const that = this;
  55. let id = that.data.id;
  56. if (id) {
  57. // 如果有ID查询数据详情,赋值给form
  58. }
  59. // wx.getStorage({
  60. // key: 'user',
  61. // success: res => {
  62. // if (res.data) {
  63. // // 查询菜单
  64. // if (res.data) this.searchRouter(res.data);
  65. // res.data.type = type.find((i) => i.value == res.data.type).label;
  66. // if (res.data) this.setData({ userInfo: res.data });
  67. // if (res.data && res.data.avatarUrl) this.setData({ avatarUrl: res.data.avatarUrl });
  68. // } else {
  69. // wx.redirectTo({ url: '/pages/login/index', })
  70. // }
  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. })