diatelyMake.js 4.9 KB
// pages/cityWide/diatelyMake/diatelyMake.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    typeOf: 0,
    maternityid: '',
    date: '',
    name: '',
    phone: '',
    brith:'',
    childbirth: '',
    commet: '',
    infoCon: ''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({
      maternityid: options.maternityid,
      date: app.nowDate()
    })
    that.getInfo();
    that.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) => {

    })
  },

  // 判断是否为空
  judgeTap: 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.commet == ''){
      wx.showToast({
        title: "请输入特殊说明",
        icon: 'none',
      });
      return false;
    }else{
      that.commitMake()
    }
  },
  // 提交立即预约
  commitMake: function(){
    let that = this;
   
    let url = "/api/portal/Maternity/toAdmin";
    let params = {
      token: wx.getStorageSync('token'),
      maternityId: that.data.maternityid,
      name: that.data.name,
      tel: that.data.phone,
      childbirth: that.data.childbirth,
      type: that.data.typeOf,
      else: that.data.commet,
      find_type: 2
    }
    app.post(url, params).then((res) => {
      console.log(res)
      if(res.length==0){
          wx.showToast({
            title: '提交成功,等待后台工作人员联系',
            icon:'none'
          })
      }

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

      
    }).catch((errMsg) => {})
  },
  // 获取详情信息
  getInfo: function(){
    let that = this;
    let url = "/api/portal/Maternity/detail";
    let params = {
      maternityId: that.data.maternityid
    }
    app.post(url, params).then((res) => {
      console.log(res)
      that.setData({
        infoCon: res.list
      })
    }).catch((errMsg) => {})
  },
  // 获取姓名
  getName: function(e){
    this.setData({
      name: e.detail.value
    })
  },
  // 获取手机号
  getPhone: function(e){
    this.setData({
      phone: e.detail.value
    })
  },
  // 获取特殊说明
  getCommit: function(e){
    this.setData({
      commet: e.detail.value
    })
  },
  // 获取预产期
  bindDateChange: function(e){
    this.setData({
      date: e.detail.value,
      childbirth: e.detail.value
    })
  },
  // 获取宝宝年龄
  getBrith: function(e){
    this.setData({
      brith: 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 () {

  }
})