detail.js 3.1 KB

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