var EpChange = {
    id: "table",	                                                                //表格id
    seItem: null,		                                                            //选中的条目
    table: null,
    layerIndex: -1
};

EpChange.initColumn = function(){
    var type = $("#type").val();
    var isShow = true;
    if(type==2){
        isShow = false;
    };
	return [
		{field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '<span style="color: red">原单位名称</span>', field: 'oldName', align: 'center', width:200, valign: 'middle', 'class': 'uitd_showTip',

        },
        // {title: '原统一社会信用代码', field: 'oldIdCard', align: 'center', width:160, valign: 'middle', 'class': 'uitd_showTip'},
        // {title: '原法人代表', field: 'oldLegal', align: 'center', width:120, valign: 'middle', 'class': 'uitd_showTip'},
        {title: '原所属街道', field: 'oldStreetName', align: 'center', width:120, valign: 'middle', 'class': 'uitd_showTip'},
        {title: '原单位标签', field: 'oldEnterpriseTagName',visible: isShow, align: 'center', width:170, valign: 'middle', 'class': 'uitd_showTip'},
        {title: '原产业领域', field: 'oldIndustryFieldNewName',visible: isShow, align: 'center', width:170, valign: 'middle', 'class': 'uitd_showTip'},
        // {title: '原单位地址', field: 'oldAddress', align: 'center', width:200, valign: 'middle', 'class': 'uitd_showTip'},
        {title: '<span style="color: red">新单位名称</span>', field: 'newName', align: 'center', width:200, valign: 'middle', 'class': 'uitd_showTip'},
        // {title: '新统一社会信用代码', field: 'newIdCard', align: 'center', width:160, valign: 'middle', 'class': 'uitd_showTip'},
        // {title: '新法人代表', field: 'newLegal', align: 'center', width:120, valign: 'middle', 'class': 'uitd_showTip'},
        {title: '新所属街道', field: 'newStreetName', align: 'center', width:120, valign: 'middle', 'class': 'uitd_showTip'},
        {title: '新单位标签', field: 'newEnterpriseTagName',visible: isShow, align: 'center', width:170, valign: 'middle', 'class': 'uitd_showTip'},
        {title: '新产业领域', field: 'newIndustryFieldNewName',visible: isShow, align: 'center', width:170, valign: 'middle', 'class': 'uitd_showTip'},
        // {title: '新单位地址', field: 'newAddress', align: 'center', width:200, valign: 'middle', 'class': 'uitd_showTip'},
        {title: '申请时间', field: 'createTime', align: 'center', width:150, valign: 'middle', 'class': 'uitd_showTip'},
        {title: '操作', field: 'id', visible: true, align: 'center', valign: 'middle',width:100,
            formatter : function (value,row,index){
                return "<span class='label label-success' onclick=\"EpChange.showLog('"+value+"')\" >" +
                    "<i class=\"fa fa-book\"></i>日志" +
                    "</span>";
            }
        },
        {title: '审核状态', field: 'checkState', align: 'center', width:120, valign: 'middle', 'class': 'uitd_showTip',
            formatter: function (value, row, index){
                if (value==null || value==''){
                    return "";
                } else if (value == 1){
                    return "保存未提交";
                } else if (value == 2){
                    return "待审核";
                } else if (value == 3){
                    return "审核驳回";
                } else if (value == 4) {
                    return "审核通过";
                } else if (value == 5) {
                    return "重新提交";
                } else {
                    return "";
                }
            },
            cellStyle: function(value, row, index) {
                if (value==null || value==''){
                    return {css:{}};
                } else if (value == 1){
                    return {css:{}};
                } else if (value == 2){
                    return {css:{"background-color":"LightGrey"}};
                } else if (value == 3){
                    return {css:{"background-color":"Orange"}};
                } else if (value == 4) {
                    return {css:{'background-color':'LightGreen'}};
                } else if (value == 5) {
                    return {css:{'background-color':'LightGrey'}};
                } else {
                    return {css:{}};
                }
            }
        },
	];
};

EpChange.search = function() {
	var queryData = {};
	queryData['oldName'] = $("#oldName").val();
	queryData['oldIdCard'] = $("#oldIdCard").val();
	queryData['oldLegal'] = $("#oldLegal").val();
    queryData['oldStreet'] = $("#oldStreet").val();
    queryData['oldEnterpriseTag'] = $("#oldEnterpriseTag").val();
    queryData['oldIndustryFieldNew'] = $("#oldIndustryFieldNew").val();
	queryData['newName'] = $("#newName").val();
	queryData['newIdCard'] = $("#newIdCard").val();
    queryData['newAgentName'] = $("#newAgentName").val();
    queryData['newStreet'] = $("#newStreet").val();
    queryData['newEnterpriseTag'] = $("#newEnterpriseTag").val();
    queryData['newIndustryFieldNew'] = $("#newIndustryFieldNew").val();
    queryData['checkState'] = $("#checkState").val();

	EpChange.table.refresh({"query": queryData});	
};

EpChange.reset = function() {
    $("#oldName").val("");
    $("#oldIdCard").val("");
    $("#oldLegal").val("");
    $("#oldStreet").val("");
    $("#oldEnterpriseTag").val("");
    $("#oldIndustryFieldNew").val("");
    $("#newName").val("");
    $("#newIdCard").val("");
    $("#newAgentName").val("");
    $("#newStreet").val("");
    $("#newEnterpriseTag").val("");
    $("#newIndustryFieldNew").val("");
    $("#checkState").val("");
};

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

EpChange.gotoEnterpriseChangeDetailPage = function() {
	if (!EpChange.check()) {
		return;
	}
    var index = layer.open({
        type: 2,
        title: '查看详情',
        area: ['830px', '450px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/admin/enterpriseChangeRecord/gotoEnterpriseChangeDetailPage?id='+EpChange.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.ecre.doExamine();
        }
    });
    layer.full(index);
    EpChange.layerIndex = index;
};



EpChange.export = function(){
    var queryData = {};
    queryData['oldName'] = $("#oldName").val();
    queryData['oldIdCard'] = $("#oldIdCard").val();
    queryData['oldLegal'] = $("#oldLegal").val();
    queryData['oldStreet'] = $("#oldStreet").val();
    queryData['oldTalentType'] = $("#oldTalentType").val();
    queryData['oldIndustryField'] = $("#oldIndustryField").val();
    queryData['newName'] = $("#newName").val();
    queryData['newIdCard'] = $("#newIdCard").val();
    queryData['newAgentName'] = $("#newAgentName").val();
    queryData['newStreet'] = $("#newStreet").val();
    queryData['newTalentType'] = $("#newTalentType").val();
    queryData['newIndustryField'] = $("#newIndustryField").val();
    queryData['checkState'] = $("#checkState").val();
    window.location.href = Feng.setUrlParam(Feng.ctxPath + "/admin/enterpriseChangeRecordExport/export", queryData);
}

EpChange.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":10,"mainId":id,"typeFileId":"","active":1})
        }
    });
}



$(function () {	
    var defaultColunms = EpChange.initColumn();
    var table = new BSTable(EpChange.id, "/admin/enterpriseChangeRecord/findEnterpriseChangeRecordByPage", defaultColunms);
    table.setPaginationType("server");
    EpChange.table = table.init();
});