385 lines
8.5 KiB
JavaScript
385 lines
8.5 KiB
JavaScript
|
function __id(a){
|
||
|
return document.getElementById(a);
|
||
|
}
|
||
|
|
||
|
var urut = 1;
|
||
|
var um = 0;
|
||
|
|
||
|
el('#filter-p').click(function(){
|
||
|
menu.css('height', '350px')
|
||
|
domp("content-menu", fill)
|
||
|
})
|
||
|
.cssFocus({
|
||
|
color: "blue"
|
||
|
})
|
||
|
|
||
|
el('#next-kpr').click(function(){
|
||
|
var getUrl = location.pathname.replaceAll('/kpr', '').split('/')
|
||
|
.filter(function(x){
|
||
|
if(x != ""){
|
||
|
return x;
|
||
|
}
|
||
|
})
|
||
|
|
||
|
var m = getUrl;
|
||
|
|
||
|
var cond = {}
|
||
|
if (m[0] != undefined) {
|
||
|
|
||
|
m[0].split('&').forEach( function(w, x) {
|
||
|
var l = w.split('~');
|
||
|
var v = l[1].replaceAll("-", " ");
|
||
|
cond[l[0]] = v;
|
||
|
});
|
||
|
|
||
|
}
|
||
|
|
||
|
makeCond = []
|
||
|
Object.keys(cond).forEach(function(s, i){
|
||
|
if(i == 0){
|
||
|
makeCond.push({
|
||
|
opsi: "", data: [s, '=', `"${cond[s]}"`]
|
||
|
});
|
||
|
}else{
|
||
|
makeCond.push({
|
||
|
opsi: "AND", data: [s, '=', `"${cond[s]}"`]
|
||
|
});
|
||
|
}
|
||
|
})
|
||
|
|
||
|
var rpm = db()
|
||
|
.master(true)
|
||
|
.table('properti')
|
||
|
.select(" COUNT(idprop) as num ");
|
||
|
if (m.length > 0) {
|
||
|
rpm.condition(makeCond)
|
||
|
}
|
||
|
rpm.get(function(x){
|
||
|
um += 21;
|
||
|
urut +=1;
|
||
|
if (um < Number(x[0].num)) {
|
||
|
loadData(um, getUrl);
|
||
|
}else{
|
||
|
urut -=1;
|
||
|
um -= 21;
|
||
|
}
|
||
|
})
|
||
|
})
|
||
|
|
||
|
el('#prev-kpr').click(function(){
|
||
|
var getUrl = location.pathname.replaceAll('/kpr', '').split('/')
|
||
|
.filter(function(x){
|
||
|
if(x != ""){
|
||
|
return x;
|
||
|
}
|
||
|
})
|
||
|
.map(function(x){
|
||
|
return x.replaceAll("-", " ");
|
||
|
})
|
||
|
if(um > 0){
|
||
|
urut -=1;
|
||
|
um -= 21;
|
||
|
loadData(um, getUrl);
|
||
|
}
|
||
|
})
|
||
|
|
||
|
function loadData(x = 0, m){
|
||
|
|
||
|
var cond = {}
|
||
|
if (m[0] != undefined) {
|
||
|
|
||
|
m[0].split('&').forEach( function(w, x) {
|
||
|
var l = w.split('~');
|
||
|
var v = l[1].replaceAll("-", " ");
|
||
|
cond[l[0]] = v;
|
||
|
});
|
||
|
|
||
|
}
|
||
|
|
||
|
makeCond = []
|
||
|
Object.keys(cond).forEach(function(s, i){
|
||
|
if(i == 0){
|
||
|
makeCond.push({
|
||
|
opsi: "", data: [s, '=', `"${cond[s]}"`]
|
||
|
});
|
||
|
}else{
|
||
|
makeCond.push({
|
||
|
opsi: "AND", data: [s, '=', `"${cond[s]}"`]
|
||
|
});
|
||
|
}
|
||
|
})
|
||
|
|
||
|
|
||
|
el("#page").text(urut);
|
||
|
el("#top-view").go(-170)
|
||
|
__id('properti').innerHTML = `
|
||
|
|
||
|
<div class="col-12 text-center">
|
||
|
<div class="loadingio-spinner-spinner-2lqweg6m29r"><div class="ldio-6xpymcz56">
|
||
|
<div></div>
|
||
|
<div></div>
|
||
|
<div></div>
|
||
|
<div></div>
|
||
|
<div></div>
|
||
|
<div></div>
|
||
|
<div></div>
|
||
|
<div></div>
|
||
|
<div></div>
|
||
|
<div></div>
|
||
|
<div></div>
|
||
|
<div></div>
|
||
|
</div></div>
|
||
|
</div>
|
||
|
|
||
|
`;
|
||
|
var prop = db()
|
||
|
.table('properti')
|
||
|
.select('properti.*, p.*, sales.nama as sales')
|
||
|
.leftJoin([
|
||
|
[`( SELECT * FROM foto GROUP BY foto.idprop ) as p`, `p.idprop`, '=', `properti.idprop `],
|
||
|
['sales', 'sales.id', '=', 'properti.idsales']
|
||
|
])
|
||
|
.order('tgldaftar', 'DESC')
|
||
|
.master(false)
|
||
|
.limit(x, 21);
|
||
|
if(m.length > 0){
|
||
|
prop.condition(makeCond)
|
||
|
}
|
||
|
prop.get(function(e){
|
||
|
var ids = 'properti';
|
||
|
__id(ids).innerHTML = e.map(function(c){
|
||
|
|
||
|
var judul = c.judulproperti;
|
||
|
|
||
|
var harga = formatRupiah(Number(c.harga).toFixed(2));
|
||
|
|
||
|
if (judul.length > 30) {
|
||
|
judul = judul.substring(0, 30)+'...';
|
||
|
}
|
||
|
|
||
|
var deskripsi = c.deskripsi;
|
||
|
|
||
|
if (deskripsi.length > 45) {
|
||
|
deskripsi = deskripsi.substring(0, 45)+'...';
|
||
|
}
|
||
|
|
||
|
return `
|
||
|
<div onclick="window.location.href = '/kpr-detail/${c.idprop}'" style="cursor: pointer;" class="col-sm-6 col-lg-4">
|
||
|
<div class="card mb-2 card-content">
|
||
|
<div class="foto images-content" style="--h:250px;
|
||
|
--foto: url('https://masuksini.com/sistem-api/androapi/upload/foto/${c.id}.jpg');
|
||
|
">
|
||
|
<div class="harga">Rp ${harga}</div>
|
||
|
<div class="status">${c.transaksi}</div>
|
||
|
</div>
|
||
|
<div class="card-body">
|
||
|
<h4 style="font-size: 14pt;">${judul}</h4>
|
||
|
<p>${deskripsi}</p>
|
||
|
<span>
|
||
|
<i class="fas fa-building"></i> <span>${c.lb}<sup>m2</sup></span>
|
||
|
</span>
|
||
|
<span>
|
||
|
<i class="fas fa-arrows-alt"></i> <span>${c.lt}<sup>m2</sup></span>
|
||
|
</span>
|
||
|
<span>
|
||
|
<i class="fas fa-bed"></i> <span>${c.jum_kt}</span>
|
||
|
</span>
|
||
|
<span>
|
||
|
<i class="fas fa-bath"></i> <span>${c.jum_km}</span>
|
||
|
</span>
|
||
|
<div class="row mt-3 agen-info">
|
||
|
<div class="col-7">
|
||
|
<div class="agen">
|
||
|
<div class="foto" style="--foto: url('/assets/upload/agen/${c.idsales}.jpg')" class="foto-agen"></div>
|
||
|
<div>
|
||
|
<h4>${c.sales}</h4>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="col-5">
|
||
|
<button><i class="fab fa-whatsapp"></i> Hubungi agen</button>
|
||
|
<button><i class="fab fa-whatsapp"></i> Hitung KPR</button>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
`;
|
||
|
}).join("");
|
||
|
})
|
||
|
}
|
||
|
|
||
|
$(document).ready(function(){
|
||
|
var getUrl = location.pathname.replaceAll('/kpr', '').split('/')
|
||
|
.filter(function(x){
|
||
|
if(x != ""){
|
||
|
return x;
|
||
|
}
|
||
|
})
|
||
|
loadData(0, getUrl);
|
||
|
|
||
|
var m = getUrl;
|
||
|
|
||
|
var cond = {}
|
||
|
if (m[0] != undefined) {
|
||
|
|
||
|
m[0].split('&').forEach( function(w, x) {
|
||
|
var l = w.split('~');
|
||
|
var v = l[1].replaceAll("-", " ");
|
||
|
cond[l[0]] = v;
|
||
|
});
|
||
|
|
||
|
}
|
||
|
|
||
|
if (cond.transaksi != undefined) {
|
||
|
__id('kpr').value = cond.transaksi;
|
||
|
}
|
||
|
|
||
|
|
||
|
db()
|
||
|
.master(true)
|
||
|
.table('properti')
|
||
|
.select(' DISTINCT(province) as prov ')
|
||
|
.condition([
|
||
|
{opsi: "", data: ["province", "<>", "''"]}
|
||
|
])
|
||
|
.get(function(b){
|
||
|
__id('provinc').innerHTML = `<option value="">Pilih Provinsi</option>`+b.map(function(s,i){
|
||
|
return `<option value="${s.prov.toLowerCase()}">${s.prov}</option>`
|
||
|
})
|
||
|
|
||
|
if (cond.province != undefined) {
|
||
|
__id('provinc').value = cond.province;
|
||
|
}
|
||
|
})
|
||
|
|
||
|
var condKota = [
|
||
|
{opsi: "", data: ["city_name", "<>", "''"]}
|
||
|
];
|
||
|
|
||
|
if (cond.province != undefined) {
|
||
|
condKota.push({
|
||
|
opsi: 'AND', data: ['province', '=', '"'+cond.province+'"']
|
||
|
})
|
||
|
}
|
||
|
|
||
|
|
||
|
db()
|
||
|
.table('properti')
|
||
|
.master(true)
|
||
|
.select(' DISTINCT(city_name) as prov ')
|
||
|
.condition(condKota)
|
||
|
.get(function(b){
|
||
|
__id('kota').innerHTML = `<option value="">Pilih kota</option>`+b.map(function(s,i){
|
||
|
return `<option value="${s.prov.toLowerCase()}">${s.prov}</option>`
|
||
|
})
|
||
|
|
||
|
if (cond.city_name != undefined) {
|
||
|
__id('kota').value = cond.city_name;
|
||
|
}
|
||
|
})
|
||
|
|
||
|
})
|
||
|
|
||
|
|
||
|
$("#provinc").change(function(){
|
||
|
var getUrl = location.pathname.replaceAll('/kpr', '').split('/')
|
||
|
.filter(function(p, i){
|
||
|
if(p != ""){
|
||
|
return p;
|
||
|
}
|
||
|
});
|
||
|
//search if defined filter not to shown
|
||
|
var search = $(this).val().replaceAll(" ", "-");
|
||
|
if (getUrl[0] != undefined) {
|
||
|
getUrl = getUrl[0].split("&").filter(function(k,i){
|
||
|
if (k.indexOf("province") == -1 && k.indexOf("city_name") == -1) {
|
||
|
console.log(k)
|
||
|
return k;
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
|
||
|
var condKota = [
|
||
|
{opsi: "", data: ["city_name", "<>", "''"]}
|
||
|
];
|
||
|
|
||
|
if ($(this).val() != "") {
|
||
|
condKota.push({
|
||
|
opsi: 'AND', data: ['province', '=', '"'+$(this).val()+'"']
|
||
|
})
|
||
|
}
|
||
|
|
||
|
db()
|
||
|
.master(true)
|
||
|
.table('properti')
|
||
|
.select(' DISTINCT(city_name) as prov ')
|
||
|
.condition(condKota)
|
||
|
.get(function(b){
|
||
|
__id('kota').innerHTML = `<option value="">Pilih kota</option>`+b.map(function(s,i){
|
||
|
return `<option value="${s.prov.toLowerCase()}">${s.prov}</option>`
|
||
|
})
|
||
|
|
||
|
document.getElementById("kota").value = "";
|
||
|
|
||
|
})
|
||
|
|
||
|
console.log(getUrl);
|
||
|
|
||
|
if (search != "") {
|
||
|
getUrl.push("province~"+search);
|
||
|
}
|
||
|
window.history.pushState({}, 'name', '/kpr/'+getUrl.join("&"));
|
||
|
var dr = [getUrl.join("&")];
|
||
|
loadData(0, dr);
|
||
|
})
|
||
|
|
||
|
$("#kpr").change(function(){
|
||
|
var getUrl = location.pathname.replaceAll('/kpr', '').split('/')
|
||
|
.filter(function(p, i){
|
||
|
if(p != ""){
|
||
|
return p;
|
||
|
}
|
||
|
});
|
||
|
//search if defined filter not to shown
|
||
|
var search = $(this).val().replaceAll(" ", "-");
|
||
|
if (getUrl[0] != undefined) {
|
||
|
getUrl = getUrl[0].split("&").filter(function(k,i){
|
||
|
if (k.indexOf("transaksi") == -1) {
|
||
|
return k;
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
if (search != "") {
|
||
|
getUrl.push("transaksi~"+search);
|
||
|
}
|
||
|
window.history.pushState({}, 'name', '/kpr/'+getUrl.join("&"));
|
||
|
var dr = [getUrl.join("&")];
|
||
|
loadData(0, dr);
|
||
|
})
|
||
|
|
||
|
$("#kota").change(function(){
|
||
|
var getUrl = location.pathname.replaceAll('/kpr', '').split('/')
|
||
|
.filter(function(p, i){
|
||
|
if(p != ""){
|
||
|
return p;
|
||
|
}
|
||
|
});
|
||
|
//search if defined filter not to shown
|
||
|
var search = $(this).val().replaceAll(" ", "-");
|
||
|
if (getUrl[0] != undefined) {
|
||
|
getUrl = getUrl[0].split("&").filter(function(k,i){
|
||
|
if (k.indexOf("city_name") == -1) {
|
||
|
return k;
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
if (search != "") {
|
||
|
getUrl.push("city_name~"+search);
|
||
|
}
|
||
|
window.history.pushState({}, 'name', '/kpr/'+getUrl.join("&"));
|
||
|
var dr = [getUrl.join("&")];
|
||
|
loadData(0, dr);
|
||
|
})
|