/**
 * 银行账号变更管理初始化
 */
var TalentBankChange = {
    id: "TalentBankChangeTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
TalentBankChange.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '对象姓名', field: 'talentName', visible: true, align: 'center', valign: 'middle',width:'100px'},
        {title: '企业名称', field: 'enterpriseName', visible: true, align: 'center', valign: 'middle',width:'120px','class': 'uitd_showTip'},
        {title: '证件号码', field: 'idCard', visible: true, align: 'center', valign: 'middle',width:'150px','class': 'uitd_showTip'},
        {title: '原开户银行', field: 'oldBankName', visible: true, align: 'center', valign: 'middle',width:'120px','class': 'uitd_showTip'},
        {title: '原开户银行网点', field: 'oldBankNerPoint', visible: true, align: 'center', valign: 'middle',width:'150px','class': 'uitd_showTip'},
        {title: '原银行账号', field: 'oldBankAccount', visible: true, align: 'center', valign: 'middle',width:'120px','class': 'uitd_showTip'},
        {title: '现开户银行', field: 'newBankName', visible: true, align: 'center', valign: 'middle',width:'120px','class': 'uitd_showTip'},
        {title: '现开户银行网点', field: 'newBankNerPoint', visible: true, align: 'center', valign: 'middle',width:'150px','class': 'uitd_showTip'},
        {title: '现银行账号', field: 'newBankAccount', visible: true, align: 'center', valign: 'middle',width:'120px','class': 'uitd_showTip'},
        {title: '备注', field: 'description', visible: true, align: 'center', valign: 'middle',width:'120px','class': 'uitd_showTip'},
        {title: '审核状态', field: 'checkState', visible: true, align: 'center', valign: 'middle',width:'100px',
            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=\"TalentBankChange.showLog('"+value+"')\" >" +
                    "<i class=\"fa fa-book\"></i>日志" +
                    "</span>";
            }
        }
    ];
};

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

/**
 * 点击添加银行账号变更
 */
TalentBankChange.openTalentBankChangeDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '银行账号变更详情',
            // area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/talentBankChange/talentBankChange_detail/' + TalentBankChange.seItem.id,
        });
        TalentBankChange.layerIndex = index;
        layer.full(index);
    }
};

/**
 * 打开查看银行账号变更详情
 */
TalentBankChange.openTalentBankChangeCheck = function () {
    if (this.check()) {
        if(TalentBankChange.seItem.checkState!=1 && TalentBankChange.seItem.checkState!=9){
            Feng.error("不在审核范围内 ");return;
        }
        var index = layer.open({
            type: 2,
            title: '银行账号变更审核',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/talentBankChange/talentBankChange_detail/' + TalentBankChange.seItem.id,
            btn: ['<i class="fa fa-check"></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.TalentBankChangeInfoDlg.submitCheck();
            }
        });
        TalentBankChange.layerIndex = index;
        layer.full(index);
    }
};


/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
TalentBankChange.formParams = function() {
    var queryData = {};
    queryData['talentName'] = $("#talentName").val();
    queryData['idCard'] = $("#idCard").val();
    queryData['oldBankName'] = $("#oldBankName").val();
    queryData['newBankName'] = $("#newBankName").val();
    queryData['checkState'] = $("#checkState").val();
    queryData['newBankAccount'] = $("#newBankAccount").val();
    queryData['oldBankAccount'] = $("#oldBankAccount").val();
    return queryData;
}

/**
 * 重置
 */
TalentBankChange.reset = function (){
    $("#talentName").val("");
    $("#idCard").val("");
    $("#oldBankName").val("");
    $("#newBankName").val("");
    $("#checkState").val("");
    $("#newBankAccount").val("");
    $("#oldBankAccount").val("");
}

/**
 * 查询银行账号变更列表
 */
TalentBankChange.search = function () {
    TalentBankChange.table.refresh({query: TalentBankChange.formParams()});
};

/**
 * 导出
 */
TalentBankChange.export = function(){
    var queryData = TalentBankChange.formParams();
    var url = Feng.ctxPath + "/talentBankChange/export?" +
        "&talentName=" + queryData.talentName +
        "&idCard=" + queryData.idCard +
        "&oldBankName=" + queryData.oldBankName +
        "&newBankName=" + queryData.newBankName +
        "&newBankAccount=" + queryData.newBankAccount +
        "&oldBankAccount=" + queryData.oldBankAccount +
        "&checkState=" + queryData.checkState ;
    window.location.href = encodeURI(encodeURI(url));
}


/**
 * 显示审核日志
 */
TalentBankChange.showLog = function (id){
    layer.open({
        type: 1,
        title:"日志",
        fixed:false,
        content: '<table id="'+id+'"></table>',
        area: ['80%', '80%'],
        maxmin: true,
        success :function (layero, index) {
            Feng.getCheckLog(id,{"type":CONFIG.project_bankchange,"mainId":id,"typeFileId":"","active":1})
        }
    });
}

$(function () {
    var defaultColunms = TalentBankChange.initColumn();
    var table = new BSTable(TalentBankChange.id, "/talentBankChange/list", defaultColunms);
    table.setPaginationType("server");
    TalentBankChange.table = table.init();
});
