//查看业务
function viewBusiness(id) {
    enterpriseQuery.listPage = $('#businessList').getGridParam('page');
    $.get('/business/management/findDetail?businessBasicInfoId='+id,function(data){
        $('.yk_rightcontent').empty().html(data)
    });
}

//删除按钮
function deleteEnterprise(id){
	bootbox.confirm({
		title : '删除',
		message : '<div style="text-align:left;font-size:0.12rem">确认删除吗？</div>',
		size : 'small',
		buttons : {
			cancel : {
				label : '取消',
				className:'btn-white btn-info'
			},
			confirm : {
				label : '确定',
				className:'btn-white btn-info colorbtn'
			}
		},
		callback:function(result){
			if (result) {
				enterpriseQuery.listPage = $('#businessList').getGridParam('page');
				$.ajax({
					url:'/customer/deleteCustomer',
					type:'post',
					data:{
						'id':id
					},
					success:function(data){
						if( data.success ){
							if( data.data ){
								new $.zui.Messager('删除成功', {
								    type: 'success'
								}).show();
								//刷新表格(当前页)
								//刷新表格
								$('#businessList').setGridParam({
									mtype:'GET',
									url : '/customer/findList',
									datatype : 'json',
									postData: {
                                        'judge':false,
                                        'condition':enterpriseQuery.searchName
									},
									page: enterpriseQuery.listPage
								});
								$('#businessList').trigger('reloadGrid');
							}else{
								new $.zui.Messager('删除失败', {
								    type: 'danger'
								}).show();
							}
						}else{
							new $.zui.Messager('删除请求失败:'+data.msg, {
							    type: 'danger'
							}).show();
						}
					},
					error:function(status){
						new $.zui.Messager('删除时发生错误:'+status, {
						    type: 'danger'
						}).show();
					}
				})
			}
		}
	})
};

$(function () {
    // 重新加载列表
    function reloadList(){
        $('#businessList').setGridParam({
            mtype:'GET',
            url : '/customer/findList',
            datatype : 'json',
            postData: {
                'judge':false,
                'condition':enterpriseQuery.searchName
            },
            page : 1
        });
        $('#businessList').trigger('reloadGrid');
    };

    $("#searchName").val(enterpriseQuery.searchName);

    // 操作列
    function operateBusiness(cellValue,options,rowObject){
        var btnstr = '';
        if($('#deleteEnterprise').length>0){
            if(rowObject.deleteFlag) {
                btnstr += '<p><span>删除</span><i class="operateIconfont operateIcon-shanchu" onclick="deleteEnterprise(\''+rowObject.id+'\')"></i></p>'; 
            }
        }
        return '<div class="operateIcon noHover">'+btnstr+'</div>';
    };

    sxUtil.jqGrid('#businessList', {
        colNames: ['ID', '序号','企业名称', '创建时间','操作'],
        colModel: [
            {name: 'id', label: 'ID', hidedlg: true, hidden: true, sortable: false, title: false},
            {name: 'orderNumber', label: '序号', sortable: false, width: 50, align: 'center', title: false},
            {name: 'enterpriseName', label: '企业名称', sortable: false,align: 'center', title: false},
            {name: 'gmtCreate', label: '创建时间', sortable: false, align: 'center', title: false},
            {
                name: 'remark',
                label: '操作',
                sortable: false,
                align: 'left',
                width: 140,
                title: false,
                formatter: operateBusiness
            }
        ],
        height: 'auto',
        mtype: 'GET',
        url: '/customer/findList',
        pager: "#businessListPage",
        multiselect: false,
        rownumbers: false,
        postData: {
            'judge':false,
            'condition':enterpriseQuery.searchName
        },
        page: enterpriseQuery.listPage,
        loadError: function () {
            new $.zui.Messager('列表加载失败', {
                type: 'warning'
            }).show();
        }
    }, true);

    //搜索
    $("#searchBusiness").click(function () {
        enterpriseQuery.searchName = $("#searchName").val();
        enterpriseQuery.listPage = 1;
        reloadList();
    })

    //刷新
    $("#refreshBusiness").click(function () {
        enterpriseQuery.searchName = '';
        enterpriseQuery.listPage = 1;
        $("#searchName").val("");
        reloadList();
    })
    //同步
    $("#conformBusiness").click(function () {

        $.ajax({
            url:'/customer/flush',
            type:'get',
            data:{

            },
            success:function(data){
                if(data.success) {
                    new $.zui.Messager('同步成功', {
                        type: 'success'
                    }).show();
                    $("#refreshBusiness").click();
                }

            },
            error:function(status){
                new $.zui.Messager('同步时出错:'+status, {
                    type: 'danger'
                }).show();
            }
        });
    })

    //切换表格
    $(".projectListTab li").click(function () {
        if ($(this).text() == '供应商') {
            $(".yk_rightcontent").load('/customer/listPage');
        } else if ($(this).text() == '核心企业') {
            $(".yk_rightcontent").load('/customer/enterpriseList');
        }else if ($(this).text() == '贸易平台') {
            $(".yk_rightcontent").load('/platform/platformList');
        }else if ($(this).text() == '电子签个人管理') {
            $(".yk_rightcontent").load('/customer/personalList');
        }
    });

    //添加企业
    $("#addBusiness").click(function () {
        $('#enterPriseBusinessDialog').load('/customer/enterpriseAdd',function(){
            $("#myModal-addEnterPriseBusinessEntry").modal("show")
        })
    })


})
