Browse Source

field editor comp - WIP

master
George Williams 5 years ago
parent
commit
2bb817ec66

+ 4
- 4
src/components/property/propertyFieldEditor.vue View File

@@ -47,7 +47,9 @@
47 47
           @change="SelectorSelected"
48 48
         >
49 49
           <option value="0"></option>
50
-          <option v-for="item in arrayObject" :value="item.id" :key="item.id">{{ item.description }}</option>
50
+          <option v-for="item in arrayObject" :value="item.id" :key="item.id">{{
51
+            item.description
52
+          }}</option>
51 53
         </select>
52 54
         <!-- yesno -->
53 55
         <select v-if="editType === 'yesno'" class="form-control" @change="YesNoSelected">
@@ -99,9 +101,7 @@ export default {
99 101
     },
100 102
     SelectorSelected(item) {
101 103
       if (item.target.options.selectedIndex > 0) {
102
-        this.updatedDisplay = this.arrayObject[
103
-          item.target.options.selectedIndex - 1
104
-        ].description;
104
+        this.updatedDisplay = this.arrayObject[item.target.options.selectedIndex - 1].description;
105 105
       }
106 106
     },
107 107
     YesNoSelected(item) {

+ 1
- 1
src/components/property/propertyImage.vue View File

@@ -28,7 +28,7 @@
28 28
         <label v-if="allowMultiple" for="checkbox" style="margin: 10px;">Main Image</label>
29 29
         <img :src="img" style="height:200px; width:150px; object-fit: cover;" />
30 30
         <br />
31
-        <span class="input-group-text" align="center" @click="removeImage(key)">
31
+        <span class="input-group-text" align="center" style="width:150px" @click="removeImage(key)">
32 32
           <eva-icon name="trash-2-outline" fill="#60CBEB"></eva-icon>Delete
33 33
         </span>
34 34
       </div>

+ 96
- 168
src/components/property/propertyeditPage.vue View File

@@ -35,13 +35,15 @@
35 35
       <div class="row mb-3">
36 36
         <div class="container col-md-10" style="text-align:left">
37 37
           <form id="mainForm">
38
+            <div class="form-goup row">
39
+              <div class="col-md-4">
40
+                <field :type="'datetime'" :mayEdit="true" />
41
+              </div>
42
+            </div>
38 43
             <div class="form-goup row">
39 44
               <div class="col-md-4">
40 45
                 <label>Usage Type</label>
41 46
                 <div class="input-group-prepend">
42
-                  <!-- <span class="input-group-text" style="color: #60CBEB">
43
-                    <b>U</b>
44
-                  </span>-->
45 47
                   <input
46 48
                     class="form-control"
47 49
                     type="text"
@@ -73,67 +75,51 @@
73 75
             <div class="form-group row">
74 76
               <div class="col-md-4">
75 77
                 <label>Property Type *</label>
76
-                <propField
77
-                  :display="property.propertyType ? property.propertyType.description : ''"
78
-                  :editType="'selector'"
79
-                  :arrayObject="propertyTypes"
80
-                  :propertyName="'propertyType'"
78
+                <field
79
+                  :type="'select'"
80
+                  :selectOptions="propertyTypes"
81
+                  :selectValue="'id'"
82
+                  :selectText="'description'"
83
+                  v-model="property.propertyType"
81 84
                   :mayEdit="mayEdit"
82
-                  @UpdateValue="UpdateValue"
83 85
                 />
84 86
               </div>
85 87
               <div v-if="propertyType === 'Commercial'" class="col-md-4">
86 88
                 <label>Property Name</label>
87
-                <propField
88
-                  :display="property.propertyName"
89
-                  :editType="'text'"
90
-                  :propertyName="'propertyName'"
91
-                  :mayEdit="mayEdit"
92
-                  @UpdateValue="UpdateValue"
93
-                />
89
+                <field :type="'text'" v-model="property.propertyName" :mayEdit="mayEdit" />
94 90
               </div>
95 91
               <div v-if="propertyType === 'Commercial'" class="col-md-4">
96 92
                 <label>Unit</label>
97
-                <propField
98
-                  :label="'Property Type'"
99
-                  :display="property.unit"
100
-                  :editType="'text'"
101
-                  :propertyName="'unit'"
102
-                  :mayEdit="mayEdit"
103
-                  @UpdateValue="UpdateValue"
104
-                />
93
+                <field :type="'text'" v-model="property.unit" :mayEdit="mayEdit" />
105 94
               </div>
106 95
             </div>
107 96
             <div class="form-group row">
108 97
               <div class="col-md-6" style="margin-bottom: 1em">
109 98
                 <label>Street Number</label>
110
-                <propField
111
-                  :display="property.addressLine1"
112
-                  :editType="'text'"
113
-                  :propertyName="'addressLine1'"
114
-                  :mayEdit="mayEdit"
115
-                  @UpdateValue="UpdateValue"
116
-                />
99
+                <field :type="'text'" v-model="property.addressLine1" :mayEdit="mayEdit" />
117 100
               </div>
118 101
               <div class="col-md-6" style="margin-bottom: 1em">
119 102
                 <label>Street Name</label>
120
-                <propField
121
-                  :display="property.addressLine2"
122
-                  :editType="'text'"
123
-                  :propertyName="'addressLine2'"
124
-                  :mayEdit="mayEdit"
125
-                  @UpdateValue="UpdateValue"
126
-                />
103
+                <field :type="'text'" v-model="property.addressLine2" :mayEdit="mayEdit" />
127 104
               </div>
128 105
               <div class="col-md-6" style="margin-bottom: 1em">
129 106
                 <label>Province *</label>
130
-                <propField
107
+                <!-- <propField
131 108
                   :display="property.province ? property.province.description : ''"
132 109
                   :editType="'selector'"
133 110
                   :arrayObject="provinces"
134 111
                   :propertyName="'province'"
135 112
                   :mayEdit="mayEdit"
136 113
                   @UpdateValue="UpdateValue"
114
+                />-->
115
+                <field
116
+                  :type="'select'"
117
+                  :selectOptions="provinces"
118
+                  :selectValue="'id'"
119
+                  :selectText="'description'"
120
+                  v-model="property.province"
121
+                  :mayEdit="mayEdit"
122
+                  @change="provChanged"
137 123
                 />
138 124
                 <div v-if="showProvinceError">
139 125
                   <p class="alert myError">Please select a Province</p>
@@ -141,27 +127,45 @@
141 127
               </div>
142 128
               <div class="col-md-6" style="margin-bottom: 1em">
143 129
                 <label>City *</label>
144
-                <propField
130
+                <!-- <propField
145 131
                   :display="property.city ? property.city.description : ''"
146 132
                   :editType="'selector'"
147 133
                   :arrayObject="cities"
148 134
                   :propertyName="'city'"
149 135
                   :mayEdit="mayEdit"
150 136
                   @UpdateValue="UpdateValue"
137
+                />-->
138
+                <field
139
+                  :type="'select'"
140
+                  :selectOptions="cities"
141
+                  :selectValue="'id'"
142
+                  :selectText="'description'"
143
+                  v-model="property.city"
144
+                  :mayEdit="mayEdit"
145
+                  @change="cityChanged"
151 146
                 />
152 147
                 <div v-if="showCityError">
153 148
                   <p class="alert myError">Please select a City</p>
154 149
                 </div>
155 150
               </div>
156 151
               <div class="col-md-6" style="margin-bottom: 1em">
157
-                <label>Suburb * </label>
158
-                <propField
152
+                <label>Suburb *</label>
153
+                <!-- <propField
159 154
                   :display="property.suburb ? property.suburb.description : ''"
160 155
                   :editType="'selector'"
161 156
                   :arrayObject="suburbs"
162 157
                   :propertyName="'suburb'"
163 158
                   :mayEdit="mayEdit"
164 159
                   @UpdateValue="UpdateValue"
160
+                />-->
161
+                <field
162
+                  :type="'select'"
163
+                  :selectOptions="suburbs"
164
+                  :selectValue="'id'"
165
+                  :selectText="'description'"
166
+                  v-model="property.suburb"
167
+                  :mayEdit="mayEdit"
168
+                  @change="suburbChanged"
165 169
                 />
166 170
                 <div v-if="showSuburbError">
167 171
                   <p class="alert myError">Please select a suburb</p>
@@ -169,13 +173,7 @@
169 173
               </div>
170 174
               <div class="col-md-6" style="margin-bottom: 1em">
171 175
                 <label>Postal Code</label>
172
-                <propField
173
-                  :display="property.addressLine3"
174
-                  :editType="'text'"
175
-                  :propertyName="'addressLine3'"
176
-                  :mayEdit="mayEdit"
177
-                  @UpdateValue="UpdateValue"
178
-                />
176
+                <field :type="'text'" v-model="property.addressLine3" :mayEdit="mayEdit" />
179 177
               </div>
180 178
             </div>
181 179
 
@@ -183,23 +181,30 @@
183 181
               <div class="col-md-6">
184 182
                 <label v-if="salesType === 'Rental'">Rental Price</label>
185 183
                 <label v-if="salesType !== 'Rental'">Sales Price</label>
186
-                <propField
184
+                <field :type="'number'" v-model="property.price" :mayEdit="mayEdit" />
185
+                <!-- <propField
187 186
                   :display="String(property.price)"
188 187
                   :editType="'number'"
189 188
                   :propertyName="'price'"
190 189
                   :mayEdit="mayEdit"
191 190
                   @UpdateValue="UpdateValue"
192
-                />
191
+                />-->
193 192
               </div>
194 193
               <div class="col-md-6" v-if="salesType === 'Rental'">
195 194
                 <label>Per</label>
196
-                <propField
195
+                <!-- <propField
197 196
                   :display="property.pricePer"
198 197
                   :editType="'selector'"
199 198
                   :propertyName="'pricePer'"
200 199
                   :arrayObject="pricePerArr"
201 200
                   :mayEdit="mayEdit"
202 201
                   @UpdateValue="UpdateValue"
202
+                />-->
203
+                <field
204
+                  :type="'selectlist'"
205
+                  :selectOptions="pricePerArr"
206
+                  v-model="property.pricePer"
207
+                  :mayEdit="mayEdit"
203 208
                 />
204 209
               </div>
205 210
             </div>
@@ -271,25 +276,13 @@
271 276
             <div class="form-group row">
272 277
               <div class="col-md-12">
273 278
                 <label>Virtual Tour (URL)</label>
274
-                <propField
275
-                  :display="property.virtualTour"
276
-                  :editType="'text'"
277
-                  :propertyName="'virtualTour'"
278
-                  :mayEdit="mayEdit"
279
-                  @UpdateValue="UpdateValue"
280
-                />
279
+                <field :type="'text'" v-model="property.virtualTour" :mayEdit="mayEdit" />
281 280
               </div>
282 281
             </div>
283 282
             <div class="form-group row">
284 283
               <div class="col-md-12">
285 284
                 <label>Video (URL)</label>
286
-                <propField
287
-                  :display="property.video"
288
-                  :editType="'text'"
289
-                  :propertyName="'video'"
290
-                  :mayEdit="mayEdit"
291
-                  @UpdateValue="UpdateValue"
292
-                />
285
+                <field :type="'text'" v-model="property.video" :mayEdit="mayEdit" />
293 286
               </div>
294 287
             </div>
295 288
             <div class="form-group row">
@@ -319,6 +312,7 @@
319 312
                   class="input-group-text spanCursor"
320 313
                   align="center"
321 314
                   @click="DeleteImage(img)"
315
+                  style="width:150px"
322 316
                 >
323 317
                   <eva-icon name="trash-2-outline" fill="#60CBEB"></eva-icon>Delete
324 318
                 </span>
@@ -371,6 +365,7 @@ import { mapState, mapActions } from 'vuex';
371 365
 import { VueEditor } from 'vue2-editor';
372 366
 import ImageLoad from './propertyImage.vue';
373 367
 import propField from './propertyFieldEditor.vue';
368
+import field from '../shared/fieldEditor.vue';
374 369
 
375 370
 export default {
376 371
   name: 'PropertyEdit',
@@ -378,6 +373,7 @@ export default {
378 373
     ImageLoad,
379 374
     VueEditor,
380 375
     propField,
376
+    field,
381 377
   },
382 378
   data() {
383 379
     return {
@@ -399,10 +395,8 @@ export default {
399 395
         { id: 1, description: 'Sale' },
400 396
         { id: 2, description: 'Rental' },
401 397
       ],
402
-      pricePerArr: [
403
-        { id: 'Month', description: 'Month' },
404
-        { id: 'Day', description: 'Day' },
405
-      ],
398
+      pricePerArr: ['Month', 'Day'],
399
+      yesno: ['Yes', 'No'],
406 400
       showPropertyTypeError: false,
407 401
       showProvinceError: false,
408 402
       showCityError: false,
@@ -418,6 +412,38 @@ export default {
418 412
     ]),
419 413
     ...mapActions('property', ['getPropertyTypes']),
420 414
     ...mapActions('propertyEdit', ['getSavedPropertyData', 'updateProperty', 'mayEditProperty']),
415
+    provChanged(item) {
416
+      this.getCities(Object.assign({}, { province: item.description }));
417
+      this.property.city = null;
418
+      this.property.suburb = null;
419
+      this.property.addressLine3 = '';
420
+      this.showProvinceError = false;
421
+      this.showCityError = true;
422
+      this.showSuburbError = true;
423
+    },
424
+    cityChanged(item) {
425
+      this.getSuburbs(
426
+        Object.assign(
427
+          {},
428
+          {
429
+            province: this.property.province.description,
430
+            city: item.description,
431
+          },
432
+        ),
433
+      );
434
+      this.property.suburb = null;
435
+      this.property.addressLine3 = '';
436
+      this.showCityError = false;
437
+      this.showSuburbError = true;
438
+    },
439
+    suburbChanged(item) {
440
+      const newSuburb = this.suburbs.find(p => p.description === item.description);
441
+      this.property.addressLine3 = newSuburb.postalCode;
442
+      this.showSuburbError = false;
443
+    },
444
+    salesTypeChanged(item) {
445
+      console.log(item);
446
+    },
421 447
     UpdateValue(item) {
422 448
       if (item.isUDF) {
423 449
         if (item.isPropOverview) {
@@ -434,104 +460,6 @@ export default {
434 460
             } else isSaleValue = false;
435 461
             this.property.isSale = isSaleValue;
436 462
           }
437
-          if (item.fieldName === 'propertyType') {
438
-            if (item.value !== '') {
439
-              this.property.propertyType = this.propertyTypes.find(
440
-                pt => pt.description === item.value,
441
-              );
442
-              this.property.propertyTypeId = this.property.propertyType.id;
443
-              this.showPropertyTypeError = false;
444
-            } else {
445
-              this.showPropertyTypeError = true;
446
-            }
447
-          }
448
-          if (item.fieldName === 'propertyName') {
449
-            this.property.propertyName = item.value;
450
-          }
451
-          if (item.fieldName === 'unit') {
452
-            this.property.unit = item.value;
453
-          }
454
-          if (item.fieldName === 'addressLine1') {
455
-            this.property.addressLine1 = item.value;
456
-          }
457
-          if (item.fieldName === 'addressLine2') {
458
-            this.property.addressLine2 = item.value;
459
-          }
460
-          if (item.fieldName === 'addressLine3') {
461
-            this.property.addressLine3 = item.value;
462
-          }
463
-          if (item.fieldName === 'province') {
464
-            if (item.value !== '') {
465
-              this.property.province = this.provinces.find(p => p.description === item.value);
466
-              this.property.provinceId = this.property.province.id;
467
-              this.getCities(Object.assign({}, { province: item.value }));
468
-              this.property.city = null;
469
-              this.property.suburb = null;
470
-              this.property.addressLine3 = '';
471
-              this.showProvinceError = false;
472
-              this.showCityError = true;
473
-              this.showSuburbError = true;
474
-            } else {
475
-              this.property.province = null;
476
-              this.property.city = null;
477
-              this.property.suburb = null;
478
-              this.property.addressLine3 = '';
479
-              this.cities = [];
480
-              this.suburbs = [];
481
-              this.showProvinceError = true;
482
-            }
483
-          }
484
-          if (item.fieldName === 'city') {
485
-            if (item.value !== '') {
486
-              const newCity = this.cities.find(p => p.description === item.value);
487
-              this.property.city = newCity;
488
-              this.property.cityId = newCity.id;
489
-              this.getSuburbs(
490
-                Object.assign(
491
-                  {},
492
-                  {
493
-                    province: this.property.province.description,
494
-                    city: item.value,
495
-                  },
496
-                ),
497
-              );
498
-              this.property.suburb = null;
499
-              this.property.addressLine3 = '';
500
-              this.showCityError = false;
501
-              this.showSuburbError = true;
502
-            } else {
503
-              this.property.city = null;
504
-              this.property.suburb = null;
505
-              this.property.addressLine3 = '';
506
-              this.suburbs = [];
507
-              this.showCityError = true;
508
-            }
509
-          }
510
-          if (item.fieldName === 'suburb') {
511
-            if (item.value !== '') {
512
-              const newSuburb = this.suburbs.find(p => p.description === item.value);
513
-              this.property.suburb = newSuburb;
514
-              this.property.suburbId = newSuburb.id;
515
-              this.property.addressLine3 = this.property.suburb.postalCode;
516
-              this.showSuburbError = false;
517
-            } else {
518
-              this.property.suburb = null;
519
-              this.property.addressLine3 = '';
520
-              this.showSuburbError = true;
521
-            }
522
-          }
523
-          if (item.fieldName === 'price') {
524
-            this.property.price = item.value;
525
-          }
526
-          if (item.fieldName === 'pricePer') {
527
-            this.property.pricePer = item.value;
528
-          }
529
-          if (item.fieldName === 'virtualTour') {
530
-            this.property.virtualTour = item.value;
531
-          }
532
-          if (item.fieldName === 'video') {
533
-            this.property.video = item.value;
534
-          }
535 463
         }
536 464
       }
537 465
     },

+ 118
- 0
src/components/shared/fieldEditor.vue View File

@@ -0,0 +1,118 @@
1
+<template>
2
+  <div>
3
+    <div v-if="!edit" class="input-group-prepend">
4
+      <input class="form-control" v-model="myDisplay" disabled />
5
+      <span
6
+        v-if="mayEdit"
7
+        @click="EditClick()"
8
+        class="input-group-text spanCursor"
9
+        style="color: #60CBEB"
10
+      >
11
+        <eva-icon name="edit-outline" fill="#60CBEB"></eva-icon>
12
+      </span>
13
+    </div>
14
+    <div v-if="edit" class="input-group-prepend">
15
+      <input v-if="type === 'text'" class="form-control" v-model="value" />
16
+      <input v-if="type === 'number'" type="number" class="form-control" v-model="value" />
17
+      <select v-if="type === 'select'" class="form-control" @change="selectionClick">
18
+        <option>Please select</option>
19
+        <option
20
+          v-for="option in selectOptions"
21
+          :value="option[selectValue]"
22
+          :key="option[selectValue]"
23
+          >{{ option[selectText] }}</option
24
+        >
25
+      </select>
26
+      <select v-if="type === 'selectlist'" class="form-control" v-model="value">
27
+        <option v-for="item in selectOptions" :value="item" :key="item">{{ item }}</option>
28
+      </select>
29
+      <!-- <Datetime class="form-control" v-if="type === 'datetime'" v-model="value" /> -->
30
+      <span
31
+        v-if="edit"
32
+        @click="UpdateValue()"
33
+        class="input-group-text spanCursor"
34
+        style="color: #60CBEB"
35
+      >
36
+        <eva-icon name="checkmark-outline" fill="#60CBEB"></eva-icon>
37
+      </span>
38
+      <span v-if="edit" @click="Close()" class="input-group-text spanCursor" style="color: #60CBEB">
39
+        <eva-icon name="close-outline" fill="#60CBEB"></eva-icon>
40
+      </span>
41
+    </div>
42
+  </div>
43
+</template>
44
+
45
+<script>
46
+export default {
47
+  props: ['value', 'type', 'mayEdit', 'selectOptions', 'selectValue', 'selectText', 'display'],
48
+  data() {
49
+    return {
50
+      edit: false,
51
+      myDisplay: '',
52
+    };
53
+  },
54
+  methods: {
55
+    UpdateValue() {
56
+      this.edit = false;
57
+      if (this.type !== 'select' && this.value) {
58
+        this.$emit('input', this.value);
59
+        this.$emit('change', this.value);
60
+      }
61
+    },
62
+    EditClick() {
63
+      this.edit = true;
64
+    },
65
+    Close() {
66
+      this.edit = false;
67
+    },
68
+    selectionClick(item) {
69
+      if (item.target.options.selectedIndex > 0) {
70
+        if (!this.value) {
71
+          this.myDisplay = this.selectOptions[item.target.options.selectedIndex - 1][
72
+            this.selectText
73
+          ];
74
+        }
75
+        if (this.selectOptions[item.target.options.selectedIndex - 1]) {
76
+          this.$emit('input', this.selectOptions[item.target.options.selectedIndex - 1]);
77
+          this.$emit('change', this.selectOptions[item.target.options.selectedIndex - 1]);
78
+        }
79
+      }
80
+    },
81
+  },
82
+  mounted() {
83
+    if (this.value) {
84
+      // eslint-disable-next-line vue/no-side-effects-in-computed-properties
85
+      this.myDisplay = this.value;
86
+    }
87
+    if (this.value && this.selectText) {
88
+      // eslint-disable-next-line vue/no-side-effects-in-computed-properties
89
+      this.myDisplay = this.value[this.selectText];
90
+    }
91
+    if (this.display) {
92
+      this.myDisplay = this.display;
93
+    }
94
+  },
95
+  computed: {
96
+    // eslint-disable-next-line vue/return-in-computed-property
97
+    checkValue() {
98
+      if (this.value) {
99
+        // eslint-disable-next-line vue/no-side-effects-in-computed-properties
100
+        this.myDisplay = this.value;
101
+      }
102
+      if (this.value && this.selectText) {
103
+        // eslint-disable-next-line vue/no-side-effects-in-computed-properties
104
+        this.myDisplay = this.value[this.selectText];
105
+      }
106
+      if (this.display) {
107
+        // eslint-disable-next-line vue/no-side-effects-in-computed-properties
108
+        this.myDisplay = this.display;
109
+      }
110
+    },
111
+  },
112
+  watch: {
113
+    checkValue() {
114
+      return null;
115
+    },
116
+  },
117
+};
118
+</script>

Loading…
Cancel
Save