/**
 * 初始化海峡计划专家评分详情对话框
 */
var ChannelplanExpertInfoDlg = {
    layerIndex:-1,
    channelplanExpertInfoData : {}
};

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

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

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

/**
 * 关闭此对话框
 */
ChannelplanExpertInfoDlg.close = function() {
    if($("#step").val()==2){
        parent.layer.close(window.parent.ChannelplanExpertLive.layerIndex);
    }
    if($("#step").val()==1){
        parent.layer.close(window.parent.ChannelplanExpert.layerIndex);
    }
}

/**
 * 收集数据
 */
ChannelplanExpertInfoDlg.collectData = function() {
    this
    .set('id')
    .set('step')
    .set('cpId')
    .set('score')
    .set('expertId')
    .set('group')
    .set('checkMsg')
    .set('recommendType')
    .set('description')
    .set('createTime')
    .set('createUser')
    .set('updateTime')
    .set('updateUser');
}

/**
 * 提交添加
 */
ChannelplanExpertInfoDlg.addSubmit = function() {

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

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/channelplanExpert/add", function(data){
        Feng.success("添加成功!");
        if($("#step").val()==1){
            window.parent.ChannelplanExpert.table.refresh();
            window.parent.ChannelplanExpert.calScore(1);
        }
        if($("#step").val()==2){
            window.parent.ChannelplanExpertLive.table.refresh();
            window.parent.ChannelplanExpertLive.calScore(2);
        }
        ChannelplanExpertInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.channelplanExpertInfoData);
    ajax.start();
}

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

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

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/channelplanExpert/update", function(data){
        Feng.success("修改成功!");
        window.parent.ChannelplanExpert.table.refresh();
        ChannelplanExpertInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.channelplanExpertInfoData);
    ajax.start();
}

/**
 * 弹出详细分数填写框
 * end:function () {
 *             window.parent.TalentInfo.xxx(value);
 *          }
 */
popDetailScore=function(obj){
    var id = $(obj).parent().children("input").eq(0).val();
    var expertId=$("#expertId").val();
    var index = layer.open({
        type: 2,
        title: '评审分值',
        area: ['420px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/channelplanExpertDetail?id='+id+"&expertId="+expertId
    });
    ChannelplanExpertInfoDlg.layerIndex = index;
}

/**
 * 弹出详细分数详情页
 */
popDetailScoreDetail=function(obj){
    var id = $(obj).parent().children("input").eq(0).val();
    var expertId=$("#expertId").val();
    var index = layer.open({
        type: 2,
        title: '评审分值',
        area: ['420px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/channelplanExpertDetail/indexDetail?id='+id+"&expertId="+expertId
    });
    ChannelplanExpertInfoDlg.layerIndex = index;
}


/**
 * 求取总分
 */
function addSum(){
    var sum=0;
    $("input[name='mScore']").each(function (index,e) {
        var num=$(e).html();
        if(num!=null&&num!=""){
            sum=sum+Number(num);
        }
    })
    $("#score").val(sum);
}

$(function() {
    //获取有效专家列表
    Feng.addAjaxSelect({
        "id": "expertId",
        "displayCode": "id",
        "displayName": "name",
        "type": "GET",
        "url": Feng.ctxPath + "/channelplanExpert/queryExpert"
    });
    //获取评审分组
    Feng.addAjaxSelect({
        "id": "group",
        "displayCode": "code",
        "displayName": "name",
        "type": "GET",
        "url": Feng.ctxPath + "/dict/findChildDictByCode?code=reviewGroup"
    });
    //获取推荐类别
    Feng.addAjaxSelect({
        "id": "recommendType",
        "displayCode": "code",
        "displayName": "name",
        "type": "GET",
        "url": Feng.ctxPath + "/dict/findChildDictByCode?code=un_declareSort"
    });
    $("select").each(function () {
        $(this).val($(this).attr("selectVal"));
    });
});
