<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="renderer" content="webkit">
    <!-- 移动设备 viewport -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <jsp:include page="../../common.jsp" />
    <style>
        .layui-input,.layui-textarea{
            border-color:#606060;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" style="width: 70%;margin-top: 1rem">
    <input name="id" value="${entity.id}" hidden/>
     <div class="layui-form-item">
        <label class="layui-form-label">用户ID</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block">
                <input name="userId" type="number" value="${entity.userId}" lay-verify="required" autocomplete="off" placeholder="请输入用户ID" class="layui-input"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">积分类型</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block">
                <select name="type" class="layui-select" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="1">交易积分</option>
                    <option value="2">活动积分</option>
                    <option value="3">任务积分</option>
                    <option value="4">签到积分</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">积分来源</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block">
                <select name="source" class="layui-select" lay-verify="required">
                    <option value="">请选择</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>
    <div class="layui-form-item">
        <label class="layui-form-label">积分</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block">
                <input name="integral" type="number" value="${entity.integral}" lay-verify="required|price" autocomplete="off"  placeholder="请输入积分" class="layui-input"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">订单号</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block">
                <input name="orderNumber" value="${entity.orderNumber}" autocomplete="off" placeholder="请输入订单号" class="layui-input"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">订单金额</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block">
                <input type="number" name="orderAmt" value="${entity.orderAmt}" autocomplete="off" placeholder="请输入订单金额" class="layui-input"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="button" id="close" class="layui-btn layui-btn-primary">关闭</button>
        </div>
    </div>
</form>

<script>
    //Demo
    layui.use(['form','layer'], function(){
        var form = layui.form;
        var layer = layui.layer;
        $('#close').click(function() {
            parent.layer.closeAll();
        });

        form.verify({
            price: [
                /((^[1-9]\d*)|^0)(\.\d{1,2}){0,1}$/
                ,'请填入正确的金额'
            ]
        });
            //监听提交
        form.on('submit(formDemo)', function(data){
            var index = layer.load(1,{shade: [0.1,'#000'] });
            $.ajax({
                url: '${ctx}/userIntegral/saveOrUpdate',
                method: 'post',
                data: data.field,
                dataType: 'JSON',
                success: function(res) {
                    layer.close(index);
                    if(res.code == 200) {
                        layer.msg(res.message, { icon: 1, time: 1000 }, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layui.table.reload('userIntegral');
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(res.message, {
                            icon: 2
                        });
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>
