<!DOCTYPE html>
<!--[if IE 8]>
<html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html>
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <base href="#springUrl('/assets/adminlte/')"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工作台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="plugins/ionicons/css/ionicons.min.css">

    <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">

    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <link rel="stylesheet"
          href="plugins\bootstrap-fileinput\fileinput.min.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body class="hold-transition skin-blue sidebar-mini">


<div class="wrapper">
    <div class="content-wrapper" style="margin-left:0;">
        <div id="importExcelDiv"></div>

        <section class="content-header">
            <h1>
                展会管理
                <small>展会信息</small>
            </h1>
            <ol class="breadcrumb">
                <li><a><i class="fa fa-dashboard"></i>首页</a></li>
                <li><a class="active">展会管理列表</a></li>
            </ol>
        </section>


        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <form id="seachTableForm" action="#springUrl('/a/exhibi/list')" method="get">

                                    <div class="col-xs-2">
                                        <input type="text" class="form-control "
                                               name="exhibi_title" placeholder="展会标题">
                                    </div>
                                    <div class="col-xs-2">
                                        <input type="text" class="form-control "
                                               name="exhibi_number" placeholder="展会号">

                                    </div>

                                    <a href="javascript:void (0)" class="btn btn-primary search">搜索</a>
                                    #if($shiro.hasPermission("qy.exhibi.edit"))
                                    <a href="#springUrl('/a/exhibi/form')" class="btn btn-primary">新增</a>
                                    #end

                            </form>
                        </div><!-- /.box-header -->
                        <div class="box-body">
                            <table id="table" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <td hidden="true">Id</td>
                                    <th>展会标题</th>
                                    <th>展会号</th>
                                    <th>展会描述</th>
                                    <th>展会类型</th>
                                    <th>阅读量</th>
                                    <th>创建时间</th>
                                    <th>是否发布</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="tablebody">
                                </tbody>

                            </table>
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->


    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div><!-- ./wrapper -->
<!-- jQuery 2.1.4 -->
<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/extensions/i18n/lanauage_ch.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<!-- FastClick -->
<script src="plugins/fastclick/fastclick.min.js"></script>
<!--fileinput js-->
<script src="plugins\bootstrap-fileinput\fileinput.js"></script>
<script src="plugins/bootstrap-fileinput/zh.js"></script>
<script src="plugins/bootstrap-fileinput/zh2.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js"></script>
<script type="text/javascript"
        src="plugins/jquery-validation/js/jquery.validate.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script>
    var csrfheader = {name:'_csrf_header',value:'${_csrf.headerName}'};
    var csrftoken  = {name:'_csrf',value:'${_csrf.token}'};
</script>
<script src="common/js/cfapp.js"></script>

<script>
    function formatDates(now) {
        var now = new Date(now);
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var date = now.getDate();
        var hour = now.getHours();
        var minute = now.getMinutes();
        var second = now.getSeconds();
        return year + "-" + month + "-" + date + "   " + hour + ":"
                + minute + ":" + second;
    }


    function seachTable() {
        var sSource = "#springUrl('/a/exhibi/listData')";
        var aoData = {
            iDisplayStart: 1,
            iDosplayLength: 10
        }
        var retrieveData = function (sSource, aoData, fnCallback) {

            $("#seachTableForm input").each(function () {
                var params = {
                    name: $(this).attr("name"),
                    value: $(this).val()
                };
                aoData.push(params);
            })

            $.ajax({
                "type": "GET",
                "url": sSource,
                "dataType": "json",
                "data": aoData, //以json格式传递
                "success": fnCallback
            });
        };

        $('#table').DataTable({
            "lengthChange": false,
            "searching": false,
            "ordering": false,
            "bFiltered": false,
            "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": sSource,
            "fnServerData": retrieveData,
            "pagingType": "full_numbers",
            "aoColumns": [
                {
                    "mData": "id"
                },
                {
                    "mData": "exhibi_title"
                },

                {
                    "mData": "exhibi_number"
                },

                {
                    "mData": "exhibi_describe"
                },
                {
                    "mData": "exhibi_type"
                },
                {
                    "mData":"reading"
                },
                {
                    "mData": "createTime"
                },
                {
                    "mData":"releas"
                },
                {
                    "mData": "id"
                }],
            "aoColumnDefs": [
                { // set default column settings
                    'visible': false,
                    'targets': [0]
                },

                {
                    "aTargets": [4],
                    "mData": "exhibi_type",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                       if(a=='0'){
                           return "汽车展会";
                       }else{
                           return "工业展会";
                       }
                    }
                },
               {
                    "aTargets":[5],
                    "mData":"reading",
                    "mRender":function(a, b, c, d){
                        var href = "#springUrl('/a/exhibi_read/list')";
                        href+="?id="+c.id;//+"&moduleType=0";
                        return "<a href='"+href+"'>"+a+"</a>"
                    }
                },
               /*{
                    "aTargets":[6],
                    "mData":"reviews",
                    "mRender":function(a, b, c, d){
                        var href = "#springUrl('/a/review/list')";
                        href+="?id="+c.id+"&moduleType=0";
                        return '<a  href='+href+' class="btn green">'+a+'</a>';
                    }
                },
                {
                    "aTargets":[7],
                    "mData":"selects",
                    "mRender":function(a, b, c, d){
                        var href = "#springUrl('/a/collection/list')";
                        href+="?id="+c.id+"&moduleType=0";
                        return '<a  href='+href+' class="btn green">'+a+'</a>';
                    }
                },*/
                {
                    "aTargets":[6],
                    "mData": "createTime",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        return formatDates(a, "yyyy-MM-dd HH:mm:ss");
                    }

                },
                {
                    "aTargets":[7],
                    "mData":"releas",
                    "mRender":function(a,b,c,d){
                        if(a=='0'){
                            return '<a href="javascript:void (0)" onclick="release('+a+','+c.id+')" class="btn btn-primary search">已发布</a>'
                        }else{
                            return '<a href="javascript:void (0))" onclick="norelease('+a+','+c.id+')" class="btn btn-primary search">未发布</a>';
                        }
                    }
                },
                {
                    "aTargets": [8],
                    "mData": "id",
                    "mRender": function (a, b, c, d) {//a表示id对应的值，c表示当前记录行对象
                        var html = '#if($shiro.hasPermission("qy.exhibi.edit"))';//
                        html += '<a href="#springUrl("/a/exhibi/form?id=' + a + '")" data-id="' + a + '" data-action="view" class="btn green">修改</a>';
                        html += '<a href="javascript:void(0);" data-id="' + a + '" data-action="remove" onclick="removeData(' + a + ')" class="btn red">删除</a>';
                        var url = '#springUrl("/a/exhibi_sample/list?exhibi_id=")'+a;
                        html += '<a href="'+url+'" data-id="' + a + '" data-action="view" class="btn green">展品信息</a>';
                        html +='<a href="#springUrl("/a/exhibi_vocation/list?exhibi_id='+a+'")"  class="btn red">人员所属行业</a>';
                        html += '<a href="#springUrl("/a/exhibi_inquiries/list?exhibi_id='+a+'")" class="btn red">相关问询</a>';
                        html += '<a href="#springUrl("/a/exhibi_material/list?exhibi_id='+a+'")" class="btn red">样本资料</a>';
                        /*html += '<a href="#springUrl("/a/email_record/list?exhibi_id='+a+'")" class="btn red">邮箱发送记录</a>';*/
                        html +='<a href="javascript:void(0);" onclick="urlView(' + a + ')" class="btn red">链接地址</a>';
                        html += '<a href="#springUrl("/a/exhibi/downloadcode?id=' + a + '")" class="btn red">下载二维码</a>';
                        html += '#end';
                        return html;
                    }
                }

            ]
        });
    }

    jQuery(document).ready(function () {
        seachTable();
        $('.datepicker').datepicker({
            show: true,
            format: 'yyyy-mm-dd',
            autoclose: true,
            language: 'zh-CN',
            todayBtn: 'linked',
            clearBtn: 'linked'

        });
        $('.search').click(function () {
            $("#table").dataTable().fnClearTable();
        });
    });

    Cfapp.init();
    function removeData(data) {
        Cfapp.confirm({
            message: "确定要删除吗",
            btnoktext: "确定",
            btncanceltext: "取消",
            success: function () {
               // alert(data);
                $.ajax({
                    type: "POST",
                    url: "#springUrl('/a/exhibi/delete')",
                    data: {id: data,_csrfheader:csrfheader.value,_csrf:csrftoken.value},
                    dataType: "json",
                    success: function (data) {
                        if (data.errorNo == 0) {
                            Cfapp.alert({
                                message: "删除成功",
                                btntext: "确定",
                                success: function () {
                                    location.href = "#springUrl('/a/exhibi/list')";
                                }
                            });
                        }
                    },
                    error: function () {
                    }
                })
            },
            cancel: function () {
                $(".modal-backdrop").fadeOut();
            }
        });
    }
    //未发布
    function norelease(releas,id){
       Cfapp.confirm({
           message:"确定要发布吗",
           btnoktext:"确定",
           btncanceltext: "取消",
           success:function(){
               $.ajax({
                   type: "POST",
                   url: "#springUrl('/a/exhibi/updaterelease')",
                   data: {releas: releas,id:id,_csrfheader:csrfheader.value,_csrf:csrftoken.value},
                   dataType: "json",
                   success: function (data) {
                       if (data.errorNo == 0) {
                           Cfapp.alert({
                               message: "发布成功",
                               btntext: "确定",
                               success: function () {
                                   location.href = "#springUrl('/a/exhibi/list')";
                               }
                           });
                       }else if(data.errorNo == 2){
                           Cfapp.alert({
                               message:"同一类型下仅可发布一场展会",
                               btntext:"确定",
                               success:function(){
                                   //location.href = "#springUrl('/a/exhibi/list')";
                                   return;
                               }
                           })
                       }
                   },
                   error: function () {
                   }
               })
           },
           cancel:function(){
               return;
           }
       })
    }
    //已发布
    function release(releas,id){
        Cfapp.confirm({
            message:"取消发布",
            btnoktext:"确定",
            btncanceltext: "取消",
            success:function(){
                $.ajax({
                    type: "POST",
                    url: "#springUrl('/a/exhibi/updaterelease')",
                    data: {releas: releas,id:id,_csrfheader:csrfheader.value,_csrf:csrftoken.value},
                    dataType: "json",
                    success: function (data) {
                        if (data.errorNo == 0) {
                            Cfapp.alert({
                                message: "取消发布成功",
                                btntext: "确定",
                                success: function () {
                                    location.href = "#springUrl('/a/exhibi/list')";
                                }
                            });
                        }
                    },
                    error: function () {
                    }
                })
            },
            cancel:function(){
                return;
            }
        })
    }
    function urlView(id){
        var pathName=window.document.location.pathname;
        var domain ="http://"+window.location.host;
        var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);//项目名称  例:/dcwechat
        Cfapp.alert({
            message: "链接地址:<br/><p style='border: #cccccc 1px solid;padding:5px;border-radius: 5px;'>"+domain+projectName+"/static/mp/schaeffler/exhibition.html?appid="+"$!{appid}"+"&id="+id+"</p>",
            btntext: "确定",
            success: function () {

            }
        });
    }
</script>

</body>
</html>
