<!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/bootstrap-fileinput.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" method="get">

                                <div class="col-xs-2">
                                    <input type="text" class="form-control required" name="title" placeholder="标题">
                                </div>

                                <div class="col-xs-2">
                                    <input type="text" class="form-control required" name="keywords" placeholder="关键字">
                                </div>

                                <div class="col-xs-2">
                                    <select id="status" name="status"
                                            class="form-control"
                                            data-placeholder="请选择活动状态">
                                        <option value="">全部</option>
                                        <option value="0">未开始</option>
                                        <option value="1">进行中</option>
                                        <option value="2">已结束</option>
                                    </select>
                                </div>

                                <div class="col-xs-5">
                                    <a  class="btn btn-primary search">搜索</a>
                                    #if($shiro.hasPermission("activity:eggs:edit"))
                                    <a href="#springUrl('/a/activity/eggs/form')" class="btn btn-primary">新增</a>
                                    #end
                                </div>
                            </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 class='piccenter'>活动开始图片</th>-->
                                    <th>活动结束title</th>
                                    <th>活动结束说明</th>
                                    <!--<th class='piccenter'>活动结束图片</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 -->
<script src="plugins/bootstrap-fileinput/bootstrap-fileinput.js"></script>
<script src="plugins/bootstrap-fileinput/fileinput.min.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;
    }

    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/dc/product-activity/golden-egg.html?appid="+"$!{appid}"+"&id="+id+"</p>",
            btntext: "确定",
            success: function () {

            }
        });
    }

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

            $("#seachTableForm input,select").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": "title"
                },
//                {
//                    "mData": "keywords"
//                },
                {
                    "mData": "explain"
                },
                {
                    "mData": "wintips"
                },
                {
                    "mData": "startTime"
                },
                {
                    "mData": "endTime"
                },
                {
                    "mData": "drawAgainReply"
                },
               /* {
                    "mData": "actStartPic"
                },*/
                {
                    "mData": "endTitle"
                },
                {
                    "mData": "endExplain"
                },
               /* {
                    "mData": "actEndPic"
                },*/
                {
                    "mData":"status"
                },
                {
                    "mData": "id"
                }],
            "aoColumnDefs": [
                { // set default column settings
                    'visible': false,
                    'targets': [0]
                },

                {
                    "aTargets": [1],
                    "mData": "title",
                    "mRender": function (a, b, c, d) {
                        return '<a href="#springUrl("/a/activity/eggs/form?id=' + c.id + '")" data-id="' + c.id + '" data-action="view">' + a + '</a>';

                    }
                },


                {
                    "aTargets": [4],
                    "mData": "startTime",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        return formatDates(a, "yyyy-MM-dd");
                    }
                },

                {
                    "aTargets": [5],
                    "mData": "endTime",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        return formatDates(a, "yyyy-MM-dd");
                    }
                },
               /* {
                    "aTargets": [8],
                    "mData": "actStartPic",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        return "<img width='80' height='80' class='piccenter' src='"+a.replace(",",'')+"'>";
                    }
                }
                ,
                {
                    "aTargets": [11],
                    "mData": "actEndPic",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        return "<img width='80' height='80' class='piccenter' src='"+a.replace(",",'')+"'>";
                    }
                },*/



                {
                    "aTargets": [8],
                    "mData": "endExplain",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                       return a;
                    }
                },{
                    "aTargets": [9],
                    "mData": "status",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        if(a==0){//未开始
                            return "<font color='orange'>未开始</font>";
                        }else if(a==1){//进行中
                            return "<font color='green'>进行中</font>";
                        }else{//已结束
                            return "<font color='red'>已结束</font>";
                        }
                    }
                },
                {
                    "aTargets": [10],
                    "mData": "id",
                    "mRender": function (a, b, c, d) {//a表示id对应的值，c表示当前记录行对象
                        var startHtml="";
                        if(c.status==0){
                            startHtml+="<a href='javascript:start("+a+")'>开始</a>";
                        }else if(c.status==1){
                            startHtml+="<a href='javascript:end("+a+")'>结束</a>";
                        }else{

                        }
                        var html = '#if($shiro.hasPermission("activity:eggs:edit"))';
                        if(c.status==0){
                            html += '<a href="#springUrl("/a/activity/eggs/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>';
                       /* html +='<a href="javascript:void(0);" onclick="urlView(' + a + ')" class="btn red">链接地址</a>';*/
                        html += '#end';
                        return startHtml+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();
        });
    });

    function start(id){//开始活动
        var formJson = {};
        formJson.id = id;
        formJson.status = "1";
        formJson._csrf_header=csrfheader.value;
        formJson._csrf=csrftoken.value;
        Cfapp.confirm({
            message: "确定要开始活动吗",
            btnoktext: "确定",
            btncanceltext: "取消",
            success: function () {
                $.post("#springUrl('/a/activity/eggs/startAndEnd')", formJson, function (returnobj, status) {
                    if (returnobj.errorNo == 0) {  //修改成功
                        Cfapp.alert({
                            message: "活动开始成功",
                            btntext: "确定",
                            success: function () {
                                location.href = "#springUrl('/a/activity/eggs/list')";
                            }
                        });
                    } else {
                        Cfapp.alert({
                            message: "创建失败",
                            btntext: "确定",
                            success: function () {

                            }
                        });
                    }
                });
            },
            cancel: function () {
                $(".modal-backdrop").fadeOut();
            }
        });
    }

    function end(id){//结束活动
        var formJson = {};
        formJson.id = id;
        formJson.status = "2";
        formJson._csrf_header=csrfheader.value;
        formJson._csrf=csrftoken.value;
        Cfapp.confirm({
            message: "确定要结束活动吗",
            btnoktext: "确定",
            btncanceltext: "取消",
            success: function () {
                $.post("#springUrl('/a/activity/eggs/startAndEnd')", formJson, function (returnobj, status) {
                    if (returnobj.errorNo == 0) {  //修改成功
                        Cfapp.alert({
                            message: "活动结束成功",
                            btntext: "确定",
                            success: function () {
                                location.href = "#springUrl('/a/activity/eggs/list')";
                            }
                        });
                    } else {
                        Cfapp.alert({
                            message: "创建失败",
                            btntext: "确定",
                            success: function () {
                                location.href = "#springUrl('/a/activity/eggs/list')";
                            }
                        });
                    }
                });
            },
            cancel: function () {
                $(".modal-backdrop").fadeOut();
            }
        });
    }

    Cfapp.init();
    function removeData(data) {
        Cfapp.confirm({
            message: "确定要删除吗",
            btnoktext: "确定",
            btncanceltext: "取消",
            success: function () {
                $.ajax({
                    type: "POST",
                    url: "#springUrl('/a/activity/eggs/delete')",
                    data: {id: data,_csrf_header:csrfheader.value,_csrf:csrftoken.value},
                    dataType: "json",
                    success: function (data) {
                        if (data.errorNo == 0) {
                            Cfapp.alert({
                                message: "删除成功",
                                btntext: "确定",
                                success: function () {
                                    location.href = "#springUrl('/a/activity/eggs/list')";
                                }
                            });
                        }
                    },
                    error: function () {
                    }
                })
            },
            cancel: function () {
                $(".modal-backdrop").fadeOut();
            }
        });
    }


</script>

</body>
</html>
