Explorar el Código

Code cleanup on porperty pages

master
George Williams hace 5 años
padre
commit
bb14f43e35

+ 42
- 67
src/components/property/propertyeditPage.vue Ver fichero

@@ -193,13 +193,13 @@
193 193
             </div>
194 194
             <div class="form-group row" />
195 195
             <UserField
196
-              v-if="ApiRunning & propertyType === 'Residential'"
197
-              :fields="propValuesProp[0].fields"
196
+              v-if="propertyType === 'Residential' & propertyOverviewFields.length > 0"
197
+              :fields="propertyOverviewFields[0].fields"
198 198
               :id="overviewProps"
199 199
               @UpdateUserDefinedFields="UpdateUserDefinedFields"
200 200
             ></UserField>
201 201
             <div class="form-group row" />
202
-            <div v-for="item in propertyValues" :key="item.id">
202
+            <div v-for="item in propertyFields" :key="item.id">
203 203
               <div class="row">
204 204
                 <div class="col-sm-12">
205 205
                   <div class="title-box-d">
@@ -228,12 +228,6 @@
228 228
               class="btn btn-b-n"
229 229
               style="width: 85px; height:40px;"
230 230
             >Save</button>
231
-            <!-- <router-link
232
-              to="/property/search"
233
-              @click.stop.prevent="SubmitData()"
234
-              class="btn btn-b"
235
-              tag="button"
236
-            >Save</router-link>-->
237 231
           </form>
238 232
         </div>
239 233
       </div>
@@ -242,8 +236,10 @@
242 236
 </template>
243 237
 
244 238
 <script>
239
+import { mapState, mapActions } from 'vuex';
245 240
 import UserField from './propertyUserField.vue';
246 241
 import ImageLoad from './propertyImage.vue';
242
+
247 243
 // https://vuejsexamples.com/a-vue-wrapper-around-the-trix-rich-text-editor/
248 244
 export default {
249 245
   name: 'PropertyEdit',
@@ -253,16 +249,8 @@ export default {
253 249
   },
254 250
   data() {
255 251
     return {
256
-      ApiRunning: true,
257 252
       propertyType: 'Residential',
258 253
       salesType: 'Rental',
259
-      imageFile: '',
260
-      provinces: [],
261
-      cities: [],
262
-      suburbs: [],
263
-      propertyValues: [],
264
-      propValuesProp: [],
265
-      propertyTypes: [],
266 254
       selectedProvince: '',
267 255
       selectedCity: '',
268 256
       property: {
@@ -287,6 +275,13 @@ export default {
287 275
     };
288 276
   },
289 277
   methods: {
278
+    ...mapActions('searchTab', ['getProvince', 'getCities', 'getSuburbs']),
279
+    ...mapActions('property', [
280
+      'getPropertyTypes',
281
+      'getPropertyOverviewFields',
282
+      'getPropertyFields',
283
+      'saveProperty',
284
+    ]),
290 285
     SubmitData() {
291 286
       let isDefault = true;
292 287
       this.images.forEach((imagedata) => {
@@ -298,13 +293,7 @@ export default {
298 293
       });
299 294
       this.property.propertyUserFields = this.propertyFieldValues;
300 295
 
301
-      const axios = require('axios');
302
-      axios
303
-        .post('http://localhost:57260/Property/Property', this.property)
304
-        .then((response) => {})
305
-        .catch((e) => {
306
-          alert(e);
307
-        });
296
+      this.saveProperty(Object.assign({}, { newProperty: this.property }));
308 297
 
309 298
       this.$router.push({
310 299
         path: '/property/search',
@@ -316,12 +305,7 @@ export default {
316 305
         this.selectedProvince = this.provinces[
317 306
           item.target.options.selectedIndex - 1
318 307
         ].description;
319
-        const axios = require('axios');
320
-        axios
321
-          .get(
322
-            `http://localhost:57260/region/city/getby/${this.selectedProvince}`,
323
-          )
324
-          .then(response => (this.cities = response.data));
308
+        this.getCities(Object.assign({}, { province: this.selectedProvince }));
325 309
       }
326 310
     },
327 311
     CitySelected(item) {
@@ -329,12 +313,12 @@ export default {
329 313
         this.selectedCity = this.cities[
330 314
           item.target.options.selectedIndex - 1
331 315
         ].description;
332
-        const axios = require('axios');
333
-        axios
334
-          .get(
335
-            `http://localhost:57260/region/Suburb/${this.selectedProvince}/${this.selectedCity}`,
336
-          )
337
-          .then(response => (this.suburbs = response.data));
316
+        this.getSuburbs(
317
+          Object.assign(
318
+            {},
319
+            { province: this.selectedProvince, city: this.selectedCity },
320
+          ),
321
+        );
338 322
       }
339 323
     },
340 324
     loadedImages(values) {
@@ -357,44 +341,35 @@ export default {
357 341
     this.propertyType = this.$route.params.propType;
358 342
     this.salesType = this.$route.params.saleType;
359 343
 
360
-    const axios = require('axios');
361
-    axios
362
-      .get('http://localhost:57260/Property/PropertyFields/Property Overview')
363
-      .then(response => (this.propValuesProp = response.data));
364
-
365
-    axios
366
-      .get(
367
-        `http://localhost:57260/property/propertyfields/Propertytype/${this.propertyType}`,
368
-      )
369
-      .then(response => (this.propertyValues = response.data));
370
-
371
-    axios
372
-      .get(
373
-        `http://localhost:57260/Property/PropertyType/type/${this.propertyType}`,
374
-      )
375
-      .then(response => (this.propertyTypes = response.data));
376
-
377
-    axios
378
-      .get('http://localhost:57260/region/province')
379
-      .then(response => (this.provinces = response.data));
344
+    this.getProvince();
345
+    this.getPropertyTypes(
346
+      Object.assign({}, { propertyType: this.$route.params.propType }),
347
+    );
348
+    this.getPropertyOverviewFields();
349
+    this.getPropertyFields(
350
+      Object.assign({}, { propertyType: this.$route.params.propType }),
351
+    );
380 352
   },
381 353
   computed: {
354
+    ...mapState('searchTab', ['provinces', 'cities', 'suburbs']),
355
+    ...mapState('property', [
356
+      'propertyTypes',
357
+      'propertyOverviewFields',
358
+      'propertyFields',
359
+    ]),
382 360
     SalesTypeChanged() {
361
+      // eslint-disable-next-line vue/no-side-effects-in-computed-properties
383 362
       this.propertyType = this.$route.params.propType;
363
+      // eslint-disable-next-line vue/no-side-effects-in-computed-properties
384 364
       this.salesType = this.$route.params.saleType;
385 365
 
386
-      const axios = require('axios');
387
-      axios
388
-        .get(
389
-          `http://localhost:57260/Property/PropertyType/type/${this.propertyType}`,
390
-        )
391
-        .then(response => (this.propertyTypes = response.data));
366
+      this.getPropertyTypes(
367
+        Object.assign({}, { propertyType: this.$route.params.propType }),
368
+      );
392 369
 
393
-      axios
394
-        .get(
395
-          `http://localhost:57260/property/propertyfields/Propertytype/${this.propertyType}`,
396
-        )
397
-        .then(response => (this.propertyValues = response.data));
370
+      this.getPropertyFields(
371
+        Object.assign({}, { propertyType: this.$route.params.propType }),
372
+      );
398 373
 
399 374
       return this.propertyType;
400 375
     },

+ 3
- 1
src/components/shared/lightBoxGallery.vue Ver fichero

@@ -31,7 +31,7 @@
31 31
       </div>
32 32
 
33 33
       <div class="light-box__caption" v-if="caption">
34
-        <!-- <p v-if="captions[currentImage]">{{ captions[currentImage]}}</p> -->
34
+        <p v-if="captions[currentImage]">{{ captions[currentImage]}}</p>
35 35
       </div>
36 36
 
37 37
       <div @click="next" class="light-box__next light-box__btn"></div>
@@ -78,6 +78,7 @@ export default {
78 78
     },
79 79
     next() {
80 80
       if (this.currentImage < this.largeImages.length - 1) {
81
+        // eslint-disable-next-line no-plusplus
81 82
         this.currentImage++;
82 83
       } else {
83 84
         this.currentImage = 0;
@@ -85,6 +86,7 @@ export default {
85 86
     },
86 87
     prev() {
87 88
       if (this.currentImage > 0) {
89
+        // eslint-disable-next-line no-plusplus
88 90
         this.currentImage--;
89 91
       } else {
90 92
         this.currentImage = this.largeImages.length - 1;

+ 37
- 0
src/store/modules/property/property.js Ver fichero

@@ -5,6 +5,9 @@ export default {
5 5
   state: {
6 6
     property: null,
7 7
     propertyImages: [],
8
+    propertyTypes: [],
9
+    propertyOverviewFields: [],
10
+    propertyFields: [],
8 11
   },
9 12
   mutations: {
10 13
     setProperty(state, property) {
@@ -13,6 +16,18 @@ export default {
13 16
     setPropertyImages(state, images) {
14 17
       state.propertyImages = images;
15 18
     },
19
+    setPropertyTypes(state, types) {
20
+      state.propertyTypes = types;
21
+    },
22
+    setPropertyOverviewFields(state, fields) {
23
+      state.propertyOverviewFields = fields;
24
+    },
25
+    setPropertyFields(state, fields) {
26
+      state.propertyFields = fields;
27
+    },
28
+    updateCurrentProperty(state, property) {
29
+      state.property = property;
30
+    },
16 31
   },
17 32
   getters: {},
18 33
   actions: {
@@ -28,5 +43,27 @@ export default {
28 43
         .then(result => commit('setPropertyImages', result.data))
29 44
         .catch(console.error);
30 45
     },
46
+    getPropertyTypes({ commit }, item) {
47
+      axios
48
+        .get(`http://localhost:57260/Property/PropertyType/type/${item.propertyType}`)
49
+        .then(result => commit('setPropertyTypes', result.data))
50
+        .catch(console.error);
51
+    },
52
+    getPropertyOverviewFields({ commit }) {
53
+      axios
54
+        .get('http://localhost:57260/Property/PropertyFields/Property Overview')
55
+        .then(response => commit('setPropertyOverviewFields', response.data));
56
+    },
57
+    getPropertyFields({ commit }, item) {
58
+      axios
59
+        .get(`http://localhost:57260/property/propertyfields/Propertytype/${item.propertyType}`)
60
+        .then(response => commit('setPropertyFields', response.data));
61
+    },
62
+    saveProperty({ commit }, item) {
63
+      axios
64
+        .post('http://localhost:57260/Property/Property', item.newProperty)
65
+        .then(result => commit('updateCurrentProperty', result.data))
66
+        .catch(console.error);
67
+    },
31 68
   },
32 69
 };

Loading…
Cancelar
Guardar