<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ 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: 80%; margin-top: 20px">
    <input name="id" value="${entity.id}" hidden/>

    <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="number" value="${entity.number}" lay-verify="required" 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">
                <%--<select name="rate" class="layui-input">
                    <c:forEach begin="0.21" end="0.38" var="item">
                        <option value="${item}"
                                <c:if test="${entity.rate.equest(item)}">
                                    selected
                                </c:if>
                        >${item}</option>
                    </c:forEach>
                </select>--%>
                <input name="rate" value="${entity.rate}" lay-verify="required" 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">
                <select name="type" lay-verify="required" lay-filter="selectAct"  class="layui-select">
                    <option value="">请选择</option>
                    <c:forEach items="${typeList}" var="item">
                        <option value="${item.value}" ${entity.type eq item.value ? 'selected' : ''}>${item.name}</option>
                    </c:forEach>
                </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="actId" id="actId" lay-verify="required" class="layui-select">
                    <option value="">请选择</option>
                    <c:if test="${ not empty actList}">
                        <c:forEach items="${actList}" var="act">
                            <option value="${act.id}" ${entity.actId eq act.id ? 'selected' : ''}>${act.officName}</option>
                        </c:forEach>
                    </c:if>
                </select>
            </div>
        </div>
    </div>

    <%--<div class="layui-form-item">
        <span class="dlblock w100 textr">开始日期</span>
        <span class="bdc pt6 pb6 pl6 pr5 w180 dlblock" style="margin-left: 6px">
            <input type="text" placeholder="" name="startTime" autocomplete="off" id="startTime" class="w150"
                   value="${entity.startTimeStr}"/>
            <i class="fa fa-calendar"></i>
        </span>
    </div>

    <div class="layui-form-item">
        <span class="dlblock w100 textr">结束日期</span>
        <span class="bdc pt6 pb6 pl6 pr5 w180 dlblock" style="margin-left: 6px">
            <input type="text" placeholder="" name="endTime" autocomplete="off" id="endTime" class="w150"
                   value="${entity.endTimeStr}"/>
            <i class="fa fa-calendar"></i>
        </span>
    </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', 'laydate'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        $('#close').click(function () {
            parent.layer.closeAll();
        });
        laydate.render({
            elem: '#startTime', //指定元素
            format:'yyyy-MM-dd'
        });
        laydate.render({
            elem: '#endTime', //指定元素
            format:'yyyy-MM-dd'
        });
        form.on('select(selectAct)',function (data) {
            let value = data.value;
            let dom = $("#actId");
            if(!value){
                dom.empty();
                return;
            }
            $.ajax({
                url: '${ctx}/inviteRate/getActType/'+value,
                method: 'get',
                dataType: 'JSON',
                contentType: "application/json",
                success: function (res) {
                    if(res.code == 200){
                        dom.empty();
                        let html = "<option value=''>请选择</option>";
                        let dataList = res.data;
                        if(dataList.length > 0){
                            $.each(dataList,function (k,v) {
                                html+= "<option value='"+v.id+"'>"+v.officName+"</option>";
                            })
                            dom.append(html);
                            form.render('select');
                        }
                    }
                }
            })
            return false;
        })
        //监听提交
        form.on('submit(formDemo)', function (data) {
            var index = layer.load(1, {shade: [0.1, '#000']});
            $.ajax({
                url: '${ctx}/inviteRate/save',
                method: 'post',
                data: JSON.stringify(data.field),
                dataType: 'JSON',
                contentType: "application/json",
                success: function (res) {
                    layer.close(index);
                    if (res.code == 200) {
                        layer.alert(res.message, function () {
                            parent.location.reload();
                        })
                    } else {
                        layer.msg(res.message, {
                            icon: 5
                        });
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>