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:
@@ -3,14 +3,15 @@
|
|||||||
<div class="about__title"><h2>{{ editable ? 'Изменить' : 'Добавить' }} объявление</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 v-if="!files[i]" type="file" @change="uploadFile">
|
||||||
<img src="@/assets/images/image_load.png" alt="">
|
<div v-else class="about__delete" @click="deletePhoto(i)">
|
||||||
<div class="about__load">
|
|
||||||
<img src="@/assets/images/upload_log.svg" alt="">
|
|
||||||
</div>
|
|
||||||
<div class="about__delete">
|
|
||||||
<img src="@/assets/images/delete_log.svg" alt="">
|
<img src="@/assets/images/delete_log.svg" alt="">
|
||||||
</div>
|
</div>
|
||||||
|
<img v-if="!files[i]" src="@/assets/images/image_load.png" alt="">
|
||||||
|
<img v-else :src="url(files[i].file)" alt="">
|
||||||
|
<div v-if="!files[i]" class="about__load">
|
||||||
|
<img src="@/assets/images/upload_log.svg" alt="">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="about__delete">-->
|
<!-- <div class="about__delete">-->
|
||||||
@@ -61,6 +62,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import offerService from "@/services/offer";
|
import offerService from "@/services/offer";
|
||||||
|
import { getURL } from "@/services/images";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ProfileAbout",
|
name: "ProfileAbout",
|
||||||
@@ -81,17 +83,16 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
async action() {
|
async action() {
|
||||||
const data = { ...this.offer };
|
const data = { ...this.offer };
|
||||||
|
const files = [ ...this.files ];
|
||||||
data.user_id = this.$store.getters.user.id;
|
|
||||||
|
|
||||||
if (!this.editable)
|
if (!this.editable)
|
||||||
offerService
|
offerService
|
||||||
.add(data)
|
.add(data, files)
|
||||||
.then(() => this.reset())
|
.then(() => this.reset())
|
||||||
.catch(() => alert('Ошибка создания объявления!'));
|
.catch(() => alert('Ошибка создания объявления!'));
|
||||||
else
|
else
|
||||||
offerService
|
offerService
|
||||||
.update(this.editData.id, data)
|
.update(this.editData.id, data, files)
|
||||||
.then(() => this.$emit('updated'))
|
.then(() => this.$emit('updated'))
|
||||||
.catch(() => alert('Ошибка изменения объявления!'));
|
.catch(() => alert('Ошибка изменения объявления!'));
|
||||||
},
|
},
|
||||||
@@ -101,7 +102,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
offer: {
|
offer: {
|
||||||
name: ed ? ed.name : '',
|
name: ed ? ed.name : '',
|
||||||
type: ed ? ed.type : 'Flat',
|
type: ed ? ed.type : 'Studio',
|
||||||
location: ed ? ed.location : '',
|
location: ed ? ed.location : '',
|
||||||
price: ed ? ed.price : '',
|
price: ed ? ed.price : '',
|
||||||
rooms: ed ? ed.rooms : 1,
|
rooms: ed ? ed.rooms : 1,
|
||||||
@@ -109,15 +110,29 @@ export default {
|
|||||||
description: ed ? ed.description : '',
|
description: ed ? ed.description : '',
|
||||||
is_group: 1,
|
is_group: 1,
|
||||||
},
|
},
|
||||||
files: [],
|
files: ed ? ed.images : [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
reset() {
|
reset() {
|
||||||
Object.assign(this.$data, this.initialState());
|
Object.assign(this.$data, this.initialState());
|
||||||
},
|
},
|
||||||
previewFiles(event) {
|
async uploadFile(event) {
|
||||||
this.files.push(event.target.files[0]);
|
const file = event.target.files[0];
|
||||||
|
|
||||||
|
const res = await offerService.uploadImage(file);
|
||||||
|
|
||||||
|
this.files.push(res.data.data);
|
||||||
},
|
},
|
||||||
|
async deletePhoto(index) {
|
||||||
|
const id = this.files[index].id;
|
||||||
|
|
||||||
|
offerService.deleteImage(id);
|
||||||
|
|
||||||
|
this.files.splice(index, 1);
|
||||||
|
},
|
||||||
|
url(path) {
|
||||||
|
return getURL(path);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
editData() {
|
editData() {
|
||||||
@@ -171,6 +186,7 @@ export default {
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
top: 2%;
|
top: 2%;
|
||||||
right: 2%;
|
right: 2%;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.about__delete > img{
|
.about__delete > img{
|
||||||
|
|||||||
@@ -4,9 +4,10 @@
|
|||||||
<h2>Мои объявления</h2>
|
<h2>Мои объявления</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="my__offer">
|
<div class="my__offer">
|
||||||
<div class="about__images" @click="activeId = i" v-for="(img, i) in offers" :key="i">
|
<div class="about__images" @click="activeId = i" v-for="(offer, i) in offers" :key="i">
|
||||||
<div class="image__load">
|
<div class="image__load">
|
||||||
<img src="@/assets/images/image_load.png" alt="">
|
<img v-if="offer.images.length === 0" src="@/assets/images/image_load.png" alt="">
|
||||||
|
<img v-else :src="url(offer.images[0].file)" alt="">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<profile-add-offer v-if="activeId !== null" :edit-data="offers[activeId]" editable @updated="loadOffers"></profile-add-offer>
|
<profile-add-offer v-if="activeId !== null" :edit-data="offers[activeId]" editable @updated="loadOffers"></profile-add-offer>
|
||||||
@@ -26,6 +27,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import offerService from "@/services/offer";
|
import offerService from "@/services/offer";
|
||||||
import ProfileAddOffer from "@/components/ProfileAddOffer.vue";
|
import ProfileAddOffer from "@/components/ProfileAddOffer.vue";
|
||||||
|
import { getURL } from "@/services/images";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ProfileAbout",
|
name: "ProfileAbout",
|
||||||
@@ -40,6 +42,9 @@ export default {
|
|||||||
async loadOffers() {
|
async loadOffers() {
|
||||||
const offers = await offerService.allUserOffers();
|
const offers = await offerService.allUserOffers();
|
||||||
this.offers = offers.data.data;
|
this.offers = offers.data.data;
|
||||||
|
},
|
||||||
|
url(path) {
|
||||||
|
return getURL(path);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
import api from "@/services/api";
|
import api from "@/services/api";
|
||||||
|
|
||||||
export const OfferService = {
|
export const OfferService = {
|
||||||
async add(data) {
|
async add(data, files) {
|
||||||
|
data.images = files;
|
||||||
const resp = await api.post('/offers', data);
|
const resp = await api.post('/offers', data);
|
||||||
return resp;
|
return resp;
|
||||||
},
|
},
|
||||||
async update(id, data) {
|
async update(id, data, files) {
|
||||||
|
data.images = files;
|
||||||
const resp = await api.put(`/offers/${id}`, data);
|
const resp = await api.put(`/offers/${id}`, data);
|
||||||
return resp;
|
return resp;
|
||||||
},
|
},
|
||||||
|
async all() {
|
||||||
|
const resp = await api.get('/offers');
|
||||||
|
return resp;
|
||||||
|
},
|
||||||
async allUserOffers() {
|
async allUserOffers() {
|
||||||
const resp = await api.get('/users/offers');
|
const resp = await api.get('/users/offers');
|
||||||
return resp;
|
return resp;
|
||||||
@@ -16,6 +22,16 @@ export const OfferService = {
|
|||||||
async getById(id) {
|
async getById(id) {
|
||||||
const resp = await api.get(`/offers/${id}`);
|
const resp = await api.get(`/offers/${id}`);
|
||||||
return resp;
|
return resp;
|
||||||
|
},
|
||||||
|
async uploadImage(file) {
|
||||||
|
const resp = await api.postForm('/offers/images', {
|
||||||
|
'image': file,
|
||||||
|
});
|
||||||
|
return resp;
|
||||||
|
},
|
||||||
|
async deleteImage(id) {
|
||||||
|
const resp = await api.delete(`/offers/images/${id}`);
|
||||||
|
return resp;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,9 @@
|
|||||||
<div class="suggestions__images">
|
<div class="suggestions__images">
|
||||||
<div class="podlozhka" v-for="offer in offers">
|
<div class="podlozhka" v-for="offer in offers">
|
||||||
<router-link :to="`/catalog/${offer.id}`" class="nav__link" href="#">
|
<router-link :to="`/catalog/${offer.id}`" class="nav__link" href="#">
|
||||||
<div class="sugg__img"><a class="gradient" href="#"><img src="@/assets/images/1.jpg" alt=""></a></div>
|
<div class="sugg__img" :style="{
|
||||||
|
'background-image': url(offer.images.length !== 0 ? offer.images[0].file : '@/assets/images/1.jpg')
|
||||||
|
}"></div>
|
||||||
<div class="sugg__text"><p>{{offer.name}}</p><h2>{{ offer.price }}₽</h2></div>
|
<div class="sugg__text"><p>{{offer.name}}</p><h2>{{ offer.price }}₽</h2></div>
|
||||||
</router-link>
|
</router-link>
|
||||||
</div>
|
</div>
|
||||||
@@ -81,6 +83,8 @@
|
|||||||
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";
|
||||||
|
import offerService from "@/services/offer";
|
||||||
|
import { getURL } from "@/services/images";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "CatalogView",
|
name: "CatalogView",
|
||||||
@@ -91,10 +95,14 @@ export default {
|
|||||||
componentForm: ''
|
componentForm: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
url(path) {
|
||||||
|
return `url(${getURL(path)})`;
|
||||||
|
}
|
||||||
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
const requests = await fetch('http://tusur.tk:9080/api/offers');
|
const offers = await offerService.all();
|
||||||
const offers = await requests.json();
|
this.offers = offers.data.data;
|
||||||
this.offers = offers.data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user