Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

commercialCreate.vue 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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">
  112. <div class="col-md-12">
  113. <label for="Property Description" style="font-family:'muli'">Description:</label>
  114. <vue-editor v-model="property.description" :editor-toolbar="customToolbar" />
  115. <br />
  116. <p>
  117. * A listing fee of R380 including VAT is payable to list your Property on the
  118. Uni-Vate website
  119. </p>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. <div class="row">
  125. <div class="col-md-12">
  126. <div v-for="item in propertyFields" :key="item.id">
  127. <div class="row">
  128. <div class="col-sm-12">
  129. <div class="section-header">
  130. <h2>{{ item.name }}</h2>
  131. </div>
  132. </div>
  133. </div>
  134. <UserField
  135. :fields="item.fields"
  136. :id="item.name"
  137. @UpdateUserDefinedFields="UpdateUserDefinedFields"
  138. :fieldValues="item.fields"
  139. />
  140. </div>
  141. </div>
  142. </div>
  143. <div class="row">
  144. <div class="col-sm-12">
  145. <div class="section-header">
  146. <h2>Media</h2>
  147. </div>
  148. </div>
  149. </div>
  150. <div class="form-group row">
  151. <div class="col-md-12">
  152. <label class="uniSelectLabel">Virtual Tour (URL)</label>
  153. <div class="input-group-prepend">
  154. <input
  155. class="form-control uniInput"
  156. type="link"
  157. name="vtlink"
  158. id="vtlink"
  159. v-model="property.virtualTour"
  160. />
  161. </div>
  162. </div>
  163. </div>
  164. <div class="row">
  165. <div class="col-md-12">
  166. <label class="uniSelectLabel">Video (URL)</label>
  167. <div class="input-group-prepend">
  168. <input
  169. class="form-control uniInput"
  170. type="link"
  171. name="vlink"
  172. id="vlink"
  173. v-model="property.video"
  174. />
  175. </div>
  176. </div>
  177. </div>
  178. <div class="row mt-3">
  179. <div class="col-md-6">
  180. <div class="content-header">
  181. <h2>Images</h2>
  182. </div>
  183. <div class="input-group-prepend"></div>
  184. </div>
  185. </div>
  186. <ImageLoad
  187. :loadedImages="loadedImages"
  188. :savedImages="propertyImages"
  189. @DefaultImage="UpdateDefaultImage"
  190. />
  191. <button v-if="!wait" type="button" @click="SubmitData()" class="btn-solid-blue">Save</button>
  192. <div v-if="showPropertyTypeError">
  193. <p class="alert myError">Missing fields. Please fill in all required fields. Marked with *</p>
  194. </div>
  195. <div v-if="!addressSet">
  196. <p class="alert myError">Please enter an address.</p>
  197. </div>
  198. <div v-if="wait" id="preloader"></div>
  199. </div>
  200. </main>
  201. </div>
  202. </template>
  203. <script>
  204. /* eslint-disable */
  205. import { mapState, mapActions } from "vuex";
  206. import { VueEditor } from "vue2-editor";
  207. import UserField from "../../propertyUserField.vue";
  208. import ImageLoad from "../../propertyImage.vue";
  209. import Log from "../../../../assets/Log";
  210. import carouselSection from "./carouselSection";
  211. import mapSection from "../../mapSection";
  212. export default {
  213. name: "PropertyCreate",
  214. components: {
  215. UserField,
  216. ImageLoad,
  217. VueEditor,
  218. carouselSection,
  219. mapSection,
  220. },
  221. data() {
  222. return {
  223. propertyType: "Commercial",
  224. salesType: "Rental",
  225. images: [],
  226. propertyFieldValues: [],
  227. defaultImage: 0,
  228. wait: false,
  229. customToolbar: [
  230. [{ header: [false, 1, 2, 3, 4, 5, 6] }],
  231. ["bold", "italic", "underline", "strike"],
  232. [
  233. { align: "" },
  234. { align: "center" },
  235. { align: "right" },
  236. { align: "justify" },
  237. ],
  238. [{ list: "ordered" }, { list: "bullet" }, { list: "check" }],
  239. [{ script: "sub" }, { script: "super" }],
  240. [{ indent: "-1" }, { indent: "+1" }],
  241. ],
  242. error: "",
  243. addressSet: false,
  244. showPropertyTypeError: false,
  245. showDateError: false,
  246. user: Log.getUser(),
  247. mayEdit: Log.isLoggedIn(),
  248. };
  249. },
  250. methods: {
  251. ...mapActions("property", [
  252. "getPropertyTypes",
  253. "getPropertyOverviewFields",
  254. "getPropertyFields",
  255. "saveProperty",
  256. "getProperty",
  257. "getPropertyImages",
  258. "clearPropertyImages",
  259. "getPropertyEditDisplay",
  260. "getPropertySavedOverviewFields",
  261. "getPropertySavedFields",
  262. "getSavedPropertyData",
  263. ]),
  264. updateLocation(place) {
  265. this.addressSet = true;
  266. this.property.streetNumber = place.streetNumber;
  267. this.property.streetName = place.streetName;
  268. this.property.suburb = place.suburb;
  269. this.property.city = place.city;
  270. this.property.province = place.province;
  271. this.property.country = place.country;
  272. this.property.postalCode = place.postalCode;
  273. this.property.addressUrl = place.url;
  274. this.property.propertCoords = place.coords;
  275. },
  276. TypeChanged() {
  277. this.property.propertyUsageType = this.propertyType;
  278. },
  279. SubmitData() {
  280. if (this.property.propertyTypeId === 0) {
  281. this.showPropertyTypeError = true;
  282. }
  283. if (
  284. this.salesType === "Rental" &&
  285. this.property.dateAvailable === "undef"
  286. ) {
  287. this.showDateError = true;
  288. }
  289. if (this.showPropertyTypeError || this.showDateError) {
  290. return;
  291. }
  292. this.wait = true;
  293. if (this.salesType === "Sale") {
  294. this.property.isSale = true;
  295. this.property.dateAvailable = new Date();
  296. }
  297. if (this.images.length > 0) {
  298. this.property.propertyImages = [];
  299. }
  300. // eslint-disable-next-line no-plusplus
  301. for (let i = 0; i < this.images.length; i++) {
  302. let setAsDefault = false;
  303. if (i === this.defaultImage) {
  304. setAsDefault = true;
  305. }
  306. this.property.propertyImages.push({
  307. image: this.images[i],
  308. isDefault: setAsDefault,
  309. });
  310. }
  311. this.property.propertyUserFields = this.propertyFieldValues;
  312. if (this.user) {
  313. this.property.userId = this.user.id;
  314. }
  315. this.saveProperty(this.property)
  316. .then((fulfilled) => {
  317. this.$router.push(
  318. `/property/commercial/property/${fulfilled.data.id}`
  319. );
  320. })
  321. .catch((error) => {
  322. console.log(error.message);
  323. });
  324. },
  325. Close() {
  326. this.$router.push("/property/admin/list/my");
  327. },
  328. Login() {
  329. this.$router.push("/user/login");
  330. },
  331. PropertyTypeSelected(item) {
  332. if (item.target.options.selectedIndex > 0) {
  333. this.showPropertyTypeError = false;
  334. } else {
  335. this.showPropertyTypeError = true;
  336. }
  337. },
  338. loadedImages(values) {
  339. this.images = values;
  340. },
  341. UpdateUserDefinedFields(item) {
  342. let update = false;
  343. this.propertyFieldValues.forEach((element) => {
  344. if (element.userDefinedFieldId === item.userDefinedFieldId) {
  345. element.value = item.value;
  346. update = true;
  347. }
  348. });
  349. if (!update) {
  350. this.propertyFieldValues.push(item);
  351. }
  352. },
  353. UpdateDefaultImage(item) {
  354. this.defaultImage = item;
  355. },
  356. },
  357. mounted() {
  358. this.wait = false;
  359. this.getProperty(0);
  360. this.clearPropertyImages();
  361. this.images = [];
  362. this.defaultImage = 0;
  363. if (this.propertyOverviewFields.length > 0) {
  364. this.propertyOverviewFields = [];
  365. }
  366. if (this.propertyFields.length > 0) {
  367. this.propertyFields = [];
  368. }
  369. if (this.property.description !== "") {
  370. this.property.description = "";
  371. }
  372. if (this.$route.params.propertyUsageType) {
  373. this.propertyType = this.$route.params.propertyUsageType;
  374. }
  375. this.salesType = this.$route.params.saleType;
  376. this.getPropertyTypes(this.propertyType);
  377. this.getPropertyOverviewFields();
  378. this.getPropertyFields(this.propertyType);
  379. },
  380. computed: {
  381. ...mapState("property", [
  382. "propertyTypes",
  383. "propertyOverviewFields",
  384. "propertyFields",
  385. "property",
  386. "propertyImages",
  387. ]),
  388. SalesTypeChanged() {
  389. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  390. // this.propertyType = this.$route.params.propType;
  391. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  392. this.salesType = this.$route.params.saleType;
  393. if (this.property && this.property.propertyUsageType) {
  394. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  395. this.propertyType = this.property.propertyUsageType;
  396. }
  397. if (!this.$route.query.id) {
  398. this.getPropertyFields(this.propertyType);
  399. }
  400. this.getPropertyTypes(this.propertyType);
  401. return this.propertyType;
  402. },
  403. },
  404. watch: {
  405. SalesTypeChanged() {
  406. return null;
  407. },
  408. },
  409. };
  410. </script>
  411. <style lang="scss" scoped></style>