define(['zepto', 'medtap', 'mui', 'mui.picker'], function($, medtap, mui) {　
    var questionnaireWeight = {
      // 获取问卷id
      followUpId: medtap.getRequest('followUpId'),
      //  获取parentId
      parentId: medtap.getRequest('parentId')||'',
       		// 修改人员id
		  adminId: medtap.getRequest('adminId')||'',
      height:'',
      weight:'',
      init:function(){
      // 点击下一题
        $('.next').on('tap',function(){
          questionnaireWeight.weight = $.trim($('#weight').val())
             if(questionnaireWeight.weight.lenght>5||questionnaireWeight.weight==''){
               medtap.winPop('请输入您的实际体重（数字）！')
               return
             }
             questionnaireWeight.height = $.trim($('#height').val())
              if(questionnaireWeight.height.lenght>5||questionnaireWeight.height=='' ){
                medtap.winPop('请输入您的实际身高（数字）！')
                return
              }
              questionnaireWeight.getNextQuestion()
        })
      },
      // 获取问题答案
      getQuestionAnswer: function(){
        var crm = questionnaireWeight.adminId==''? '':'/crm'
        medtap.submitAjax({
          url: 'https://testdevgw.medtap.cn/operation/followUp'+crm+'/getAnswer',
          type: 'post',
          async: false,
          contentType: 'application/json',
          data: {
            "followUpId": questionnaireWeight.followUpId,
            "questionId":'1',
          },
          success: function(res) {
            console.log(res)  
            if(!res.success) return medtap.winPop('获取数据失败')
            if(!res.content.followAnswer.answer) {
              return
            }
           $('#weight').val(res.content.followAnswer.answer.weight||'')
           $('#height').val(res.content.followAnswer.answer.height||'')
          }
        })
      },
      // 下一题
      getNextQuestion:function(){
        var crm = questionnaireWeight.adminId==''? '':'/crm'
        medtap.submitAjax({
          url: 'https://testdevgw.medtap.cn/operation/followUp'+crm+'/nextQuestion',
          type: 'post',
          async: false,
          contentType: 'application/json',
          data: {
            "parentId":questionnaireWeight.parentId,
            "questionId":'1',
            "answer":{"weight":questionnaireWeight.weight,"height":questionnaireWeight.height},
            "questionNo":1,
            "followUpId": questionnaireWeight.followUpId
          },
          success: function(res) {
            console.log(res)
             // 获取下一题的id和序号通过url传递
            var parentId = res.content.nextQuestion.parentId||''
            var questionId = res.content.nextQuestion.questionId||''
            var questionNo = res.content.nextQuestion.questionNo||''
            medtap.pushWindow('furtherConsultation.html?followUpId='+questionnaireWeight.followUpId + '&questionId='+questionId + '&questionNo='+questionNo+'&parentId='+parentId+'&adminId='+questionnaireWeight.adminId);
          }
        })
      }
    }
    questionnaireWeight.init()
    questionnaireWeight.getQuestionAnswer()
  })