<link href="<?php echo base_url();?>public/h5/css/bootstrap.min14ed.css" rel="stylesheet">
<link href="<?php echo base_url();?>public/h5/css/font-awesome.min93e3.css" rel="stylesheet">
<link href="<?php echo base_url();?>public/h5/css/plugins/jqgrid/ui.jqgridffe4.css?0820" rel="stylesheet">
<link href="<?php echo base_url();?>public/h5/css/animate.min.css" rel="stylesheet">
<link href="<?php echo base_url();?>public/h5/css/style.min862f.css" rel="stylesheet">
<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
<link rel="stylesheet" href="<?php echo base_url();?>public/css/jquery.timepicker.min.css">
<style>
    #alertmod_activity_list {
        top: 900px !important;
        display: none;
    }
    #alertmod_schedule_list {
        top: 900px !important;
        display: none;
    }
    html{
        height: 3000px;
    }
</style>

<div class="container-fluid" style="background-color: #f3f3f4;">
    <div class="row">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>运营后台/活动配置</h5>
            </div>
<!--            <div class="ibox-content">-->
<!--                <h3 style="font-weight: bold">活动配置</h3>-->
<!--            </div>-->
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="tabs-container">
                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">活动排期列表</a></li>
                    <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">其他配置</a></li>
                    <li class=""><a href="/#activity/reward/" target="_blank">奖励页面</a></li>
                </ul>
                <div class="tab-content">
                    <div id="tab-1" class="tab-pane active">
                        <div class="panel-body">
                            <div class="ibox-title" style="border-style: none" >
                                <?php if(!empty($importActs) && is_array($importActs)){ ?>
                                    <?php foreach ($importActs as $k => $importAct){ ?>

                                        <span class="btn btn-success fileinput-button importFileSpanBtn" data-fileid="upfilepro<?=$k?>" data-href="<?=$importAct['href']?>" style="position: relative;margin-bottom: 3px">
                                            <span><?=$importAct['title']?></span>
                                            <input type="file" id="upfilepro<?=$k?>" style="position: absolute;right: 0px;top: 0px;left: 0px;bottom: 0px;opacity: 0;">
                                        </span>

                                    <?php }?>
                                <?php }?>
                            </div>
                            <div class="ibox-title" style="border-style: none">
                                <a type="button" class="btn btn-outline btn-success"  href="#activity/hadd/">新建排期</a>
                                <button  class="btn btn-outline btn-info exportJson" onclick="$('#exportJsonFile').click()"  href="###">导入JSON</button>
                                <form id="exportJsonForm" action="/activity/importJson" method="post" enctype="multipart/form-data">
                                    <input type="file" name="file" id="exportJsonFile" style="display: none">
                                </form>
                                <div class="ibox-tools">
                                    <div class="btn-group" style="width:1200px">
                                        <form action="#activity/h5" method="post" enctype="multipart/form-data">
                                            <label class="col-sm-1 control-label" style="height:34px;text-align: center;line-height: 34px">分类：</label>
                                            <div class="col-sm-3">
                                                <select class="form-control m-b select2" name="type" id="select_type">
                                                    <option value="all">所有</option>
                                                    <?php if(!empty($act_type)) foreach ($act_type as $k => $v) { ?>
                                                        <option value="<?php echo $k?>" <?php if($selType&&$k == $selType) echo 'selected';?>><?php echo $v['tips']?></option>
                                                    <?php }?>
                                                </select>
                                            </div>
                                            <label class="col-sm-1 control-label" style="height:34px;text-align: center;line-height: 34px">道具：</label>
                                            <div class="col-sm-1">
                                                <select class="form-control m-b" name="uc_type" id="uc_type">
                                                    <option value="0">否</option>
                                                    <option value="1" <?php if($uc_type&&1 == $uc_type) echo 'selected';?>>是</option>
                                                </select>
                                            </div>
                                            <input type="hidden" name="status" value="<?=$s_status?>" id="s_status">
                                            <button class="btn  s_status <?php if($s_status==1) echo "btn-primary";?>" type="button" value="1">全部</button>
                                            <button class="btn  s_status <?php if($s_status==2) echo "btn-primary";?>" type="button" value="2" >已上线</button>
                                            <button class="btn  s_status <?php if($s_status==3) echo "btn-primary";?>" type="button" value="3" >排期中</button>
                                            <button class="btn  s_status <?php if($s_status==4) echo "btn-primary";?>" type="button" value="4" >已下线</button>
                                            <input type="text" class="btn btn-white layer-date" id="times" placeholder=" 时间选择 " name="sn_time">
                                            <button class="btn btn-success" type="submit">搜索</button>
                                        </form>
                                    </div>
                                </div>

                            </div>
                            <div class="ibox float-e-margins">
                                <div class="ibox-content" id="firstTable" style="padding: 0;">
                                    <div class="jqGrid_wrapper">
                                        <table id="activity_list"></table>
                                        <div id="activity_pager_list"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div id="tab-2" class="tab-pane">
                        <div class="panel-body">
<!--                            <div class="col-sm-12">-->
<!--                                <button type="button" class="btn btn-outline btn-success" data-toggle="modal" data-target="#myModal5">新建排期</button>-->
<!--                            </div>-->
                            <div class="ibox float-e-margins">
                                <div class="ibox-title" style="border-top: 0;">
                                    <h3 style="font-weight: bold">收集活动限时设置</h3>
                                </div>
                                <div class="ibox-content" style="padding: 0;">
                                    <form method="post" class="form-horizontal" id="tsCollectFrom" enctype="multipart/form-data" action="#">
                                        <input type="hidden" name="type" value="collect">
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">开启时间：</label>
                                            <div class="col-sm-3 input-group">
                                                <input type="text" class="form-control" id="times2" placeholder="yyyy-mm-dd hh:ii:ss" name="ts_collect_sn_time" value="<?php echo date("Y-m-d H:i:s",$collect_cfg['ts_collect_stime']);?>">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">开启时长:</label>
                                            <div class="col-sm-3 input-group">
                                                <input type="text" placeholder="" name="ts_collect_time" value="<?php echo $collect_cfg['ts_collect_time'];?>" class="form-control"><span class="input-group-addon">分钟</span>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">当前状态:</label>
                                            <div class="col-sm-4 input-group">
                                                <label class="checkbox-inline">
                                                    <input type="radio" name="ts_collect_status" <?php if($collect_cfg['ts_collect_status']==0) echo "checked";?> value="0">关闭
                                                </label>
                                                <label class="checkbox-inline">
                                                    <input type="radio" name="ts_collect_status" <?php if($collect_cfg['ts_collect_status']==1) echo "checked";?> value="1">开启
                                                </label>
                                            </div>
                                        </div>
                                        <button class="btn btn-primary" id="submitBtn_collect_ts" type="button">保存内容</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script src="<?php echo base_url();?>public/h5/js/jquery.min.js"></script>
<script src="<?php echo base_url();?>public/h5/js/bootstrap.min.js"></script>
<script src="<?php echo base_url();?>public/h5/js/plugins/peity/jquery.peity.min.js"></script>
<script src="<?php echo base_url();?>public/h5/js/plugins/jqgrid/i18n/grid.locale-cnffe4.js?0820"></script>
<script src="<?php echo base_url();?>public/h5/js/plugins/jqgrid/jquery.jqGrid.minffe4.js?0820"></script>
<script src="<?php echo base_url();?>public/h5/js/content.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/timepicker/timepicker.min.js"></script>


<!--select2-->
<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/select2/select2.min.css">
<script src="<?php echo base_url();?>public/js/vendor/select2/select2.full.min.js"></script>
<script>
    $(document).ready(function(){
        $('#content').css("padding","0");
        $('#page_footer').css("position","fixed");
        // $('#left_panel').css("position","fixed");
        $.jgrid.defaults.styleUI = "Bootstrap";
        var mydata = <? echo $mydata;?>;
        $("#activity_list").jqGrid({
            data: mydata,
            datatype: "local",
            height: 'auto',
            autoheight: true,
            autowidth: true,
            shrinkToFit: true,
            rowNum: 20,
            rowList: [20, 30, 50],
            colNames: ["活动ID", "活动名称","活动分类", "活动类型&优先级","状态","群体区分", "开始时间", "结束时间", "操作"],
            colModel: [{
                name: "id",
                index: "id",
                editable: true,
                width: 30,
                sorttype: "int",
                search: true,
                align: "center"
            }, {
                name: "name",
                index: "name",
                editable: true,
                width: 60,
                align: "center",
            }, {
                name: "type",
                index: "type",
                editable: true,
                width: 50,
                align: "center",
            }, {
                name: "priority",
                index: "priority",
                editable: true,
                width: 80,
                align: "center",
            }, {
                name: "status",
                index: "status",
                editable: true,
                width: 50,
                align: "center",
            }, {
                name: "userGroup",
                index: "userGroup",
                editable: true,
                width: 120,
                align: "center",
            },{
                name: "lastUpdateTime",
                index: "lastUpdateTime",
                editable: true,
                width: 80,
                align: "center",
                sorttype: "date",
                formatter: function (cellValue, options, rowObject) {
                    return cellValue;
                }
            },{
                name: "lastEndTime",
                index: "lastEndTime",
                editable: true,
                width: 80,
                align: "center",
                sorttype: "date",
                formatter: function (cellValue, options, rowObject) {
                    return cellValue;
                }
            },{
                name: "action",
                index: "action",
                editable: true,
                width: 200,
                align: "center",
                sortable: false
            }],
            pager: "#activity_pager_list",
            viewrecords: true,
            caption: "",
            add: true,
            edit: true,
            addtext: "Add",
            edittext: "Edit",
            hidegrid: false
        });
        // $("#activity_list").jqGrid("navGrid", "#activity_pager_list", {
        //     edit: false,
        //     add: false,
        //     del: false,
        //     search: true
        // }, {
        //     height: 200,
        //     reloadAfterSubmit: true
        // });
        //
        // $("#schedule_list").jqGrid("navGrid", "#schedule_pager_list", {
        //     edit: false,
        //     add: false,
        //     del: false,
        //     search: true
        // }, {
        //     height: 200,
        //     reloadAfterSubmit: true
        // });
    });

    // $('.stime,.etime,.rtime').datepicker({
    //     language:'zh-CN',
    //     format:'yyyy-mm-dd',
    //     zIndexOffset:906  //控制z-index
    // });
    //选择时间段
    // $('.datetimepicker').timepicker({
    //     timeFormat:'HH:mm'
    // });

    function online(id,is_online) {
        // console.log(id,is_online);
        $.ajax({
            url: rootPath + 'activity/onlineOrNo',
            type: 'POST',
            data: {id:id,is_online:is_online},
            dataType:'json',
            success: function (data) {
                alert(data.msg);
                window.location.reload();
            },
            error: function (data) {
                alert(data.msg);
            }
        });
    }
    function confirmMsg(id,msg) {
        var msg = msg+"\n\n您真的确定要删除吗？\n\n请确认！";
        if (confirm(msg)==true){
            del(id);
        }else{
            return false;
        }
    }

    function del(id) {
        $.ajax({
            url: rootPath + 'activity/hdel',
            type: 'POST',
            data: {id:id},
            dataType:'json',
            success: function (data) {
                alert(data.msg);
                window.location.reload();
            },
            error: function (data) {
                alert(data.msg);
            }
        });
    }
    $('#submitBtn_collect_ts').click(function () {
        var datas = $('#tsCollectFrom').serializeArray();
        console.log(datas);
        $.ajax({
            url: rootPath + 'activity/hExitCommonCfg',
            type: 'POST',
            data: datas,
            dataType:'json',
            success: function (data) {
                alert(data.msg);
                console.log(data);
                // window.location.reload();
            },
            error: function (data) {
                alert(data.msg);
                console.log(data);
            }
        });
    });
</script>
<script>
    $(".importFileSpanBtn").on("change", "input[type='file']", function() {
        var _this = $(this)
        var filePath = _this.val();
        var fileId = _this.parents('span').data('fileid')
        var href = _this.parents('span').data('href')
        // console.log(_this.parents('span').data())
        if (filePath) {
            var formData = new FormData();
            formData.append("file",document.getElementById(fileId).files[0]);
            showLoading()
            $.ajax({
                type: "POST", // 数据提交类型
                url: href,//"activity/importSerialPack", // 发送地址
                data: formData, //发送数据
                async: true, // 是否异步
                processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
                contentType: false, //
                success: function(data) { // 成功回调
                    hideLoading()
                    _this.val('');
                    if(typeof data == 'string')data = JSON.parse(data);
                    console.log(data)
                    alert(data.msg)
                    if(data.ret == 0){
                        window.location.reload();
                    }
                },
                error:function(e,x,h){
                    hideLoading()
                    _this.val('');
                    alert(h)
                }
            });
        } else {
            return false
        }
    });

    $("#exportJsonFile").on("change", function() {
        var _this = $(this)
        var filePath = _this.val();
        var fileId = _this.parents('span').data('fileid')
        var href = _this.parents('span').data('href')
        console.log(filePath)
        if (filePath) {
            $('#exportJsonForm').submit()
        } else {
            return false
        }
    });
</script>
<script>
    var status =1;
    laydate.render({
        elem: '#times'
        ,type: 'datetime'
        ,range: true //或 range: '~' 来自定义分割字符
        // ,format: 'yyyy-MM-dd HH:mm'
    });
    laydate.render({
        elem: '#times2'
        ,type: 'datetime'
        // , range: true
        // ,done:function(value, date, endDate){
        //     console.log(date);
        //     console.log(endDate);
        // }
        // ,format: 'yyyy-MM-dd HH:mm'
    });
    //选类型
    $('.s_status').click(function(){
        $(this).siblings().removeClass('btn-primary');
        $(this).toggleClass('btn-primary');
        if($(this).hasClass('btn-primary')){
            status = $(this).val();
        }else{
            status = 1;
        }
        $("#s_status").val(status);
        console.log($("#s_status").val());
        ;console.log($('#times').val());
    });
    $('#subSearch').click(function () {
        sn_time = $('#times').val();
        console.log(status,sn_time);
        // $.ajax({
        //     url: rootPath + 'activity/h5',
        //     type: 'POST',
        //     data: {status:status,sn_time:sn_time},
        //     dataType:'json',
        //     success: function (data) {
        //         alert(data.msg);
        //         window.location.reload();
        //     },
        //     error: function (data) {
        //         alert(data.msg);
        //     }
        // });
    });

    $('.select2').select2({})
</script>