123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- import axios from "axios";
- import { Date } from "core-js";
- import { result } from "lodash";
- import { resolve } from "core-js/fn/promise";
-
- export default {
- namespaced: true,
- state: {
- statuses: [],
- property: {},
- propertyImages: [],
- propertyTypes: [],
- propertyTypesRes: [],
- propertyTypesCom: [],
- propertyOverviewFields: [],
- propertyFields: []
- },
- mutations: {
- setProperty(state, property) {
- state.property = property;
- },
- setPropertyImages(state, images) {
- state.propertyImages = images;
- state.propertyImageList = [];
- for (let i = 0; i < images.length; i++) {
- state.propertyImageList.push(images[i].image);
- }
- },
- setPropertyTypes(state, types) {
- state.propertyTypes = types;
- },
- setPropertyTypesRes(state, types) {
- state.propertyTypesRes = types;
- },
- setPropertyTypesCom(state, types) {
- state.propertyTypesCom = types;
- },
- setPropertyOverviewFields(state, fields) {
- state.propertyOverviewFields = fields;
- },
- setPropertyFields(state, fields) {
- state.propertyFields = fields;
- },
- updateCurrentProperty(state, property) {
- if (state.properties) {
- state.properties.push(property);
- }
- },
- clearPropertyImages(state) {
- state.propertyImages = [];
- },
- setStatuses(state, stats) {
- state.statuses = stats;
- }
- },
- getters: {},
- actions: {
- getStatuses({ commit }) {
- axios
- .get("/api/property/GetPropertyStatuses")
- .then(result => commit("setStatuses", result.data));
- },
- getProperty({ commit, dispatch }, id) {
- return new Promise((resolve, reject) => {
- axios
- .get(`/api/Property/getDetailed/${id}`)
- .then(result => {
- commit("setProperty", result.data);
- dispatch("getPropertyTypes", result.data.propertyUsageType);
- dispatch("getSavedPropertyImages", result.data.id);
- dispatch("getSavedPropertyFields", result.data.id);
- dispatch("getStatuses");
- resolve();
- })
- .catch(error => reject(new Error(error.message)));
- });
- },
- getPropertyImages({ commit }, id) {
- axios
- .get(`/api/PropertyImage/GetImagesByProperty/${id}`)
- .then(result => commit("setPropertyImages", result.data))
- .catch(console.error);
- },
- getSavedPropertyImages({ commit }, id) {
- axios
- .get(`/api/PropertyImage/GetProperySavedImages/${id}`)
- .then(result => commit("setPropertyImages", result.data))
- .catch(console.error);
- },
- getPropertyTypes({ commit }, propertyType) {
- axios
- .get(`/api/PropertyType/type/${propertyType}`)
- .then(result => commit("setPropertyTypes", result.data))
- .catch(console.error);
- },
- getPropertyTypesRes({ commit }) {
- axios
- .get("/api/PropertyType/type/Residential")
- .then(result => commit("setPropertyTypesRes", result.data))
- .catch(console.error);
- },
- getPropertyTypesCom({ commit }) {
- axios
- .get("/api/PropertyType/type/Commercial")
- .then(result => commit("setPropertyTypesCom", result.data))
- .catch(console.error);
- },
- getPropertyOverviewFields({ commit }) {
- axios
- .get("/api/PropertyFields/Property Overview")
- .then(response => commit("setPropertyOverviewFields", response.data));
- },
- getPropertyFields({ commit }, propertyType) {
- axios
- .get(`/api/propertyFields/PropertyType/${propertyType}`)
- .then(response => commit("setPropertyFields", response.data));
- },
- getSavedPropertyFields({ commit }, id) {
- axios
- .get(`/api/PropertyFields/GetSavedPropertyUserFields/${id}`)
- .then(result => commit("setPropertyFields", result.data));
- },
- getPropertySavedOverviewFields({ commit }, id) {
- axios
- .get(`/api/PropertyFields/GetSavedValues/Residential/Property Overview/${id}`)
- .then(response => commit("setPropertyOverviewFields", response.data))
- .catch(console.error);
- },
- getPropertySavedFields({ commit }, item) {
- axios
- .get(`/api/PropertyFields/GetSavedValues/${item.type}/All/${item.id}`)
- .then(response => commit("setPropertyFields", response.data))
- .catch(console.error);
- },
- saveProperty({ commit }, item) {
- return new Promise((resolve, reject) => {
- axios
- .post("/api/Property", item)
- .then(resp => {
- commit("updateCurrentProperty", resp);
- resolve(resp);
- })
- .catch(() => {
- reject(console.error);
- });
- });
- },
- clearProperty({ commit }) {
- axios
- .get("/api/Property/getDetailed/0")
- .then(result => {
- alert(JSON.stringify(result.data));
- commit("setProperty", result.data);
- })
- .catch(console.error);
- },
- clearPropertyImages({ commit }) {
- commit("clearPropertyImages");
- },
- getSavedPropertyData({ commit }, item) {
- commit("clearProperty");
- commit("clearPropertyImages");
-
- axios
- .get(`/api/Property/getProperty/${item.id}`)
- .then(result => commit("setProperty", result.data))
- .catch(console.error);
-
- axios
- .get(`/api/PropertyImage/GetProperySavedImages/${item.id}`)
- .then(result => commit("setPropertyImages", result.data))
- .catch(console.error);
-
- axios
- .get(`/api/PropertyFields/GetSavedValues/Residential/Property Overview/${item.id}`)
- .then(response => commit("setPropertyOverviewFields", response.data))
- .catch(console.error);
-
- axios
- .get(`/api/PropertyFields/GetSavedValues/${item.type}/All/${item.id}`)
- .then(response => commit("setPropertyFields", response.data))
- .catch(console.error);
- },
- getSavedPropertyImages({ commit }, id) {
- axios
- .get(`/api/PropertyImage/GetProperySavedImages/${id}`)
- .then(result => commit("setPropertyImages", result.data))
- .catch(console.error);
- },
- updateProperty({ commit }, property) {
- return new Promise((resolve, reject) => {
- axios
- .put("/api/property", property)
- .then(response => {
- resolve();
- })
- .catch(() => {
- reject(console.error);
- });
- });
- }
- }
- };
|