generated from posva/vite-tailwind-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(price add): new LocationInputRow component (#647)
- Loading branch information
Showing
3 changed files
with
101 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<template> | ||
<v-row> | ||
<v-col cols="12"> | ||
<h3 class="mb-1"> | ||
{{ $t('AddPriceSingle.WhereWhen.Location') }} | ||
</h3> | ||
<v-chip | ||
v-for="location in recentLocations" | ||
:key="getLocationUniqueID(location)" | ||
class="mb-2" | ||
:style="isSelectedLocation(location) ? 'border: 1px solid #4CAF50' : 'border: 1px solid transparent'" | ||
@click="setLocationData(location)" | ||
> | ||
<v-icon start :icon="isSelectedLocation(location) ? 'mdi-check-circle-outline' : 'mdi-history'" :color="isSelectedLocation(location) ? 'green' : ''" /> | ||
{{ getLocationTitle(location, true, true, true) }} | ||
</v-chip> | ||
<br v-if="recentLocations.length"> | ||
<v-btn class="mb-2" size="small" prepend-icon="mdi-magnify" @click="locationSelectorDialog = true"> | ||
{{ $t('AddPriceSingle.WhereWhen.Find') }} | ||
</v-btn> | ||
<p v-if="!locationFormFilled" class="text-red mb-2"> | ||
<i>{{ $t('AddPriceSingle.WhereWhen.SelectLocation') }}</i> | ||
</p> | ||
</v-col> | ||
</v-row> | ||
|
||
<LocationSelectorDialog | ||
v-if="locationSelectorDialog" | ||
v-model="locationSelectorDialog" | ||
@location="setLocationData($event)" | ||
@close="locationSelectorDialog = false" | ||
/> | ||
</template> | ||
|
||
<script> | ||
import { defineAsyncComponent } from 'vue' | ||
import { mapStores } from 'pinia' | ||
import { useAppStore } from '../store' | ||
import utils from '../utils.js' | ||
export default { | ||
components: { | ||
LocationSelectorDialog: defineAsyncComponent(() => import('../components/LocationSelectorDialog.vue')), | ||
}, | ||
props: { | ||
locationForm: { | ||
type: Object, | ||
default: () => ({ location_osm_id: null, location_osm_type: null }) | ||
}, | ||
}, | ||
data() { | ||
return { | ||
locationSelectorDialog: false, | ||
} | ||
}, | ||
computed: { | ||
...mapStores(useAppStore), | ||
recentLocations() { | ||
return this.appStore.getRecentLocations(3) | ||
}, | ||
locationFormFilled() { | ||
let keys = ['location_osm_id', 'location_osm_type'] | ||
return Object.keys(this.locationForm).filter(k => keys.includes(k)).every(k => !!this.locationForm[k]) | ||
}, | ||
}, | ||
mounted() { | ||
this.initLocationForm() | ||
}, | ||
methods: { | ||
initLocationForm() { | ||
if (this.recentLocations.length) { | ||
this.setLocationData(this.recentLocations[0]) | ||
} | ||
}, | ||
showLocationSelectorDialog() { | ||
this.locationSelectorDialog = true | ||
}, | ||
getLocationTitle(location, withName=true, withRoad=false, withCity=true) { | ||
return utils.getLocationTitle(location, withName, withRoad, withCity) | ||
}, | ||
getLocationUniqueID(location) { | ||
return utils.getLocationUniqueID(location) | ||
}, | ||
setLocationData(location) { | ||
this.appStore.addRecentLocation(location) | ||
this.locationForm.location_osm_id = utils.getLocationID(location) | ||
this.locationForm.location_osm_type = utils.getLocationType(location) | ||
}, | ||
isSelectedLocation(location) { | ||
return (this.locationForm.location_osm_id === utils.getLocationID(location)) && (this.locationForm.location_osm_type === utils.getLocationType(location)) | ||
}, | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters