/**
 * 初始化channelplanExpertDetail详情对话框
 */
var ChannelplanExpertDetailInfoDlg = {
    channelplanExpertDetailInfoData : {}
};

/**
 * 清除数据
 */
ChannelplanExpertDetailInfoDlg.clearData = function() {
    this.channelplanExpertDetailInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
ChannelplanExpertDetailInfoDlg.set = function(key, val) {
    this.channelplanExpertDetailInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
ChannelplanExpertDetailInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
ChannelplanExpertDetailInfoDlg.close = function() {
    parent.layer.close(window.parent.ChannelplanExpertInfoDlg.layerIndex);
}

/**
 * 收集数据
 */
ChannelplanExpertDetailInfoDlg.collectData = function() {
    this
    .set('id')
    .set('cpExpertId')
    .set('parentId')
    .set('standardId')
    .set('score')
    .set('description')
    .set('createTime')
    .set('createUser')
    .set('updateTime')
    .set('updateUser');
}

/**
 * 提交添加
 */
ChannelplanExpertDetailInfoDlg.addSubmit = function() {
    var list=[];
    var expertId=$("#expertId").val();
    $("#scoreDetail_table tr:gt(0)").each(function (index,e) {
        var a=new Object();
        a.standardId=$(e).children("input").eq(0).val();
        a.score=$(e).children("td").eq(3).children("input").eq(0).val();
        a.expertId=expertId;
        list.push(a);
    })
    list=JSON.stringify(list);

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/channelplanExpertDetail/addList", function(data){
        Feng.success("保存成功!");
        ChannelplanExpertDetailInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.setData(list);
    ajax.setcontentType("application/json");
    ajax.start();
}

/**
 * 提交修改
 */
ChannelplanExpertDetailInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/channelplanExpertDetail/update", function(data){
        Feng.success("修改成功!");
        ChannelplanExpertDetailInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.channelplanExpertDetailInfoData);
    ajax.start();
}

function submitScore(){
    var sum=0;
    $("input[name='scoreAdd']").each(function (index,e) {
        var num=$(e).val();
        if(num!=null&&num!=""){
            sum=sum+Number(num);
        }
    })
    $("#score").val(sum);
    $("#javaScore",parent.document).html(sum);
    var score=0;
    $("td[name='mScore']",parent.document).each(function (index,e) {
        var num1=$(e).html();
        if(num1!=null&&num1!=""){
            score=score+Number(num1);
        }
    })
    $("#score",parent.document).val(score);
}

$(function() {

});
