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.

commercialCreateNew.vue 18KB

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