/**
 * 初始化评分标准详情对话框
 */
var ChannelplanScoreStandardInfoDlg = {
    channelplanScoreStandardInfoData : {}
};

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

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

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

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

/**
 * 收集数据
 */
ChannelplanScoreStandardInfoDlg.collectData = function() {
    this
    .set('id')
    .set('parentId')
    .set('step')
    .set('name')
    .set('score')
    .set('sn')
    .set('description')
    .set('createTime')
    .set('createUser')
    .set('updateTime')
    .set('updateUser');
}

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

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

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/channelplanScoreStandard/add", function(data){
        Feng.success("添加成功!");
        window.parent.ChannelplanScoreStandard.table.refresh();
        ChannelplanScoreStandardInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.channelplanScoreStandardInfoData);
    ajax.start();
}

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

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

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

$(function() {
    //获取父Id
    Feng.addAjaxSelect({
        "id": "parentId",
        "displayCode": "id",
        "displayName": "name",
        "type": "GET",
        "url": Feng.ctxPath + "/channelplanScoreStandard/fatherList"
    });
    $("select").each(function () {
        $(this).val($(this).attr("selectVal"));
    });
});
