dicaribapak11

SelectRecAccount

Oct 10th, 2025
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script setup lang="ts">
  2.   import { stateKey } from "./FormRegistration.vue";
  3.   import { useField } from "vee-validate";
  4.   import { onMounted } from "vue";
  5.  
  6.   const { t } = useI18n();
  7.   const state = inject(stateKey, ref());
  8.   const isLoading = ref(false);
  9.   const token = ref(null);
  10.   token.value = localStorage.getItem("sanctum.storage.token");
  11.   const config = useRuntimeConfig();
  12.   const data = ref([]);
  13.   const error = ref();
  14.  
  15.   function handleSelect(name: string) {
  16.     state!.value.rec_account = name;
  17.   }
  18.  
  19.   async function fetchData() {
  20.     try {
  21.       isLoading.value = true;
  22.       const { return: _data } = await $fetch(
  23.         `${config.public.apiBaseUrl}/api/v1/references/recc-accounts/index`,
  24.         {
  25.           method: "GET",
  26.           headers: {
  27.             authorization: `Bearer ${token.value}`,
  28.           },
  29.           server: false,
  30.         },
  31.       );
  32.  
  33.       data.value = _data.data;
  34.     } catch (error) {
  35.       isLoading.value = false;
  36.     } finally {
  37.       isLoading.value = false;
  38.     }
  39.   }
  40.   onMounted(fetchData);
  41. </script>
  42.  
  43. <template>
  44.   <MoleculeSelectBase v-model="state.rec_account_uuid" :placeholder="t('select')">
  45.     <SelectGroup>
  46.       <template v-if="isLoading">
  47.         <SelectItem disabled="">Loading ...</SelectItem>
  48.       </template>
  49.       <template v-else-if="error">
  50.         <SelectItem disabled>Failed load data</SelectItem>
  51.       </template>
  52.       <template v-else>
  53.         <SelectItem
  54.           v-for="{ uuid, name } in data"
  55.           :key="uuid"
  56.           :value="uuid"
  57.           @select="() => handleSelect(name)"
  58.         >
  59.           {{ name }}
  60.         </SelectItem>
  61.       </template>
  62.     </SelectGroup>
  63.   </MoleculeSelectBase>
  64. </template>
  65.  
Advertisement
Add Comment
Please, Sign In to add comment