keyFind.js 4.8 KB
// pages/cityWide/keyFind/keyFind.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    typeOf: 0,
    brith: '',
    date: '',
    childbirth: '',
    name: '',
    phone: '',
    comment: ''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.setData({
      date: app.nowDate(),
    })
    this.getlastdate() 
  },

  //获取上次的预产期
  getlastdate() {
    let that = this;

    var url = '/api/portal/childbirth/getLastChildbirthDate';
    var params = {
      token: wx.getStorageSync('token'),

    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        date: res.childbirth_date
      })
      console.log(that.data.date)


    }).catch((err) => {

    })
  },

  bindDateChange: function (e) {
    console.log(e)
    var val = e.detail.value;
    console.log(val)
    var sval = val.split("-")
    console.log(sval)
    sval = sval[0] + "年" + sval[1] + "月" + sval[2] + "日"
    console.log(sval)
   
    this.setData({
      childbirth: sval
    })
  },


  // 判断是否为空
  judgEmpty: function(){
    let that = this;
    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (that.data.name == ''){
      wx.showToast({
        title: "请输入姓名",
        icon: 'none',
        duration: 1500
      });
      return false;
    }else if(that.data.phone == ''){
      wx.showToast({
        title: "请输入手机号",
        icon: 'none',
        duration: 1500
      });
      return false;
    } else if (!myreg.test(that.data.phone)){
      wx.showToast({
        title: "手机号输入有误",
        icon: 'none',
        duration: 1500
      });
      return false;
    }
    else if (that.data.typeOf==0){
       wx.showToast({
         title: '请选择类型',
         icon:'none'
       })
       return false;

    } else if (that.data.childbirth==""){
      wx.showToast({
        title: '请输入宝宝年龄',
        icon:'none'
      })
      return false

    }else if(that.data.comment == ''){
      wx.showToast({
        title: "请输入特殊说明",
        icon: 'none',
        duration: 1500
      });
      return false;
    }else{
      that.commitInfo()
    }
  },
  // 提交一键找月嫂信息
  commitInfo: function(){
    let that = this;
    let url = "/api/portal/Maternity/toAdmin";
    let params = {
      token: wx.getStorageSync('token'),
      name: that.data.name,
      tel: that.data.phone,
      childbirth: that.data.childbirth,
      type: that.data.typeOf,
      else: that.data.comment,
      find_type: 1
    }
    app.post(url, params).then((res) => {
      console.log(res.length)
      if(res.length==0){
        console.log(999)
        wx.showToast({
          title: '提交成功,等待后台工作人员联系',
          icon: 'none',
        })

        setTimeout(function () {
            // wx.navigateTo({
            //   url: '../matronPrepon/matronPrepon',
            // })

            wx.navigateBack({
              checked:true
            })
          },1500)
      }
      
     

    
    }).catch((errMsg) => {})
  },
  // 获取姓名
  getName: function(e){
    this.setData({
      name: e.detail.value
    })
  },
  // 获取手机号
  getPhone: function(e){
    this.setData({
      phone: e.detail.value
    })
  },
  // 获取宝宝年龄
  getBrith: function(e){
    this.setData({
      brith: e.detail.value,
      childbirth: e.detail.value
    })
  },
  // 获取特殊说明
  getElse: function(e){
    this.setData({
      comment: e.detail.value
    })
  },
  // 选择预产期
  // bindDateChange: function (e) {
  //   this.setData({
  //     date: e.detail.value,
  //     childbirth: e.detail.value
  //   })
  // },
  // 点击切换
  clickTab: function (e) {
    var that = this;
    if (this.data.typeOf === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        typeOf: e.target.dataset.current
      })

      if(that.data.typeOf == 1){
        that.setData({
          childbirth: that.data.date
        })
      } else if (that.data.typeOf == 2){
        that.setData({
          childbirth: that.data.brith
        })
      }
    }
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})