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

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