<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" th:href="@{/images/logo.jpg}"/>
    <link rel="stylesheet" th:href="@{/js/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/js/layui/css/admin.css}">
    <script type="text/javascript" th:src="@{/js/jquery-3.3.1.min.js}"></script>
    <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
</head>
<body>

<div class="layui-form" style="padding: 20px 0 0 0;">
    <form id="formId" onsubmit="return false;">
        <div style="float: left">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">积分</label>
                    <div class="layui-input-inline">
                        <input type="number" step="0.01" class="layui-input" name="dincome" id="dincome">
                    </div>
                </div>
            </div>
        </div>

        <input type="hidden" id="userId" name="userId">
        <button class="layui-btn" style="display: none;" id="saveBtn" onclick="save()">保存</button>
    </form>
</div>

<script>


    layui.use('form', function () {
        var form = layui.form;
        form.render();
    });


    $("#formId input").attr("disabled", false);
    var id = '[[${userId}]]';



    function save() {

        var id = '[[${userId}]]';

        var dincome = $("#dincome").val();
        if (dincome == '' || dincome == null || dincome <= 0) {
            layer.msg("积分数额不能为空或小于等于0");
            return false;
        }

        var param = {};
        param.id = id;
        param.dincome = dincome;

        $.ajax({
            url: "addIntegral",
            data: JSON.stringify(param),
            type: "POST",
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            success: function (result) {
                if (result.code == 100) {
                    layer.msg("恭喜您,增加成功", {icon: 6, time: 1000}, function () {
                        closeLayer();
                        parent.layui.table.reload('tableId');
                    });

                } else {
                    layer.msg(result.msg, {icon: 5});
                }
            }
        });
    }


    function closeLayer() {
        var index = parent.layer.getFrameIndex(window.name);
        //关闭当前frame
        parent.layer.close(index);
    }


    function xmTanUploadImg(obj, id) {
        var file = obj.files[0];
        var reader = new FileReader();
        //读取文件过程方法
        reader.onloadstart = function (e) {
            console.log("开始读取....");
        }
        reader.onprogress = function (e) {
            console.log("正在读取中....");
        }
        reader.onabort = function (e) {
            console.log("中断读取....");
        }
        reader.onerror = function (e) {
            console.log("读取异常....");
        }
        reader.onload = function (e) {
            console.log("成功读取....");
            var img = document.getElementById(id + 'img');
            img.src = e.target.result;
        }
        reader.readAsDataURL(file);
    }

    function chioceImage(i) {
        $('#file' + i).trigger("click");
    }


</script>


</body>
</html>