detail.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. countyList: [
  15. { id: '12', name: '测试区县1' },
  16. { id: '34', name: '测试区县2' },
  17. ]
  18. },
  19. initValidate() {
  20. const rules = { name: { required: true, }, phone: { required: true }, email: { required: true }, address: { required: true, } }
  21. // 验证字段的提示信息,若不传则调用默认的信息
  22. const messages = { name: { required: '请输入姓名', }, phone: { required: '请输入联系电话', }, email: { required: '请输入电子邮箱', }, address: { required: '请输入联系地址', } };
  23. this.WxValidate = new WxValidate(rules, messages)
  24. },
  25. back: function () {
  26. wx.navigateBack({ url: '/pages/merchant/index' })
  27. },
  28. // 选择区县
  29. countyChange: function (e) {
  30. let { value } = e.detail;
  31. let data = this.data.countyList[value];
  32. this.setData({ 'form.county_id': data.id })
  33. this.setData({ 'form.county_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. console.log(id);
  66. },
  67. // 计算高度
  68. searchHeight: function () {
  69. let frameStyle = this.data.frameStyle;
  70. let client = app.globalData.client;
  71. // 减去状态栏
  72. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  73. // 是否减去底部菜单
  74. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  75. if (infoHeight) this.setData({ infoHeight: infoHeight })
  76. },
  77. /**
  78. * 生命周期函数--监听页面初次渲染完成
  79. */
  80. onReady: function () {
  81. },
  82. /**
  83. * 生命周期函数--监听页面显示
  84. */
  85. onShow: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面隐藏
  89. */
  90. onHide: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面卸载
  94. */
  95. onUnload: function () {
  96. },
  97. /**
  98. * 页面相关事件处理函数--监听用户下拉动作
  99. */
  100. onPullDownRefresh: function () {
  101. },
  102. /**
  103. * 页面上拉触底事件的处理函数
  104. */
  105. onReachBottom: function () {
  106. },
  107. /**
  108. * 用户点击右上角分享
  109. */
  110. onShareAppMessage: function () {
  111. }
  112. })