/**
 * 银行账号变更管理初始化
 */
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: "80px", 'class': 'uitd_showTip'},
        {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: "120px", '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: "120px", 'class': 'uitd_showTip'},
        {title: '现银行账号', field: 'newBankAccount', visible: true, align: 'center', valign: 'middle', width: "120px", 'class': 'uitd_showTip'},
        {title: '审核状态', field: 'checkState', visible: true, align: 'center', valign: 'middle', width: "80px", 'class': 'uitd_showTip',
            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: 'description', visible: true, align: 'center', valign: 'middle', width: "100px", 'class': 'uitd_showTip'},
        {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.openAddTalentBankChange = function () {
    var index = layer.open({
        type: 2,
        title: '添加银行账号变更',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/enterprise/talent_bank_change/apply',
        btn: ['<i class="fa fa-eye"></i>&nbsp;&nbsp;保存未提交', '<i class="fa fa-check 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.TalentBankChangeInfoDlg.addSubmit();
        }, btn2: function (index, layero) {
            var obj = layero.find("iframe")[0].contentWindow;
            obj.TalentBankChangeInfoDlg.editSubmit(2);
            return false;
        },
        success: function (layero, index) {
            layer.tips('添加基本信息并上传附件后点击', '.layui-layer-btn1', {tips: [1, "#78BA32"], time: 0, closeBtn: 2});
        },
        end: function () {
            layer.closeAll('tips');
        }
    });
    TalentBankChange.layerIndex = index;
    layer.full(index);
};

/**
 * 打开查看银行账号变更详情
 */
TalentBankChange.openTalentBankChangeDetail = function () {
    if (this.check()) {
        if (TalentBankChange.seItem.checkState == 1) {
            Feng.error("申报正在审核中");
            return;
        }
        if (TalentBankChange.seItem.checkState == 3) {
            Feng.error("审核通过，无法修改");
            return;
        }
        var index = layer.open({
            type: 2,
            title: '银行账号变更详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/enterprise/talent_bank_change/apply/id/' + TalentBankChange.seItem.id,
            btn: ['<i class="fa fa-eye"></i>&nbsp;&nbsp;保存未提交', '<i class="fa fa-check 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.TalentBankChangeInfoDlg.addSubmit();
            }, btn2: function (index, layero) {
                var obj = layero.find("iframe")[0].contentWindow;
                obj.TalentBankChangeInfoDlg.editSubmit(2);
                return false;
            },
            success: function (layero, index) {
                layer.tips('添加基本信息并上传附件后点击', '.layui-layer-btn1', {tips: [1, "#78BA32"], time: 0, closeBtn: 2});
            },
            end: function () {
                layer.closeAll('tips');
            }
        });
        TalentBankChange.layerIndex = index;
        layer.full(index);
    }
};

/**
 * 打开查看银行账号变更详情
 */
TalentBankChange.openTalentBankChangeSelect = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '银行账号变更详情',
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/enterprise/talent_bank_change/view/id/' + TalentBankChange.seItem.id,
        });
        TalentBankChange.layerIndex = index;
        layer.full(index);
    }
};

/**
 * 删除银行账号变更
 */
TalentBankChange.delete = function () {
    if (this.check()) {
        if (TalentBankChange.seItem.checkState != -1) {
            Feng.error("已提交审核，无法删除");
            return;
        }
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/enterprise/talent_bank_change/delete", function (data) {
                Feng.success("删除成功!");
                TalentBankChange.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", TalentBankChange.seItem.id);
            ajax.start();
        }
        Feng.confirm("删除后无法恢复，确认删除吗?", operation);
    }
};

/**
 * 查询表单提交参数对象
 * @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();
    return queryData;
}

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

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

/**
 * 显示审核日志
 */
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, "/enterprise/talent_bank_change/list", defaultColunms);
    table.setPaginationType("server");
    TalentBankChange.table = table.init();
});
