refactor: use table product

This commit is contained in:
Thanaphon Frappet 2024-11-27 14:56:23 +07:00
parent 9083dab4af
commit 696b465e7b

View file

@ -36,6 +36,7 @@ import {
UndoButton, UndoButton,
ToggleButton, ToggleButton,
} from 'components/button'; } from 'components/button';
import TableProduct from 'src/components/04_product-service/TableProduct.vue';
import useFlowStore from 'stores/flow'; import useFlowStore from 'stores/flow';
@ -233,6 +234,8 @@ const productTab = ref(1);
const productGroup = ref<ProductGroup[]>(); const productGroup = ref<ProductGroup[]>();
const product = ref<(Product & { type: 'product' })[]>(); const product = ref<(Product & { type: 'product' })[]>();
const productIsAdd = ref<(Product & { type: 'product' })[]>(); const productIsAdd = ref<(Product & { type: 'product' })[]>();
const modeViewIsAdd = ref<boolean>(false);
const service = ref<(Service & { type: 'service' })[]>(); const service = ref<(Service & { type: 'service' })[]>();
const resultSearchProduct = ref<Product[]>(); const resultSearchProduct = ref<Product[]>();
@ -3354,18 +3357,8 @@ watch(
} }
" "
> >
<div <div class="full-width q-pa-lg column full-height no-wrap">
class="full-width q-pa-lg column" <div class="row items-center q-mb-md" v-if="productIsAdd?.length !== 0">
:class="
resultSearchProduct?.length === 0 || productIsAdd?.length === 0
? 'full-height no-wrap'
: ''
"
>
<div
class="row items-center justify-between q-mb-md"
v-if="productIsAdd?.length !== 0"
>
<q-checkbox <q-checkbox
:label="$t('general.selectAll')" :label="$t('general.selectAll')"
:model-value=" :model-value="
@ -3413,6 +3406,52 @@ watch(
} }
" "
/> />
<q-btn-toggle
v-model="modeViewIsAdd"
id="btn-mode"
dense
class="no-shadow bordered rounded surface-1 q-ml-auto q-mr-sm"
:toggle-color="$q.dark.isActive ? 'grey-9' : 'grey-2'"
size="xs"
:options="[
{ value: true, slot: 'folder' },
{ value: false, slot: 'list' },
]"
>
<template v-slot:folder>
<q-icon
name="mdi-view-grid-outline"
size="16px"
class="q-px-sm q-py-xs rounded"
:style="{
color: $q.dark.isActive
? modeViewIsAdd
? '#C9D3DB '
: '#787B7C'
: modeViewIsAdd
? '#787B7C'
: '#C9D3DB',
}"
/>
</template>
<template v-slot:list>
<q-icon
name="mdi-format-list-bulleted"
class="q-px-sm q-py-xs rounded"
size="16px"
:style="{
color: $q.dark.isActive
? modeView === false
? '#C9D3DB'
: '#787B7C'
: modeView === false
? '#787B7C'
: '#C9D3DB',
}"
/>
</template>
</q-btn-toggle>
<q-input <q-input
id="input-search-add-product" id="input-search-add-product"
outlined outlined
@ -3442,64 +3481,75 @@ watch(
" "
/> />
</div> </div>
<div v-else class="row q-col-gutter-md full-width"> <div v-else class="flex col scroll" style="max-height: 100%">
<div <TableProduct
class="col-md-3 col-sm-6 col-12" :row="!!inputSearchWorkProduct ? resultSearchProduct : productIsAdd"
v-for="i in (!!inputSearchWorkProduct :column="tbColumn.product"
? resultSearchProduct :fieldSelected="tbControl.product.fieldSelected"
: productIsAdd :grid="modeViewIsAdd"
)?.filter((i) => { v-model:selectedItem="selectProduct"
if (i.status === 'INACTIVE') { card-container-class="row q-col-gutter-md"
return false; @select="
} (data) => {
return true; {
})" const tempValue = selectProduct.find((v) => v.id === data.id);
:key="i.id"
>
<TotalProductCardComponent
no-time-img
:index="selectProduct.findIndex((v) => v.id === i.id)"
:is-add-product="!!selectProduct.find((v) => v.id === i.id)"
:action="false"
:data="{ ...i, type: 'product' }"
:title="i.name"
:status="i.status === 'INACTIVE' ? true : false"
:price-display="priceDisplay"
@menu-view-detail="
() => {
currentIdProduct = i.id;
assignFormDataProduct(i);
dialogProductEdit = true;
}
"
@menu-edit="
() => {
currentIdProduct = i.id;
infoProductEdit = true;
assignFormDataProduct(i);
dialogProductEdit = true;
}
"
@view-detail="
() => {
currentIdProduct = i.id;
infoProductEdit = false;
assignFormDataProduct(i);
dialogProductEdit = true;
}
"
@select="
(data) => {
const tempValue = selectProduct.find((v) => v.id === i.id);
if (tempValue) { if (tempValue) {
selectProduct = selectProduct.filter((v) => v.id !== i.id); selectProduct = selectProduct.filter((v) => v.id !== data.id);
} else { } else {
selectProduct.push(data); selectProduct.push(data);
} }
} }
" }
/> "
</div> >
<template #grid="{ row }">
<TotalProductCardComponent
no-time-img
:index="selectProduct.findIndex((v) => v.id === row.id)"
:is-add-product="!!selectProduct.find((v) => v.id === row.id)"
:action="false"
:data="{ ...row, type: 'product' }"
:title="row.name"
:status="row.status === 'INACTIVE' ? true : false"
:price-display="priceDisplay"
@menu-view-detail="
() => {
currentIdProduct = row.id;
assignFormDataProduct(row);
dialogProductEdit = true;
}
"
@menu-edit="
() => {
currentIdProduct = row.id;
infoProductEdit = true;
assignFormDataProduct(row);
dialogProductEdit = true;
}
"
@view-detail="
() => {
currentIdProduct = row.id;
infoProductEdit = false;
assignFormDataProduct(row);
dialogProductEdit = true;
}
"
@select="
(data) => {
const tempValue = selectProduct.find((v) => v.id === row.id);
if (tempValue) {
selectProduct = selectProduct.filter(
(v) => v.id !== row.id,
);
} else {
selectProduct.push(data);
}
}
"
/>
</template>
</TableProduct>
</div> </div>
</div> </div>
</DialogForm> </DialogForm>
@ -4081,6 +4131,7 @@ watch(
JSON.stringify(workItems[currentWorkIndex].product), JSON.stringify(workItems[currentWorkIndex].product),
); );
dialogTotalProduct = true; dialogTotalProduct = true;
modeViewIsAdd = false;
} }
" "
@manage-work-name=" @manage-work-name="
@ -4470,6 +4521,7 @@ watch(
JSON.stringify(workItems[currentWorkIndex].product), JSON.stringify(workItems[currentWorkIndex].product),
); );
dialogTotalProduct = true; dialogTotalProduct = true;
modeViewIsAdd = false;
} }
" "
@manage-work-name=" @manage-work-name="