diff --git a/frontend/src/components/ProfileAddOffer.vue b/frontend/src/components/ProfileAddOffer.vue index f4a3f23..8000e6c 100644 --- a/frontend/src/components/ProfileAddOffer.vue +++ b/frontend/src/components/ProfileAddOffer.vue @@ -1,6 +1,6 @@ - Добавить объявление + {{ editable ? 'Изменить' : 'Добавить' }} объявление @@ -50,7 +50,7 @@ - Отправить + Отправить @@ -59,30 +59,49 @@ import offerService from "@/services/offer"; export default { name: "ProfileAbout", + emits: ['updated'], + props: { + editData: { + type: Object, + default: null, + }, + editable: { + type: Boolean, + default: false, + }, + }, data() { return this.initialState() }, methods: { - async addOffer() { + async action() { const data = { ...this.offer }; data.user_id = this.$store.getters.user.id; - offerService - .add(data) - .then(() => this.reset()) - .catch(() => alert('Ошибка!')); + if (!this.editable) + offerService + .add(data) + .then(() => this.reset()) + .catch(() => alert('Ошибка создания объявления!')); + else + offerService + .update(this.editData.id, data) + .then(() => this.$emit('updated')) + .catch(() => alert('Ошибка изменения объявления!')); }, initialState() { + const ed = this.editData; + return { offer: { - name: '', - type: 'Flat', - location: '', - price: '', - rooms: 1, - space: '', - description: '', + name: ed ? ed.name : '', + type: ed ? ed.type : 'Flat', + location: ed ? ed.location : '', + price: ed ? ed.price : '', + rooms: ed ? ed.rooms : 1, + space: ed ? ed.space : '', + description: ed ? ed.description : '', is_group: 1, }, files: [], @@ -94,6 +113,11 @@ export default { previewFiles(event) { this.files.push(event.target.files[0]); }, + }, + watch: { + editData() { + this.reset(); + } } } @@ -103,7 +127,6 @@ export default { .about__load{ position: absolute; width: 100%; - margin-left: 40%; } diff --git a/frontend/src/components/ProfileMyOffers.vue b/frontend/src/components/ProfileMyOffers.vue index f42f95a..6586e91 100644 --- a/frontend/src/components/ProfileMyOffers.vue +++ b/frontend/src/components/ProfileMyOffers.vue @@ -24,8 +24,27 @@ @@ -44,7 +63,6 @@ export default { .about__images { display: flex; - flex-direction: row; justify-content: space-between; margin-top: 1%; } diff --git a/frontend/src/services/offer.js b/frontend/src/services/offer.js index de028b6..feda739 100644 --- a/frontend/src/services/offer.js +++ b/frontend/src/services/offer.js @@ -5,6 +5,18 @@ export const OfferService = { const resp = await api.post('/offers', data); 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; diff --git a/frontend/src/views/CatalogView.vue b/frontend/src/views/CatalogView.vue index 1b6d867..9ed2d15 100644 --- a/frontend/src/views/CatalogView.vue +++ b/frontend/src/views/CatalogView.vue @@ -66,7 +66,7 @@ diff --git a/frontend/src/views/ProfileView.vue b/frontend/src/views/ProfileView.vue index 57bb122..4f8d1d9 100644 --- a/frontend/src/views/ProfileView.vue +++ b/frontend/src/views/ProfileView.vue @@ -80,7 +80,7 @@ export default { this.$router.push('/'); }); } - } + }, } >