//获取质检比例详细信息
$(function(){
	$.ajax({
        cache: true,
        type: "POST",
        url: getRootPath()+"/bpomanage/proportion/queryProportionDetl.do",
        data:{ },
        async: false,
        error: function(request) {
            alert("获取信息失败！");
        },
        success: function(data) {
        	var list=data;
        	var html="";
        	$("#proportionTbody").html(html);
        	for(var i=0;i<list.length;i++){
        		var businessFlag=list[i].businessFlag;
				if (businessFlag != null ){
					businessFlag = businessFlag == 1 ? "半外包" : (businessFlag == 2 ? "全外包" : "其他");
				}
				if(list[i].businessFlag==1){
					html+="<tr>"+
							"<td>"+(list[i].compFlag!=null?list[i].compFlag:'')+"</td>"+
							"<td>"+
								 "<select id='businessFlag"+list[i].objId+"' name='businessFlag'>"+
								     /*"<option selected value='"+list[i].businessFlag+"'>"+businessFlag+"</option>"+*/
									 "<option value='1' selected>半外包</option>"+
									 "<option value='2'>全外包</option>"+
								 "</select>"+
							"</td>"+
							"<td>"+
								 "<input style='width:50px' id='proportion"+list[i].objId+"' type='text' name='proportion' readonly='readonly' value='"+
								    (list[i].proportion!=null?list[i].proportion:'')+
								 "'/>"+"<span>%</span>"+
							"</td>"+
							"<td>"+"----"+"</td>"+
							"<td><input type='button' class='btn_blue' value='编辑' onclick='updateProportion("+list[i].objId+")' /></td>"+
							"<td><input type='button' class='btn_blue' id='saveP"+list[i].objId+"' disabled='disabled' value='保存' onclick='saveProportion("+list[i].objId+")' /></td>"+
						"</tr>";
				} else{
					html+="<tr>"+
							"<td>"+(list[i].compFlag!=null?list[i].compFlag:'')+"</td>"+
							"<td>"+
								 "<select id='businessFlag"+list[i].objId+"' name='businessFlag'>"+
								     /*"<option selected value='"+list[i].businessFlag+"'>"+businessFlag+"</option>"+*/
									 "<option value='1'>半外包</option>"+
									 "<option value='2'selected>全外包</option>"+
								 "</select>"+
							"</td>"+
							"<td>"+
								 "<input style='width:50px' id='proportion"+list[i].objId+"' type='text' name='proportion' readonly='readonly' value='"+
								    (list[i].proportion!=null?list[i].proportion:'')+
								 "'/>"+"<span>%</span>"+
							"</td>"+
							"<td>"+"----"+"</td>"+
							"<td><input type='button' class='btn_blue' value='编辑' onclick='updateProportion("+list[i].objId+")' /></td>"+
							"<td><input type='button' class='btn_blue' id='saveP"+list[i].objId+"' disabled='disabled' value='保存' onclick='saveProportion("+list[i].objId+")' /></td>"+
						"</tr>";
				}
        	}
        	$('#topOpen7').hide();
        	$('#rightOpen1').hide();
        	$('#rightOpen2').hide();
        	$("#proportionTbody").html(html);
			$("#openQualityPropDk").show();
        }
    });
});

function updateProportion(objId){
	$('#proportion'+objId).removeAttr('readonly');
	$('#saveP'+objId).removeAttr('disabled');
}

function saveProportion(objId){
	var businessFlag=document.getElementById('businessFlag'+objId).value;
	var proportion=document.getElementById('proportion'+objId).value;
	
	//校验输入的数据
	if(isNaN(proportion)){
		alert("只能输入数字!");
		return;
	}else{
		if(proportion<0||proportion>100) {
			alert("只能输入0~100之间的数字!");
			return;
		}
	}
	
	$.ajax({
        cache: true,
        type: "POST",
        url: getRootPath()+"/bpomanage/proportion/saveProportionDetl.do",
        data:{"objId":objId, "businessFlag":businessFlag, "proportion":proportion},
        async: false,
        error: function(request) {
            alert("获取信息失败！");
        },
        success: function(data) {
        	if(data=='SUCCESS'){
        		alert("保存成功！");
        		$('#proportion'+objId).attr('readonly','readonly');
        		$('#saveP'+objId).attr('disabled','disabled');
        	}
        }
    });
}