1
0
mirror of https://github.com/robonen/metr.git synced 2026-03-20 02:44:42 +00:00

Vue, back edited,added

This commit is contained in:
Konstantin Vinokurov
2022-05-31 00:39:41 +07:00
parent 2825c1a4c8
commit 9de12f2c3f
6 changed files with 99 additions and 22 deletions

View File

@@ -1,6 +1,6 @@
<template> <template>
<div class="about__user"> <div class="about__user">
<div class="about__title"><h2>Добавить объявление</h2></div> <div class="about__title"><h2>{{ editable ? 'Изменить' : 'Добавить' }} объявление</h2></div>
<div class="about__images"> <div class="about__images">
<div class="image__load" v-for="(img, i) in 3" :key="i"> <div class="image__load" v-for="(img, i) in 3" :key="i">
<input type="file" @change="previewFiles"> <input type="file" @change="previewFiles">
@@ -50,7 +50,7 @@
<input type="text" size="40" v-model.trim="offer.description"> <input type="text" size="40" v-model.trim="offer.description">
</div> </div>
</div> </div>
<button @click="addOffer">Отправить</button> <button @click="action">Отправить</button>
</div> </div>
</template> </template>
@@ -59,30 +59,49 @@ import offerService from "@/services/offer";
export default { export default {
name: "ProfileAbout", name: "ProfileAbout",
emits: ['updated'],
props: {
editData: {
type: Object,
default: null,
},
editable: {
type: Boolean,
default: false,
},
},
data() { data() {
return this.initialState() return this.initialState()
}, },
methods: { methods: {
async addOffer() { async action() {
const data = { ...this.offer }; const data = { ...this.offer };
data.user_id = this.$store.getters.user.id; data.user_id = this.$store.getters.user.id;
if (!this.editable)
offerService offerService
.add(data) .add(data)
.then(() => this.reset()) .then(() => this.reset())
.catch(() => alert('Ошибка!')); .catch(() => alert('Ошибка создания объявления!'));
else
offerService
.update(this.editData.id, data)
.then(() => this.$emit('updated'))
.catch(() => alert('Ошибка изменения объявления!'));
}, },
initialState() { initialState() {
const ed = this.editData;
return { return {
offer: { offer: {
name: '', name: ed ? ed.name : '',
type: 'Flat', type: ed ? ed.type : 'Flat',
location: '', location: ed ? ed.location : '',
price: '', price: ed ? ed.price : '',
rooms: 1, rooms: ed ? ed.rooms : 1,
space: '', space: ed ? ed.space : '',
description: '', description: ed ? ed.description : '',
is_group: 1, is_group: 1,
}, },
files: [], files: [],
@@ -94,6 +113,11 @@ export default {
previewFiles(event) { previewFiles(event) {
this.files.push(event.target.files[0]); this.files.push(event.target.files[0]);
}, },
},
watch: {
editData() {
this.reset();
}
} }
} }
</script> </script>
@@ -103,7 +127,6 @@ export default {
.about__load{ .about__load{
position: absolute; position: absolute;
width: 100%; width: 100%;
margin-left: 40%; margin-left: 40%;
} }

View File

@@ -24,8 +24,27 @@
</template> </template>
<script> <script>
import offerService from "@/services/offer";
import ProfileAddOffer from "@/components/ProfileAddOffer.vue";
export default { export default {
name: "ProfileAbout" name: "ProfileAbout",
components: {ProfileAddOffer},
data() {
return {
activeId: null,
offers: [],
};
},
methods: {
async loadOffers() {
const offers = await offerService.allUserOffers();
this.offers = offers.data.data;
}
},
async mounted() {
await this.loadOffers();
}
} }
</script> </script>
@@ -44,7 +63,6 @@ export default {
.about__images { .about__images {
display: flex; display: flex;
flex-direction: row;
justify-content: space-between; justify-content: space-between;
margin-top: 1%; margin-top: 1%;
} }

View File

@@ -5,6 +5,18 @@ export const OfferService = {
const resp = await api.post('/offers', data); const resp = await api.post('/offers', data);
return resp; return resp;
}, },
async update(id, data) {
const resp = await api.put(`/offers/${id}`, data);
return resp;
},
async allUserOffers() {
const resp = await api.get('/users/offers');
return resp;
},
async getById(id) {
const resp = await api.get(`/offers/${id}`);
return resp;
}
}; };
export default OfferService; export default OfferService;

View File

@@ -66,7 +66,7 @@
</template> </template>
<script> <script>
import TheHeader from "../components/TheHeader.vue"; import TheHeader from "@/components/TheHeader.vue";
import TheFooter from "@/components/TheFooter.vue"; import TheFooter from "@/components/TheFooter.vue";
import CatalogType from "@/components/CatalogType.vue"; import CatalogType from "@/components/CatalogType.vue";

View File

@@ -6,11 +6,11 @@
<div class="adv__main"> <div class="adv__main">
<div class="adv__main__title"> <div class="adv__main__title">
<div class="mtitle"> <div class="mtitle">
<h2>4-к. квартира, 78,4 м², 20/28 эт.</h2> <h2>{{ offer.name }}</h2>
</div> </div>
<div class="mprice__fav"> <div class="mprice__fav">
<div class="price"> <div class="price">
<h2>40 610 000 </h2> <h2>{{ offer.price }} </h2>
</div> </div>
<!-- <a href="#" class="favoritext"><div class="favorite">--> <!-- <a href="#" class="favoritext"><div class="favorite">-->
<!-- <h4>Добавить в избранное</h4>--> <!-- <h4>Добавить в избранное</h4>-->
@@ -110,10 +110,34 @@
import RatingStars from "@/components/RatingStars.vue"; import RatingStars from "@/components/RatingStars.vue";
import TheHeader from "@/components/TheHeader.vue"; import TheHeader from "@/components/TheHeader.vue";
import TheFooter from "@/components/TheFooter.vue"; import TheFooter from "@/components/TheFooter.vue";
import offerService from "@/services/offer";
export default { export default {
name: "OfferView",
components: {TheFooter, TheHeader, RatingStars}, components: {TheFooter, TheHeader, RatingStars},
name: "OfferView" data() {
return {
offer: {}
};
},
computed: {
offerType() {
return {
'Flat': 'Квартира',
'House': 'Дом',
'Land': 'Участок',
}[this.offer.type];
}
},
async mounted() {
const id = this.$route.params.id;
if (id === undefined)
return this.$router.back();
const resp = await offerService.getById(id);
this.offer = resp.data.data;
}
} }
</script> </script>

View File

@@ -80,7 +80,7 @@ export default {
this.$router.push('/'); this.$router.push('/');
}); });
} }
} },
} }
</script>> </script>>