0
0
Fork 0

feat(VnTable): refs #6825 execute function when create

This commit is contained in:
Alex Moreno 2024-05-22 14:20:38 +02:00
parent a715122a66
commit 4ae580543b
5 changed files with 59 additions and 26 deletions

View File

@ -54,7 +54,7 @@ const router = useRouter();
const mode = ref('card'); const mode = ref('card');
const selected = ref([]); const selected = ref([]);
const params = ref({}); const params = ref({});
const VnPaginateRef = ref(); const VnPaginateRef = ref({});
const showForm = ref(false); const showForm = ref(false);
const splittedColumns = ref({ columns: [] }); const splittedColumns = ref({ columns: [] });
const tableModes = [ const tableModes = [
@ -118,22 +118,34 @@ function splitColumns(columns) {
field: 'status', field: 'status',
label: t('status'), label: t('status'),
name: 'status', name: 'status',
customFilter: false, columnFilter: false,
}); });
} }
} }
const rowClickFunction = computed(() => { const rowClickFunction = computed(() => {
if ($props.rowClick) return $props.rowClick; if ($props.rowClick) return $props.rowClick;
if ($props.redirect) if ($props.redirect) return ({ id }) => redirectFn(id);
return ({ id }) => router.push({ path: `/${$props.redirect}/${id}` });
return () => {}; return () => {};
}); });
function redirectFn(id) {
router.push({ path: `/${$props.redirect}/${id}` });
}
function stopEventPropagation(event) { function stopEventPropagation(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
} }
function reload() {
VnPaginateRef.value.fetch();
}
defineExpose({
reload,
redirect: redirectFn,
});
</script> </script>
<template> <template>
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above> <QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above>
@ -240,6 +252,7 @@ function stopEventPropagation(event) {
:row="row" :row="row"
:is-editable="false" :is-editable="false"
v-model="row[col.field]" v-model="row[col.field]"
component-prop="columnField"
/> />
</QTd> </QTd>
</template> </template>
@ -317,7 +330,11 @@ function stopEventPropagation(event) {
:icon="btn.icon" :icon="btn.icon"
class="q-pa-xs" class="q-pa-xs"
flat flat
:class="{ 'text-primary-light': btn.isPrimary }" :class="
btn.isPrimary
? 'text-primary-light'
: 'color-vn-text '
"
@click="btn.action(row)" @click="btn.action(row)"
/> />
</QCardSection> </QCardSection>
@ -337,6 +354,7 @@ function stopEventPropagation(event) {
<FormModelPopup <FormModelPopup
v-bind="{ ...$attrs, ...create }" v-bind="{ ...$attrs, ...create }"
:model="$attrs['data-key'] + 'Create'" :model="$attrs['data-key'] + 'Create'"
@on-data-saved="(_, res) => create.onDataSaved(res)"
> >
<template #form-inputs="{ data }"> <template #form-inputs="{ data }">
<div class="grid-create"> <div class="grid-create">
@ -362,10 +380,7 @@ function stopEventPropagation(event) {
.bg-header { .bg-header {
background-color: #5d5d5d; background-color: #5d5d5d;
color: var(--vn-page-color); color: var(--vn-text-color);
* {
font-weight: bold !important;
}
} }
.q-table--dark .q-table__bottom, .q-table--dark .q-table__bottom,
@ -466,6 +481,7 @@ function stopEventPropagation(event) {
.vn-label-value { .vn-label-value {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
color: var(--vn-text-color);
.value { .value {
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;

View File

@ -82,7 +82,9 @@ const defaultComponents = {
}; };
const value = computed(() => { const value = computed(() => {
return $props.column.format ? $props.column.format($props.row) : $props.row; return $props.column.format
? $props.column.format($props.row, dashIfEmpty)
: dashIfEmpty($props.row[$props.column.field]);
}); });
const col = computed(() => { const col = computed(() => {
@ -108,22 +110,22 @@ const components = computed(() => $props.components ?? defaultComponents);
v-if="col.before" v-if="col.before"
:prop="col.before" :prop="col.before"
:components="components" :components="components"
:value="value" :value="$props.row"
v-model="model" v-model="model"
/> />
<VnComponent <VnComponent
v-if="col.component" v-if="col.component"
:prop="col" :prop="col"
:components="components" :components="components"
:value="value" :value="$props.row"
v-model="model" v-model="model"
/> />
<span :title="row[col.field]" v-else>{{ dashIfEmpty(row[col.field]) }}</span> <span :title="value" v-else>{{ value }}</span>
<VnComponent <VnComponent
v-if="col.after" v-if="col.after"
:prop="col.after" :prop="col.after"
:components="components" :components="components"
:value="value" :value="$props.row"
v-model="model" v-model="model"
/> />
</template> </template>

View File

@ -18,7 +18,7 @@
default="input" default="input"
v-model="model" v-model="model"
:components="components" :components="components"
:component-prop="`columnFilter`" component-prop="columnFilter"
/> />
</span> </span>
</div> </div>

View File

@ -85,14 +85,6 @@ watch(
} }
); );
watch(
() => arrayData.store.filter,
(val) => {
console.log('watch filter: ', val);
},
{ deep: true }
);
const isLoading = ref(false); const isLoading = ref(false);
async function search() { async function search() {
store.filter.where = {}; store.filter.where = {};
@ -184,7 +176,7 @@ function formatValue(value) {
</script> </script>
<template> <template>
<div id="filterPanelForm"> <QForm id="filterPanelForm">
<QList dense> <QList dense>
<QItem class="q-mt-xs"> <QItem class="q-mt-xs">
<QItemSection top> <QItemSection top>
@ -274,7 +266,7 @@ function formatValue(value) {
</QItem> </QItem>
<QSeparator /> <QSeparator />
</template> </template>
</div> </QForm>
<QInnerLoading <QInnerLoading
:label="t('globals.pleaseWait')" :label="t('globals.pleaseWait')"
:showing="isLoading" :showing="isLoading"

View File

@ -32,6 +32,7 @@ const selectedSalesPersonId = ref(0);
const allColumnNames = ref([]); const allColumnNames = ref([]);
const visibleColumns = ref([]); const visibleColumns = ref([]);
const postcodesOptions = ref([]); const postcodesOptions = ref([]);
const tableRef = ref();
const tableColumnComponents = { const tableColumnComponents = {
customerStatus: { customerStatus: {
@ -316,6 +317,10 @@ const columns = computed(() => [
where: { role: 'salesPerson' }, where: { role: 'salesPerson' },
}, },
create: true, create: true,
columnField: {
component: null,
},
format: (row, dashIfEmpty) => dashIfEmpty(row.salesPerson),
}, },
{ {
align: 'left', align: 'left',
@ -406,6 +411,10 @@ const columns = computed(() => [
optionLabel: 'description', optionLabel: 'description',
optionValue: 'code', optionValue: 'code',
}, },
columnField: {
component: null,
},
format: (row, dashIfEmpty) => dashIfEmpty(row.businessType),
}, },
{ {
align: 'left', align: 'left',
@ -463,7 +472,7 @@ const columns = computed(() => [
name: 'isFreezed', name: 'isFreezed',
chip: { chip: {
color: null, color: null,
condition: (v, { isActive, isFreezed }) => isActive && isFreezed == true, condition: (v, { isActive, isFreezed }) => isActive && isFreezed,
icon: 'vn:frozen', icon: 'vn:frozen',
}, },
}, },
@ -570,15 +579,29 @@ function handleLocation(data, location) {
</VnSubToolbar> --> </VnSubToolbar> -->
<VnTable <VnTable
ref="tableRef"
data-key="CustomerExtendedList" data-key="CustomerExtendedList"
url="Clients/extendedListFilter" url="Clients/extendedListFilter"
url-create="Clients/createWithUser" url-create="Clients/createWithUser"
:create="{ :create="{
urlCreate: 'Clients/createWithUser', urlCreate: 'Clients/createWithUser',
title: 'Create client', title: 'Create client',
onDataSaved: ({ id }) => tableRef.redirect(id),
formInitialData: { formInitialData: {
active: true, active: true,
isEqualizated: false, isEqualizated: false,
name: 'FFFF',
socialName: 'FFFFFF',
fi: '58233369H',
salesPersonFk: 15,
street: 'FASD',
businessTypeFk: 'individual',
email: 'adddssssd@asd.es',
userName: 'asdasdax',
postcode: '46680',
city: 'Algemesi',
provinceFk: 1,
countryFk: 1,
}, },
}" }"
order="id DESC" order="id DESC"