/**
 * 合同信息变更管理初始化
 */
var TalentHetongChange = {
    id: "TalentHetongChangeTable", //表格id
    seItem: null, //选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
TalentHetongChange.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '姓名', field: 'name', visible: true, align: 'center', valign: 'middle', width: "100px", 'class': 'uitd_showTip'},
        {title: '证件号码', field: 'card_number', visible: true, align: 'center', valign: 'middle', width: "150px", 'class': 'uitd_showTip'},
        {title: '劳动合同时间', field: 'labor_contract_rangetime', 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=\"TalentHetongChange.openAddTalentHetongChange('" + value + "')\" >" +
                    "<i class=\"fa fa-book\"></i>更新合同" +
                    "</span>";
            }
        }
    ];
};

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

/**
 * 点击添加人才基础信息变更
 */
TalentHetongChange.openAddTalentHetongChange = function (id=0) {
    var index = layer.open({
        type: 2,
        title: '添加人才基础信息变更',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/enterprise/talent_basic_change/apply?talent_id='+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.TalentBasicChangeInfoDlg.addSubmit();
        }, btn2: function (index, layero) {
            var obj = layero.find("iframe")[0].contentWindow;
            obj.TalentBasicChangeInfoDlg.submitToCheck();
            return false;
        },
        success: function (layero, index) {
            layer.tips('添加基本信息并上传附件后点击', '.layui-layer-btn1', {tips: [1, "#78BA32"], time: 0, closeBtn: 2});
        },
        end: function () {
            layer.closeAll('tips');
        }
    });
    TalentHetongChange.layerIndex = index;
    layer.full(index);
};

/**
 * 显示导出模态框
 */
TalentHetongChange.export = function () {
    var operation = function () {

        var url = "/enterprise/talent_basic_change/htEndExport";

        window.location.href = url;
    };
    Feng.confirm("确定要导出数据吗？", operation);
}

/**
 * 打开查看人才基础信息变更详情
 */
TalentHetongChange.openTalentHetongChangeDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '人才基础信息变更详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/enterprise/talent_basic_change/apply/id/' + TalentHetongChange.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.TalentHetongChangeInfoDlg.addSubmit();
            }, btn2: function (index, layero) {
                var obj = layero.find("iframe")[0].contentWindow;
                obj.TalentHetongChangeInfoDlg.submitToCheck();
                return false;
            },
            success: function (layero, index) {
                layer.tips('添加基本信息并上传附件后点击', '.layui-layer-btn1', {tips: [1, "#78BA32"], time: 0, closeBtn: 2});
            },
            end: function () {
                layer.closeAll('tips');
            }
        });
        TalentHetongChange.layerIndex = index;
        layer.full(index);
    }
};

TalentHetongChange.openTalentHetongChangeSelect = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '人才基础信息变更详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/enterprise/talent_basic_change/view/id/' + TalentHetongChange.seItem.id
        });
        TalentHetongChange.layerIndex = index;
        layer.full(index);
    }
}

/**
 * 删除人才基础信息变更
 */
TalentHetongChange.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/enterprise/talent_basic_change/delete", function (data) {
            Feng.success("删除成功!");
            TalentHetongChange.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("id", this.seItem.id);
        ajax.start();
    }
};

TalentHetongChange.formParams = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['card_number'] = $("#idCard").val();
    return queryData;
}

/**
 * 查询人才基础信息变更列表
 */
TalentHetongChange.search = function () {
    TalentHetongChange.table.refresh({query: TalentHetongChange.formParams()});
};

TalentHetongChange.reset = function () {
    $("#name").val("");
    $("#idCard").val("");
}

$(function () {
    var defaultColunms = TalentHetongChange.initColumn();
    var table = new BSTable(TalentHetongChange.id, "/enterprise/talent_basic_change/htEndList", defaultColunms);
    table.setPaginationType("server");
    TalentHetongChange.table = table.init();
    var arr = [
        {"name": "oldCardType", "code": "card_type"},
        {"name": "newCardType", "code": "card_type"}
    ];
    Feng.findChildDictBatch(JSON.stringify(arr));
});
