index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // pages/test/index.js
  2. const app = getApp()
  3. import WxValidate from '../../utils/wxValidate'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '测试页面', leftArrow: true, useBar: true },
  10. // 主体高度
  11. infoHeight: '',
  12. // 图片
  13. img_url: [],
  14. // dialog弹框
  15. dialog: { title: '弹框标题', show: false, type: '1' },
  16. form: {}
  17. },
  18. initValidate() {
  19. const rules = { start_time: { required: true } }
  20. // 验证字段的提示信息,若不传则调用默认的信息
  21. const messages = { start_time: { required: '开始时间' } };
  22. this.WxValidate = new WxValidate(rules, messages)
  23. },
  24. // 跳转菜单
  25. tabPath(e) {
  26. let { route } = e.detail.detail;
  27. if (route) wx.redirectTo({ url: `/${route}` })
  28. },
  29. // 返回上一页
  30. back: function () {
  31. wx.navigateBack({ delta: 1 })
  32. },
  33. // 上传图片
  34. imgUpl: function (e) {
  35. const that = this;
  36. let data = that.data.img_url;
  37. data.push(e.detail)
  38. that.setData({ img_url: data })
  39. },
  40. // 删除图片
  41. imgDel: function (e) {
  42. const that = this;
  43. let list = that.data.img_url;
  44. let arr = list.filter((i, index) => index != e.detail.index)
  45. that.setData({ img_url: arr })
  46. },
  47. // 打开弹框
  48. toDialog: function () {
  49. const that = this;
  50. that.setData({ dialog: { title: '弹框标题', show: true, type: '1' } })
  51. },
  52. // 关闭弹框
  53. toClose: function () {
  54. const that = this;
  55. that.setData({ dialog: { title: '弹框标题', show: false, type: '1' } })
  56. },
  57. // 确认选择
  58. datetimeChange: function (e) {
  59. const that = this;
  60. that.setData({ [`form.${e.detail.name}`]: e.detail.datetime });
  61. },
  62. // 提交保存
  63. toSubmit: function (e) {
  64. const that = this;
  65. const params = e.detail.value;
  66. const form = that.data.form;
  67. params.start_time = form.start_time;
  68. if (!this.WxValidate.checkForm(params)) {
  69. const error = this.WxValidate.errorList[0];
  70. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  71. return false
  72. } else {
  73. console.log(params);
  74. }
  75. },
  76. /**
  77. * 生命周期函数--监听页面加载
  78. */
  79. onLoad: async function (options) {
  80. const that = this;
  81. //验证规则函数
  82. that.initValidate();
  83. },
  84. /**
  85. * 生命周期函数--监听页面初次渲染完成
  86. */
  87. onReady: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面显示
  91. */
  92. onShow: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面隐藏
  96. */
  97. onHide: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面卸载
  101. */
  102. onUnload: function () {
  103. },
  104. /**
  105. * 页面相关事件处理函数--监听用户下拉动作
  106. */
  107. onPullDownRefresh: function () {
  108. },
  109. /**
  110. * 页面上拉触底事件的处理函数
  111. */
  112. onReachBottom: function () {
  113. },
  114. /**
  115. * 用户点击右上角分享
  116. */
  117. onShareAppMessage: function () {
  118. }
  119. })