<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 网站用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">签支类型</label>
                    <div class="layui-input-block">
                        <select name="type" lay-filter="type">
                            <option value="0">全部</option>
                            <option value="1">上上签</option>
                            <option value="2">中上签</option>
                            <option value="3">中中签</option>
                            <option value="4">中下签</option>
                            <option value="5">下下签</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div class="layui-hide" style="padding-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
            </div>
            <table id="LAY-user-manage" lay-filter="LAY-user-manage"></table>
        </div>
    </div>
</div>

@verbatim

    <script type="text/html" id="type">
        {{# if (d.type === 1) { }}
        <span>上上签</span>
        {{# } else if (d.type === 2) { }}
        <span>中上签</span>
        {{# } else if (d.type === 3) { }}
        <span>中中签</span>
        {{# } else if (d.type === 4) { }}
        <span>中下签</span>
        {{# } else { }}
        <span>下下签</span>
        {{# } }}
    </script>

    <script type="text/html" id="cover">
        <img src="{{ d.cover}}" style="max-height: 100%;max-width: 100%;cursor: pointer;" lay-event="cover"/>
        <span>{{d.goods_name}}</span>
    </script>

    <script type="text/html" id="toolbar">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs layui-bg-orange" lay-event="del">删除</a>
    </script>


    <script type="text/html" id="status">
        <input lay-event="status" type="checkbox" name="status" value="{{ d.id }}" title="上架|下架" lay-skin="switch" lay-filter="status" {{ d.status == 1 ? "checked" : "" }}>
    </script>

    <script type="text/html" id="head-toolbar">
        <div class="layui-table-tool-temp">
            <div class="layui-inline" lay-event="add"><i class="layui-icon layui-icon-add-1"></i></div>
        </div>
    </script>

@endverbatim
<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'form', 'table', 'layer'], function () {
        const $ = layui.$, form = layui.form, table = layui.table, layer = layui.layer;
        form.on('select(type)', function (data) {
            tableList.reloadData({
                where: {type: data.value}
            });
        });
        var active = {
            add() {
                layer.open({
                    type: 2,
                    title: '添加签支',
                    content: "{{ route('divination.edit') }}",
                    resize: false,
                    area: ['500px', '400px'],
                    btn: ['确定', '取消'],
                    success(layero, index, that) {
                        let iframe = layero.find('iframe')[0];
                        let iframeWindow = iframe.contentWindow;
                        iframeWindow.layui.form.val('form', {
                            type: tableList.config.where.type,
                        });
                    },
                    end() {
                        tableList.reloadData();
                    },
                    yes: function (index, layero) {
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
            }
        };

        table.on('toolbar(LAY-user-manage)', function (obj) {
            let type = obj.event;
            active[type] ? active[type].call(this) : '';
        });
        let tableList = table.render({
            elem: '#LAY-user-manage',
            url: "{{url('divination/getList')}}",
            // toolbar: true,
            toolbar: '#head-toolbar',
            defaultToolbar: [],
            cols: [[
                {field: 'type', title: '类型', templet: "#type", align: "center", width: 106},
                {field: 'text', title: '内容'},
                {title: '操作', width: 140, align: "center", toolbar: '#toolbar'}
            ]],
            page: true,
            limit: 50,
            limits: [50, 100, 200, 300],
            where: {lang: 'zh-CN', type: 0},
            height: 'full-130',
            text: {none: '无数据'},
            parseData(res) {
                return {
                    code: res.data.code,
                    msg: res.data.msg,
                    count: res.data.count,
                    data: res.data.data
                };
            }
        });

        table.on('tool(LAY-user-manage)', function (obj) {
            switch (obj.event) {
                case "del":
                    layer.alert('删除？', function (index) {
                        $.ajax({
                            url: "{{ route('divination.del') }}",
                            method: 'post',
                            data: {id: obj.data.id},
                            headers: {'X-CSRF-TOKEN': "{{ csrf_token() }}"},
                            success(res) {
                                if (res.code === 0) {
                                    layer.close(index);
                                    tableList.reloadData();
                                } else {
                                    layer.msg(res.msg);
                                }
                            }
                        });
                    });
                    break;
                case "edit":
                    layer.open({
                        type: 2,
                        title: '编辑签支',
                        content: "{{ route('divination.edit') }}",
                        resize: false,
                        area: ['500px', '400px'],
                        btn: ['确定', '取消'],
                        success(layero, index, that) {
                            let iframe = layero.find('iframe')[0];
                            layero.find('iframe').contents().find("#cover").attr('src', obj.data.cover);
                            let iframeWindow = iframe.contentWindow;
                            iframeWindow.layui.form.val('form', {
                                type: obj.data.type,
                                id: obj.data.id,
                                text: obj.data.text,
                            });
                        },
                        end() {
                            tableList.reloadData();
                        },
                        yes: function (index, layero) {
                            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                            submit.click();
                        }
                    });
                    break;
            }

            // console.log(this.src);
            // console.log(obj)
        });
        form.on('submit(LAY-user-front-search)', function (data) {
            let where = data.field;
            tableList.reloadData({where});
        });
    });
</script>
</body>
</html>
