<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <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">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
        .layui-form-select dl{
            max-height:180px;
            width: 80%;
        }

        html{
            background-color: #fff;
        }
    </style>
</head>
<body>
<div class="layui-form">
    <div class="layui-card">
        <div class="layui-card-body over pt-20 pb-40 h-200" style="height: 190px" id="detailSet">
            <div class="layui-col-xs12 mb-20 pr-30">
                <label class="layui-form-label w-130">计算里程默认地址：</label>
                <div class="layui-input-block ml-130">
                    <div class="layui-col-xs4 pr-20">
                        <select class="province" id="province" name="province" lay-verify="province" lay-filter="province" lay-search>
                            <option value="">请选择省</option>
                            <c:forEach items="${province}" var="pro">
                                <option value="${pro.columns.ProvinceName}" title="${pro.columns.ProvinceID}" <c:if test="${siteEditorAddress.columns.province == pro.columns.ProvinceName}">selected</c:if>>${pro.columns.ProvinceName}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="layui-col-xs4 pr-20">
                        <select class="city" name="city" id="city" lay-verify="city" lay-filter="city" lay-search>
                            <option value="">请选择市</option>
                            <c:forEach items="${city}" var="cityList">
                                <option value="${cityList.columns.CityName}" title="${cityList.columns.CityID}" <c:if test="${siteEditorAddress.columns.city==cityList.columns.CityName}">selected</c:if>>${cityList.columns.CityName}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="layui-col-xs4">
                        <select class="area" name="area" id="area" lay-verify="area" lay-filter="area" lay-search>
                            <option value="">请选择县/区</option>
                            <c:forEach items="${area}" var="areaList">
                                <option value="${areaList.columns.DistrictName}" <c:if test="${siteEditorAddress.columns.area==areaList.columns.DistrictName}">selected</c:if>>${areaList.columns.DistrictName}</option>
                            </c:forEach>
                        </select>
                    </div>
                    <div class="layui-col-xs12 mt-20">
                        <input type="text" id="detailAddress" name="address" lay-verify="address" class="layui-input layui-col-lg2"
                               value="${siteEditorAddress.columns.address}">
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide  mb-20">
                <input type="button" lay-submit lay-filter="LAY-user-front-addRess" id="LAY-user-front-addRess" value="确认">
                <input type="hidden" id="id" name="id" value="${siteEditorAddress.columns.id}"/>
            </div>
        </div>
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/data.js"></script>
<script type="text/javascript">
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    layui.use(['form', 'table', 'upload', 'jquery'], function () {
        $ = layui.jquery;
        form = layui.form;
        upload = layui.upload;
        $form = $('form');

        form.verify({
            address:function(value,item){
                if(!$.trim(value)){
                    return "详细地址不能为空,请输入地址后保存！";
                }
            }
        })

        form.on('select(province)', function (data) {
            var province = $(data.elem).find("option:selected").attr("title");
            $("#city").empty();
            $("#detailAddress").val("");
            if (isBlank(province)) {
                $("#city").append("<option value=''>请选择市</option>");
                return "";
            }
            $.ajax({
                type: "POST",
                url: "${ctx}/main/redirect/getCitysByProId",
                data: {
                    province: province
                },
                success: function (result) {
                    if (result == "205") {
                        layer.msg("暂无数据!")
                        return
                    }
                    var html = "";
                    for (var i = 0; i < result.length; i++) {
                        var city = result[i];
                        html = html + '<option value="' + city.columns.CityName + '" title="' + city.columns.CityID + '">' + city.columns.CityName + '</option>';
                    }
                    $("#city").append(html);
                    form.render('select');
                },
                complete: function () {
                    var city = $("#city").find("option:selected").attr("title");
                    $("#area").empty()
                    if (isBlank(city)) {
                        $("#area").append("<option value=''>请选择县/区</option>");
                        return "";
                    }
                    $.ajax({
                        type: "POST",
                        url: "${ctx}/main/redirect/getAreaByCityId",
                        data: {
                            city: city
                        },
                        success: function (result) {
                            if (result == "205") {
                                layer.msg("暂无数据!")
                                return
                            }
                            var html = "";
                            for (var i = 0; i < result.length; i++) {
                                var area = result[i];
                                html = html + '<option value="' + area.columns.DistrictName + '" >' + area.columns.DistrictName + '</option>';
                            }
                            $("#area").append(html);
                            form.render('select');
                        }
                    });
                }

            });

        });

        form.on('select(city)', function (data) {
            var city = $(data.elem).find("option:selected").attr("title");
            $("#area").empty();
            $("#detailAddress").val("");
            if (isBlank(city)) {
                $("#area").append("<option value=''>请选择县/区</option>");
                return "";
            }
            $.ajax({
                type: "POST",
                url: "${ctx}/main/redirect/getAreaByCityId",
                data: {
                    city: city
                },
                success: function (result) {
                    if (result == "205") {
                        layer.msg("暂无数据!")
                        return
                    }
                    var html = "";
                    for (var i = 0; i < result.length; i++) {
                        var area = result[i];
                        html = html + '<option value="' + area.columns.DistrictName + '" >' + area.columns.DistrictName + '</option>';
                    }
                    $("#area").append(html);
                    form.render('select');
                }
            });

        });

        function isBlank(val) {
            if (val == null || val == '' || val == undefined) {
                return true;
            }
            return false;
        }
    })
</script>
</body>
</html>
