Browse Source

Code cleanup on porperty pages

master
George Williams 5 years ago
parent
commit
bb14f43e35

+ 42
- 67
src/components/property/propertyeditPage.vue View File

193
             </div>
193
             </div>
194
             <div class="form-group row" />
194
             <div class="form-group row" />
195
             <UserField
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
               :id="overviewProps"
198
               :id="overviewProps"
199
               @UpdateUserDefinedFields="UpdateUserDefinedFields"
199
               @UpdateUserDefinedFields="UpdateUserDefinedFields"
200
             ></UserField>
200
             ></UserField>
201
             <div class="form-group row" />
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
               <div class="row">
203
               <div class="row">
204
                 <div class="col-sm-12">
204
                 <div class="col-sm-12">
205
                   <div class="title-box-d">
205
                   <div class="title-box-d">
228
               class="btn btn-b-n"
228
               class="btn btn-b-n"
229
               style="width: 85px; height:40px;"
229
               style="width: 85px; height:40px;"
230
             >Save</button>
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
           </form>
231
           </form>
238
         </div>
232
         </div>
239
       </div>
233
       </div>
242
 </template>
236
 </template>
243
 
237
 
244
 <script>
238
 <script>
239
+import { mapState, mapActions } from 'vuex';
245
 import UserField from './propertyUserField.vue';
240
 import UserField from './propertyUserField.vue';
246
 import ImageLoad from './propertyImage.vue';
241
 import ImageLoad from './propertyImage.vue';
242
+
247
 // https://vuejsexamples.com/a-vue-wrapper-around-the-trix-rich-text-editor/
243
 // https://vuejsexamples.com/a-vue-wrapper-around-the-trix-rich-text-editor/
248
 export default {
244
 export default {
249
   name: 'PropertyEdit',
245
   name: 'PropertyEdit',
253
   },
249
   },
254
   data() {
250
   data() {
255
     return {
251
     return {
256
-      ApiRunning: true,
257
       propertyType: 'Residential',
252
       propertyType: 'Residential',
258
       salesType: 'Rental',
253
       salesType: 'Rental',
259
-      imageFile: '',
260
-      provinces: [],
261
-      cities: [],
262
-      suburbs: [],
263
-      propertyValues: [],
264
-      propValuesProp: [],
265
-      propertyTypes: [],
266
       selectedProvince: '',
254
       selectedProvince: '',
267
       selectedCity: '',
255
       selectedCity: '',
268
       property: {
256
       property: {
287
     };
275
     };
288
   },
276
   },
289
   methods: {
277
   methods: {
278
+    ...mapActions('searchTab', ['getProvince', 'getCities', 'getSuburbs']),
279
+    ...mapActions('property', [
280
+      'getPropertyTypes',
281
+      'getPropertyOverviewFields',
282
+      'getPropertyFields',
283
+      'saveProperty',
284
+    ]),
290
     SubmitData() {
285
     SubmitData() {
291
       let isDefault = true;
286
       let isDefault = true;
292
       this.images.forEach((imagedata) => {
287
       this.images.forEach((imagedata) => {
298
       });
293
       });
299
       this.property.propertyUserFields = this.propertyFieldValues;
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
       this.$router.push({
298
       this.$router.push({
310
         path: '/property/search',
299
         path: '/property/search',
316
         this.selectedProvince = this.provinces[
305
         this.selectedProvince = this.provinces[
317
           item.target.options.selectedIndex - 1
306
           item.target.options.selectedIndex - 1
318
         ].description;
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
     CitySelected(item) {
311
     CitySelected(item) {
329
         this.selectedCity = this.cities[
313
         this.selectedCity = this.cities[
330
           item.target.options.selectedIndex - 1
314
           item.target.options.selectedIndex - 1
331
         ].description;
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
     loadedImages(values) {
324
     loadedImages(values) {
357
     this.propertyType = this.$route.params.propType;
341
     this.propertyType = this.$route.params.propType;
358
     this.salesType = this.$route.params.saleType;
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
   computed: {
353
   computed: {
354
+    ...mapState('searchTab', ['provinces', 'cities', 'suburbs']),
355
+    ...mapState('property', [
356
+      'propertyTypes',
357
+      'propertyOverviewFields',
358
+      'propertyFields',
359
+    ]),
382
     SalesTypeChanged() {
360
     SalesTypeChanged() {
361
+      // eslint-disable-next-line vue/no-side-effects-in-computed-properties
383
       this.propertyType = this.$route.params.propType;
362
       this.propertyType = this.$route.params.propType;
363
+      // eslint-disable-next-line vue/no-side-effects-in-computed-properties
384
       this.salesType = this.$route.params.saleType;
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
       return this.propertyType;
374
       return this.propertyType;
400
     },
375
     },

+ 3
- 1
src/components/shared/lightBoxGallery.vue View File

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

+ 37
- 0
src/store/modules/property/property.js View File

5
   state: {
5
   state: {
6
     property: null,
6
     property: null,
7
     propertyImages: [],
7
     propertyImages: [],
8
+    propertyTypes: [],
9
+    propertyOverviewFields: [],
10
+    propertyFields: [],
8
   },
11
   },
9
   mutations: {
12
   mutations: {
10
     setProperty(state, property) {
13
     setProperty(state, property) {
13
     setPropertyImages(state, images) {
16
     setPropertyImages(state, images) {
14
       state.propertyImages = images;
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
   getters: {},
32
   getters: {},
18
   actions: {
33
   actions: {
28
         .then(result => commit('setPropertyImages', result.data))
43
         .then(result => commit('setPropertyImages', result.data))
29
         .catch(console.error);
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…
Cancel
Save