<!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">
    <style>
        .ws-word {
            position: absolute;
            right: 20px;
            bottom: 5px;
            color: #aaa;
            font-size: 12px;
        }
    </style>
</head>
<body>


<div class="layui-form" lay-filter="form" id="form" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <input type="hidden" name="id" value="0"/>
            <select name="type" lay-verify="required" lay-reqtext="请选择类型">
                <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-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block" style="margin-bottom: 10px;">
            <textarea lay-reqtext="请输入内容" placeholder="请输入签支内容" id="textarea" rows='8' maxlength="500" type="text" name="text" style="resize: none;" lay-verify="required" autocomplete="off" class="layui-textarea"></textarea>
            <div class="ws-word">
                <span id="numCount" class="text_count ainfo">0</span>&nbsp;/&nbsp;
                <span class="num_count">500</span>
            </div>
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index', 'form', 'table', 'layer', 'upload'], function () {
        const $ = layui.$, form = layui.form, table = layui.table, layer = layui.layer, upload = layui.upload;
        let textArea = $('#textarea');
        textArea.on('input', textLen);
        textLen();

        function textLen() {
            $('#numCount').text(textArea.val().length);
        }


        form.on('submit(layuiadmin-app-form-submit)', function (obj) {
            let data = obj.field;
            $.ajax({
                url: "{{ route('divination.setData') }}",
                method: 'post',
                headers: {'X-CSRF-TOKEN': "{{ csrf_token() }}"},
                data,
                success: res => {
                    if (res.code === 0) {
                        parent.layer.close(parent.layer.index);
                    } else if (res.code === 101009) {
                        let msg = "";
                        Object.keys(res.data).forEach(key => res.data[key].forEach(m => msg += m));
                        layer.alert(msg, {title: res.msg});
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                }
            });
        });
    });

</script>
</body>
</html>