<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/animate.min.css" rel="stylesheet">
<link href="<?php echo base_url();?>public/h5/css/style.min862f.css" rel="stylesheet">
<style>
    .c1{
        color: #8c8c8c;
    }
    .c2{
        color: #c9302c;
    }
    .c3{
        color: #00ff1f;
    }
    .unshow{
        display: none;
    }
</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>
    </div>
    <div class="tab-content">
        <div id="tab-1" class="tab-pane active">
            <div class="panel-body">
                <form method="post" class="form-horizontal" id="emailFrom" enctype="multipart/form-data" action="#">
                    <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:25px 0;">
                            <div class="form-group ">
                                <label class="col-sm-2 control-label m-b">任务名:</label>
                                <div class="col-sm-4">
                                    <input type="text" class="form-control" name="title" value="">
                                </div>
                            </div>

                            <div class="form-group ">
                                <label class="col-sm-2 control-label m-b">邮件类型:</label>
                                <div class="col-sm-4">
                                    <select class="form-control m-b emailcontent" name="mtype" id="selMtype">
                                        <option value="1" <?php if($taskCfg['mtype']==1) echo "selected";?>>常规邮件</option>
                                        <option value="2" >召回邮件</option><?php if($taskCfg['mtype']==2) echo "selected";?>
                                        <option value="3" <?php if($taskCfg['mtype']==3) echo "selected";?>>验证邮箱</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group unshow" id="callDay">
                                <label class="col-sm-2 control-label m-b">召回天数配置(已英文","隔开):</label>
                                <div class="col-sm-2">
                                    <input class="form-control" type="text" name="ext[callDay]" value="">
                                </div>
                            </div>
                            <div class="form-group ">
                                <label class="col-sm-2 control-label m-b">操作类型:</label>
                                <div class="col-sm-4">
                                    <select class="form-control m-b emailcontent selType" name="type">
                                        <option value="1" <?php if($taskCfg['type']==1) echo "selected";?>>立即发送(只支持指定uid)</option>
<!--                                        <option value="2" >定时发送</option>--><?php //if($taskCfg['type']==2) echo "selected";?>
                                        <option value="3" <?php if($taskCfg['type']==3) echo "selected";?>>自动发</option>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group ">
                                <label class="col-sm-2 control-label m-b">用户群:</label>
                                <div class="col-sm-4">
                                    <select class="form-control m-b emailcontent" name="utype">
                                        <option value="1" <?php if($taskCfg['utype']==1) echo "selected";?>>指定uid列表</option>
                                        <option value="2" <?php if($taskCfg['utype']==2) echo "selected";?>>待验证邮箱的用户(用于邮箱验证)(<?php echo $len?>)</option>
                                        <option value="3" >已验证过并领奖邮箱的用户</option><?php if($taskCfg['utype']==3) echo "selected";?>
                                        <option value="4" >所有新版填写邮箱用户</option><?php if($taskCfg['utype']==4) echo "selected";?>
                                        <option value="5" >所有邮箱用户(包括用户表fb回传邮箱)</option><?php if($taskCfg['utype']==5) echo "selected";?>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">指定用户id以","隔开：</label>
                                <div class="col-sm-5">
                                    <input type="text" class="form-control" name="ext[person]" value="">
                                </div>
                            </div>
<!--                            <div class="form-group">-->
<!--                                <label class="col-sm-2 control-label">定时发送：</label>-->
<!--                                <div class="col-sm-5">-->
<!--                                    <input type="text" class="form-control" id="test" placeholder=" 时间选择 " name="send_time" value="--><?php //echo date("Y-m-d H:i:s",$taskCfg['send_time'])?><!--">-->
<!--                                </div>-->
<!--                            </div>-->
                            <div class="form-group ">
                                <label class="col-sm-2 control-label m-b">选择内容：</label>
                                <div class="col-sm-4">
                                    <select class="form-control m-b emailcontent" name="cid">
                                        <?php
                                            foreach ($emailClass as $k=>$v){
                                               echo '<option value="'.$v['id'].'" >'.$v['title'].'</option>';
                                            }
                                        ?>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group ">
                                <label class="col-sm-2 control-label m-b"></label>
                                <div class="col-sm-4">
                                    <button class="btn btn-primary" id="submitBtn" type="button">发布</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
        </div>
    </div>
    <div class="content_wrapper">
        <div class="container-fluid">
            <aside>
                <header><i class="fa fa-fw fa-file"></i>发送记录</header>
                <section>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <table class="table table-striped">
                                    <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>邮件模板</th>
                                        <th>创建时间</th>
                                        <th>发送时间</th>
                                        <th>邮件类型</th>
                                        <th>发送类型</th>
                                        <th>当前状态</th>
                                        <th>召回天数</th>
                                        <th>受众人数</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    foreach($emailLog as $k => $v){
                                        ?>
                                        <tr>
                                            <td><?php echo $v['id']; ?></td>
                                            <td><?php echo $v['title']; ?></td>
                                            <td>
                                                <?php if($v['create_time']) echo "<spin>".date("Y-m-d H:i:s",$v['create_time'])."</spin>"; ?>
                                            </td>
                                            <td>
                                                <?php if($v['send_time']) echo "<spin>".date("Y-m-d H:i:s",$v['send_time'])."</spin>"; ?>
                                            </td>
                                            <td>
                                                <?php if($v['mtype']==1){echo "<spin>常规邮件</spin>";}else if($v['mtype']==2){echo "<spin>召回邮件</spin>";} else if($v['mtype']==3){echo "<spin>验证邮箱</spin>";}?>
                                            </td>
                                            <td>
                                                <?php if($v['type']==1){echo "<spin>立即发送</spin>";}else if($v['type']==2){echo "<spin>定时发送</spin>";} else if($v['type']==3){echo "<spin>自动发</spin>";}?>
                                            </td>
                                            <td>
                                                <?php if($v['status']==0){echo '<spin class="c1">待发送</spin>';}else if($v['status']==1){echo '<spin class="c2">发送中</spin>';}else if($v['status']==2){echo '<spin class="c3">发送完成</spin>';}else if($v['status']==3){echo '<spin class="c3">已关闭</spin>';}  ?>
                                            </td>
                                            <td>
                                                <?php $one =json_decode($v['ext'],true); if(!empty($one)&&!empty($one['callDay'])){echo $one['callDay'];} ?>
                                            </td>
                                            <td>
                                                <?php echo $v['sendNum']; ?>
                                            </td>
                                            <td>
                                                <a type="button" class="btn btn-success" href="/#email/showEmailClass/<?php echo $v['cid']; ?>" >查看</a>
                                                <a type="button" class="btn btn-success" href="/#email/closeEmail/<?php echo $v['id']; ?>" >关闭</a>
                                                <a type="button" class="btn btn-success" href="/#email/sendNew/<?php echo $v['id']; ?>" >立即执行(调试)</a>
                                            </td>
                                        </tr>
                                        <?php
                                    }
                                    ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </section>
            </aside>
        </div>
    </div>
    <div class="content_wrapper">
        <div class="container-fluid">
            <aside>
                <header><i class="fa fa-fw fa-file"></i>邮件模板列表</header>
                <section>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <table class="table table-striped">
                                    <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>邮件模板名</th>
                                        <th>创建时间</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <?php
                                    foreach($emailClass as $k => $v){
                                        ?>
                                        <tr>
                                            <td><?php echo $v['id']; ?></td>
                                            <td><?php echo $v['title']; ?></td>
                                            <td>
                                                <?php if($v['create_time']) echo "<spin>".date("Y-m-d H:i:s",$v['create_time'])."</spin>"; ?>
                                            </td>
                                            <td>
                                                <a type="button" class="btn btn-success" href="/#email/showEmailClass/<?php echo $v['id']; ?>" >编辑</a>
                                                <a type="button" class="btn btn-success" href="/#email/addEmailClass/<?php echo $v['id']; ?>" >复制新建</a>
                                            </td>
                                        </tr>
                                        <?php
                                    }
                                    ?>
                                    <tr>
                                        <td colspan="4">
                                            <a type="button" class="btn btn-success" href="/#email/addEmailClass" >新增</a>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </section>
            </aside>
        </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/content.min.js"></script>
<script>
    var status,title;
    title = $('.emailcontent').find("option:selected").text();
    $("#emailFrom").find('.emtitle').val(title);
    //选类型
    $('.s_status').click(function(){
        $(this).siblings().removeClass('btn-primary');
        $(this).toggleClass('btn-primary');
        if($(this).hasClass('btn-primary')){
            status = $(this).val();
        }else{
            status = 1;
        }
        $("#emailFrom").find('.emtype').val(status);
    });
    $(document).on('change','.emailcontent',function(e){
        title = $(this).find("option:selected").text();
        console.log(title);
        $("#emailFrom").find('.emtitle').val(title);
    });
    laydate.render({
        elem: '#test',
        type: 'datetime',
    });
    $('#submitBtn').click(function (){
        var datas = $('#emailFrom').serializeArray();
        console.log(datas);
        $.ajax({
            url: 'Email/saveEmail',
            type: 'POST',
            data: datas,
            dataType:'json',
            success: function (data) {
                console.log(data);
                alert(data.msg);
                // if(data.code==1){
                    window.location.reload();
                // }
            },
            error: function (data) {
                alert(data.msg);
            }
        });
    });
    $('#selMtype').change(function () {

        mtype =$(this).val();
        if(mtype==2){
            $("#callDay").show();
            $(".selType").val(3);
        }else{
            $("input[name='ext[callDay]']").val("");
            $("#callDay").hide()
        }
    });
</script>