This commit is contained in:
Bob 2020-10-13 14:46:15 +08:00
parent 5084800861
commit 24bcc589b4
4 changed files with 125 additions and 38 deletions

View File

@ -69,10 +69,26 @@
{# </label>#} {# </label>#}
{# </p>#} {# </p>#}
<p style="display: inline-block"> <p style="display: inline-block">
<label for="name">单位<br/> <div class="input-group main-search">
<input type="text" id="search-text" name="organization"> <input type="text" class="form-control" placeholder="请输入关键字"
<p><span id='search-result'></span></p> style="height: 40px;width: 230px;opacity: 1 " name="organization">
</label> <div class="input-group-btn" style="display: none">
<button class="btn btn-default" type="button">
<span class="glyphicon glyphicon-search"></span>
</button>
</div>
</div>
<div class="autocomplete-panel" style="margin-left: 50px;z-index: 999">
</div>
{# <div class="result-panel">#}
{# <div class="panel panel-default">#}
{# <div style="padding: 10px; text-align: center">loading...</div>#}
{# <div style="color: black;z-index: 9999">#}
{# <p id="point_lat">{{ points.point_lat }}</p>#}
{# <p id="point_lon">{{ points.point_lon }}</p>#}
{# </div>#}
{# </div>#}
{# </div>#}
</p> </p>
<a href="{% url 'organization-management-create' %}"><span class="glyphicon glyphicon-plus" <a href="{% url 'organization-management-create' %}"><span class="glyphicon glyphicon-plus"
aria-hidden="true" aria-hidden="true"
@ -192,23 +208,65 @@
}); });
}); });
$("#search-text").keyup(function () { $('.main-search input').focus(function (e) {
var q = $("#search-text").val(); e.preventDefault();
$.getJSON("/get/organization/", {'q': q}, function (data) { $("#history_query").hide()
console.log(data[0].name) var width = $(this).width();
for (var i = 0; i < data.length; i++) { var position = $(this).position();
$('#search-result').append(data[i].name + '<br/>') var val = $(this).val();
} var params = {keyword: val}
; if (val) {
}) $('.autocomplete-panel').load('/get/organization/' + '?' + $.param(params));
}
$('.autocomplete-panel').css({
width: width + 12,
top: position.top + 34,
left: position.left + 5
}).show();
}).blur(function (e) {
e.preventDefault();
resetAutoCompletePanel();
}).on('input', function (e) {
var val = $(this).val();
var params = {keyword: val}
$('.autocomplete-panel').load('/get/organization/' + '?' + $.param(params))
}); });
$('#search-text').keydown(function () {
$('#search-result').empty(); function search(value) {
}) console.log('search');
$('#search-text').blur(function () { $('.main-search input').val(value);
$('#search-result').empty(); {#resetAutoCompletePanel();#}
}) {#showFilterPanel();#}
{#resetResultPanel();#}
{#showResultPanel(value);#}
}
function showFilterPanel() {
$('.filter-panel').show();
}
function resetFilterCompletePanel() {
$('.filter-panel').hide();
}
function resetAutoCompletePanel() {
$('.autocomplete-panel').html("<div style='padding: 10px; text-align: center'>loading...</div>").hide();
}
function showResultPanel(name) {
$('.result-panel').show();
$('.result-panel').load('{% url "get-organization" %}' + '?keyword=' + encodeURIComponent(name));
}
function resetResultPanel() {
$('.result-panel').html(" <div class=\"panel panel-default\">\n" +
" <div style=\"padding: 10px; text-align: center\">loading...</div>\n" +
" </div>")
}
}) })
</script> </script>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,24 @@
{% load static %}
<ul class="list-group">
{% for topten in topten_list %}
<li class="list-group-item">
<a href="#" class="autocomplete-panel-item" data-name="{{ topten.name }},{{ topten.province }},{{ topten.cities }},{{ topten.district }}" style="color: #16a085">
{{ topten.name }}- (<span id="lat">{{ topten.province }}</span>,<span
id="lon">{{ topten.cities }}</span>,<span id="lon">{{ topten.district }}</span>)
</a>
</li>
{% endfor %}
</ul>
<script>
$(function () {
console.log("2222222222222222")
$('.autocomplete-panel-item').click(function (e) {
e.preventDefault();
var name = $(this).data('name');
console.log(name+"11111111111111111111111111111111")
$('.main-search input').val(value)
})
})
</script>

View File

@ -18,6 +18,6 @@ urlpatterns = [
path('get/town/',views.get_town), path('get/town/',views.get_town),
path('get/village/',views.get_village), path('get/village/',views.get_village),
#单位搜索 #单位搜索
path('get/organization/',views.get_organization) path('get/organization/',views.get_organization,name='get-organization')
] ]

View File

@ -219,21 +219,26 @@ def get_village(request):
def get_organization(request): def get_organization(request):
q = request.GET.get('q') # q = request.GET.get('q')
organization = Organization.objects.filter(name__contains=q)[:20] # organization = Organization.objects.filter(name__contains=q)[:20]
res = [] # res = []
for o in organization: # for o in organization:
d = dict() # d = dict()
d['name'] = o.name # d['name'] = o.name
d['province'] = Area_code_2020.objects.get(code=o.province).name # d['province'] = Area_code_2020.objects.get(code=o.province).name
if o.cities: # if o.cities:
d['cities'] = Area_code_2020.objects.get(code=o.cities).name # d['cities'] = Area_code_2020.objects.get(code=o.cities).name
else: # else:
d['cities'] = '' # d['cities'] = ''
if o.district: # if o.district:
d['district'] = Area_code_2020.objects.get(code=o.district).name # d['district'] = Area_code_2020.objects.get(code=o.district).name
else: # else:
d['district'] = '' # d['district'] = ''
res.append(d) # res.append(d)
print(res) # print(res)
return HttpResponse(json.dumps(res)) # return HttpResponse(json.dumps(res))
keywords = request.GET.get('keyword')
if len(keywords) != 0:
topten_list = Organization.objects.filter(Q(name__contains=keywords))
print(str(topten_list))
return render(request, 'dashboard/results_by_keywords.html', {'topten_list': topten_list})