detail.js 2.9 KB

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