<!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-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-inline">
            <input type="hidden" name="id" value="0"/>
            <input type="hidden" name="type" value=""/>
            <input type="text" name="goodsName" lay-verify="required" maxlength="32" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权重</label>
        <div class="layui-input-inline">
            <input type="text" name="probability" lay-verify="required|probability" autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">中奖</label>
        <div class="layui-input-inline">
            <input type="checkbox" lay-verify="required" name="isPrize" lay-skin="switch" lay-text="是|否">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-inline">
            <img id="cover" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKoAAACqCAYAAAA9dtSCAAAAAXNSR0IArs4c6QAACpdJREFUeF7tnc9rHOcZx9/RquCLtau7oTJEtIeC9L6v7vHSQAytsUJb2psccmghBcvQu517wQ400B6K7UOhpS1WcEsbSFnnrplXgl4CASt/QbS6NMHyPtUzzDu83kiL8D7vat+Zrw5Bm3fmmef9PB/Pj0ezM5k648c59/5oNHqQZdkiL2KMycJFi6L4SinVC/7fijHmS/+5KAqnlFoPxq8ZYz7zn51zT4ho03/OsmxTa/1xMP6QiG4F49ta6w+D8btEdM9/JqIH1to7wfgWET0Kxneste8E4zeJaCfI79lJfv1gfJ2IeA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Ef+ej/NHR0R9ZUv585sUUT2I0Gv2WW1e8IERVEDWiqNyCUkptW2s/Cv9x+9//D4bLpi9FMaJMAAAAAElFTkSuQmCC" style="cursor: pointer;max-width:60px;max-height: 60px;"/>
            <input type="text" name="cover" lay-verify="required" lay-reqtext="请上传图片" autocomplete="off" class="layui-input layui-hide"/>
        </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 loadIndex;
        upload.render({
            elem: "#cover",
            url: '/upload-image',
            field: "image",
            data: {
                _token: "{{ csrf_token() }}",
            },
            choose: (obj) => {
                loadIndex =  layer.load(0, {time: 10*1000});

            },
            done: function (res) {
                layer.close(loadIndex);
                if (res.code === 0) {
                    $('#cover').attr('src', res.data.path);
                    form.val('form', {
                        cover: res.data.path
                    });

                } 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});
                }
            }
        });

        form.verify({
            probability: function (value, elem) {
                let test = /^(0|[1-9]\d*)$/;
                if (!test.test(value)) return '请输入正确的数值';
                if (value > 1000) return '最大1000';
            }
        });


        form.on('submit(layuiadmin-app-form-submit)', function (obj) {
            let data = obj.field;
            $.ajax({
                url: "{{ route('goods.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>