<?php


use backend\assets\AppAsset;

?>
<style>
    body {
        padding: 15px;
    }

    .layui-elem-quote {
        margin-bottom: 0;
        border-left: none;
        padding: 10px;
    }

    .layui-table-page .layui-laypage {
        float: right;
        margin-right: 1%;
    }

    .layui-table-view .layui-form-switch {
        right: 0px
    }

</style>

<form action="" class="layui-form">
    <fieldset class="layui-elem-field">
        <legend>搜索信息</legend>
        <div class="layui-field-box">
            <blockquote class="quoteBox demoTable">
                <div class="layui-inline">
                    <span>楼盘:</span>
                    <div class="layui-input-inline">
                        <input type="text" name="input_house_text" class="layui-input searchVal"
                               placeholder="请输入需要搜索的楼盘"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn search_btn" data-type="reload"><i class="layui-icon layui-icon-search"></i>搜索</a>
                </div>
                <input type="hidden" name="typeid" value="<?php echo $type ?>">

            </blockquote>
        </div>
    </fieldset>
</form>
<blockquote class="layui-elem-quote quoteBox demoTable">
    <div class="layui-btn-group demoTable">
        <a class="layui-btn" data-type="addData">新增</a>
    </div>
</blockquote>
<table id="videolist" lay-filter="videolist"></table>


<script type="text/html" id="operate">

    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 排序 -->
<script type="text/html" id="sortBox">
    {{#  if(d.sort){ }}
    <div style="border:1px solid #E6E6E6;height:27px;line-height:27px;box-shadow:1px 1px 1px 1px rgba(224, 224, 224, 0.76);">
        {{ d.sort }}
    </div>
    {{#  } }}
</script>

<script>
    window.onload = function(){
        layui.use(['laypage', 'layer', 'table', 'element', 'form', 'upload'], function () {

            var laypage = layui.laypage //分页
                , $ = layui.jquery
                , layer = layui.layer //弹层
                , table = layui.table //表格
                , element = layui.element //元素操作
                , form = layui.form
                , upload = layui.upload;


            var tableIds = 'videolist';  //表格ID
            var type_id = $('input[name="typeid"]').val();
            //第一个实例
            table.render({
                elem: '#' + tableIds
                , url: '/push/hothouseform' //数据接口
                , where: {token: csrfToken, type: type_id}
                , method: 'post'
                , page: true //开启分页
                , text: '数据加载中'
                , id: 'tablerReload'
                , cols: [[ //表头
                    {type: 'numbers', title: '序号', width: 50},
                    {field: 'name', title: '楼盘名称', align: 'center'},
                    {
                        field: 'sort',
                        title: '排序',
                        width: 100,
                        event: 'sortData',
                        edit: 'text',
                        align: 'center',
                        sort: true,
                        templet: "#sortBox"
                    },
                    {field: 'create_at', title: '添加时间', width: 150, align: 'center'},
                    {
                        field: 'state', title: '审核', align: 'center', width: 100, templet: function (d) {
                            if (d.state == 2) {
                                return '<input type="checkbox"  value="' + d.id + '" name="open"  lay-skin="switch" lay-filter="switchTest" lay-text="|">'
                            } else {
                                return '<input type="checkbox" checked  value="' + d.id + '" name="open"  lay-skin="switch" lay-filter="switchTest" lay-text="|">'
                            }
                        }
                    }
                    , {fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#operate'}

                ]]
            });

            //监听指定开关
            form.on('switch(switchTest)', function (data) {
                layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
                    $.post('/push/hothousedelshow', {id: data.value, type: 'show'}, function (data) {
                        layer.msg(data.msg);
                        table.reload('tablerReload');
                    })
                }, function (aa) {
                    table.reload('tablerReload');        //重新加载
                })
            });


            //列表操作
            table.on('tool(' + tableIds + ')', function (obj) {
                var layEvent = obj.event,
                    data = obj.data;
                if (layEvent === 'sortData') {       //修改排序
                    table.on('edit(' + tableIds + ')', function (obj) {
                        var data = obj.data;
                        // console.log(data)
                        $.post('/push/hothousedelshow', {
                            id: data.id,
                            type: 'sort',
                            sort: data.sort
                        }, function (data) {
                            if (data.code == 200) {
                                layer.msg(data.msg);
                            } else if (data.code == 300) {
                                layer.msg(data.msg);
                            }
                        })
                    })

                }
                if (layEvent === 'del') {
                    layer.confirm('您确定要删除吗?', {btn: ['确定', '取消']}, function () {
                        $.post('/push/hothousedelshow', {id: data.id, type: 'del'}, function (data) {
                            layer.msg(data.msg);
                            table.reload('tablerReload');
                        })
                    })
                }

            });

            // 新增
            var $ = layui.$, active = {
                addData: function () { //获取选中数据
                    var index = layui.layer.open({
                        type: 2,
                        title: '添加楼盘',
                        closeBtn: 1, //不显示关闭按钮
                        area: ['600px', '300px'],
                        content: '/pushm/hothouseadd?type=' + type_id
                        , success: function (layero, index) {
                            // indexOpen = layer.getChildFrame('body', index)  ;
                            // console.log(indexOpen);
                        },
                        end: function () {
                            table.reload('tablerReload');
                        }
                    });
                },
                reload: function () {
                    var form = pfgs_serialize($('form'));

                    table.reload('tablerReload', {
                        where: {
                            name: form.input_house_text
                        }
                    })
                }
            };
            $('.demoTable .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });


        })
    }
    
    
</script>