define(['zepto', 'medtap', 'mui', 'mui.picker'], function($, medtap, mui) {　
  var otherTreatment = {
     // 获取问卷id
    followUpId: medtap.getRequest('followUpId')||'',
    // 获取本题序号
		questionNo: medtap.getRequest('questionNo')||'',
		//  获取本题id
    questionId: medtap.getRequest('questionId')||'',	
    //  获取parentId
    parentId: medtap.getRequest('parentId')||'',
    // 修改人员id
    adminId: medtap.getRequest('adminId')||'',  
    // 
    treatmentTypePicker: '',
    // 选择有或者无
    flag: '',
    // 治疗类型
    treatmentTypeVal: '',
    // 具体疗法和药物
    specificTherapy: '',
    init:function(){
      	// 用户点击了无
			$('.noHas').click(function(){
				otherTreatment.flag=false
				console.log(otherTreatment.flag)
			})
			// 用户点击了有
			$('.has').click(function(){
				otherTreatment.flag=true
				console.log(otherTreatment.flag)
			})
       // 点击下一题
       $('.next').on('click',function(){
        if(otherTreatment.flag){
          otherTreatment.treatmentTypeVal = $.trim($('.input_item_treatmentType').val())
          otherTreatment.specificTherapy = $.trim($('#content_body__specificTherapy').val())
					if(otherTreatment.treatmentTypeVal==''){
						medtap.winPop('请选择治疗类型')
						return
          }
          var dataHas = {
            "parentId":otherTreatment.parentId,
            "questionId":otherTreatment.questionId,
						"answer":{
              "treatmentTypeVal": otherTreatment.treatmentTypeVal,
              "specificTherapy": otherTreatment.specificTherapy,
              "status":1
            },
						"questionNo":Number(otherTreatment.questionNo),
						"followUpId": otherTreatment.followUpId
          }
          otherTreatment.getNextQuestion(dataHas)
        }else{
          var dataNo = {
            "parentId":otherTreatment.parentId,
            "questionId":otherTreatment.questionId,
						"answer":{
              "treatmentTypeVal": '',
              "specificTherapy": '',
              "status":0
            },
						"questionNo":Number(otherTreatment.questionNo),
						"followUpId": otherTreatment.followUpId
          }
          otherTreatment.getNextQuestion(dataNo)
        }
			})
			 // 点击上一题
			 $('.pre').on('click',function(){
        otherTreatment.getPreQuestion()
      })
      // tab切换
      $(".tabbox li").click(function ()
  　　{
  　　　　//获取点击的元素给其添加样式，讲其兄弟元素的样式移除
  　　　　$(this).addClass("active").siblings().removeClass("active");
  　　　　//获取选中元素的下标
  　　　　var index = $(this).index();
  　　　　$(this).parent().siblings().children().eq(index).addClass("active")
  　　　　.siblings().removeClass("active");
  　　})
    otherTreatment.inintTreatmentType();
    otherTreatment.selectItems();
    },
    // 初始化drugTypesPicker
    inintTreatmentType:function(){
      otherTreatment.treatmentTypePicker = new mui.PopPicker();
      otherTreatment.treatmentTypePicker.setData([
        {value:'1',text:'药物'},
        {value:'2',text:'手术'},
        {value:'3',text:'放疗'},
        {value:'4',text:'PD-1/PD-L1'},
        {value:'5',text:'中药治疗'},
      ]);
    },
     // 点击picker后的事件注册
     selectItems:function(){
      // 点击药物类型的判断
      $('.content_body_treatmentType').click(function(){
        otherTreatment.treatmentTypePicker.show(function (Items) {
        // console.log(Items[0].text);
        // console.log(Items[0].value);
        $('.input_item_treatmentType').val(Items[0].text)
      })
    })
  
    },
    // 获取答案
    getQuestionAnswer: function(){
      var crm = otherTreatment.adminId==''? '':'/crm'
      medtap.submitAjax({
        url: 'https://testdevgw.medtap.cn/operation/followUp'+crm+'/getAnswer',
        type: 'post',
        async: false,
        contentType: 'application/json',
        data: {
          "followUpId": otherTreatment.followUpId,
          "questionId": otherTreatment.questionId,
        },
        success: function(res) {
          console.log(res) 
          if(!res.success) return winPop('获取数据失败')
          if(!res.content.followAnswer.answer) {
            otherTreatment.flag=true
            return
          }
         var status = res.content.followAnswer.answer.status=undefined?  '1':res.content.followAnswer.answer.status
          if(status=='1'){
            otherTreatment.flag=true
          $('.input_item_treatmentType').val(res.content.followAnswer.answer.treatmentTypeVal || '')
          $('#content_body__specificTherapy').val(res.content.followAnswer.answer.specificTherapy || '')
          }else if(status=='0'){
            otherTreatment.flag=false
            $('.noHas').addClass('active').siblings('.has').removeClass('active')
            $('.content_select_no').addClass('active').siblings('.content_select').removeClass('active')
          }else{
            otherTreatment.flag=true
            $('.input_item_treatmentType').val(res.content.followAnswer.answer.treatmentTypeVal || '')
            $('#content_body__specificTherapy').val(res.content.followAnswer.answer.specificTherapy || '')
          }
        }
      })
    },
      // 上一题
		getPreQuestion:function(){
      var crm = otherTreatment.adminId==''? '':'/crm'
			medtap.submitAjax({
				url: 'https://testdevgw.medtap.cn/operation/followUp'+crm+'/previousQuestion',
				type: 'post',
				async: false,
				contentType: 'application/json',
				data: {
					"questionId":otherTreatment.questionId,
					"questionNo":otherTreatment.questionNo,
					"followUpId":otherTreatment.followUpId,
				},
				success: function(res) {
          console.log(res)
          if(!res.success) return winPop('获取数据失败')
          var parentId = res.content.previousQuestion.parentId||''
					var questionId = res.content.previousQuestion.questionId||''
					var questionNo = res.content.previousQuestion.questionNo||''
						medtap.pushWindow('targetedTherapy.html?followUpId='+otherTreatment.followUpId+'&questionId='+questionId+'&questionNo='+questionNo+'&parentId='+parentId+'&adminId='+otherTreatment.adminId);
				}
			})
		},
    // 下一题
		getNextQuestion:function(data){
      var crm = otherTreatment.adminId==''? '':'/crm'
			medtap.submitAjax({
				url: 'https://testdevgw.medtap.cn/operation/followUp'+crm+'/nextQuestion',
				type: 'post',
				async: false,
				contentType: 'application/json',
				data: data,
				success: function(res) {
          console.log(res)
          if(!res.success) return winPop('获取数据失败')
            // 获取下一题的id和序号通过url传递
          var parentId = res.content.nextQuestion.parentId||''
					var questionId = res.content.nextQuestion.questionId||''
					var questionNo = res.content.nextQuestion.questionNo||''
					medtap.pushWindow('examination.html?followUpId='+otherTreatment.followUpId+'&questionId='+questionId+'&questionNo='+questionNo+'&parentId='+parentId+'&adminId='+otherTreatment.adminId);
				}
			})
		}
}
otherTreatment.init()
otherTreatment.getQuestionAnswer()
})