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

/**
 * 初始化表格的列
 */
TalentInfo.initColumn = function () {
    var type = $("#type").val();
    var isShow = true;
    if(type==2){
        isShow = false;
    };
    return [
        {field: 'selectItem', radio: true},
        {title: '申报年度', field: 'year', visible: true, align: 'center', valign: 'middle',width:'80px'},
        {title: '企业名称', field: 'enterpriseName', visible: true, align: 'center', valign: 'middle'},
        {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle',
            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: 'talentArrangeName', visible: true, align: 'center', valign: 'middle'},
        {title: '人才标签', field: 'talentTypeName', visible: isShow, align: 'center', valign: 'middle'},
        {title: '证件号码', field: 'idCard', visible: true, align: 'center', valign: 'middle'},
        {title: '认定条件', field: 'identifyConditionText', visible: true, align: 'center', valign: 'middle','class': 'uitd_showTip'},
        {title: '认定条件名称', field: 'identifyConditionName', visible: true, align: 'center', valign: 'middle','class': 'uitd_showTip'},
        {title: '获得时间', field: 'identifyGetTime', visible: true, align: 'center', valign: 'middle','class': 'uitd_showTip'},
        {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: 'checkState', visible: true, align: 'center', valign: 'middle',width:"120px",
            formatter : function (value,row,index) {
                if(value==-1){
                    return "<span class='label label-danger'>审核不通过</span>"
                }if(value == 25){
                    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 == 30 || value <= 20){
                    return "<span class='label label-danger'>已驳回</span>"
                }if(value >= 35){
                    return "<span class='label label-primary'>已通过</span>"
                }
            }
        },
        {title: '操作', field: 'id', visible: true, align: 'center', valign: 'middle',
            formatter : function (value,row,index){
                var data = {"type":CONFIG.project_rcrd,"mainId":value,"typeFileId":"","active":1};
                return "<span class='label label-success' onclick=\"Feng.getCheckLogModel('"+value+"','"+CONFIG.project_rcrd+"',null)\" >" +
                    "<i class=\"fa fa-book\"></i>日志" +
                    "</span>";
            }
        }
    ];
};
/**
 * 检查是否选中
 */
TalentInfo.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        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,
            content: Feng.ctxPath + '/talentInfo/talentInfo_toCommonCheck/' + TalentInfo.seItem.id + '/3',
            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.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.openTalentInfoDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '人才认定申报详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/talentInfo/talentInfo_toDetail/' + TalentInfo.seItem.id+'/3'
        });
        layer.full(index);
        TalentInfo.layerIndex = index;
    }
};

TalentInfo.cancleThirdCheck = function(){
    if (this.check()) {
        var index = layer.open({
            type: 1,
            title: '撤销复核',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: '<form >\n' +
                '                    <div class="form-group" style="margin: 10px;">\n' +
                '                        <label for="checkMsg" class="control-label">撤销原因</label>\n' +
                '                        <textarea class="form-control" id="msg" rows="6"></textarea>\n' +
                '                    </div>\n' +
                '                </form>',
            btn: ['<i class="fa fa-save layui-bg-green"></i>&nbsp;&nbsp;提交' ,'<i class="fa fa-eraser"></i>&nbsp;&nbsp;关闭'],
            yes: function (index, layero) {
                var cancleMsg = $("#msg").val();
                if(Feng.isEmptyStr(cancleMsg)){
                    Feng.error("撤销原因不能为空");return ;
                }
                var operation = function(){
                    var ajax = new $ax(Feng.ctxPath + "/talentInfo/cancleThirdCheck", function (data) {
                        if(data.code==200){
                            Feng.success(data.msg);
                            TalentInfo.table.refresh();
                            layer.close(index);
                        }else{
                            Feng.error(data.msg);
                        }
                        locked = false;
                    }, function (data) {
                        Feng.error("撤销复核失败!" + data.responseJSON.message + "!");
                        locked = false;
                    });
                    ajax.setData({"id":TalentInfo.seItem.id,"checkMsg":cancleMsg})
                    ajax.start();
                };
                Feng.confirm("一旦提交无法修改，确定要撤销吗?", operation);
            }
        });
    }
}

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
TalentInfo.formParams = function() {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['idCard'] = $("#idCard").val();
    queryData['sex'] = $("#sex").val();
    queryData['nation'] = $("#nation").val();
    queryData['nationality'] = $("#nationality").val();
    queryData['talentType'] = $("#talentType").val();
    queryData['talentArrange'] = $("#talentArrange").val();
    queryData['address'] = $("#address").val();
    queryData['identifyCondition'] = $("#identifyCondition").val();
    queryData['checkState'] = $("#checkState").val();
    return queryData;
}

/**
 * 查询人才认定申报列表
 */
TalentInfo.search = function () {
    TalentInfo.table.refresh({query: TalentInfo.formParams()});
};

/**
 * 重置
 */
TalentInfo.reset = function (){
    $("#name").val("");
    $("#idCard").val("");
    $("#sex").val("");
    $("#nation").val("");
    $("#nationality").val("");
    $("#talentType").val("");
    $("#talentArrange").val("").trigger("change");
    $("#address").val("");
    $("#identifyCondition").val("");
    $("#checkState").val("");
}

/**
 * 获取人才认定
 */
TalentInfo.getIdentifyCondition = function() {
    var level = $("#talentArrange").val();
    if(level==null||level==''){
        $("#identifyCondition").empty();
        $("#identifyCondition").trigger('chosen:updated');
        return;
    }
    Feng.addAjaxSelect({
        "id": "identifyCondition",
        "displayCode": "id",
        "displayName": "name",
        "type": "GET",
        "url": Feng.ctxPath + "/identifyCondition/findIdentifyConditionByLevel?talentLevel="+level
    });
    $("#identifyCondition").trigger('chosen:updated');
}

$(function () {
    var defaultColunms = TalentInfo.initColumn();
    var table = new BSTable(TalentInfo.id, "/talentInfo/list/3", defaultColunms);
    table.setPaginationType("server");
    table.setOnDblClickRow(function () {
        TalentInfo.openCheckTalentInfo();
    });
    TalentInfo.table = table.init();
    TalentInfo.init();
});
