/**
 * 人才类别变更管理初始化
 */
var TalentTypeChange = {
    id: "TalentTypeChangeTable", //表格id
    seItem: null, //选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
TalentTypeChange.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '审核单位', field: 'companyName', visible: true, align: 'center', valign: 'middle', width: '10%', 'class': 'uitd_showTip'},
        {title: '原申报年度', field: 'oldYear', visible: true, align: 'center', valign: 'middle', width: '80px'},
        {title: '工作单位', field: 'enterpriseName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        {title: '姓名', field: 'talentName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        {title: '原人才层次', field: 'oldTalentArrangeName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        {title: '原认定条件', field: 'oldIdentifyConditionCH', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "130px"},
        // {title: '原认定条件证书取得时间', field: 'oldIdentifyGetTime', visible: true, align: 'center', valign: 'middle','class': 'uitd_showTip',width:"140px"},
        {title: '原认定条件名称', field: 'oldIdentifyConditionName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "140px"},
        {title: '原证书有效期', field: 'oldCertificateStartTime', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "140px",
            formatter: function (value, row, index) {
                return row.oldCertificateStartTime + "至" + row.oldCertificateOutTime
            }
        },
        {title: '原公布入选月份', field: 'oldIdentifyMonth', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        {title: '新申报年度', field: 'newYear', visible: true, align: 'center', valign: 'middle', width: '80px'},
        {title: '新人才层次', field: 'newTalentArrangeName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        {title: '新认定条件', field: 'newIdentifyConditionCH', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "140px"},
        // {title: '新认定条件证书取得时间', field: 'newIdentifyGetTime', visible: true, align: 'center', valign: 'middle','class': 'uitd_showTip',width:"140px"},
        {title: '新认定条件名称', field: 'newIdentifyConditionName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "130px"},
        // {title: '新公布入选月份', field: 'newIdentifyMonth', visible: true, align: 'center', valign: 'middle','class': 'uitd_showTip',width:"100px"},
        {title: '首次提交时间', field: 'firstSubmitTime', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        {title: '最新提交时间', field: 'newSubmitTime', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        {title: '审核状态', field: 'depState', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px",
            formatter: function (value, row, index) {
                if (value == 1) {
                    if (row.highProcess != null && row.highProcess != '' && row.highProcess >= 2) {
                        return "<span class='label label-success'>重新提交</span>"
                    }
                    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>"
                }
            }
        },
        {title: '操作', field: 'id', visible: true, align: 'center', valign: 'middle', width: "80px",
            formatter: function (value, row, index) {
                return "<span class='label label-success' onclick=\"TalentTypeChange.showLog('" + value + "')\" >" +
                        "<i class=\"fa fa-book\"></i>日志" +
                        "</span>";
            }
        }
    ];
};

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

/**
 * 点击人才类别审核
 */
TalentTypeChange.openTalentTypeChangeCheck = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '人才类别审核',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/admin/talentTypeChange/toDepCheck/id/' + TalentTypeChange.seItem.id + '/companyId/' + TalentTypeChange.seItem.companyId,
            btn: ['<i class="fa fa-eye"></i>&nbsp;&nbsp;保存未提交', '<i class="fa fa-save layui-bg-green"></i>&nbsp;&nbsp;提交审核', '<i class="fa fa-eraser"></i>&nbsp;&nbsp;关闭'],
            btnAlign: 'c',
            btn1: function (index, layero) {
                var obj = layero.find("iframe")[0].contentWindow;
                obj.TalentTypeChangeInfoDlg.showCommonCheckModal();
            }, btn2: function (index, layero) {
                var obj = layero.find("iframe")[0].contentWindow;
                obj.TalentTypeChangeInfoDlg.submitCheck();
                return false;
            }
        });
        TalentTypeChange.layerIndex = index;
        layer.full(index);
    }
};

/**
 * 打开查看人才类别变更详情
 */
TalentTypeChange.openTalentTypeChangeDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '人才层次变更详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/admin/talentTypeChange/deptDetail/id/' + TalentTypeChange.seItem.id + '/companyId/' + TalentTypeChange.seItem.companyId,
        });
        TalentTypeChange.layerIndex = index;
        layer.full(index);
    }
};

$(function () {
    var defaultColunms = TalentTypeChange.initColumn();
    var table = new BSTable(TalentTypeChange.id, "/admin/talentTypeChange/list/process/2", defaultColunms);
    table.setPaginationType("server");
    // table.setHeight(665);
    TalentTypeChange.table = table.init();
    TalentTypeChange.init();
});
