addbchao.js 4.8 KB
// pages/addbchao/addbchao.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    weeksArry:[],
    create_date:'',
    head_circumference:'',
    abdominal_circumference:'',
    femur_length:'',
    neck_length:''
  },
  getWeeks() {
    let url = '/user/getWeekDay'
    app.post(url, {}).then((res) => {
      console.log(res)
      this.setData({
        multiIndex: [res.default.week, res.default.day],
        week: res.default.week,
        day: res.default.day
      })
      console.log(this.data.multiIndex)
      let tempData = []
    let tempWeeks = []
    let tempDays = []
    for (let i = 0; i <= this.data.week; i++) {
      let tempText = '孕期' + i + '周'
      let tempw = { 
        id: i,
        text: tempText
      }
      tempWeeks.push(tempw)
    }
    for (let i = 0; i <= this.data.day; i++) {
      let tempText = '加' + i + '天'
      let tempD = {
        id: i,
        text: tempText
      }
      tempDays.push(tempD)
    }
    tempData[0] = tempWeeks;
    tempData[1] = tempDays;
    this.setData({
      weeksArry: tempData
    })
    }).catch((errMsg) => {

    })
  },
  bindMultiPickerChange: function (e) {
    console.log(e)
    let chooseW = this.data.weeksArry[0][e.detail.value[0]]
    let chooseD = this.data.weeksArry[1][e.detail.value[1]]
    this.setData({
      multiIndex: e.detail.value,
      week: chooseW.id,
      day: chooseD.id
    })
  },
  bindMultiPickerColumnChange: function (e) {
    console.log(e)
    let row = e.detail.column;
    let value = e.detail.value;
    let baseWeek = this.data.week;
    let weeksArry = this.data.weeksArry;
    let tempDays = [];
    let nowDays = []
    if(row==0){
      if (value < baseWeek){
        for (let i = 0; i < 7; i++) {
          let tempText = '加' + i + '天'
          let tempD = {
            id: i,
            text: tempText
          }
          tempDays.push(tempD)
        }
        weeksArry[1] = tempDays;
        this.setData({
          weeksArry: weeksArry
        })
      }else{
        for (let i = 0; i <= this.data.day; i++) {
          let tempText = '加' + i + '天'
          let tempD = {
            id: i,
            text: tempText
          }
          nowDays.push(tempD)
        }
        weeksArry[1] = nowDays;
        this.setData({
          weeksArry: weeksArry
        })
      }
    }
  },
  getHead(e){
    this.setData({
      head_circumference:e.detail.value
    })
  },
  getadominal(e){
    this.setData({
      abdominal_circumference: e.detail.value
    })
  },
  getfemur(e){
    this.setData({
      femur_length:e.detail.value
    })
  },
  getneck(e){
    this.setData({
      neck_length: e.detail.value
    })
  },
  savebinfo(){
    let url = '/user/addBCLog'
    let params = {
      create_date: this.data.create_date,
      head_circumference: this.data.head_circumference,
      abdominal_circumference: this.data.abdominal_circumference,
      femur_length: this.data.femur_length,
      neck_length: this.data.neck_length
    }
    console.log(params)
    if(params.head_circumference==''){
      wx.showToast({
        title: '请输入头围',
        icon: 'none'
      })
      return false
    }else if(params.abdominal_circumference == ''){
      wx.showToast({
        title: '请输入腹围',
        icon: 'none'
      })
      return false
    }else if(params.femur_length == ''){
      wx.showToast({
        title: '请输入股骨长',
        icon: 'none'
      })
      return false
    }else if(params.neck_length == ''){
      wx.showToast({
        title: '请输入胎儿头颈长度',
        icon: 'none'
      })
      return false 
    }else{
        app.post(url,params).then((res)=>{
          wx.showToast({
            title:'保存成功'
          })
          setTimeout(function(){
             wx.switchTab({ 
              url: '/pages/bchao/bchao', 
            })  
          },1000) 
        })
    }
  },
  inputDate: function (e) {
    this.setData({
      create_date: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载 
   */
  onLoad: function (options) {
    this.setData({
      create_date: app.nowDate(),
      endDate: app.nowDate(),
      startDate: app.minDate()
    }) 
  },

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

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

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

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

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

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

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