error.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. userList: [
  15. { id: 1, name: '办案人员' },
  16. { id: 2, name: '办案人员' }
  17. ]
  18. },
  19. initValidate() {
  20. const rules = { user_name: { required: true, }, content: { required: true, } }
  21. // 验证字段的提示信息,若不传则调用默认的信息
  22. const messages = { user_name: { required: '请选择办案人员', }, content: { required: '请输入纠错内容', } };
  23. this.WxValidate = new WxValidate(rules, messages)
  24. },
  25. back: function () {
  26. wx.navigateBack({ url: '/pages/county/index' })
  27. },
  28. // 选择办案人员
  29. userChange: function (e) {
  30. let { value } = e.detail;
  31. let data = this.data.userList[value];
  32. this.setData({ 'form.user_id': data.id })
  33. this.setData({ 'form.user_name': data.name })
  34. },
  35. // 取消保存
  36. onReset: function (e) {
  37. this.back()
  38. },
  39. // 提交保存
  40. onSubmit: function (e) {
  41. const params = e.detail.value;
  42. if (!this.WxValidate.checkForm(params)) {
  43. const error = this.WxValidate.errorList[0];
  44. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  45. return false
  46. } else {
  47. console.log(params);
  48. wx.showToast({ title: `创建信息成功`, icon: 'success', duration: 2000 })
  49. }
  50. },
  51. /**
  52. * 生命周期函数--监听页面加载
  53. */
  54. onLoad: function (options) {
  55. //验证规则函数
  56. this.initValidate()
  57. const { id } = options;
  58. // 查询信息
  59. if (id) this.search(id);
  60. // 计算高度
  61. this.searchHeight()
  62. },
  63. // 查询信息
  64. search: function (id) {
  65. this.setData({ 'form.merchant_id': id })
  66. this.setData({ 'form.merchant_name': '测试商户' })
  67. },
  68. // 计算高度
  69. searchHeight: function () {
  70. let frameStyle = this.data.frameStyle;
  71. let client = app.globalData.client;
  72. // 减去状态栏
  73. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  74. // 是否减去底部菜单
  75. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  76. if (infoHeight) this.setData({ infoHeight: infoHeight })
  77. },
  78. /**
  79. * 生命周期函数--监听页面初次渲染完成
  80. */
  81. onReady: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面隐藏
  90. */
  91. onHide: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面卸载
  95. */
  96. onUnload: function () {
  97. },
  98. /**
  99. * 页面相关事件处理函数--监听用户下拉动作
  100. */
  101. onPullDownRefresh: function () {
  102. },
  103. /**
  104. * 页面上拉触底事件的处理函数
  105. */
  106. onReachBottom: function () {
  107. },
  108. /**
  109. * 用户点击右上角分享
  110. */
  111. onShareAppMessage: function () {
  112. }
  113. })