<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<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 type="text" name="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">
                <select name="merchantCode" lay-filter="selectMerchantCode" id="merchantCode">
                    <option value="">请选择</option>
                    <c:forEach items="${merchantBaseInfoList }" var="mb">
                        <option value="${mb.merchantCode }"
                                <c:if test="${userApp.merchantCode eq mb.merchantCode }">selected</c:if> >${mb.merchantName }</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">
                <input type="text" name="loginName" id="loginName" lay-verify="title" autocomplete="off"
                       placeholder="账号后面会自动拼接@shouyin" 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="text" name="userName" id="userName" lay-verify="title" 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="text" name="phone" id="phone" lay-verify="title" 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="password" name="password" id="password" lay-verify="title" autocomplete="off"
                       placeholder="请输入内容" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item has-error">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block" style="margin-left:0px">
            <div class="layui-input-block">
                <input type="password" name="verifyPassword" id="verifyPassword" lay-verify="title"
                       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.on('submit(formDemo)', function (data) {
            var index = layer.load(1, {shade: [0.1, '#000']});
            $.ajax({
                url: '${ctx}/questionsAnswers/saveOrUpdate',
                method: 'post',
                data: JSON.stringify(data.field),
                dataType: 'JSON',
                contentType: "application/json",
                success: function (res) {
                    if (res.code == 200) {
                        layer.alert(res.message, function () {
                            parent.location.reload();
                        })
                    } else {
                        layer.msg(res.message, {
                            icon: 5
                        });
                    }
                }
            })
            return false;
        });

        form.on('select()',function (data) {
            var areaCode = data.value;
            var domId = $(data.elem).attr("data-dom");
            $.ajax({
                url: ctx + '/promoter/getDowntown/' + areaCode,
                method: 'get',
                dataType: 'json',
                success: function (res) {
                    if (res.code == 200) {
                        var dom = $("#" + domId);
                        var html = "<option value=''>请选择</option>";
                        dom.empty();
                        if (res.areaCityList.length > 0) {
                            $.each(res.areaCityList, function (k, v) {
                                html += "<option value='" + v.areaCode + "'>" + v.areaName + "</option>";
                            })
                            dom.append(html);
                        }
                        form.render('select');
                    } else {
                        layer.msg(res.message, {
                            icon: 5
                        });
                    }
                }
            })
        });
    });
</script>
</body>
</html>

