Viewing file: rent.php (4.62 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?= $this->extend(currentTheme() . '/layout'); ?>
<?= $this->section('content'); ?>
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-12">
<a href="<?= base_url('panel/rent/numbers'); ?>" class="btn btn-primary">Kiraladığım Numaralar</a>
</div>
</div>
<div class="row bg-dark py-3 rounded mx-1">
<div class="col-md-4">
<label>Ülke:</label>
<div class="mb-3">
<select class="form-control bg-default" id="rentCountries" disabled></select>
</div>
</div>
<div class="col-md-4">
<label>Süre:</label>
<div class="mb-3">
<input type="number" id="rentTime" value="4" min="1" class="form-control bg-default">
</div>
</div>
<div class="col-md-4">
<label>Tür:</label>
<div class="mb-3">
<select id="rentType" class="form-control bg-default">
<option value="hours">Saat</option>
<option value="days">Gün</option>
<option value="weeks">Hafta</option>
</select>
<small>Minimum 4 saat kiralanabilir.</small>
</div>
</div>
</div>
<div class="col">
<div class="row py-3 m-1 gap-2 justify-content-center" id="serviceList">
</div>
</div>
</div>
</div>
</div>
</div>
<style>
.hidden {
display: none !important;
}
</style>
<?= $this->endSection('content'); ?>
<?= $this->section('js'); ?>
<script>
let types = {
'hours': 1,
'days': 24,
'weeks': 24 * 7
};
function buyNumber(id, name, price) {
Swal.fire({
title: `Aşağıdaki servisi satın almak istiyor musunuz?`,
text: name,
showDenyButton: true,
showCancelButton: false,
confirmButtonText: `Satın Al (${price}TL)`,
denyButtonText: `İptal Et`,
}).then((result) => {
if (result.isConfirmed) {
Swal.showLoading();
$.get('<?= base_url('api/buyRentNumber') ?>/' + id + '/' + $('#rentCountries').val() + '/' + $('#rentTime').val() * types[$('#rentType').val()], function(response) {
Swal.fire({
title: response.title,
icon: response.status ? 'success' : 'error'
}).then(() => {
if (response.status) {
window.location.href = "<?= base_url('panel/rent/numbers') ?>";
}
});
});
}
})
}
window.addEventListener('load', () => {
window.blockLoad = false;
$.get('<?= base_url('api/getRentCountries'); ?>', function(response) {
$('#rentCountries').attr('disabled', false).html(response.map(r => `<option value="${r.id}">${r.name}</option>"`));
$("#rentCountries").val($("#rentCountries option:first").val()).change();
});
$('#rentCountries').change(renderServices);
$('#rentType').change(renderServices);
$('#rentTime').change(renderServices);
function renderServices() {
if (window.blockLoad) return false;
Swal.showLoading();
window.blockLoad = true;
$('#rentCountries').attr('disabled', true);
$('#rentType').attr('disabled', true);
$('#rentTime').attr('disabled', true);
$.get('<?= base_url('api/getRentServices'); ?>/' + $(this).val() + '/' + $('#rentTime').val() * types[$('#rentType').val()], function(response) {
Swal.close();
window.blockLoad = false;
$('#rentCountries').attr('disabled', false);
$('#rentType').attr('disabled', false);
$('#rentTime').attr('disabled', false);
$('#serviceList').html(response.map(r => {
return `<div class="card col-md-3"><div class="card-body"><h5>${r.name}</h5><p class="m-0">Fiyat: ${r.cost}TL</p><p class="m-0">Mevcut Stok: ${r.count} Adet</p></div><div class="card-footer py-0"><button class="btn btn-dark btn-sm" onclick="buyNumber('${r.id}', '${r.name}', '${r.cost}')">Kirala</button></div></div>`;
}));
});
}
});
</script>
<?= $this->endSection('js'); ?>
|