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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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="value"
  100. @input="value = $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="unit"
  143. v-model="property.streetNumber"
  144. disabled
  145. />
  146. </div>
  147. </div>
  148. <div class="row my-3">
  149. <div class="col-md-12">
  150. <div v-if="!property.streetName">
  151. <label for="streetName" class="uniSelectLabel">STREET NAME</label>
  152. </div>
  153. <input
  154. class="form-control uniInput"
  155. type="text"
  156. name="streetName"
  157. id="unit"
  158. v-model="property.streetName"
  159. disabled
  160. />
  161. </div>
  162. </div>
  163. <div class="row my-3">
  164. <div class="col-md-12">
  165. <div v-if="!property.suburb">
  166. <label for="suburb" class="uniSelectLabel">SUBURB</label>
  167. </div>
  168. <input
  169. class="form-control uniInput"
  170. type="text"
  171. name="suburb"
  172. id="unit"
  173. v-model="property.suburb"
  174. disabled
  175. />
  176. </div>
  177. </div>
  178. <div class="row my-3">
  179. <div class="col-md-12">
  180. <div v-if="!property.city">
  181. <label for="city" class="uniSelectLabel">CITY</label>
  182. </div>
  183. <input
  184. class="form-control uniInput"
  185. type="text"
  186. name="city"
  187. id="unit"
  188. v-model="property.city"
  189. disabled
  190. />
  191. </div>
  192. </div>
  193. <div class="row my-3">
  194. <div class="col-md-12">
  195. <div v-if="!property.province">
  196. <label for="province" class="uniSelectLabel">PROVINCE</label>
  197. </div>
  198. <input
  199. class="form-control uniInput"
  200. type="text"
  201. name="province"
  202. id="unit"
  203. v-model="property.province"
  204. disabled
  205. />
  206. </div>
  207. </div>
  208. <div class="row my-3">
  209. <div class="col-md-12">
  210. <div v-if="!property.postalCode">
  211. <label for="postalCode" class="uniSelectLabel">POSTAL CODE</label>
  212. </div>
  213. <input
  214. class="form-control uniInput"
  215. type="text"
  216. name="postalCode"
  217. id="unit"
  218. v-model="property.postalCode"
  219. disabled
  220. />
  221. </div>
  222. </div>
  223. <div class="row my-3">
  224. <div class="col-md-12">
  225. <div v-if="!property.country">
  226. <label for="country" class="uniSelectLabel">COUNTRY</label>
  227. </div>
  228. <input
  229. class="form-control uniInput"
  230. type="text"
  231. name="country"
  232. id="unit"
  233. v-model="property.country"
  234. disabled
  235. />
  236. </div>
  237. </div>
  238. <div class="row my-3">
  239. <div class="col-md-12">
  240. <button type="button" @click="clearAddress()" class="btn-solid-blue">
  241. Clear Address
  242. </button>
  243. </div>
  244. </div>
  245. </div>
  246. </div>
  247. <div class="row">
  248. <div class="col-md-12">
  249. <label for="Property Description" style="font-family:'muli'">Description:</label>
  250. <vue-editor v-model="property.description" :editor-toolbar="customToolbar" />
  251. <br />
  252. <p>
  253. * A listing fee of R{{ getListingFee.amount }} including VAT is payable to list your
  254. Property on the Uni-Vate website
  255. </p>
  256. </div>
  257. </div>
  258. <div class="section-header">
  259. <h2>Property Information</h2>
  260. </div>
  261. <div v-for="item in propertyFields" :key="item.id">
  262. <div v-if="item.name === 'Commercial Fields'">
  263. <UserField
  264. :fields="item.fields"
  265. :id="item.name"
  266. @UpdateUserDefinedFields="UpdateUserDefinedFields"
  267. :fieldValues="item.fields"
  268. />
  269. </div>
  270. </div>
  271. <div class="row">
  272. <div class="col-sm-12">
  273. <div class="section-header">
  274. <h2>Media</h2>
  275. </div>
  276. </div>
  277. </div>
  278. <div class="form-group row">
  279. <div class="col-md-12">
  280. <label v-if="!property.virtualTour" class="uniSelectLabel">Virtual Tour (URL)</label>
  281. <div class="input-group-prepend">
  282. <float-label label="Virtual Tour (URL)" style="width:100%">
  283. <input
  284. class="form-control uniInput"
  285. type="link"
  286. name="vtlink"
  287. id="vtlink"
  288. v-model="property.virtualTour"
  289. />
  290. </float-label>
  291. </div>
  292. </div>
  293. </div>
  294. <div class="row">
  295. <div class="col-md-12 mt-2">
  296. <label v-if="!property.video" class="uniSelectLabel">Video (URL)</label>
  297. <div class="input-group-prepend">
  298. <float-label label="video " style="width:100%">
  299. <input
  300. class="form-control uniInput"
  301. type="link"
  302. name="vlink"
  303. id="vlink"
  304. v-model="property.video"
  305. />
  306. </float-label>
  307. </div>
  308. </div>
  309. </div>
  310. <div class="row mt-3">
  311. <div class="col-md-6">
  312. <div class="content-header">
  313. <h2>Images</h2>
  314. </div>
  315. <div class="input-group-prepend"></div>
  316. </div>
  317. </div>
  318. <ImageLoad
  319. :loadedImages="loadedImages"
  320. :savedImages="propertyImages"
  321. @DefaultImage="UpdateDefaultImage"
  322. />
  323. <button v-if="!wait" type="button" @click="SubmitData()" class="btn-solid-blue">
  324. Save
  325. </button>
  326. <div v-if="showPropertyTypeError">
  327. <p class="alert myError">
  328. Missing fields. Please fill in all required fields. Marked with *
  329. </p>
  330. </div>
  331. <div v-if="wait" id="preloader"></div>
  332. </div>
  333. </main>
  334. </div>
  335. </template>
  336. <script>
  337. /* eslint-disable */
  338. import { mapState, mapActions, mapGetters } from "vuex";
  339. import { VueEditor } from "vue2-editor";
  340. import UserField from "../../propertyUserField.vue";
  341. import ImageLoad from "../../propertyImage.vue";
  342. import Log from "../../../../assets/Log";
  343. import carouselSection from "./carouselSection";
  344. import mapSection from "../../mapSection";
  345. export default {
  346. name: "PropertyCreate",
  347. components: {
  348. UserField,
  349. ImageLoad,
  350. VueEditor,
  351. carouselSection,
  352. mapSection
  353. },
  354. data() {
  355. return {
  356. propertyType: "Commercial",
  357. salesType: "Rental",
  358. images: [],
  359. propertyFieldValues: [],
  360. defaultImage: 0,
  361. wait: false,
  362. customToolbar: [
  363. [{ header: [false, 1, 2, 3, 4, 5, 6] }],
  364. ["bold", "italic", "underline", "strike"],
  365. [{ align: "" }, { align: "center" }, { align: "right" }, { align: "justify" }],
  366. [{ list: "ordered" }, { list: "bullet" }, { list: "check" }],
  367. [{ script: "sub" }, { script: "super" }],
  368. [{ indent: "-1" }, { indent: "+1" }]
  369. ],
  370. error: "",
  371. addressSet: false,
  372. showPropertyTypeError: false,
  373. showDateError: false,
  374. user: Log.getUser(),
  375. mayEdit: Log.isLoggedIn()
  376. };
  377. },
  378. methods: {
  379. ...mapActions("property", [
  380. "getPropertyTypes",
  381. "getPropertyOverviewFields",
  382. "getPropertyFields",
  383. "saveProperty",
  384. "getProperty",
  385. "getPropertyImages",
  386. "clearPropertyImages",
  387. "getPropertyEditDisplay",
  388. "getPropertySavedOverviewFields",
  389. "getPropertySavedFields",
  390. "getSavedPropertyData"
  391. ]),
  392. updateLocation(place) {
  393. this.addressSet = true;
  394. this.property.streetNumber = place.streetNumber;
  395. this.property.streetName = place.streetName;
  396. this.property.suburb = place.suburb;
  397. this.property.city = place.city;
  398. this.property.province = place.province;
  399. this.property.country = place.country;
  400. this.property.postalCode = place.postalCode;
  401. this.property.addressUrl = place.url;
  402. this.property.propertCoords = place.coords;
  403. },
  404. TypeChanged() {
  405. this.property.propertyUsageType = this.propertyType;
  406. },
  407. SubmitData() {
  408. if (this.property.propertyTypeId === 0) {
  409. this.showPropertyTypeError = true;
  410. }
  411. if (this.salesType === "Rental" && this.property.dateAvailable === "undef") {
  412. this.showDateError = true;
  413. }
  414. if (this.showPropertyTypeError || this.showDateError) {
  415. return;
  416. }
  417. this.wait = true;
  418. if (this.salesType === "Sale") {
  419. this.property.isSale = true;
  420. this.property.dateAvailable = new Date();
  421. }
  422. if (this.images.length > 0) {
  423. this.property.propertyImages = [];
  424. }
  425. // eslint-disable-next-line no-plusplus
  426. for (let i = 0; i < this.images.length; i++) {
  427. let setAsDefault = false;
  428. if (i === this.defaultImage) {
  429. setAsDefault = true;
  430. }
  431. this.property.propertyImages.push({
  432. image: this.images[i],
  433. isDefault: setAsDefault
  434. });
  435. }
  436. this.property.propertyUserFields = this.propertyFieldValues;
  437. if (this.user) {
  438. this.property.userId = this.user.id;
  439. }
  440. this.property.propertyUserFields.forEach(item => {
  441. if (item.value === true) {
  442. item.value = "yes";
  443. } else if (item.value === false) {
  444. item.value = "no";
  445. }
  446. });
  447. console.log(this.property);
  448. this.saveProperty(this.property)
  449. .then(fulfilled => {
  450. this.$router.push(`/property/commercial/property/${fulfilled.data.id}`);
  451. })
  452. .catch(error => {
  453. console.log(error.message);
  454. });
  455. },
  456. Close() {
  457. this.$router.push("/property/admin/list/my");
  458. },
  459. Login() {
  460. this.$router.push("/user/login");
  461. },
  462. PropertyTypeSelected(item) {
  463. if (item.target.options.selectedIndex > 0) {
  464. this.showPropertyTypeError = false;
  465. } else {
  466. this.showPropertyTypeError = true;
  467. }
  468. },
  469. loadedImages(values) {
  470. this.images = values;
  471. },
  472. UpdateUserDefinedFields(item) {
  473. let update = false;
  474. this.propertyFieldValues.forEach(element => {
  475. if (element.userDefinedFieldId === item.userDefinedFieldId) {
  476. element.value = item.value;
  477. update = true;
  478. }
  479. });
  480. if (!update) {
  481. this.propertyFieldValues.push(item);
  482. }
  483. },
  484. UpdateDefaultImage(item) {
  485. this.defaultImage = item;
  486. },
  487. clearAddress() {
  488. this.addressSet = false;
  489. this.property.streetNumber = undefined;
  490. this.property.streetName = undefined;
  491. this.property.suburb = undefined;
  492. this.property.city = undefined;
  493. this.property.province = undefined;
  494. this.property.country = undefined;
  495. this.property.postalCode = undefined;
  496. this.property.addressUrl = undefined;
  497. this.property.propertCoords = undefined;
  498. }
  499. },
  500. mounted() {
  501. this.wait = false;
  502. this.getProperty(0);
  503. this.clearPropertyImages();
  504. this.images = [];
  505. this.defaultImage = 0;
  506. if (this.propertyOverviewFields.length > 0) {
  507. this.propertyOverviewFields = [];
  508. }
  509. if (this.propertyFields.length > 0) {
  510. this.propertyFields = [];
  511. }
  512. if (this.property.description !== "") {
  513. this.property.description = "";
  514. }
  515. if (this.$route.params.propertyUsageType) {
  516. this.propertyType = this.$route.params.propertyUsageType;
  517. }
  518. this.salesType = this.$route.params.saleType;
  519. this.getPropertyOverviewFields();
  520. //this.getPropertyFields(this.propertyType);
  521. },
  522. computed: {
  523. ...mapState("property", [
  524. "propertyTypes",
  525. "propertyOverviewFields",
  526. "propertyFields",
  527. "property",
  528. "propertyImages"
  529. ]),
  530. ...mapState("authentication", ["user"]),
  531. ...mapGetters("fees", ["getListingFee"]),
  532. SalesTypeChanged() {
  533. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  534. // this.propertyType = this.$route.params.propType;
  535. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  536. this.salesType = this.$route.params.saleType;
  537. if (this.property && this.property.propertyUsageType) {
  538. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  539. this.propertyType = this.property.propertyUsageType;
  540. }
  541. if (!this.$route.query.id) {
  542. this.getPropertyFields(this.propertyType);
  543. }
  544. this.getPropertyTypes(this.propertyType);
  545. return this.propertyType;
  546. }
  547. },
  548. watch: {
  549. SalesTypeChanged() {
  550. return null;
  551. }
  552. }
  553. };
  554. </script>
  555. <style lang="scss" scoped></style>