/**
 * 人才基础信息变更管理初始化
 */
var TalentBasicChange = {
    id: "TalentBasicChangeTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
TalentBasicChange.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '申报单位', field: 'enterpriseName', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
        {title: '原姓名', field: 'oldName', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
        // {title: '原出生日期', field: 'oldBirthday', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
        {title: '原国籍', field: 'oldNationalityName', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        {title: '原民族', field: 'oldNationName', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        {title: '原政治面貌', field: 'oldPoliticsName', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        {title: '原证件类型', field: 'oldCardTypName', visible: true, align: 'center', valign: 'middle',width:"80px",'class': 'uitd_showTip'},
        {title: '原证件号码', field: 'oldIdCard', visible: true, align: 'center', valign: 'middle',width:"150px",'class': 'uitd_showTip'},
        // {title: '原电子邮箱', field: 'oldEmail', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
        {title: '现姓名', field: 'newName', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
        // {title: '现出生日期', field: 'newBirthday', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        {title: '现国籍', field: 'newNationalityName', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        {title: '现民族', field: 'newNationName', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        {title: '现政治面貌', field: 'newPoliticsName', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        {title: '现证件类型', field: 'newCardTypName', visible: true, align: 'center', valign: 'middle',width:"80px",'class': 'uitd_showTip'},
        {title: '现证件号码', field: 'newIdCard', visible: true, align: 'center', valign: 'middle',width:"150px",'class': 'uitd_showTip'},
        // {title: '现邮箱', field: 'newEmail', visible: true, align: 'center', valign: 'middle',width:"100px",'class': 'uitd_showTip'},
        {title: '首次提交时间', field: 'firstSubmitTime', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        {title: '最新提交时间', field: 'newSubmitTime', visible: true, align: 'center', valign: 'middle',width:"120px",'class': 'uitd_showTip'},
        {title: '审核状态', field: 'checkState', visible: true, align: 'center', valign: 'middle',width:"80px",
            formatter : function (value,row,index) {
                if(value==-1){
                    return '<span class=\'label\'>待提交</span>';
                }if(value==1){
                    return '<span class=\'label label-success\'>待审核</span>';
                }if(value==2){
                    return '<span class=\'label label-danger\'>已驳回</span>';
                }if(value==3){
                    return '<span class=\'label label-primary\'>已通过</span>';
                }if(value==9){
                    return '<span class=\'label label-success\'>重新提交</span>';
                }
            }
        },
        {title: '操作', field: 'id', visible: true, align: 'center', valign: 'middle',width:"80px",
            formatter: function (value,row,index) {
                return "<span class='label label-success' onclick=\"Feng.getCheckLogModel('"+value+"','"+CONFIG.project_basicchange+"')\" >" +
                    "<i class=\"fa fa-book\"></i>日志" +
                    "</span>";
            }
        }
    ];
};

/**
 * 检查是否选中
 */
TalentBasicChange.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        TalentBasicChange.seItem = selected[0];
        return true;
    }
};

/**
 * 打开查看人才基础信息变更详情
 */
TalentBasicChange.openTalentBasicChangeDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '人才基础信息变更审核',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/talentBasicChange/check/' + TalentBasicChange.seItem.id,
            btn: ['<i class="fa fa-eye"></i>&nbsp;&nbsp;审核', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;取消'],
            btnAlign: 'c',
            yes: function (index, layero) {
                var obj = layero.find("iframe")[0].contentWindow;
                obj.TalentBasicChangeInfoDlg.showCheckModal();
            }
        });
        TalentBasicChange.layerIndex = index;
        layer.full(index);
    }
};

TalentBasicChange.export = function(){
    var queryData = TalentBasicChange.formParams();
    var url = Feng.setUrlParam(Feng.ctxPath + "/talentBasicChange/export",queryData);
    window.location.href = url;
}


TalentBasicChange.formParams = function() {
    var queryData = {};
    queryData['enterpriseName'] = $("#enterpriseName").val();
    queryData['oldName'] = $("#oldName").val();
    queryData['oldCardType'] = $("#oldCardType").val();
    queryData['oldIdCard'] = $("#oldIdCard").val();
    queryData['newName'] = $("#newName").val();
    queryData['newCardType'] = $("#newCardType").val();
    queryData['newIdCard'] = $("#newIdCard").val();
    queryData['checkState'] = $("#checkState").val();
    return queryData;
}

/**
 * 查询人才基础信息变更列表
 */
TalentBasicChange.search = function () {
    TalentBasicChange.table.refresh({query: TalentBasicChange.formParams()});
};

TalentBasicChange.reset = function(){
    $("#enterpriseName").val("");
    $("#oldName").val("");
    $("#oldCardType").val("");
    $("#oldIdCard").val("");
    $("#newName").val("");
    $("#newCardType").val("");
    $("#newIdCard").val("");
    $("#checkState").val("");
}

$(function () {
    var defaultColunms = TalentBasicChange.initColumn();
    var table = new BSTable(TalentBasicChange.id, "/talentBasicChange/list", defaultColunms);
    table.setPaginationType("server");
    TalentBasicChange.table = table.init();
    var arr = [
        {"name": "oldCardType", "code": "un_cardType"},
        {"name": "newCardType", "code": "un_cardType"}
    ];
    Feng.findChildDictBatch(JSON.stringify(arr));
});
