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.

propertySearch.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* eslint-disable valid-typeof */
  2. /* eslint-disable max-len */
  3. /* eslint-disable indent */
  4. import axios from "axios";
  5. import _ from "lodash";
  6. import log from "../../../assets/Log";
  7. export default {
  8. namespaced: true,
  9. state: {
  10. propertySearch: {
  11. userName: "",
  12. salesType: "Sale",
  13. propertyUsageType: "All",
  14. propertyType: "All",
  15. province: "All",
  16. city: "All",
  17. suburb: "All",
  18. minPrice: 0,
  19. maxPrice: 0,
  20. availableFrom: undefined,
  21. propertyId: 0
  22. },
  23. properties: [],
  24. latestProperties: [],
  25. suburbs: [],
  26. searchText: "",
  27. suburbList: [],
  28. resultsShowing: false
  29. },
  30. mutations: {
  31. updateSearch(state, propertySearch) {
  32. state.properties = [];
  33. state.properties = propertySearch;
  34. },
  35. setLatestProperties(state, properties) {
  36. state.latestProperties = properties;
  37. },
  38. setPropertySearch(state, search) {
  39. state.propertySearch = search;
  40. },
  41. onClearFilter(state, filter) {
  42. if (filter === "availableFrom") {
  43. state.propertySearch[filter] = undefined;
  44. } else {
  45. state.propertySearch[filter] = "All";
  46. }
  47. },
  48. setSuburbs(state, items) {
  49. state.suburbList = [];
  50. state.suburbs = items;
  51. // eslint-disable-next-line no-plusplus
  52. for (let i = 0; i < state.suburbs.length; i++) {
  53. state.suburbList.push(state.suburbs[i].display);
  54. }
  55. },
  56. setFilter(state, value) {
  57. state.searchText = value;
  58. },
  59. setResultsShowing(state, value) {
  60. state.resultsShowing = value;
  61. }
  62. },
  63. getters: {
  64. filterSuburbs: state => {
  65. let subs = state.suburbs;
  66. if (state.searchText) {
  67. subs = _.filter(subs, s => s.display.contains(state.searchText));
  68. }
  69. return subs;
  70. }
  71. },
  72. actions: {
  73. clearFilter({ commit }, filter) {
  74. commit("onClearFilter", filter);
  75. },
  76. searchProperties({ commit }, item) {
  77. if (item.keyword === "") {
  78. item.keyword = "All";
  79. }
  80. if (log.isLoggedIn()) {
  81. item.userName = log.getUser().username;
  82. } else if (item.userName === "") {
  83. item.userName = "Unknown";
  84. }
  85. if (item.suburb === "") {
  86. item.suburb = "All";
  87. }
  88. if (item.city === "") {
  89. item.city = "All";
  90. }
  91. if (item.province === "") {
  92. item.province = "All";
  93. }
  94. axios
  95. .get(
  96. `/api/Property/Search/${item.userName}/${item.keyword}/${item.salesType}/${item.propertyUsageType}/${item.propertyType}/${item.province}/${item.city}/${item.suburb}/${item.minPrice}/${item.maxPrice}/${item.availableFrom}/${item.propertyId}`
  97. )
  98. .then(result => commit("updateSearch", result.data))
  99. .catch(console.error);
  100. },
  101. searchLatestProperties({ commit }) {
  102. axios
  103. .get("/api/property/latestProperties")
  104. .then(response => commit("setLatestProperties", response.data))
  105. .catch(console.error);
  106. },
  107. getSuburbs({ commit }) {
  108. axios
  109. .get("/api/suburb/GetSearchList")
  110. .then(response => commit("setSuburbs", response.data))
  111. .catch(console.error);
  112. },
  113. applyFilter({ commit }, value) {
  114. commit("setFilter", { value });
  115. },
  116. updateResultsShowing({ commit }, value) {
  117. commit("setResultsShowing", value);
  118. }
  119. }
  120. };