inspect.js 3.6 KB

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