{extend name="public/container"}
{block name="content"}
<div class="row">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-title">
                <button type="button" class="btn btn-w-m btn-primary" onclick="$eb.createModalFrame(this.innerText,'{:Url('create')}')">添加模板消息</button>
                <button type="button" class="layui-btn  btn btn-w-m btn-primary" onclick="syncTemplate()">一键同步</button>
                <div class="ibox-tools">

                </div>
            </div>
            <div class="ibox-content">
                <div class="row">
                    <div class="m-b m-l">
                        <form action="" class="form-inline">
                            <select name="status" aria-controls="editable" class="form-control input-sm">
                                <option value="">是否有效</option>
                                <option value="1" {eq name="where.status" value="1"}selected="selected"{/eq}>开启</option>
                                <option value="0" {eq name="where.status" value="0"}selected="selected"{/eq}>关闭</option>
                            </select>
                            <div class="input-group">
                                <input type="text" name="name" value="{$where.name}" placeholder="请输入模板名" class="input-sm form-control"> <span class="input-group-btn">
                                    <button type="submit" class="btn btn-sm btn-primary"> <i class="fa fa-search" ></i>搜索</button> </span>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="table-responsive">
                    <table class="table table-striped  table-bordered">
                        <thead>
                        <tr>
                            <th class="text-center">编号</th>
                            <th class="text-center">模板编号</th>
                            <th class="text-center">模板ID</th>
                            <th class="text-center">模板名</th>
                            <th class="text-center">回复内容</th>
                            <th class="text-center">状态</th>
                            <th class="text-center">添加时间</th>
                            <th class="text-center">操作</th>
                        </tr>
                        </thead>
                        <tbody class="">
                        {volist name="list" id="vo"}
                        <tr>
                            <td class="text-center">
                                {$vo.id}
                            </td>
                            <td class="text-center">
                                {$vo.tempkey}
                            </td>
                            <td class="text-center">
                                {$vo.tempid}
                            </td>
                            <td class="text-center">
                                {$vo.name}
                            </td>
                            <td class="text-center">
                                <pre>{$vo.content}</pre>
                            </td>
                            <td class="text-center">
                                <i class="fa {eq name='vo.status' value='1'}fa-check text-navy{else/}fa-close text-danger{/eq}"></i>
                            </td>
                            <td class="text-center">
                                {$vo.add_time|date='Y-m-d H:i:s'}
                            </td>
                            <td class="text-center">
                                <button class="btn btn-info btn-xs" type="button"  onclick="$eb.createModalFrame('编辑','{:Url('edit',array('id'=>$vo['id']))}',{h:400})"><i class="fa fa-edit"></i>编辑</button>
                                <button class="btn btn-danger btn-xs" data-url="{:Url('delete',array('id'=>$vo['id']))}" type="button"><i class="fa fa-times"></i> 删除
                                </button>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                {include file="public/inner_page"}
            </div>
        </div>
    </div>
</div>
{/block}
<script src="{__ADMIN_PATH}js/layuiList.js"></script>
{block name="script"}
<script>
    $('.btn-danger').on('click',function(){
        window.t = $(this);
        var _this = $(this),url =_this.data('url');
        $eb.$swal('delete',function(){
            $eb.axios.get(url).then(function(res){
                console.log(res);
                if(res.status == 200 && res.data.code == 200) {
                    $eb.$swal('success',res.data.msg);
                    _this.parents('tr').remove();
                }else
                    return Promise.reject(res.data.msg || '删除失败')
            }).catch(function(err){
                $eb.$swal('error',err);
            });
        });
    });
    function syncTemplate(){
        // var url = layList.U({c: 'routine.routine_template', a: 'syncSubscribe'});
        var url = "{:Url('routine.routine_template/syncSubscribe')}";
        // var url = "{__ADMIN_PATH}js/layuiList.js";
        console.log(url);
        $eb.axios.get(url).then(function (res) {
            if (res.status == 200 && res.data.code == 200) {
                $eb.$swal('success', res.data.msg);
            } else
                return Promise.reject(res.data.msg || '同步失败')
        }).catch(function (err) {
            $eb.$swal('error', err);
        });
    }
    // require(['vue'], function (Vue) {
    //     new Vue({
    //         el: "#app",
    //         data:{},
    //         methods: {
    //             syncTemplate: function() {
    //                 console.log(layList.Url({c: 'routine.routine_template', a: 'syncSubscribe'}));
    //                 // layList.baseGet(layList.Url({c: 'routine.routine_template', a: 'syncSubscribe'}), function (rem) {
    //                 //     if(res.status == 200) {
    //                 //         $eb.$swal('success',res.data.msg);
    //                 //     }else
    //                 //         return Promise.reject(res.data.msg || '同步失败')
    //                 // });
    //             }
    //         },
    //         mounted: function () {}
    //     })
    // });
</script>
{/block}
