Commit 37c6fb2c authored by Rémy Marronnier's avatar Rémy Marronnier

adress ban + zrr + autocomplete wip

parent b409554a
export const CLARA_API_URL = "https://***/api/";
export default CLARA_API_URL;
\ No newline at end of file
import { BAN_API_URL } from "./config";
export default function BANService(postcode) {
return fetch(BAN_API_URL.concat(postcode), {
credentials: 'include',
method: "GET",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
})
}
\ No newline at end of file
export const CLARA_API_URL = "https://***/api/";
export const BAN_API_URL = "https://api-adresse.data.gouv.fr/search/?limit=5&q=";
export const ZRR_API_URL = "https://public.opendatasoft.com/api/records/1.0/search/?dataset=communes-zrr-2017&q=";
export default CLARA_API_URL;
\ No newline at end of file
import { ZRR_API_URL } from "./config";
export default function ZRRService(postcode) {
return fetch(ZRR_API_URL.concat(postcode), {
credentials: 'include',
method: "GET",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
})
}
\ No newline at end of file
import ClaraService from "@/api/clara"; // import ClaraService from "@/services/clara";
export default { // export default {
state: { // state: {
}, // },
mutations: { // mutations: {
}, // },
actions: { // actions: {
} // }
} // }
\ No newline at end of file \ No newline at end of file
//import ClaraService from "@/api/clara"; import ZRRService from "@/services/zrr";
export default { export default {
state: { state: {
...@@ -10,7 +10,9 @@ export default { ...@@ -10,7 +10,9 @@ export default {
allocation_type: "", allocation_type: "",
monthly_allocation_value: 0, monthly_allocation_value: 0,
age: 0, age: 0,
address: "",
location_citycode: "", location_citycode: "",
zrr: "non renseigné",
category: "", category: "",
}, },
mutations: { mutations: {
...@@ -38,24 +40,49 @@ export default { ...@@ -38,24 +40,49 @@ export default {
updateAge(state, age) { updateAge(state, age) {
state.age = age state.age = age
}, },
updateAddress(state, address) {
state.address = address
},
updateLocationCitycode(state, location_citycode) { updateLocationCitycode(state, location_citycode) {
state.location_citycode = location_citycode state.location_citycode = location_citycode
}, },
updateZRR(state, zrr) {
state.zrr = zrr
},
updateCategory(state, category) { updateCategory(state, category) {
state.category = category state.category = category
}, },
}, },
actions: { actions: {
// submitInscription({ commit }, inscription_period) { submitInscription({ commit, state }, inscription_period) {
if (inscription_period != state.inscription_period) {
// }, commit('updateInscriptionPeriod', inscription_period)
submitAddress({ commit, state }, location_citycode) { commit('updateChanged', true)
}
},
submitAddress({ commit, state }, address) {
if (address != state.address) {
commit('updateAddress', address)
commit('updateChanged', true)
}
},
submitCitycode({ commit, dispatch, state }, location_citycode) {
if (location_citycode != state.location_citycode) { if (location_citycode != state.location_citycode) {
commit('updateLocationCitycode', location_citycode) commit('updateLocationCitycode', location_citycode)
commit('updateChanged', true) commit('updateChanged', true)
ZRRService(location_citycode)
.then(res => res.json())
.then(res => {
dispatch('submitZRR', res.records.first.fields.zrr_2017);
})
}
},
submitZRR({ commit, state }, zrr) {
if (zrr != state.zrr) {
commit('updateZRR', zrr)
commit('updateChanged', true)
} }
// this.$router.push('other')
}, },
submitAge({ commit, state }, age) { submitAge({ commit, state }, age) {
if (age != state.age) { if (age != state.age) {
...@@ -130,6 +157,7 @@ export default { ...@@ -130,6 +157,7 @@ export default {
allocation_type: state => state.allocation_type, allocation_type: state => state.allocation_type,
monthly_allocation_value: state => state.monthly_allocation_value, monthly_allocation_value: state => state.monthly_allocation_value,
age: state => state.age, age: state => state.age,
address: state => state.address,
location_citycode: state => state.location_citycode, location_citycode: state => state.location_citycode,
category: state => state.category, category: state => state.category,
......
...@@ -4,6 +4,33 @@ ...@@ -4,6 +4,33 @@
Code postal - facultatif Code postal - facultatif
<v-row> <v-row>
<v-col> <v-col>
<v-autocomplete
v-model="model"
:items="items"
:loading="isLoading"
:search-input.sync="search"
autofocus
hide-no-data
hide-selected
item-text="Description"
item-value="Citycode"
label="Exemple : 44220"
placeholder="Exemple : 44220"
prepend-icon="mdi-database-search"
return-object
></v-autocomplete>
<v-expand-transition>
<v-list v-if="model" class="red lighten-3">
<v-list-item v-for="(field, i) in fields" :key="i">
<v-list-item-content>
<v-list-item-title v-text="field.value"></v-list-item-title>
<v-list-item-subtitle v-text="field.key"></v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</v-list>
</v-expand-transition>
<v-text-field autofocus v-model.number="address" type="number" label="Exemple : 44220"></v-text-field> <v-text-field autofocus v-model.number="address" type="number" label="Exemple : 44220"></v-text-field>
</v-col> </v-col>
<v-col> <v-col>
...@@ -19,14 +46,20 @@ ...@@ -19,14 +46,20 @@
</template> </template>
<script> <script>
import BANService from "@/services/ban";
export default { export default {
name: "Address", name: "Address",
created() { created() {
this.address = this.$store.state.situation.location_citycode; this.address = this.$store.state.situation.address;
this.citycode = this.$store.state.situation.location_citycode;
}, },
data: () => ({ data: () => ({
address: 0, address: "",
validity: false citycode: null,
validity: false,
results: [],
search: null,
model: null
}), }),
methods: { methods: {
validate() { validate() {
...@@ -40,8 +73,53 @@ export default { ...@@ -40,8 +73,53 @@ export default {
submitAddress() { submitAddress() {
this.validate(); this.validate();
this.$store.dispatch("submitAddress", this.address); this.$store.dispatch("submitAddress", this.address);
this.$store.dispatch("submitCitycode", this.citycode);
this.$router.push("autres-situations"); this.$router.push("autres-situations");
} }
},
computed: {
fields() {
if (!this.model) return [];
return Object.keys(this.model).map(key => {
return {
key,
value: this.model[key] || "n/a"
};
});
},
items() {
return this.results.map(result => {
const Description =
result.properties.city + " " + result.properties.postcode;
const Citycode = result.properties.citycode;
return Object.assign({}, result, { Description, Citycode });
});
}
},
watch: {
search() {
// Items have already been loaded
if (this.items.length > 0) return;
// Items have already been requested
if (this.isLoading) return;
this.isLoading = true;
// Lazily load input items
BANService(this.address)
.then(res => res.json())
.then(res => {
this.results = res.features;
})
// .catch(err => {
// //console.log(err);
// })
.finally(() => (this.isLoading = false));
}
} }
}; };
</script> </script>
......
...@@ -34,8 +34,11 @@ export default { ...@@ -34,8 +34,11 @@ export default {
submitInscription() { submitInscription() {
this.validate(); this.validate();
this.$store.dispatch("submitInscription", this.inscription); this.$store.dispatch("submitInscription", this.inscription);
// if choice != non inscrit if (this.inscription != "not_registred") {
this.$router.push("categorie"); this.$router.push("categorie");
} else {
this.$router.push("votre-allocation");
}
} }
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment