代码提交
This commit is contained in:
parent
5a69578af9
commit
ae5c99296a
@ -45,4 +45,9 @@ public class ActivityRouteController extends DefaultBaseController {
|
||||
return new ModelAndView("activity/map-view");
|
||||
}
|
||||
|
||||
@GetMapping("get-select")
|
||||
public ModelAndView getSelect() {
|
||||
return new ModelAndView("activity/get-select");
|
||||
}
|
||||
|
||||
}
|
176
src/main/resources/templates/activity/get-select.html
Normal file
176
src/main/resources/templates/activity/get-select.html
Normal file
@ -0,0 +1,176 @@
|
||||
<!doctype html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<base th:href="${#request.getContextPath() + '/'} ">
|
||||
<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">
|
||||
<link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
|
||||
<link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
|
||||
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
|
||||
<style>
|
||||
.layui-form-selected dl {
|
||||
max-height: 100px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="layui-fluid layui-anim layui-anim-fadein" style="padding: 0;">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body" style="padding: 15px;">
|
||||
<form class="layui-form" lay-filter="dataForm">
|
||||
<div class="layui-row">
|
||||
<div class="layui-col-xs6">
|
||||
<div class="layui-form-item">
|
||||
<div id="area1IdSelectTemplateBox" lay-filter="area1IdSelectTemplateBox"></div>
|
||||
<script id="area1IdSelectTemplate" type="text/html">
|
||||
<select id="area1Id" name="area1Id" lay-filter="area1Id" lay-search>
|
||||
<option value="">1级区域</option>
|
||||
{{# for(var i = 0, item; item = d[i++];) { }}
|
||||
<option value="{{item.areaId}}_{{item.areaCode}}_{{item.areaName}}">
|
||||
{{item.areaName}}
|
||||
</option>
|
||||
{{# } }}
|
||||
</select>
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-col-xs2">
|
||||
<button id="confirmBtn" type="button" class="layui-btn" style="width: 100%;">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-row">
|
||||
<div class="layui-col-xs12">
|
||||
<fieldset class="layui-elem-field layui-field-title">
|
||||
<legend>当前地区</legend>
|
||||
<div class="layui-field-box" id="currentAreaName"></div>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="assets/layuiadmin/layui/layui.js"></script>
|
||||
<script>
|
||||
layui.config({
|
||||
base: 'assets/layuiadmin/' //静态资源所在路径
|
||||
}).extend({
|
||||
index: 'lib/index' //主入口模块
|
||||
}).use(['index', 'form', 'laytpl'], function () {
|
||||
top.dialog.dialogData.selectedAreaArray = [];
|
||||
var $ = layui.$;
|
||||
var form = layui.form;
|
||||
var laytpl = layui.laytpl;
|
||||
var defaultAreaName = top.restAjax.params(window.location.href).areaName;
|
||||
|
||||
var selectedAreaArray = [];
|
||||
|
||||
function closeBox() {
|
||||
top.dialog.dialogData.selectedAreaArray = selectedAreaArray;
|
||||
parent.layer.close(parent.layer.getFrameIndex(window.name));
|
||||
}
|
||||
|
||||
// 显示选择地区
|
||||
function showAreaName() {
|
||||
if (selectedAreaArray.length == 0) {
|
||||
$('#currentAreaName').text(defaultAreaName ? decodeURI(defaultAreaName) : '无');
|
||||
return;
|
||||
}
|
||||
var areaNames = '';
|
||||
for (var i = 0, item; item = selectedAreaArray[i++];) {
|
||||
if (areaNames.length > 0) {
|
||||
areaNames += ' / ';
|
||||
}
|
||||
areaNames += item.areaName;
|
||||
}
|
||||
$('#currentAreaName').text(areaNames);
|
||||
|
||||
}
|
||||
|
||||
// 初始化选择框、单选、复选模板
|
||||
function initSelectRadioCheckboxTemplate(templateId, templateBoxId, data, callback) {
|
||||
laytpl(document.getElementById(templateId).innerHTML).render(data, function (html) {
|
||||
document.getElementById(templateBoxId).innerHTML = html;
|
||||
});
|
||||
form.render('select');
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化1级区域下拉选择
|
||||
function initArea1CodeSelect() {
|
||||
top.restAjax.get(top.restAjax.path('api/area/listbyparentid/110889', []), {}, null, function (code, data, args) {
|
||||
initSelectRadioCheckboxTemplate('area1IdSelectTemplate', 'area1IdSelectTemplateBox', data);
|
||||
}, function (code, data) {
|
||||
top.dialog.msg(data.msg);
|
||||
});
|
||||
}
|
||||
|
||||
// 初始化2级区域下拉选择
|
||||
function initArea2CodeSelect(area1) {
|
||||
alert(area1)
|
||||
if (!area1) {
|
||||
initSelectRadioCheckboxTemplate('area2IdSelectTemplate', 'area2IdSelectTemplateBox', []);
|
||||
return;
|
||||
}
|
||||
top.restAjax.get(top.restAjax.path('api/area/listbyparentid/{area1}', [area1]), {}, null, function (code, data, args) {
|
||||
initSelectRadioCheckboxTemplate('area2IdSelectTemplate', 'area2IdSelectTemplateBox', data);
|
||||
}, function (code, data) {
|
||||
top.dialog.msg(data.msg);
|
||||
});
|
||||
}
|
||||
|
||||
// 初始化
|
||||
function initData() {
|
||||
initArea1CodeSelect();
|
||||
// initArea2CodeSelect();
|
||||
}
|
||||
|
||||
initData();
|
||||
showAreaName();
|
||||
|
||||
// 获取地区ID
|
||||
function getAreaId(areaLevel, data) {
|
||||
var areaId = data.value;
|
||||
var index = areaLevel - 1;
|
||||
if (areaId) {
|
||||
var valueArray = data.value.split('_');
|
||||
areaId = valueArray[0];
|
||||
// 结果存在,替换,不存在新增
|
||||
if (!selectedAreaArray[index]) {
|
||||
selectedAreaArray.push({
|
||||
areaId: valueArray[0],
|
||||
areaCode: valueArray[1],
|
||||
areaName: valueArray[2]
|
||||
});
|
||||
} else {
|
||||
selectedAreaArray.splice(index, 1, {
|
||||
areaId: valueArray[0],
|
||||
areaCode: valueArray[1],
|
||||
areaName: valueArray[2]
|
||||
});
|
||||
}
|
||||
} else {
|
||||
selectedAreaArray.splice(index, selectedAreaArray.length);
|
||||
}
|
||||
showAreaName();
|
||||
return areaId;
|
||||
}
|
||||
|
||||
// area1Id 选择事件
|
||||
form.on('select(area1Id)', function (data) {
|
||||
var areaId = getAreaId(1, data);
|
||||
// initArea2CodeSelect(areaId);
|
||||
});
|
||||
|
||||
$('#confirmBtn').on('click', function () {
|
||||
closeBox();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -646,8 +646,8 @@
|
||||
$('#areaSelectBtn').on('click', function() {
|
||||
top.dialog.open({
|
||||
title: '选择地区',
|
||||
url: top.restAjax.path('route/area/get-select?areaName={areaName}', [encodeURI($('#areaName').val())]),
|
||||
width: '600px',
|
||||
url: top.restAjax.path('route/activity/get-select?areaName={areaName}', [encodeURI($('#areaName').val())]),
|
||||
width: '400px',
|
||||
height: '225px',
|
||||
onClose: function() {
|
||||
var selectedAreaArray = top.dialog.dialogData.selectedAreaArray;
|
||||
|
@ -666,6 +666,39 @@
|
||||
// 校验
|
||||
form.verify({
|
||||
});
|
||||
|
||||
// 区域选择
|
||||
(function() {
|
||||
$('#areaSelectBtn').on('click', function() {
|
||||
top.dialog.open({
|
||||
title: '选择地区',
|
||||
url: top.restAjax.path('route/activity/get-select?areaName={areaName}', [encodeURI($('#areaName').val())]),
|
||||
width: '400px',
|
||||
height: '225px',
|
||||
onClose: function() {
|
||||
var selectedAreaArray = top.dialog.dialogData.selectedAreaArray;
|
||||
if(selectedAreaArray.length > 0) {
|
||||
var areaCode = '';
|
||||
var areaName = '';
|
||||
areaCode = selectedAreaArray[selectedAreaArray.length - 1].areaCode;
|
||||
for(var i = 0, item; item = selectedAreaArray[i++];) {
|
||||
if(areaName) {
|
||||
areaName += ' / ';
|
||||
}
|
||||
areaName += item.areaName;
|
||||
}
|
||||
$('#areaCode').val(areaCode);
|
||||
$('#areaName').val(areaName);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
$('#areaCleanBtn').on('click', function () {
|
||||
$('#areaCode').val('');
|
||||
$('#areaName').val('');
|
||||
})
|
||||
})();
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
Loading…
Reference in New Issue
Block a user