applicationPartener.js 2.27 KB
// pages/applicationPartener/applicationPartener.js

import WxValidate from "../../utils/WxValidate"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    parternerForm: {
      applyName: '',
      telphone: '',
      province: []
    }
  },

    // 表单验证规则
    initValidate() {
      const rules = {
        applyName: {
            required: true
        },
        telphone: {
          required: true
        },
        province: {
          required: true
      }
    }
  
      const messages = {
        applyName: {
              required: '请填写申请人名称',
          },
          telphone: {
            required: '请填写联系电话'
        },
        province: {
          required: '请选择省市'
      }
      }
  
    this.WxValidate = new WxValidate(rules, messages)
    },

   //报错
 showModal(error) {
  wx.showModal({
    content: error.msg,
    showCancel: false,
  })
},

    // 提交表单
    submitParterner(e) {
      console.log(e);
      const params = e.detail.value
      // 校验表单
      if(!this.WxValidate.checkForm(params)) {
        const error = this.WxValidate.errorList[0]
        this.showModal(error)
        return false
      }
      this.showModal({
        msg: '提交成功'
      })
      // 跳转申请成功页面
      wx.$router.go("applySuccess");
    },

      // 选择省市
  bindRegionChange(e) {
    console.log(e.detail.value);
    this.setData({
      "parternerForm.province": e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     // 初始化验证规则函数
     this.initValidate()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})