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. </div>
  257. </div> -->
  258. <UserField :fields="propFields" @UpdateUserDefinedFields="UpdateUserDefinedFields" />
  259. <div class="row">
  260. <div class="col-sm-12">
  261. <div class="section-header">
  262. <h2>Media</h2>
  263. </div>
  264. </div>
  265. </div>
  266. <div class="form-group row">
  267. <div class="col-md-12">
  268. <label v-if="!property.virtualTour" class="uniSelectLabel">Virtual Tour (URL)</label>
  269. <div class="input-group-prepend">
  270. <float-label label="Virtual Tour (URL)" style="width:100%">
  271. <input
  272. class="form-control uniInput"
  273. type="link"
  274. name="vtlink"
  275. id="vtlink"
  276. v-model="property.virtualTour"
  277. />
  278. </float-label>
  279. </div>
  280. </div>
  281. </div>
  282. <div class="row">
  283. <div class="col-md-12 mt-2">
  284. <label v-if="!property.video" class="uniSelectLabel">Video (URL)</label>
  285. <div class="input-group-prepend">
  286. <float-label label="video " style="width:100%">
  287. <input
  288. class="form-control uniInput"
  289. type="link"
  290. name="vlink"
  291. id="vlink"
  292. v-model="property.video"
  293. />
  294. </float-label>
  295. </div>
  296. </div>
  297. </div>
  298. <div class="row mt-3">
  299. <div class="col-md-6">
  300. <div class="content-header">
  301. <h2>Images</h2>
  302. </div>
  303. <div class="input-group-prepend"></div>
  304. </div>
  305. </div>
  306. <ImageLoad
  307. :loadedImages="loadedImages"
  308. :savedImages="propertyImages"
  309. @DefaultImage="UpdateDefaultImage"
  310. />
  311. <button v-if="!wait" type="button" @click="SubmitData()" class="btn-solid-blue">
  312. Save
  313. </button>
  314. <div v-if="showPropertyTypeError">
  315. <p class="alert myError">
  316. Missing fields. Please fill in all required fields. Marked with *
  317. </p>
  318. </div>
  319. <div v-if="wait" id="preloader"></div>
  320. </div>
  321. </main>
  322. </div>
  323. </template>
  324. <script>
  325. /* eslint-disable */
  326. import { mapState, mapActions, mapGetters } from "vuex";
  327. import { VueEditor } from "vue2-editor";
  328. import UserField from "../../propertyUserField.vue";
  329. import ImageLoad from "../../propertyImage.vue";
  330. import Log from "../../../../assets/Log";
  331. import carouselSection from "./carouselSection";
  332. import mapSection from "../../mapSection";
  333. export default {
  334. name: "PropertyCreate",
  335. components: {
  336. UserField,
  337. ImageLoad,
  338. VueEditor,
  339. carouselSection,
  340. mapSection
  341. },
  342. props: {
  343. propFields: {}
  344. },
  345. data() {
  346. return {
  347. propertyType: "Commercial",
  348. salesType: "Rental",
  349. images: [],
  350. propertyFieldValues: [],
  351. defaultImage: 0,
  352. wait: false,
  353. customToolbar: [
  354. [{ header: [false, 1, 2, 3, 4, 5, 6] }],
  355. ["bold", "italic", "underline", "strike"],
  356. [{ align: "" }, { align: "center" }, { align: "right" }, { align: "justify" }],
  357. [{ list: "ordered" }, { list: "bullet" }, { list: "check" }],
  358. [{ script: "sub" }, { script: "super" }],
  359. [{ indent: "-1" }, { indent: "+1" }]
  360. ],
  361. error: "",
  362. addressSet: false,
  363. showPropertyTypeError: false,
  364. showDateError: false,
  365. user: Log.getUser(),
  366. mayEdit: Log.isLoggedIn()
  367. };
  368. },
  369. methods: {
  370. ...mapActions("property", [
  371. "getPropertyTypes",
  372. "getPropertyOverviewFields",
  373. "getPropertyFields",
  374. "saveProperty",
  375. "getProperty",
  376. "getPropertyImages",
  377. "clearPropertyImages",
  378. "getPropertyEditDisplay",
  379. "getPropertySavedOverviewFields",
  380. "getPropertySavedFields",
  381. "getSavedPropertyData"
  382. ]),
  383. updateLocation(place) {
  384. this.addressSet = true;
  385. this.property.streetNumber = place.streetNumber;
  386. this.property.streetName = place.streetName;
  387. this.property.suburb = place.suburb;
  388. this.property.city = place.city;
  389. this.property.province = place.province;
  390. this.property.country = place.country;
  391. this.property.postalCode = place.postalCode;
  392. this.property.addressUrl = place.url;
  393. this.property.propertCoords = place.coords;
  394. },
  395. TypeChanged() {
  396. this.property.propertyUsageType = this.propertyType;
  397. },
  398. SubmitData() {
  399. if (this.property.propertyTypeId === 0) {
  400. this.showPropertyTypeError = true;
  401. }
  402. if (this.salesType === "Rental" && this.property.dateAvailable === "undef") {
  403. this.showDateError = true;
  404. }
  405. if (this.showPropertyTypeError || this.showDateError) {
  406. return;
  407. }
  408. this.wait = true;
  409. if (this.salesType === "Sale") {
  410. this.property.isSale = true;
  411. this.property.dateAvailable = new Date();
  412. }
  413. if (this.images.length > 0) {
  414. this.property.propertyImages = [];
  415. }
  416. // eslint-disable-next-line no-plusplus
  417. for (let i = 0; i < this.images.length; i++) {
  418. let setAsDefault = false;
  419. if (i === this.defaultImage) {
  420. setAsDefault = true;
  421. }
  422. this.property.propertyImages.push({
  423. image: this.images[i],
  424. isDefault: setAsDefault
  425. });
  426. }
  427. this.property.propertyUserFields = this.propertyFieldValues;
  428. if (this.user) {
  429. this.property.userId = this.user.id;
  430. }
  431. // this.property.propertyUserFields.forEach(item => {
  432. // if (item.value === true) {
  433. // item.value = "yes";
  434. // } else if (item.value === false) {
  435. // item.value = "no";
  436. // }
  437. // });
  438. if (Log.getUser().role === "Agency" || Log.getUser().role === "Agent") {
  439. this.retrieveAgency().then(() => {
  440. this.property.agentId = this.agent[0].id;
  441. this.property.agencyId = this.agent[0].agencyId;
  442. });
  443. }
  444. console.log(this.property);
  445. this.saveProperty(this.property)
  446. .then(fulfilled => {
  447. this.$router.push(`/property/commercial/property/${fulfilled.data.id}`);
  448. })
  449. .catch(error => {
  450. console.log(error.message);
  451. });
  452. },
  453. Close() {
  454. this.$router.push("/property/admin/list/my");
  455. },
  456. Login() {
  457. this.$router.push("/user/login");
  458. },
  459. PropertyTypeSelected(item) {
  460. if (item.target.options.selectedIndex > 0) {
  461. this.showPropertyTypeError = false;
  462. } else {
  463. this.showPropertyTypeError = true;
  464. }
  465. },
  466. loadedImages(values) {
  467. this.images = values;
  468. },
  469. UpdateUserDefinedFields(item) {
  470. let update = false;
  471. this.propertyFieldValues.forEach(element => {
  472. if (element.userDefinedFieldId === item.userDefinedFieldId) {
  473. element.value = item.value;
  474. update = true;
  475. }
  476. });
  477. if (!update) {
  478. this.propertyFieldValues.push(item);
  479. }
  480. },
  481. UpdateDefaultImage(item) {
  482. this.defaultImage = item;
  483. },
  484. clearAddress() {
  485. this.addressSet = false;
  486. this.property.streetNumber = undefined;
  487. this.property.streetName = undefined;
  488. this.property.suburb = undefined;
  489. this.property.city = undefined;
  490. this.property.province = undefined;
  491. this.property.country = undefined;
  492. this.property.postalCode = undefined;
  493. this.property.addressUrl = undefined;
  494. this.property.propertCoords = undefined;
  495. }
  496. },
  497. mounted() {
  498. this.wait = false;
  499. this.getProperty(0);
  500. this.clearPropertyImages();
  501. this.images = [];
  502. this.defaultImage = 0;
  503. if (this.propertyOverviewFields.length > 0) {
  504. this.propertyOverviewFields = [];
  505. }
  506. if (this.propertyFields.length > 0) {
  507. this.propertyFields = [];
  508. }
  509. if (this.property.description !== "") {
  510. this.property.description = "";
  511. }
  512. if (this.$route.params.propertyUsageType) {
  513. this.propertyType = this.$route.params.propertyUsageType;
  514. }
  515. this.salesType = this.$route.params.saleType;
  516. this.getPropertyOverviewFields();
  517. //this.getPropertyFields(this.propertyType);
  518. },
  519. computed: {
  520. ...mapState("property", [
  521. "propertyTypes",
  522. "propertyOverviewFields",
  523. "propertyFields",
  524. "property",
  525. "propertyImages"
  526. ]),
  527. ...mapState("authentication", ["user"]),
  528. ...mapGetters("fees", ["getListingFee"]),
  529. sortFields() {
  530. var display = [];
  531. display = this.propertyFields[0].fields.sort((a, b) => (a.rank > b.rank ? 1 : -1));
  532. return display;
  533. },
  534. SalesTypeChanged() {
  535. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  536. // this.propertyType = this.$route.params.propType;
  537. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  538. this.salesType = this.$route.params.saleType;
  539. if (this.property && this.property.propertyUsageType) {
  540. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  541. this.propertyType = this.property.propertyUsageType;
  542. }
  543. if (!this.$route.query.id) {
  544. this.getPropertyFields(this.propertyType);
  545. }
  546. this.getPropertyTypes(this.propertyType);
  547. return this.propertyType;
  548. }
  549. },
  550. watch: {
  551. SalesTypeChanged() {
  552. return null;
  553. }
  554. }
  555. };
  556. </script>
  557. <style lang="scss" scoped></style>