123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- /* eslint-disable valid-typeof */
- /* eslint-disable max-len */
- /* eslint-disable indent */
- import axios from "axios";
- import _ from "lodash";
- import log from "../../../assets/Log";
-
- export default {
- namespaced: true,
- state: {
- propertySearch: {
- userName: "",
- salesType: "Sale",
- propertyUsageType: "All",
- propertyType: "All",
- province: "All",
- city: "All",
- suburb: "All",
- minPrice: 0,
- maxPrice: 0,
- availableFrom: undefined,
- propertyId: 0
- },
- properties: [],
- latestProperties: [],
- suburbs: [],
- searchText: "",
- suburbList: [],
- resultsShowing: false
- },
- mutations: {
- updateSearch(state, propertySearch) {
- state.properties = [];
- state.properties = propertySearch;
- },
- setLatestProperties(state, properties) {
- state.latestProperties = properties;
- },
- setPropertySearch(state, search) {
- state.propertySearch = search;
- },
- onClearFilter(state, filter) {
- if (filter === "availableFrom") {
- state.propertySearch[filter] = undefined;
- } else {
- state.propertySearch[filter] = "All";
- }
- },
- setSuburbs(state, items) {
- state.suburbList = [];
- state.suburbs = items;
- // eslint-disable-next-line no-plusplus
- for (let i = 0; i < state.suburbs.length; i++) {
- state.suburbList.push(state.suburbs[i].display);
- }
- },
- setFilter(state, value) {
- state.searchText = value;
- },
- setResultsShowing(state, value) {
- state.resultsShowing = value;
- }
- },
- getters: {
- filterSuburbs: state => {
- let subs = state.suburbs;
- if (state.searchText) {
- subs = _.filter(subs, s => s.display.contains(state.searchText));
- }
- return subs;
- }
- },
- actions: {
- clearFilter({ commit }, filter) {
- commit("onClearFilter", filter);
- },
- searchProperties({ commit }, item) {
- if (item.keyword === "") {
- item.keyword = "All";
- }
- if (log.isLoggedIn()) {
- item.userName = log.getUser().username;
- } else if (item.userName === "") {
- item.userName = "Unknown";
- }
- if (item.suburb === "") {
- item.suburb = "All";
- }
- if (item.city === "") {
- item.city = "All";
- }
- if (item.province === "") {
- item.province = "All";
- }
- axios
- .get(
- `/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}`
- )
- .then(result => commit("updateSearch", result.data))
- .catch(console.error);
- },
- searchLatestProperties({ commit }) {
- axios
- .get("/api/property/latestProperties")
- .then(response => commit("setLatestProperties", response.data))
- .catch(console.error);
- },
- getSuburbs({ commit }) {
- axios
- .get("/api/suburb/GetSearchList")
- .then(response => commit("setSuburbs", response.data))
- .catch(console.error);
- },
- applyFilter({ commit }, value) {
- commit("setFilter", { value });
- },
- updateResultsShowing({ commit }, value) {
- commit("setResultsShowing", value);
- }
- }
- };
|