|
| 1 | +<template> |
| 2 | + <div v-if="depot"> |
| 3 | + <div class="mb-2"> |
| 4 | + <h1 class="text-4xl font-bold">{{ depot.titre }}</h1> |
| 5 | + <p class="text-xl">{{ depot.description }}</p> |
| 6 | + </div> |
| 7 | + <div class="mt-4 px-4 py-2 bg-white rounded-xl"> |
| 8 | + <h2 class="text-md font-semibold">Création d'une nouvelle réponse</h2> |
| 9 | + <form class="flex flex-col gap-2" @submit.prevent="creer"> |
| 10 | + <input type="text" v-model="titre" placeholder="Titre" class="border border-gray-300 rounded-lg p-2"> |
| 11 | + <textarea v-model="description" placeholder="Description" class="border border-gray-300 rounded-lg p-2"></textarea> |
| 12 | + <select v-model="type" class="border border-gray-300 rounded-lg p-2" placeholder="Priorité"> |
| 13 | + <option selected disabled value="0">Type de réponse</option> |
| 14 | + <option v-for="type in getTypes()" :value="type" :key="type">{{ getTypeLabel(type) }}</option> |
| 15 | + </select> |
| 16 | + <button |
| 17 | + class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" |
| 18 | + :class="{ |
| 19 | + 'cursor-not-allowed': loading, |
| 20 | + }" |
| 21 | + :disabled="loading" |
| 22 | + >{{ loading ? 'En cours' : 'Creer' }}</button> |
| 23 | + </form> |
| 24 | + </div> |
| 25 | + </div> |
| 26 | + <div v-else> |
| 27 | + <p>Le dépot n'existe pas</p> |
| 28 | + </div> |
| 29 | +</template> |
| 30 | + |
| 31 | +<script> |
| 32 | +import { mapActions, mapGetters } from 'vuex'; |
| 33 | +import api from '@/api'; |
| 34 | +import {getAll, getLabel} from '@/enum/demande_clinique/reponse/type'; |
| 35 | +
|
| 36 | +export default { |
| 37 | + name: 'Depot', |
| 38 | + data: function () { |
| 39 | + return { |
| 40 | + titre: '', |
| 41 | + description: '', |
| 42 | + loading: false, |
| 43 | + type: 0, |
| 44 | + }; |
| 45 | + }, |
| 46 | + computed: { |
| 47 | + ...mapGetters({ |
| 48 | + depots: 'demande_clinique/depots', |
| 49 | + }), |
| 50 | + id: function () { |
| 51 | + return parseInt(this.$route.params.id); |
| 52 | + }, |
| 53 | + depot: function () { |
| 54 | + return this.depots.find((depot) => depot.id === this.id); |
| 55 | + }, |
| 56 | + }, |
| 57 | + methods: { |
| 58 | + ...mapActions({ |
| 59 | + chargerDepots: 'demande_clinique/chargerDepots', |
| 60 | + }), |
| 61 | + getTypes: getAll, |
| 62 | + getTypeLabel: getLabel, |
| 63 | + creer: async function() { |
| 64 | + if (!(this.titre && this.description)) { |
| 65 | + window.alert('Veuillez remplir tous les champs'); |
| 66 | + return; |
| 67 | + } |
| 68 | +
|
| 69 | + try { |
| 70 | + this.loading = true; |
| 71 | + await api.demande_clinique.depots.ajouterReponse(this.depot.id, this.titre, this.description, this.type); |
| 72 | + await this.chargerDepots(); |
| 73 | + this.$router.push('/'); |
| 74 | + } catch (e) { |
| 75 | + console.error(e); |
| 76 | + window.alert('Une erreur est survenue'); |
| 77 | + this.loading = false; |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | +} |
| 82 | +</script> |
0 commit comments