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.

residentialCreate.vue 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. <template>
  2. <div>
  3. <carouselSection :salesType="salesType" />
  4. <main id="main" style="margin-top:-20px">
  5. <div class="container pt-5 pb-5">
  6. <div class="row">
  7. <div class="col-md-6">
  8. <div v-if="!property.propertyName">
  9. <label for="propertyName" class="uniSelectLabel">PROPERTY NAME</label>
  10. </div>
  11. <input
  12. class="form-control uniInput"
  13. type="text"
  14. name="propertyName"
  15. v-model="property.propertyName"
  16. />
  17. </div>
  18. <div class="col-md-6">
  19. <div v-if="!property.propertyRef">
  20. <label for="propertyName" class="uniSelectLabel">PROPERTY REFERENCE</label>
  21. </div>
  22. <input
  23. class="form-control uniInput"
  24. type="text"
  25. name="propertyRef"
  26. v-model="property.propertyRef"
  27. />
  28. </div>
  29. </div>
  30. <div class="row my-5">
  31. <div class="col-md-6">
  32. <select
  33. class="form-control uniSelect"
  34. name="propertyType"
  35. id="propertyType"
  36. v-model="property.propertyTypeId"
  37. @change="PropertyTypeSelected"
  38. >
  39. <option value="0">Please select type *</option>
  40. <option
  41. v-for="item in propertyTypes"
  42. :value="item.id"
  43. :key="item.id"
  44. >{{ item.description }}</option>
  45. </select>
  46. </div>
  47. <div v-if="propertyType === 'Commercial'" class="col-md-2">
  48. <div v-if="!property.unit">
  49. <label for="unit" class="uniSelectLabel">UNIT</label>
  50. </div>
  51. <input
  52. class="form-control uniInput"
  53. type="text"
  54. name="unit"
  55. id="unit"
  56. v-model="property.unit"
  57. />
  58. </div>
  59. </div>
  60. <div class="row my-5">
  61. <div class="col-md-6">
  62. <mapSection v-on:map-location="updateLocation" />
  63. <input
  64. type="checkbox"
  65. v-model="property.showAddress"
  66. style="margin-right: 10px; margin-top: 10px;"
  67. />
  68. <label>Show address on listing</label>
  69. </div>
  70. <div class="col-md-6">
  71. <div class="row">
  72. <div class="col-md-6">
  73. <div v-if="property.price < 1">
  74. <label
  75. for="price"
  76. class="uniSelectLabel"
  77. style="text-transform:uppercase; margin-left:17px; background-color:white"
  78. >{{ salesType }} Price</label>
  79. </div>
  80. <input
  81. class="form-control uniInput"
  82. type="number"
  83. name="price"
  84. id="price"
  85. v-model="property.price"
  86. />
  87. </div>
  88. <div v-if="salesType === 'Rental'" class="col-md-6">
  89. <select
  90. class="form-control uniSelect"
  91. name="propertyType"
  92. id="propertyType"
  93. v-model="property.pricePer"
  94. >
  95. <option value>Please select</option>
  96. <option value="Month">Month</option>
  97. <option value="Day">Day</option>
  98. </select>
  99. </div>
  100. </div>
  101. <div class="row my-3">
  102. <div class="col-md-12">
  103. <input
  104. type="date"
  105. class="form-control uniInput"
  106. name="date"
  107. v-model="property.dateAvailable"
  108. />
  109. </div>
  110. </div>
  111. <div class="row my-3">
  112. <br />
  113. </div>
  114. <div class="row my-3">
  115. <div class="col-md-12">
  116. <div v-if="!property.streetNumber">
  117. <label for="streetNumber" class="uniSelectLabel">STREET NUMBER</label>
  118. </div>
  119. <input
  120. class="form-control uniInput"
  121. type="text"
  122. name="streetNumber"
  123. id="unit"
  124. v-model="property.streetNumber"
  125. disabled
  126. />
  127. </div>
  128. </div>
  129. <div class="row my-3">
  130. <div class="col-md-12">
  131. <div v-if="!property.streetName">
  132. <label for="streetName" class="uniSelectLabel">STREET NAME</label>
  133. </div>
  134. <input
  135. class="form-control uniInput"
  136. type="text"
  137. name="streetName"
  138. id="unit"
  139. v-model="property.streetName"
  140. disabled
  141. />
  142. </div>
  143. </div>
  144. <div class="row my-3">
  145. <div class="col-md-12">
  146. <div v-if="!property.suburb">
  147. <label for="suburb" class="uniSelectLabel">SUBURB</label>
  148. </div>
  149. <input
  150. class="form-control uniInput"
  151. type="text"
  152. name="suburb"
  153. id="unit"
  154. v-model="property.suburb"
  155. disabled
  156. />
  157. </div>
  158. </div>
  159. <div class="row my-3">
  160. <div class="col-md-12">
  161. <div v-if="!property.city">
  162. <label for="city" class="uniSelectLabel">CITY</label>
  163. </div>
  164. <input
  165. class="form-control uniInput"
  166. type="text"
  167. name="city"
  168. id="unit"
  169. v-model="property.city"
  170. disabled
  171. />
  172. </div>
  173. </div>
  174. <div class="row my-3">
  175. <div class="col-md-12">
  176. <div v-if="!property.province">
  177. <label for="province" class="uniSelectLabel">PROVINCE</label>
  178. </div>
  179. <input
  180. class="form-control uniInput"
  181. type="text"
  182. name="province"
  183. id="unit"
  184. v-model="property.province"
  185. disabled
  186. />
  187. </div>
  188. </div>
  189. <div class="row my-3">
  190. <div class="col-md-12">
  191. <div v-if="!property.postalCode">
  192. <label for="postalCode" class="uniSelectLabel">POSTAL CODE</label>
  193. </div>
  194. <input
  195. class="form-control uniInput"
  196. type="text"
  197. name="postalCode"
  198. id="unit"
  199. v-model="property.postalCode"
  200. disabled
  201. />
  202. </div>
  203. </div>
  204. <div class="row my-3">
  205. <div class="col-md-12">
  206. <div v-if="!property.country">
  207. <label for="country" class="uniSelectLabel">COUNTRY</label>
  208. </div>
  209. <input
  210. class="form-control uniInput"
  211. type="text"
  212. name="country"
  213. id="unit"
  214. v-model="property.country"
  215. disabled
  216. />
  217. </div>
  218. </div>
  219. <div class="row my-3">
  220. <div class="col-md-12">
  221. <button type="button" @click="clearAddress()" class="btn-solid-blue">Clear Address</button>
  222. </div>
  223. </div>
  224. </div>
  225. </div>
  226. <div class="row">
  227. <div class="col-md-12">
  228. <label for="Property Description" style="font-family:'muli'">Description:</label>
  229. <vue-editor v-model="property.description" :editor-toolbar="customToolbar" />
  230. <br />
  231. <p>
  232. * A listing fee of R380 including VAT is payable to list your Property on the
  233. Uni-Vate website
  234. </p>
  235. </div>
  236. </div>
  237. <div class="row" />
  238. <div class="section-header">
  239. <h2>Extra Information</h2>
  240. </div>
  241. <UserField
  242. v-if="propertyOverviewFields.length > 0"
  243. :fields="propertyOverviewFields[0].fields"
  244. @UpdateUserDefinedFields="UpdateUserDefinedFields"
  245. :id="1"
  246. ></UserField>
  247. <div class="row">
  248. <div class="col-md-12">
  249. <div v-for="item in propertyFields" :key="item.id">
  250. <div class="row">
  251. <div class="col-sm-12">
  252. <div class="section-header">
  253. <h2>{{ item.name }}</h2>
  254. </div>
  255. </div>
  256. </div>
  257. <UserField
  258. :fields="item.fields"
  259. :id="item.name"
  260. @UpdateUserDefinedFields="UpdateUserDefinedFields"
  261. :fieldValues="item.fields"
  262. />
  263. </div>
  264. </div>
  265. </div>
  266. <div class="row">
  267. <div class="col-sm-12">
  268. <div class="section-header">
  269. <h2>Media</h2>
  270. </div>
  271. </div>
  272. </div>
  273. <div class="form-group row">
  274. <div class="col-md-12">
  275. <label class="uniSelectLabel">Virtual Tour (URL)</label>
  276. <div class="input-group-prepend">
  277. <input
  278. class="form-control uniInput"
  279. type="link"
  280. name="vtlink"
  281. id="vtlink"
  282. v-model="property.virtualTour"
  283. />
  284. </div>
  285. </div>
  286. </div>
  287. <div class="row">
  288. <div class="col-md-12">
  289. <label class="uniSelectLabel">Video (URL)</label>
  290. <div class="input-group-prepend">
  291. <input
  292. class="form-control uniInput"
  293. type="link"
  294. name="vlink"
  295. id="vlink"
  296. v-model="property.video"
  297. />
  298. </div>
  299. </div>
  300. </div>
  301. <div class="row mt-3">
  302. <div class="col-md-6">
  303. <div class="content-header">
  304. <h2>Images</h2>
  305. </div>
  306. <div class="input-group-prepend"></div>
  307. </div>
  308. </div>
  309. <ImageLoad
  310. :loadedImages="loadedImages"
  311. :savedImages="propertyImages"
  312. @DefaultImage="UpdateDefaultImage"
  313. />
  314. <button v-if="!wait" type="button" @click="SubmitData()" class="btn-solid-blue">Save</button>
  315. <div v-if="showPropertyTypeError">
  316. <p class="alert myError">Missing fields. Please fill in all required fields. Marked with *</p>
  317. </div>
  318. <div v-if="wait" id="preloader"></div>
  319. </div>
  320. </main>
  321. </div>
  322. </template>
  323. <script>
  324. /* eslint-disable */
  325. import { mapState, mapActions } from "vuex";
  326. import { VueEditor } from "vue2-editor";
  327. import UserField from "../../propertyUserField.vue";
  328. import ImageLoad from "../../propertyImage.vue";
  329. import Log from "../../../../assets/Log";
  330. import carouselSection from "./carouselSection";
  331. import mapSection from "../../mapSection";
  332. export default {
  333. name: "PropertyCreate",
  334. components: {
  335. UserField,
  336. ImageLoad,
  337. VueEditor,
  338. carouselSection,
  339. mapSection,
  340. },
  341. data() {
  342. return {
  343. propertyType: "Residential",
  344. salesType: "Rental",
  345. images: [],
  346. propertyFieldValues: [],
  347. defaultImage: 0,
  348. wait: false,
  349. customToolbar: [
  350. [{ header: [false, 1, 2, 3, 4, 5, 6] }],
  351. ["bold", "italic", "underline", "strike"],
  352. [
  353. { align: "" },
  354. { align: "center" },
  355. { align: "right" },
  356. { align: "justify" },
  357. ],
  358. [{ list: "ordered" }, { list: "bullet" }, { list: "check" }],
  359. [{ script: "sub" }, { script: "super" }],
  360. [{ indent: "-1" }, { indent: "+1" }],
  361. ],
  362. error: "",
  363. addressSet: false,
  364. showPropertyTypeError: false,
  365. showDateError: false,
  366. user: Log.getUser(),
  367. mayEdit: Log.isLoggedIn(),
  368. };
  369. },
  370. methods: {
  371. ...mapActions("property", [
  372. "getPropertyTypes",
  373. "getPropertyOverviewFields",
  374. "getPropertyFields",
  375. "saveProperty",
  376. "getProperty",
  377. "getPropertyImages",
  378. "clearPropertyImages",
  379. "getPropertyEditDisplay",
  380. "getPropertySavedOverviewFields",
  381. "getPropertySavedFields",
  382. "getSavedPropertyData",
  383. ]),
  384. updateLocation(place) {
  385. this.addressSet = true;
  386. this.property.streetNumber = place.streetNumber;
  387. this.property.streetName = place.streetName;
  388. this.property.suburb = place.suburb;
  389. this.property.city = place.city;
  390. this.property.province = place.province;
  391. this.property.country = place.country;
  392. this.property.postalCode = place.postalCode;
  393. this.property.addressUrl = place.url;
  394. this.property.propertCoords = place.coords;
  395. },
  396. TypeChanged() {
  397. this.property.propertyUsageType = this.propertyType;
  398. },
  399. SubmitData() {
  400. if (this.property.propertyTypeId === 0) {
  401. this.showPropertyTypeError = true;
  402. }
  403. if (
  404. this.salesType === "Rental" &&
  405. this.property.dateAvailable === "undef"
  406. ) {
  407. this.showDateError = true;
  408. }
  409. if (this.showPropertyTypeError || this.showDateError) {
  410. return;
  411. }
  412. this.wait = true;
  413. if (this.salesType === "Sale") {
  414. this.property.isSale = true;
  415. this.property.dateAvailable = new Date();
  416. }
  417. if (this.images.length > 0) {
  418. this.property.propertyImages = [];
  419. }
  420. // eslint-disable-next-line no-plusplus
  421. for (let i = 0; i < this.images.length; i++) {
  422. let setAsDefault = false;
  423. if (i === this.defaultImage) {
  424. setAsDefault = true;
  425. }
  426. this.property.propertyImages.push({
  427. image: this.images[i],
  428. isDefault: setAsDefault,
  429. });
  430. }
  431. this.property.propertyUserFields = this.propertyFieldValues;
  432. if (this.user) {
  433. this.property.userId = this.user.id;
  434. }
  435. this.saveProperty(this.property)
  436. .then((fulfilled) => {
  437. this.$router.push(
  438. `/property/residential/property/${fulfilled.data.id}`
  439. );
  440. })
  441. .catch((error) => {
  442. console.log(error.message);
  443. });
  444. },
  445. Close() {
  446. this.$router.push("/property/admin/list/my");
  447. },
  448. Login() {
  449. this.$router.push("/user/login");
  450. },
  451. PropertyTypeSelected(item) {
  452. if (item.target.options.selectedIndex > 0) {
  453. this.showPropertyTypeError = false;
  454. } else {
  455. this.showPropertyTypeError = true;
  456. }
  457. },
  458. loadedImages(values) {
  459. this.images = values;
  460. },
  461. UpdateUserDefinedFields(item) {
  462. let update = false;
  463. this.propertyFieldValues.forEach((element) => {
  464. if (element.userDefinedFieldId === item.userDefinedFieldId) {
  465. element.value = item.value;
  466. update = true;
  467. }
  468. });
  469. if (!update) {
  470. this.propertyFieldValues.push(item);
  471. }
  472. },
  473. UpdateDefaultImage(item) {
  474. this.defaultImage = item;
  475. },
  476. clearAddress() {
  477. this.addressSet = false;
  478. this.property.streetNumber = undefined;
  479. this.property.streetName = undefined;
  480. this.property.suburb = undefined;
  481. this.property.city = undefined;
  482. this.property.province = undefined;
  483. this.property.country = undefined;
  484. this.property.postalCode = undefined;
  485. this.property.addressUrl = undefined;
  486. this.property.propertCoords = undefined;
  487. },
  488. },
  489. mounted() {
  490. this.wait = false;
  491. this.getProperty(0);
  492. this.clearPropertyImages();
  493. this.images = [];
  494. this.defaultImage = 0;
  495. if (this.propertyOverviewFields.length > 0) {
  496. this.propertyOverviewFields = [];
  497. }
  498. if (this.propertyFields.length > 0) {
  499. this.propertyFields = [];
  500. }
  501. if (this.property.description !== "") {
  502. this.property.description = "";
  503. }
  504. if (this.$route.params.propertyUsageType) {
  505. this.propertyType = this.$route.params.propertyUsageType;
  506. }
  507. this.salesType = this.$route.params.saleType;
  508. this.getPropertyTypes(this.propertyType);
  509. this.getPropertyOverviewFields();
  510. this.getPropertyFields(this.propertyType);
  511. },
  512. computed: {
  513. ...mapState("property", [
  514. "propertyTypes",
  515. "propertyOverviewFields",
  516. "propertyFields",
  517. "property",
  518. "propertyImages",
  519. ]),
  520. ...mapState("authentication", ["user"]),
  521. SalesTypeChanged() {
  522. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  523. // this.propertyType = this.$route.params.propType;
  524. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  525. this.salesType = this.$route.params.saleType;
  526. if (this.property && this.property.propertyUsageType) {
  527. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  528. this.propertyType = this.property.propertyUsageType;
  529. }
  530. if (!this.$route.query.id) {
  531. this.getPropertyFields(this.propertyType);
  532. }
  533. this.getPropertyTypes(this.propertyType);
  534. return this.propertyType;
  535. },
  536. },
  537. watch: {
  538. SalesTypeChanged() {
  539. return null;
  540. },
  541. },
  542. };
  543. </script>
  544. <style lang="scss" scoped></style>