feat: hecha la parte de gestion de propiedades en venta

This commit is contained in:
2025-02-01 18:10:24 -03:00
parent af231344b6
commit 2a8ba5a9f4
9 changed files with 257 additions and 10 deletions

View File

@@ -0,0 +1,159 @@
<script lang="ts">
import { onMount } from "svelte";
import NavBarAutocompletable from "../Componentes/NavBarAutocompletable.svelte";
import type { PropiedadDto, setVenta } from "../types";
import BarraHorizontalConTexto from "../Componentes/BarraHorizontalConTexto.svelte";
import { fade } from "svelte/transition";
import { urlG } from "../stores/urlStore";
import ModalEstatico from "../Componentes/ModalEstatico.svelte";
import ModalPublicarPropiedadParaVenta from "../Componentes/ModalPublicarPropiedadParaVenta.svelte";
import ModificarPropiedadForm from "../Componentes/modificarPropiedadForm.svelte";
let token = sessionStorage.getItem("token")||"";
let modaldata:string =$state("");
let propiedades:PropiedadDto[]|null = $state(null);
let modificar:boolean = $state(false);
let selprop:PropiedadDto = $state({canthabitaciones:0, id:0, iddivisa:0, letra:"", monto:0, piso:"", servicios:"", tipo:"", ubicacion:""});
onMount(()=>{
obtenerpropiedadesenventa();
});
async function obtenerpropiedadesenventa() {
try{
const r = await fetch($urlG+"/api/propiedades/Venta/Propietario", {
method:"GET",
headers: {
"Auth": token,
},
});
if (r.ok) {
let data = await r.json();
propiedades =data;
return;
}
} catch {
modaldata= "Fallo la request"
}
}
function setmod(p:PropiedadDto) {
if (modificar == false) selprop = p;
modificar =! modificar;
}
let showBajaVenta:boolean = $state(false);
function unsetventa(p:PropiedadDto) {
selprop = p;
showBajaVenta= true;
}
async function submitBajaVenta(data:setVenta) {
data.idpropiedad = selprop.id;
try {
const responce = await fetch(String($urlG)+"/api/propiedad/unsetPropiedadAVenta", {
method: "PUT",
headers:{
'Auth' : String(sessionStorage.getItem("token")),
'Content-Type': "application/json",
},
body: JSON.stringify(data),
});
if(responce.ok){
window.location.reload();
}
const json = await responce.json();
modaldata = json.message;
}catch (e){
console.error(e);
}
}
function BajaPropiedad(): any {
throw new Error("Function not implemented.");
}
</script>
<NavBarAutocompletable/>
{#if modaldata}
<ModalEstatico payload={modaldata} close={()=>!!(modaldata = "")}/>
{/if}
{#if showBajaVenta}
<ModalPublicarPropiedadParaVenta btntext="Bajar de Venta" title="Bajar de venta" onClose={()=>!!(showBajaVenta=false)} onConfirm={submitBajaVenta}/>
{/if}
<div class="container-fluid table-responsive mt-2">
<BarraHorizontalConTexto text="Propiedades En Venta"/>
<table class="container-fluid table-responsive table table-striped table-bordered">
<thead>
<tr>
<th>#</th>
<th>ubicacion</th>
<th>Habitaciones</th>
<th>Letra</th>
<th>Piso</th>
<th>Tipo</th>
<th>Servicios</th>
<th>Divisa</th>
<th>Monto</th>
<th></th>
</tr>
</thead>
<tbody>
{#if propiedades == null}
<tr>
<td colspan="10">
<div class="spinner-border" role="status"></div>
<span>Cargando...</span>
</td>
</tr>
{:else if propiedades.length <=0}
<tr>
<td colspan="10">No hay propiedades en venta para este usuario</td>
</tr>
{:else}
{#each propiedades as p}
<tr in:fade>
<td>{p.id}</td>
<td>{p.ubicacion}</td>
<td>{p.canthabitaciones}</td>
<td>{p.letra}</td>
<td>{p.piso}</td>
<td>{p.tipo}</td>
<td>{p.servicios}</td>
<td>
{#if p.iddivisa == 0}
AR$
{:else}
US$
{/if}
</td>
<td>{p.monto}</td>
<td class="d-flex justify-content-between gap-2">
<button class="btn btn-secondary btn-sm" onclick={()=> setmod(p)}>Modificar</button>
<button class="btn btn-secondary btn-sm" onclick={()=> unsetventa(p)}>Bajar de venta</button>
</td>
</tr>
{#if modificar}
<tr transition:fade={{duration:100}}>
<td colspan="10">
<ModificarPropiedadForm id={selprop.id} ubicacion={selprop.ubicacion}
canthabitaciones={selprop.canthabitaciones} letra={selprop.letra} piso={selprop.piso}
tipo={selprop.tipo} servicios={selprop.servicios} monto={selprop.monto} iddivisa={selprop.iddivisa}/>
</td>
</tr>
{/if}
{/each}
{/if}
</tbody>
</table>
</div>