new Vue({
  el: '#app',
  data: {
  	frequency_dict:recipe_frequency_dict,
  	unit_dict:measure_unit_dict,
  	DRUG_COMPLIANCE_CODE:'',
  	hasInsulin:[],//胰岛素药
		noInsulin:[],//其他药
		objData:''
  },
  mounted: function() {
  	var vm = this
  	console.log(measure_unit_dict)
  	var Request = GetRequest();
  	recordAPI.getFollowupProjectData({id:Request["id"],followupProject:6}).then(function(res){
			if(res.status==200){
				var data = res.data;
				vm.objData = res.data
				vm.DRUG_COMPLIANCE_CODE = data.DRUG_COMPLIANCE_CODE;
			}
		})
  	recordAPI.getFollowupDrugs({id:Request["id"]}).then(function(res){
			if(res.status==200){
				var data = res.data.DRUG_LIST;
				if(data.length>0){
					for(var i=0;i<data.length;i++){
						if(data[i].drugsGroup == 'insulin'){//胰岛素药品
							vm.hasInsulin.push(data[i])
						}else{
							vm.noInsulin.push(data[i])
						}
					}
				}
			}else{
				toastr.error('获取数据失败')
			}
		})
  },
  methods:{
		saveButton:function(){
			var vm = this;
     	if(!vm.DRUG_COMPLIANCE_CODE){
     		toastr.error('请选择服药依从性')
     		return
     	}
     	 params = {id: vm.objData.followup_id}
			 var arr = [];
      $(".inline-container-p").each(function(i,v){//把所有被选中的复选框的值存入数组
      			var checkID = {};
	      		checkID['drugsName'] = $(this).attr('name')
	      		checkID['drugsCode'] = $(this).attr('code')
	      		checkID['drugsGroup'] = $(this).attr('group')
	      		checkID['dose'] = $(this).attr('dose')
	      		checkID['unit'] = $(this).attr('value1')
	      		checkID['frequency'] = $(this).attr('value2')
	      		arr.push(checkID)
      });
      $(".inline-container-y").each(function(i,v){//把所有被选中的复选框的值存入数组
      			var checkID1 = {};
	      		checkID1['drugsName'] = $(this).attr('name')
	      		checkID1['drugsCode'] = $(this).attr('code')
	      		checkID1['drugsGroup'] = $(this).attr('group')
	      		checkID1['dose'] = $(this).attr('dose')
	      		checkID1['unit'] = $(this).attr('value1')
	      		checkID1['frequency'] = $(this).attr('value2')
	      		arr.push(checkID1)
      });
        params.drugsData = JSON.stringify(arr)
				recordAPI.saveDrugs(params).then(function(res){
				if(res.status==200){
//					toastr.error("保存成功")
						var params = {};
	            	params.id = vm.objData.followup_id;
	            	params.followupProject = vm.objData.followup_project;
	              params.followupProjectData = JSON.stringify({'DRUG_COMPLIANCE_CODE':vm.DRUG_COMPLIANCE_CODE})
	              recordAPI.saveDrugsLaw(params).then(function(res){
								if(res.status==200){
									toastr.error("保存成功")
								}else{
									toastr.error(res.msg)
								}
							})
				}else{
					toastr.error(res.msg)
				}
			})
		}
  }
})