You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

propertyeditPage.vue 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <!-- eslint-disable max-len -->
  3. <div>
  4. <div class="container">
  5. <div class="col-sm-12">
  6. <div class="tobuy-img-box">
  7. <img
  8. src="img/Listings2.jpg"
  9. alt="Timeshare To Buy"
  10. class="img-fluid"
  11. style="width:800px;height:400px;"
  12. />
  13. </div>
  14. <div class="sinse-box">
  15. <h3 class="sinse-title">
  16. List {{ propertyType }} {{ salesType }} Property
  17. <span></span>
  18. </h3>
  19. </div>
  20. </div>
  21. <br />
  22. <div class="row">
  23. <div class="container col-md-10">
  24. <div class="title-box-d">
  25. <h5 class="title-d">Property Overview</h5>
  26. </div>
  27. </div>
  28. </div>
  29. <div class="row mb-3">
  30. <div class="container col-md-10">
  31. <form id="mainForm">
  32. <div class="form-group row">
  33. <div class="col-md-4">
  34. <label>Property Type</label>
  35. <select
  36. class="form-control"
  37. name="propertyType"
  38. id="propertyType"
  39. v-model="property.propertyTypeId"
  40. >
  41. <option value="0">Please select type</option>
  42. <option
  43. v-for="item in propertyTypes"
  44. :value="item.id"
  45. :key="item.id"
  46. >{{ item.description }}</option>
  47. </select>
  48. </div>
  49. <div v-if="propertyType === 'Commercial'" class="col-md-4">
  50. <label>Property Name</label>
  51. <input
  52. class="form-control"
  53. type="text"
  54. name="propertyName"
  55. id="propertyName"
  56. v-model="property.propertyName"
  57. />
  58. </div>
  59. <div v-if="propertyType === 'Commercial'" class="col-md-4">
  60. <label>Unit</label>
  61. <input
  62. class="form-control"
  63. type="text"
  64. name="unit"
  65. id="unit"
  66. v-model="property.unit"
  67. />
  68. </div>
  69. </div>
  70. <div class="form-group row">
  71. <div class="col-md-4">
  72. <label>Address Line 1</label>
  73. <input
  74. class="form-control"
  75. type="text"
  76. name="address1"
  77. placeholder="Apartment, suite, unit, building, floor, Po Box etc."
  78. style="font-size: 50%"
  79. id="address1"
  80. v-model="property.addressLine1"
  81. />
  82. </div>
  83. <div class="col-md-4">
  84. <label>Address Line 2</label>
  85. <input
  86. class="form-control"
  87. type="text"
  88. name="address2"
  89. placeholder="Complex, estate, company name, etc."
  90. style="font-size: 50%"
  91. id="address2"
  92. v-model="property.addressLine2"
  93. />
  94. </div>
  95. <div class="col-md-4">
  96. <label>Street</label>
  97. <input
  98. class="form-control"
  99. type="text"
  100. name="address3"
  101. placeholder="Street or c/o name"
  102. style="font-size: 50%"
  103. id="address3"
  104. v-model="property.addressLine3"
  105. />
  106. </div>
  107. </div>
  108. <div class="form-group row">
  109. <div class="col-md-4">
  110. <label>Province</label>
  111. <select
  112. class="form-control"
  113. name="propertyType"
  114. id="propertyType"
  115. @change="ProvinceSelected"
  116. v-model="property.provinceId"
  117. >
  118. <option value="0">Please select province</option>
  119. <option
  120. v-for="province in provinces"
  121. :value="province.id"
  122. :key="province.id"
  123. >{{ province.description }}</option>
  124. </select>
  125. </div>
  126. <div class="col-md-4">
  127. <label>City</label>
  128. <select
  129. class="form-control"
  130. name="propertyType"
  131. id="propertyType"
  132. @change="CitySelected"
  133. v-model="property.cityId"
  134. >
  135. <option value="0">Please select city</option>
  136. <option
  137. v-for="city in cities"
  138. :value="city.id"
  139. :key="city.id"
  140. >{{ city.description }}</option>
  141. </select>
  142. </div>
  143. <div class="col-md-4">
  144. <label>Suburb</label>
  145. <select
  146. class="form-control"
  147. name="propertyType"
  148. id="suburbselector"
  149. v-model="property.suburbId"
  150. >
  151. <option value="0">Please select suburb</option>
  152. <option
  153. v-for="suburb in suburbs"
  154. :value="suburb.id"
  155. :key="suburb.id"
  156. >{{ suburb.description }}</option>
  157. </select>
  158. </div>
  159. </div>
  160. <div class="form-group row">
  161. <div class="col-md-4">
  162. <label v-if="salesType === 'Rental'">Rental Price</label>
  163. <label v-if="salesType !== 'Rental'">Sales Price</label>
  164. <div class="input-group-prepend">
  165. <span class="input-group-text" style="color: #60CBEB">
  166. <b>R</b>
  167. </span>
  168. <input
  169. class="form-control"
  170. type="number"
  171. name="price"
  172. id="price"
  173. placeholder="R"
  174. v-model="property.price"
  175. />
  176. </div>
  177. </div>
  178. <div class="col-md-4" v-if="salesType === 'Rental'">
  179. <label>Per</label>
  180. <select
  181. class="form-control"
  182. name="propertyType"
  183. id="propertyType"
  184. v-model="property.pricePer"
  185. >
  186. <option value>Please select</option>
  187. <option value="Month">Month</option>
  188. <option value="Day">Day</option>
  189. </select>
  190. </div>
  191. </div>
  192. <div class="form-group row">
  193. <div class="col-md-12">
  194. <label for="Property Description">Description</label>
  195. <TextEditor
  196. name="description"
  197. v-model="property.description"
  198. id="description"
  199. style="text-align:left"
  200. />
  201. <br />
  202. <p>* A listing fee of R380 including VAT is payable to list your Property on the Uni-Vate website</p>
  203. </div>
  204. </div>
  205. <div class="form-group row" />
  206. <UserField
  207. v-if="propertyType === 'Residential' & propertyOverviewFields.length > 0"
  208. :fields="propertyOverviewFields[0].fields"
  209. @UpdateUserDefinedFields="UpdateUserDefinedFields"
  210. :id="1"
  211. ></UserField>
  212. <div class="form-group row" />
  213. <div v-for="(item, i) in propertyFields" :key="item.id">
  214. <div class="row">
  215. <div class="col-sm-12">
  216. <div class="title-box-d">
  217. <h5 class="title-d">{{ item.name }}</h5>
  218. </div>
  219. </div>
  220. </div>
  221. <UserField
  222. :fields="item.fields"
  223. :id="item.name"
  224. @UpdateUserDefinedFields="UpdateUserDefinedFields"
  225. />
  226. </div>
  227. <div class="form-group row" />
  228. <div class="row">
  229. <div class="col-sm-12">
  230. <div class="title-box-d">
  231. <h5 class="title-d">Images</h5>
  232. </div>
  233. </div>
  234. </div>
  235. <ImageLoad :loadedImages="loadedImages" :savedImages="propertyImages" />
  236. <button
  237. v-if="!wait"
  238. type="button"
  239. @click="SubmitData()"
  240. class="btn btn-b-n"
  241. style="width: 85px; height:40px;"
  242. >
  243. <!-- <span class="spinner-border" role="status" aria-hidden="true"></span>
  244. <span class="sr-only">Loading...</span>-->
  245. Save
  246. </button>
  247. <label v-if="wait">Please wait...</label>
  248. </form>
  249. </div>
  250. </div>
  251. </div>
  252. </div>
  253. </template>
  254. <script>
  255. import { mapState, mapActions } from 'vuex';
  256. import TextEditor from 'vue-trix';
  257. import UserField from './propertyUserField.vue';
  258. import ImageLoad from './propertyImage.vue';
  259. export default {
  260. name: 'PropertyEdit',
  261. components: {
  262. UserField,
  263. ImageLoad,
  264. TextEditor,
  265. },
  266. data() {
  267. return {
  268. propertyType: 'Residential',
  269. salesType: 'Rental',
  270. selectedProvince: '',
  271. selectedCity: '',
  272. images: [],
  273. propertyFieldValues: [],
  274. defaultImage: 0,
  275. wait: false,
  276. };
  277. },
  278. methods: {
  279. ...mapActions('searchTab', ['getProvince', 'getCities', 'getSuburbs']),
  280. ...mapActions('property', [
  281. 'getPropertyTypes',
  282. 'getPropertyOverviewFields',
  283. 'getPropertyFields',
  284. 'saveProperty',
  285. 'getProperty',
  286. 'getPropertyImages',
  287. 'clearProperty',
  288. 'clearPropertyImages',
  289. 'getPropertyEditDisplay',
  290. 'getPropertySavedOverviewFields',
  291. 'getPropertySavedFields',
  292. 'getSavedPropertyData',
  293. ]),
  294. SubmitData() {
  295. this.wait = true;
  296. for (let i = 0; i < this.images.length; i++) {
  297. let setAsDefault = false;
  298. if (i === this.defaultImage) {
  299. setAsDefault = true;
  300. }
  301. this.property.propertyImages.push({
  302. image: this.images[i],
  303. isDefault: setAsDefault,
  304. });
  305. }
  306. this.property.createdBy = 'GeorgeW';
  307. this.saveProperty(this.property);
  308. setTimeout(
  309. () => this.$router.push({
  310. path: '/property/search',
  311. query: { type: this.salesType, propertyType: this.propertyType },
  312. }),
  313. 3000,
  314. );
  315. },
  316. ProvinceSelected(item) {
  317. if (item.target.options.selectedIndex > 0) {
  318. this.selectedProvince = this.provinces[
  319. item.target.options.selectedIndex - 1
  320. ].description;
  321. this.getCities(Object.assign({}, { province: this.selectedProvince }));
  322. }
  323. },
  324. CitySelected(item) {
  325. if (item.target.options.selectedIndex > 0) {
  326. this.selectedCity = this.cities[
  327. item.target.options.selectedIndex - 1
  328. ].description;
  329. this.getSuburbs(
  330. Object.assign(
  331. {},
  332. { province: this.selectedProvince, city: this.selectedCity },
  333. ),
  334. );
  335. }
  336. },
  337. loadedImages(values) {
  338. this.images = values;
  339. },
  340. UpdateUserDefinedFields(item) {
  341. let update = false;
  342. this.propertyFieldValues.forEach((element) => {
  343. if (element.userDefinedFieldId === item.userDefinedFieldId) {
  344. element.value = item.value;
  345. update = true;
  346. }
  347. });
  348. if (!update) {
  349. this.propertyFieldValues.push(item);
  350. }
  351. },
  352. UpdateDefaultImage(item) {
  353. this.defaultImage = item;
  354. },
  355. },
  356. mounted() {
  357. this.wait = false;
  358. this.clearProperty();
  359. this.clearPropertyImages();
  360. this.images = [];
  361. this.defaultImage = 0;
  362. if (this.propertyOverviewFields.length > 0) {
  363. this.propertyOverviewFields = [];
  364. }
  365. if (this.propertyFields.length > 0) {
  366. this.propertyFields = [];
  367. }
  368. this.propertyType = this.$route.params.propType;
  369. this.salesType = this.$route.params.saleType;
  370. this.getPropertyTypes(this.$route.params.propType);
  371. this.getProvince();
  372. if (this.$route.query.id) {
  373. // this.getCities(Object.assign({}, { province: this.selectedProvince }));
  374. this.getSavedPropertyData(
  375. Object.assign({}, { id: this.$route.query.id, type: this.propertyType }),
  376. );
  377. } else {
  378. this.getPropertyOverviewFields();
  379. this.getPropertyFields(this.$route.params.propType);
  380. }
  381. // if (this.$route.params.id) {
  382. // this.getPropertyEditDisplay(4); // (this.$route.params.id);
  383. // this.propertyType = 'Residential'; // this.propertyEditDisplay.propertyType;
  384. // this.salesType = 'Rental'; // this.propertyEditDisplay.saleType;
  385. // this.getProvince();
  386. // this.getPropertyTypes('Residential');
  387. // this.getPropertySavedOverviewFields(4);
  388. // this.getPropertySavedFields(
  389. // Object.assign(
  390. // {},
  391. // {
  392. // type: 'Residential',
  393. // id: 4,
  394. // },
  395. // ),
  396. // );
  397. // this.getProperty(this.$route.params.id);
  398. // } else {
  399. // }
  400. },
  401. computed: {
  402. ...mapState('searchTab', ['provinces', 'cities', 'suburbs']),
  403. ...mapState('property', [
  404. 'propertyTypes',
  405. 'propertyOverviewFields',
  406. 'propertyFields',
  407. 'property',
  408. 'propertyImages',
  409. ]),
  410. SalesTypeChanged() {
  411. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  412. this.propertyType = this.$route.params.propType;
  413. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  414. this.salesType = this.$route.params.saleType;
  415. if (!this.$route.query.id) {
  416. this.getPropertyTypes(this.$route.params.propType);
  417. this.getPropertyFields(this.$route.params.propType);
  418. }
  419. return this.propertyType;
  420. },
  421. },
  422. watch: {
  423. SalesTypeChanged() {
  424. console.log(this.salesType);
  425. },
  426. },
  427. };
  428. </script>