var type="auction"
$(document).ready(function(){
get_map_list(0);
$("#form input, #form select").change(function(){
get_map_list(0);
});
// selltype에 따른 드롭다운 메뉴 보이기 설정
$(".selltype_nav").click(function(event) {
event.preventDefault(); // 기본 링크 동작을 막음
// 클릭한 탭의 data-selltype 값을 가져옴
var selltype = $(this).data('selltype');
// form 내에 있는 selltype 값을 업데이트
$("#form input[name='selltype']").val(selltype);
// selltype에 맞는 드롭다운 메뉴만 보이게 설정
if (selltype === 'sell') {
$(".price_dropdown_none").addClass("d-none");
$(".price_dropdown_sell").removeClass("d-none");
$(".price_dropdown_full").addClass("d-none");
$(".price_dropdown_rent").addClass("d-none");
} else if (selltype === 'full') {
$(".price_dropdown_none").addClass("d-none");
$(".price_dropdown_sell").addClass("d-none");
$(".price_dropdown_full").removeClass("d-none");
$(".price_dropdown_rent").addClass("d-none");
} else if (selltype === 'rent') {
$(".price_dropdown_none").addClass("d-none");
$(".price_dropdown_sell").addClass("d-none");
$(".price_dropdown_full").addClass("d-none");
$(".price_dropdown_rent").removeClass("d-none");
} else if(selltype == ''){
$(".price_dropdown_none").removeClass("d-none");
$(".price_dropdown_sell").addClass("d-none");
$(".price_dropdown_full").addClass("d-none");
$(".price_dropdown_rent").addClass("d-none");
}
// 기존에 설정한 가격값 초기화
price_reset();
});
$('.dropdown-menu').click(function(e) {
e.stopPropagation();
});
// 드롭다운 항목 클릭 이벤트
$(".sorting-menu .dropdown-item").on('click', function(e) {
e.preventDefault(); // 링크의 기본 동작을 막음
var sortingValue = $(this).data('sorting'); // data-sorting 속성에서 값 가져오기
var selectedText = $(this).text(); // 클릭한 항목의 텍스트 가져오기
// hidden input에 값 설정
$('input[name="sorting"]').val(sortingValue);
// 버튼 텍스트 변경
$('#sorting_button').text(selectedText);
// 숨겨진 input에 선택된 값 설정
$('input[name="sorting"]').val(sortingValue);
// 드롭다운 닫기
$('#sorting_button').dropdown('toggle');
get_map_list(0);
});
$(".price_reset").on('click', function(e) {
price_reset();
});
$(".area_reset").on('click', function(e) {
area_reset();
});
$(".price_submit").on('click', function(e) {
selltype = $("#form input[name='selltype']").val();
price_from = $(".price-dropdown-menu input[name='price_min']").val();
price_to = $(".price-dropdown-menu input[name='price_max']").val();
// 매매일때
if(selltype == "sell"){
$("#form input[name='sell_from']").val(price_from);
$("#form input[name='sell_to']").val(price_to);
}
// 전세일때
else if(selltype == "full"){
$("#form input[name='full_from']").val(price_from);
$("#form input[name='full_to']").val(price_to);
}
// 월세일때
else if(selltype == "rent"){
$("#form input[name='rent_from']").val(price_from);
$("#form input[name='rent_to']").val(price_to);
}
// 분양
else if(selltype == "installation"){
$("#form input[name='price_installation_start_from']").val(price_from);
$("#form input[name='price_installation_start_to']").val(price_to);
}
// 경매
else if(selltype == "auction"){
$("#form input[name='price_appraisal_from']").val(price_from);
$("#form input[name='price_appraisal_to']").val(price_to);
}
$("#priceRangeSelector_" + selltype).removeClass("show"); // 드롭다운 닫기
//$('.price-button').removeClass('selected');
clickCount = 0;
startIndex = null;
endIndex = null;
get_map_list(0);
});
$(".area_submit").on('click', function(e) {
selltype = $("#form input[name='selltype']").val();
area_from = $(".area-dropdown-menu input[name='area_min']").val();
area_to = $(".area-dropdown-menu input[name='area_max']").val();
// 경매
if(selltype == "auction"){
$("#form input[name='area_land_from']").val(area_from);
$("#form input[name='area_land_to']").val(area_to);
$("#areaRangeSelector_area_auction").removeClass("show"); // 드롭다운 닫기
}
// 분양과 매물
else{
$("#form input[name='area_exclusive_from']").val(area_from);
$("#form input[name='area_exclusive_to']").val(area_to);
$("#areaRangeSelector_area").removeClass("show"); // 드롭다운 닫기
}
//$('.area-button').removeClass('selected');
clickCount = 0;
startIndex = null;
endIndex = null;
get_map_list(0);
});
if($("#keyword").length > 0){
$("#keyword").autocomplete({
selectFirst: false,
autoFill: false,
autoFocus: false,
focus: function(event,ui){
return false;
},
delay: 0,
scrollHeight:40,
minLength:2,
select: function(a,b){
$("#form input[name='lat']").val(b.item.lat);
$("#form input[name='lng']").val(b.item.lng);
$("#sorting").val("distance_asc");
get_map_list(0);
a.stopPropagation();
return false;
},
source: function(request, response){
totalSearch(lat,lng, response);
},
}).data("ui-autocomplete")._renderItem = autoCompleteRenderSearch;
}
});
function totalSearch(lat,lng, response){
//숫자일 경우에는 매물검색으로 인식해서 해당 매물번호로 이동되므로 아무 것도 하지 않는다.
if($.isNumeric($("#search").val())){
return;
} else {
$.ajax({
url: "/search/address",
type: "POST",
data: {
keyword : $("#keyword").val(),
},
dataType: "json",
success: function(data) {
if(data!=""){
response( $.map( data, function( item ) {
return {
id: item.id,
title: item.title,
type: item.type,
lat: item.lat,
lng: item.lng
};
}));
}
}
});
}
}
function autoCompleteRenderSearch(ul, item) {
return $("").data("item.autocomplete", item).append(' '+item.title).appendTo(ul);
}
function get_map_list(page){
var total = 0;
var formData = $("#form").serialize();
//formData+='&sorting='+$("#sorting").val();
formData+='&method=grid';
console.log(formData);
$.ajax({
type : "POST",
url : "/"+type+"/ajax_grid/"+page,
data : formData,
dataType: 'json',
success: function(data) {
$.each(data, function(key, val) {
if(key=="result") {
$("#property_list").html(val);
// 새로 추가된 요소에 애니메이션 적용
anime({
targets: '[data-anime]',
translateY: function(el) {
return JSON.parse(el.getAttribute('data-anime')).translateY;
},
opacity: function(el) {
return JSON.parse(el.getAttribute('data-anime')).opacity;
},
duration: function(el) {
return JSON.parse(el.getAttribute('data-anime')).duration;
},
delay: function(el) {
return JSON.parse(el.getAttribute('data-anime')).delay;
},
easing: function(el) {
return JSON.parse(el.getAttribute('data-anime')).easing;
},
// 추가 속성 설정
});
// .property-zzim 요소에 클릭 이벤트 다시 바인딩
init_zzim();
}
if(key=="pagination") {
$(".pagination").html(val);
get_map_list_paging();
}
if(key=="total"){
total = val;
$("#map_label").html("" + total.toLocaleString() + "개 의 매물");
}
});
$("#property_list").animate({
scrollTop: 0
}, 600);
if(total=="0") {
$("#property_list").html("매물이 없습니다.
지도를 옮기거나 검색조건을 변경해 보세요.
");
}
}
});
}
function get_map_list_paging(){
$(".page-link").click(function(e){
e.preventDefault();
var page = $(this).attr("href").substring($(this).attr("href").lastIndexOf('/') + 1)
get_map_list(page);
$(".property_list_wrapper").animate({
scrollTop: 0
}, 600);
});
}
function init_zzim() {
// .property-zzim 클릭 이벤트 바인딩
$(".property-zzim").off('click').on('click', function() {
if (confirm("로그인하시겠습니까?")) {
location.href = "/member/signin";
}
});
}
function price_reset(reset=true){
$(".price-dropdown-menu input").each(function(){
$(this).val("");
})
$("#form input[name='sell_from']").val("");
$("#form input[name='sell_to']").val("");
$("#form input[name='full_from']").val("");
$("#form input[name='full_to']").val("");
$("#form input[name='rent_from']").val("");
$("#form input[name='rent_to']").val("");
$("#form input[name='price_installation_start_from']").val("");
$("#form input[name='price_installation_start_to']").val("");
$("#form input[name='price_appraisal_from']").val("");
$("#form input[name='price_appraisal_to']").val("");
$('.price-button').removeClass('selected');
clickCount = 0;
startIndex = null;
endIndex = null;
if(reset)
get_map_list(0);
}
function area_reset(reset=true){
$(".area-dropdown-menu input").each(function(){
$(this).val("");
})
$("#form input[name='area_exclusive_from']").val("");
$("#form input[name='area_exclusive_to']").val("");
$("#form input[name='area_land_from']").val("");
$("#form input[name='area_land_to']").val("");
$('.area-button').removeClass('selected');
clickCount = 0;
startIndex = null;
endIndex = null;
if(reset)
get_map_list(0);
}