feat: hecha la parte de gestion de propiedades en venta
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
import ControlPagos from "./paginas/ControlPagos.svelte";
|
||||
import ContratoAdmin from "./paginas/ContratoAdmin.svelte";
|
||||
import BuscarVentas from "./paginas/BuscarVentas.svelte";
|
||||
import MisPropiedadesEnVenta from "./paginas/MisPropiedadesEnVenta.svelte";
|
||||
</script>
|
||||
|
||||
<Router>
|
||||
@@ -116,10 +117,16 @@
|
||||
<ProteRoute componente={ControlPagos}/>
|
||||
</Route>
|
||||
|
||||
<!-- VerPropiedadesEnVenta -->
|
||||
<Route path="/accion/15">
|
||||
<ProteRoute componente={MisPropiedadesEnVenta}/>
|
||||
</Route>
|
||||
|
||||
<!-- Buscar Ventas -->
|
||||
<Route path="/accion/16">
|
||||
<ProteRoute componente={BuscarVentas}/>
|
||||
</Route>
|
||||
|
||||
<!-- Pagina Ventas -->
|
||||
<Route path="/Ventas">
|
||||
<ProteRoute componente={Ventas}/>
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
<script lang="ts">
|
||||
import type { PatchPropiedad, setVenta } from "../types";
|
||||
|
||||
let {onClose, onConfirm}: {onClose:()=>void, onConfirm:()=>void} = $props();
|
||||
let {onClose, onConfirm, title = "Publicar para venta", btntext = "Publicar a la venta"
|
||||
} : {
|
||||
onClose:()=>void, onConfirm:(data:setVenta)=>void, title:string, btntext:string
|
||||
} = $props();
|
||||
|
||||
let data:setVenta = $state({iddivisa:0, idpropiedad:0, monto:0});
|
||||
let monto:number = $state(0);
|
||||
|
||||
|
||||
function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
onConfirm();onClose();
|
||||
onConfirm(data);onClose();
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -14,7 +19,7 @@
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Contrato</h5>
|
||||
<h5 class="modal-title">{title}</h5>
|
||||
<button type="button" class="btn-close" onclick={onClose} aria-label="Cerrar"></button>
|
||||
</div>
|
||||
|
||||
@@ -25,17 +30,23 @@
|
||||
type="number"
|
||||
id="monto"
|
||||
class="form-control"
|
||||
bind:value={monto}
|
||||
bind:value={data.monto}
|
||||
placeholder="0"
|
||||
required
|
||||
/>
|
||||
<label for="monto">Monto</label>
|
||||
</div>
|
||||
|
||||
<label for="divisa">divisa</label>
|
||||
<select id="divisa" class="form-select">
|
||||
<option value="0" selected>AR$</option>
|
||||
<option value="1">US$</option>
|
||||
</select>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-primary" onclick={(e)=> handleSubmit(e)}>Publicar a la venta</button>
|
||||
<button class="btn btn-primary" onclick={(e)=> handleSubmit(e)}>{btntext}</button>
|
||||
|
||||
<button class="btn btn-secondary ms-auto" onclick={onClose}>Cerrar</button>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { Navbar, NavbarBrand, NavbarToggler, NavItem, Nav, NavLink, Collapse } from "@sveltestrap/sveltestrap";
|
||||
|
||||
let isOpen:boolean = false;
|
||||
let isOpen:boolean =$state(false);
|
||||
let theme = $state(localStorage.getItem("theme") ?? "light");
|
||||
const toggleTheme = () => {
|
||||
theme = theme === "light" ? "dark" : "light";
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import { urlG } from "../stores/urlStore";
|
||||
import ModalPublicarPropiedadParaVenta from "./ModalPublicarPropiedadParaVenta.svelte";
|
||||
import type { setVenta } from "../types";
|
||||
|
||||
let modal: boolean = $state(false);
|
||||
let modalpayload: string = $state("");
|
||||
@@ -41,8 +42,27 @@
|
||||
function setventa() {
|
||||
showPublicarVenta = true;
|
||||
}
|
||||
async function sendMod() {
|
||||
|
||||
async function sendMod(data:setVenta) {
|
||||
data.idpropiedad = id;
|
||||
try {
|
||||
const responce = await fetch(String($urlG)+"/api/propiedad/setPropiedadAVenta", {
|
||||
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();
|
||||
modalpayload = json.message;
|
||||
modal = true;
|
||||
}catch (e){
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
159
Front/src/paginas/MisPropiedadesEnVenta.svelte
Normal file
159
Front/src/paginas/MisPropiedadesEnVenta.svelte
Normal 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>
|
||||
13
Front/src/types.d.ts
vendored
13
Front/src/types.d.ts
vendored
@@ -193,4 +193,17 @@ export type setVenta = {
|
||||
idpropiedad:number,
|
||||
monto:number,
|
||||
iddivisa:number,
|
||||
}
|
||||
|
||||
export type PatchPropiedad = {
|
||||
id:number,
|
||||
ubicacion:string,
|
||||
canthabitaciones:number,
|
||||
piso:number,
|
||||
letra:string,
|
||||
email:string,
|
||||
tipo:number,
|
||||
servicios: string[],
|
||||
monto:number,
|
||||
iddivisa:number
|
||||
}
|
||||
Reference in New Issue
Block a user