forked from verdnatura/salix-front
feat: create VnSelectEnum and add in AccountBasicData and ClaimBasicData
This commit is contained in:
parent
f1759eca04
commit
21a7fafba5
|
@ -0,0 +1,52 @@
|
|||
<script setup>
|
||||
import { onBeforeMount, ref, useAttrs } from 'vue';
|
||||
import axios from 'axios';
|
||||
import VnSelect from 'components/common/VnSelect.vue';
|
||||
|
||||
const { schema, table, column, translation, defaultOptions } = defineProps({
|
||||
schema: {
|
||||
type: String,
|
||||
default: 'vn',
|
||||
},
|
||||
table: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
column: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
translation: {
|
||||
type: Function,
|
||||
default: null,
|
||||
},
|
||||
defaultOptions: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
const $attrs = useAttrs();
|
||||
const options = ref([]);
|
||||
onBeforeMount(async () => {
|
||||
options.value = [].concat(defaultOptions);
|
||||
const { data } = await axios.get(`Applications/get-enum-values`, {
|
||||
params: { schema, table, column },
|
||||
});
|
||||
|
||||
for (const value of data)
|
||||
options.value.push({
|
||||
[$attrs['option-value'] ?? 'id']: value,
|
||||
[$attrs['option-label'] ?? 'name']: translation ? translation(value) : value,
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<VnSelect
|
||||
v-bind="$attrs"
|
||||
:options="options"
|
||||
:key="options.length"
|
||||
:input-debounce="0"
|
||||
/>
|
||||
</template>
|
|
@ -2,6 +2,7 @@
|
|||
import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||
import VnSelectEnum from 'src/components/common/VnSelectEnum.vue';
|
||||
import FormModel from 'components/FormModel.vue';
|
||||
import VnInput from 'src/components/common/VnInput.vue';
|
||||
import { ref, watch } from 'vue';
|
||||
|
@ -43,9 +44,11 @@ watch(
|
|||
option-value="code"
|
||||
option-label="code"
|
||||
/>
|
||||
<VnSelect
|
||||
url="TwoFactorTypes"
|
||||
v-model="data.twoFactorFk"
|
||||
<VnSelectEnum
|
||||
schema="account"
|
||||
table="user"
|
||||
column="twoFactor"
|
||||
v-model="data.twoFactor"
|
||||
:label="t('account.card.twoFactor')"
|
||||
option-value="code"
|
||||
option-label="code"
|
||||
|
|
|
@ -3,58 +3,18 @@ import { ref } from 'vue';
|
|||
import { useRoute } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||
import VnSelectEnum from 'src/components/common/VnSelectEnum.vue';
|
||||
import FetchData from 'components/FetchData.vue';
|
||||
import FormModel from 'components/FormModel.vue';
|
||||
import VnRow from 'components/ui/VnRow.vue';
|
||||
import VnInput from 'src/components/common/VnInput.vue';
|
||||
import VnInputDate from 'components/common/VnInputDate.vue';
|
||||
|
||||
import axios from 'axios';
|
||||
import VnAvatar from 'src/components/ui/VnAvatar.vue';
|
||||
|
||||
const route = useRoute();
|
||||
const { t } = useI18n();
|
||||
|
||||
const claimStates = ref([]);
|
||||
const claimStatesCopy = ref([]);
|
||||
const optionsList = ref([]);
|
||||
|
||||
const workersOptions = ref([]);
|
||||
|
||||
function setClaimStates(data) {
|
||||
claimStates.value = data;
|
||||
claimStatesCopy.value = data;
|
||||
}
|
||||
|
||||
async function getEnumValues() {
|
||||
optionsList.value = [{ id: null, description: t('claim.null') }];
|
||||
const { data } = await axios.get(`Applications/get-enum-values`, {
|
||||
params: {
|
||||
schema: 'vn',
|
||||
table: 'claim',
|
||||
column: 'pickup',
|
||||
},
|
||||
});
|
||||
for (let value of data)
|
||||
optionsList.value.push({ id: value, description: t(`claim.${value}`) });
|
||||
}
|
||||
|
||||
getEnumValues();
|
||||
|
||||
const statesFilter = {
|
||||
options: claimStates,
|
||||
filterFn: (options, value) => {
|
||||
const search = value.toLowerCase();
|
||||
|
||||
if (value === '') return claimStatesCopy.value;
|
||||
|
||||
return options.value.filter((row) => {
|
||||
const description = row.description.toLowerCase();
|
||||
|
||||
return description.indexOf(search) > -1;
|
||||
});
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<template>
|
||||
<FetchData
|
||||
|
@ -70,7 +30,7 @@ const statesFilter = {
|
|||
auto-load
|
||||
:reload="true"
|
||||
>
|
||||
<template #form="{ data, validate, filter }">
|
||||
<template #form="{ data, validate }">
|
||||
<VnRow>
|
||||
<VnInput
|
||||
v-model="data.client.name"
|
||||
|
@ -101,20 +61,14 @@ const statesFilter = {
|
|||
/>
|
||||
</template>
|
||||
</VnSelect>
|
||||
<QSelect
|
||||
<VnSelect
|
||||
v-model="data.claimStateFk"
|
||||
:options="claimStates"
|
||||
option-value="id"
|
||||
option-label="description"
|
||||
emit-value
|
||||
url="ClaimStates"
|
||||
:label="t('claim.state')"
|
||||
map-options
|
||||
use-input
|
||||
@filter="(value, update) => filter(value, update, statesFilter)"
|
||||
option-label="description"
|
||||
:rules="validate('claim.claimStateFk')"
|
||||
:input-debounce="0"
|
||||
>
|
||||
</QSelect>
|
||||
/>
|
||||
</VnRow>
|
||||
<VnRow>
|
||||
<QInput
|
||||
|
@ -123,16 +77,14 @@ const statesFilter = {
|
|||
:rules="validate('claim.packages')"
|
||||
type="number"
|
||||
/>
|
||||
<QSelect
|
||||
<VnSelectEnum
|
||||
v-model="data.pickup"
|
||||
:options="optionsList"
|
||||
option-value="id"
|
||||
option-label="description"
|
||||
emit-value
|
||||
:label="t('claim.pickup')"
|
||||
map-options
|
||||
use-input
|
||||
:input-debounce="0"
|
||||
table="claim"
|
||||
column="pickup"
|
||||
option-label="description"
|
||||
:translation="(value) => t(`claim.${value}`)"
|
||||
:default-options="[{ id: null, description: t('claim.null') }]"
|
||||
/>
|
||||
</VnRow>
|
||||
</template>
|
||||
|
|
|
@ -12,7 +12,7 @@ describe('Two Factor', () => {
|
|||
cy.request(
|
||||
'PATCH',
|
||||
`http://localhost:3000/api/VnUsers/${userId}/update-user?access_token=DEFAULT_TOKEN`,
|
||||
{ twoFactorFk: 'email' }
|
||||
{ twoFactor: 'email' }
|
||||
);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue