/**
 * 人才认定申报管理初始化
 */
var TalentInfo = {
    id: "TalentInfoTable", //表格id
    seItem: null, //选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
TalentInfo.initColumn = function () {
    return [
        {field: 'selectItem', checkbox: true},
        {title: '申报年度', field: 'apply_year', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px"},
        {title: '医院名称', field: 'enterpriseName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px"},
        {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px",
            formatter: function (value, row, index) {
                if (row.sex == 1) {
                    return value + '<span style="color:#6495ED">【男】</span>';
                }
                if (row.sex == 2) {
                    return value + '<span style="color:#FF82AB">【女】</span>';
                }
            }
        },
        {title: '证件号码', field: 'card_number', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "120px"},
        {title: '认定层次', field: 'talentArrangeName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "80px"},
        {title: '认定条件', field: 'talentConditionName', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "150px"},
        {title: '首次提交时间', field: 'first_submit_time', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        {title: '最新提交时间', field: 'new_submit_time', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px"},
        {title: '审核状态', field: 'checkState', visible: true, align: 'center', valign: 'middle', 'class': 'uitd_showTip', width: "100px",
            formatter: function (value, row, index) {
                console.log(value, row.real_state, row.last_state)
                if (typeof row.deptCheckState != "undefined") {
                    if ((row.deptActive == 0 && row.real_state == 10) || !row.deptActive) {
                        if (row.resubmit) {
                            return "<span class='label label-success'>待部门并审（重新提交）</span>";
                        } else {
                            return "<span class='label label-success'>待部门并审（首次提交）</span>";
                        }
                    }
                    if (row.deptActive == 1 && row.newState == 12) {
                        return "<span class='label label-primary'>部门并审通过</span>";
                    }
                    if (row.deptActive == 1 && row.newState == 9) {
                        return "<span class='label label-danger'>部门并审驳回</span>";
                    }
                } else {
                    if (value == 1) {
                        if (row.real_state == 4) {
                            return "<span class='label label-danger'>审核驳回</span>"
                        }
                        if (row.real_state == 11) {
                            return "<span class='label label-danger'>初审驳回</span>"
                        }
                    }
                    if (value == 2) {
                        if (row.last_state == 4) {
                            return "<span class='label label-success'>待审核（重新提交）</span>"
                        }
                        if (row.real_state == 6) {
                            return "<span class='label label-danger'>复审驳回</span>"
                        }
                        return "<span class='label label-success'>待审核</span>"
                    }
                    if (value == 3) {
                        return "<span class='label label-success'>待初审</span>"
                    }
                    if (value == 5) {
                        return "<span class='label label-success'>复审通过</span>"
                    }
                    if (value == 10) {
                        return "<span class='label label-success'>待上级审核</span>";
                    }
                    if (value == 8) {
                        if (row.real_state == 11) {
                            return "<span class='label label-danger'>初审驳回</span>"
                        } else {
                            return "<span class='label label-success'>保存未提交</span>"
                        }
                    }
                    if (value == 9) {
                        if (row.real_state == 13) {
                            return "<span class='label label-danger'>部门并审驳回</span>";
                        } else if (row.real_state == 15) {
                            return "<span class='label label-danger'>复审驳回</span>";
                        } else {
                            return "<span class='label label-success'>待初审</span>"
                        }
                    }
                    if (value == -2) {
                        return "<span class='label label-danger'>初审不通过</span>"
                    }
                    if (value == 16) {
                        return "<span class='label label-danger'>复审不通过</span>"
                    }
                    if (value == -1 || value == 7) {
                        return "<span class='label label-danger'>审核不通过</span>"
                    }
                    if (value == 4) {
                        if (row.highProcess != null && row.highProcess != '' && row.highProcess >= 1) {
                            return "<span class='label label-success'>上级驳回</span>"
                        } else {
                            return "<span class='label label-success'>待审核</span>"
                        }
                    }
                    if (value == 11) {
                        if (row.highProcess != null && row.highProcess != '' && row.highProcess >= 3) {
                            return "<span class='label label-success'>上级驳回</span>"
                        } else {
                            return "<span class='label label-success'>待审核</span>"
                        }
                    }
                    if (value == 12) {
                        return "<span class='label label-success'>待复审</span>";
                    }
                    if (value == 13) {
                        if (row.highProcess != null && row.highProcess != '' && row.highProcess >= 4) {
                            return "<span class='label label-danger'>上级驳回</span>"
                        } else {
                            return "<span class='label label-success'>待审核</span>"
                        }
                    }
                    if (value == 14) {
                        return "<span class='label label-primary'>复审通过</span>"
                    }
                    if (value == 15) {
                        if (row.highProcess != null && row.highProcess != '' && row.highProcess >= 5) {
                            return "<span class='label label-success'>上级驳回</span>"
                        } else {
                            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=\"TalentInfo.showLog('" + value + "')\" >" +
                        "<i class=\"fa fa-book\"></i>日志" +
                        "</span>";
            }
        }
    ];
};
/**
 * 检查是否选中
 */
TalentInfo.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length != 1) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        TalentInfo.seItem = selected[0];
        return true;
    }
};


TalentInfo.openCheckTalentInfo = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '优秀人才审核',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            shade: 0,
            content: '/enterprise/talent/examinePage/id/' + TalentInfo.seItem.id,
            btn: ['<i class="fa fa-eye"></i>&nbsp;&nbsp;保存未提交', '<i class="fa fa-save"></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.TalentInfoInfoDlg.showFirstCheckModal();
            }, btn2: function (index, layero) {
                var obj = layero.find("iframe")[0].contentWindow;
                obj.TalentInfoInfoDlg.submitCheck();
                return false;
            }
        });
        layer.full(index);
        TalentInfo.layerIndex = index;
    }
}

TalentInfo.creatFieldCheckModal = function () {
    return '<form id="firstCheckForm">\n' +
            '                    <div class="form-group" style="margin: 10px;">\n' +
            '                        <div >\n' +
            '                            <label for="checkMsg" class="control-label">可修改字段</label>\n' +
            '                            <div id="field_info">\n' +
            '                                <ul>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="name"><span>姓名</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="sex"><span>性别</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="birthday"><span>出生日期</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="nationality"><span>国籍/地区</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="provinceCode" onchange="TalentInfo.fieldCheckd(this)"><span>籍贯省</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="cityCode" onchange="TalentInfo.fieldCheckd(this)"><span>籍贯市</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="countyCode"><span>籍贯县</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="nation"><span>民族</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="politics"><span>政治面貌</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="cardType"><span>证件类型</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="idCard"><span>证件号码</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="firstInJJTime"><span>首次来晋工作时间</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="source" onchange="TalentInfo.sourceCheckd(this)"><span>申报来源</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="ourCitySource"><span>公布入选来源</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="fromCity"><span>入选来源县市</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="qzBatch"><span>入选名单的文件号及批次</span></li>\n' +
            '                                    <li style="width:31%"><input type="checkbox" value="certificateStartTime"><span>泉州高层次人才证书发证日期</span></li>\n' +
            '                                    <li style="width:31%"><input type="checkbox" value="qzgccrcActiveTime"><span>泉州高层次人才证书的有效期</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" id="talentArrangeCheckBox" value="talentArrange" onchange="TalentInfo.fieldCheckd(this)"><span>人才层次</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="identifyCondition"><span>认定条件</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="identifyConditionName"><span>认定条件名称</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="identifyGetTime"><span>认定条件证书取得时间</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="talentType"><span>人才标签</span></li>\n' +
            '                                    <li style="width:31%"><input type="checkbox" value="letterTime"><span>首次来晋行政介绍信时间</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="introductionMode"><span>引进方式</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="entryTime"><span>本单位入职时间</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="post"><span>职务</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="startTime"><span>工作合同开始时间</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="endTime"><span>工作合同结束时间</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="lastYearWages"><span>上一年度年薪</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="highEducation"><span>最高学历</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="graduateSchool"><span>毕业院校</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="major"><span>专业</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="title"><span>职称</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="professionalQualifications"><span>国家职业资格</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="studyAbroad"><span>是否有留学经历</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="phone"><span>手机号码</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="email"><span>电子邮箱</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="bank"><span>开户银行</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="bankNetwork"><span>开户银行网点</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="bankNumber"><span>银行行号</span></li>\n' +
            '                                    <li style="width:10%"><input type="checkbox" value="bankAccount"><span>银行账号</span></li>\n' +
            '                                    <li style="width:31%"><input type="checkbox" value="breakFaith"><span>曾被相关主管部门列为失信个人</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="educationAndResume"><span>教育背景及工作简历</span></li>\n' +
            '                                    <li style="width:20.5%"><input type="checkbox" value="mainHonours"><span>主要业绩及取得的荣誉</span></li>\n' +
            '                                </ul>\n' +
            '                            </div>\n' +
            '                            <label for="checkMsg" class="control-label">可修改附件</label>\n' +
            '                            <div id="field_file">\n' +
            '                            </div>\n' +
            '                            <div class="form-group" style="text-align: center">\n' +
            '                                <button type="button" class="btn btn-primary" onclick="TalentInfo.checkAll()">全选</button>\n' +
            '                                <button type="button" class="btn btn-success" onclick="TalentInfo.unCheckAll()">反选</button>\n' +
            '                            </div>\n' +
            '                        </div>\n' +
            '                    </div>\n' +
            '                </form>';
}

TalentInfo.fieldCheckd = function (context) {
    if ($(context).get(0).checked) {
        $(context).parent().next().children()[0].checked = true;
        $(context).parent().next().children().eq(0).trigger("change");
    }
}

TalentInfo.sourceCheckd = function (context) {
    if ($(context).get(0).checked) {
        $("#talentArrangeCheckBox").attr("checked", true);
        $("#talentArrangeCheckBox").trigger("change");
    }
}

$(function () {
    var defaultColunms = TalentInfo.initColumn();
    var process = $("#process").val();
    var table = new BSTable(TalentInfo.id, "/enterprise/talent/examineList", defaultColunms);
    table.setPaginationType("server");
    table.setSingleSelect(false);
    table.setOnDblClickRow(function () {
        TalentInfo.openCheckTalentInfo();
    });
    TalentInfo.table = table.init();
    TalentInfo.init();

    // var defaultColunms = TalentInfo.initColumn();
    // var table = new KDTable(TalentInfo.id, "/talentInfo/list/1", defaultColunms);
    // table.setPaginationType("server");
    // TalentInfo.table = table.init();
});
