jws-frontend/src/pages/04_product-service/MainPage.vue

607 lines
16 KiB
Vue
Raw Normal View History

2024-06-10 16:42:59 +07:00
<script setup lang="ts">
import { ref } from 'vue';
import AppBox from 'components/app/AppBox.vue';
2024-06-12 15:37:17 +07:00
import AddButton from 'components/AddButton.vue';
2024-06-10 16:42:59 +07:00
import ProductCardComponent from 'src/components/04_product-service/ProductCardComponent.vue';
import StatCard from 'components/StatCardComponent.vue';
2024-06-10 17:42:37 +07:00
import NewProductCardCompoent from 'components/04_product-service/NewProductCardComponent.vue';
import DrawerInfo from 'src/components/DrawerInfo.vue';
import BasicInformation from 'src/components/04_product-service/BasicInformation.vue';
import FormDialog from 'src/components/FormDialog.vue';
2024-06-12 15:37:17 +07:00
import TooltipComponent from 'components/TooltipComponent.vue';
import { dialog } from 'src/stores/utils';
2024-06-11 15:04:01 +07:00
import useProductServiceStore from 'src/stores/product-service';
import {
2024-06-12 15:37:17 +07:00
Product,
ProductCreate,
ProductUpdate,
2024-06-11 15:04:01 +07:00
} from 'src/stores/product-service/types';
const productServiceStore = useProductServiceStore();
const {
2024-06-12 15:37:17 +07:00
createProductServiceType,
editProductServiceType,
deleteProductServiceType,
fetchListProductServiceType,
2024-06-11 15:04:01 +07:00
fetchStatsProductGroup,
fetchListProductService,
createProductService,
editProductService,
deleteProductService,
2024-06-11 15:04:01 +07:00
} = productServiceStore;
import ItemCard from 'src/components/ItemCard.vue';
import TotalProductComponent from 'src/components/04_product-service/TotalProductComponent.vue';
2024-06-10 16:42:59 +07:00
const cardData = ref({
title: 'งาน MCU',
subtitle: 'G00000000001',
2024-06-10 17:42:37 +07:00
color: 'var(--pink-6)',
2024-06-10 16:42:59 +07:00
status: true,
date: new Date(),
});
const cardTypeData = ref({
title: 'บริการพิสูจน์สัญชาติ',
subtitle: 'TG10000000001',
color: 'var(--purple-11)',
status: true,
date: new Date(),
});
2024-06-10 16:42:59 +07:00
const stat = ref<
{
count: number;
label: string;
2024-06-12 15:37:17 +07:00
color: 'pink' | 'purple' | 'green' | 'orange';
2024-06-10 16:42:59 +07:00
}[]
>([
2024-06-12 15:37:17 +07:00
{ count: 0, label: 'productAndService', color: 'pink' },
{ count: 0, label: 'productAndServiceType', color: 'purple' },
{ count: 0, label: 'service', color: 'orange' },
{ count: 0, label: 'service', color: 'green' },
2024-06-10 16:42:59 +07:00
]);
import { useI18n } from 'vue-i18n';
2024-06-11 15:04:01 +07:00
import { onMounted } from 'vue';
const { t } = useI18n();
2024-06-10 16:42:59 +07:00
const inputSearch = ref<string>('');
const drawerInfo = ref<boolean>(false);
const isEdit = ref<boolean>(false);
const dialogInputForm = ref<boolean>(false);
2024-06-11 16:52:35 +07:00
const groupName = ref<string>('งาน MOU');
const dialogProductServiceType = ref<boolean>(false);
const dialogTotalProduct = ref<boolean>(false);
const productMode = ref<'group' | 'type' | 'service' | 'product'>('group');
2024-06-12 15:37:17 +07:00
const productGroup = ref<Product[]>();
const productType = ref<Product[]>();
2024-06-11 15:04:01 +07:00
const previousValue = ref();
2024-06-12 15:37:17 +07:00
const formData = ref<ProductCreate>({
remark: '',
detail: '',
name: '',
code: '',
});
const currentId = ref<string>('');
2024-06-12 15:37:17 +07:00
const currentIdType = ref<string>('');
async function fetchListType() {
const res = await fetchListProductServiceType({
productGroupId: currentId.value,
});
if (res) {
productType.value = res;
}
}
async function fetchListGroups() {
const res = await fetchListProductService();
if (res) {
productGroup.value = res;
}
}
async function submitType() {
2024-06-12 15:37:17 +07:00
if (drawerInfo.value) {
await editProductServiceType(currentIdType.value, {
...formData.value,
productGroupId: currentId.value,
});
drawerInfo.value = false;
} else {
dialogInputForm.value = false;
await createProductServiceType(currentId.value, formData.value);
}
await fetchListType();
}
const itemCard = [
{
icon: 'mdi:server-network',
text: 'บริการ',
color: 'var(--orange-5)',
},
{
icon: 'mdi:shopping',
text: 'สินค้า',
color: 'var(--green-9)',
},
];
async function deleteProductById() {
dialog({
color: 'negative',
icon: 'mdi-alert',
title: t('deleteConfirmTitle'),
actionText: t('ok'),
persistent: true,
message: t('deleteConfirmMessage'),
action: async () => {
2024-06-11 16:52:35 +07:00
if (productMode.value === 'type') {
// Product Type
2024-06-12 15:37:17 +07:00
await deleteProductServiceType(currentIdType.value);
await fetchListType();
} else {
// Product Group
2024-06-12 15:37:17 +07:00
const res = await deleteProductService(currentId.value);
if (res) {
stat.value[0].count = stat.value[0].count - 1;
}
await fetchListGroups();
}
drawerInfo.value = false;
},
cancel: () => {},
});
}
2024-06-11 15:04:01 +07:00
function undoProductGroup() {
formData.value = {
remark: previousValue.value.remark,
detail: previousValue.value.detail,
name: previousValue.value.name,
code: previousValue.value.code,
};
isEdit.value = false;
}
2024-06-12 15:37:17 +07:00
function assignFormData(data: Product) {
previousValue.value = data;
formData.value = {
remark: data.remark,
detail: data.detail,
name: data.name,
code: data.code,
};
}
2024-06-11 15:04:01 +07:00
function clearForm() {
formData.value = {
remark: '',
detail: '',
name: '',
code: '',
};
dialogInputForm.value = false;
}
async function submitGroup() {
if (drawerInfo.value) {
await editProductService(currentId.value, formData.value);
} else {
2024-06-12 15:37:17 +07:00
const res = await createProductService(formData.value);
if (res) {
stat.value[0].count = stat.value[0].count + 1;
}
}
2024-06-11 15:04:01 +07:00
await fetchListGroups();
2024-06-11 15:04:01 +07:00
clearForm();
}
onMounted(async () => {
2024-06-12 15:37:17 +07:00
const resStatsGroup = await fetchStatsProductGroup();
stat.value[0].count = resStatsGroup ?? 0;
await fetchListGroups();
2024-06-11 15:04:01 +07:00
});
2024-06-10 16:42:59 +07:00
</script>
<template>
2024-06-12 15:37:17 +07:00
<div class="column q-pb-lg">
<div class="row text-h6 text-weight-bold q-mb-md">
{{ $t('productAndService') }}
</div>
2024-06-11 16:52:35 +07:00
<AppBox
2024-06-12 15:37:17 +07:00
v-if="productGroup?.length === 0"
class="column"
:no-padding="productGroup?.length !== 0"
2024-06-11 16:52:35 +07:00
bordered
2024-06-12 15:37:17 +07:00
style="min-height: 70vh"
2024-06-11 16:52:35 +07:00
>
2024-06-12 15:37:17 +07:00
<template>
<TooltipComponent
class="self-end"
title="messageTooltipNoProduct"
caption="messageTooltipProductCreate"
imgSrc="personnel-table-"
/>
<div class="row items-center justify-center" style="flex-grow: 1">
<AddButton
label="productCreate"
@trigger="() => (dialogInputForm = true)"
/>
</div>
</template>
2024-06-10 16:42:59 +07:00
</AppBox>
2024-06-12 15:37:17 +07:00
<div v-if="productGroup?.length !== 0">
<div
v-if="productMode === 'group'"
class="text-h6 text-weight-bold q-mb-md"
></div>
<div v-else-if="productMode === 'type'" class="row items-center q-mb-md">
<q-btn
round
icon="mdi-arrow-left"
flat
dense
@click="productMode = 'group'"
class="q-mr-md"
/>
<div class="text-h6 app-text-muted q-mr-sm hover-underline">
{{ groupName }}
</div>
2024-06-12 15:37:17 +07:00
<div class="text-h6 app-text-muted q-mx-sm">/</div>
<div class="text-h6 text-weight-bold">
{{ $t('productAndServiceType') }}
</div>
</div>
<div
v-else-if="productMode === 'service'"
class="row items-center q-mb-md"
>
<q-btn
round
icon="mdi-arrow-left"
flat
dense
@click="productMode = 'type'"
class="q-mr-md"
/>
<div class="text-h6 app-text-muted q-mr-sm hover-underline">
{{ groupName }}
</div>
<div class="text-h6 app-text-muted q-mx-sm">/</div>
<div class="text-h6 app-text-muted q-mr-sm hover-underline">
{{ 'บริการพิสูจน์สัญชาติ' }}
2024-06-10 16:42:59 +07:00
</div>
2024-06-12 15:37:17 +07:00
<div class="text-h6 app-text-muted q-mx-sm">/</div>
<div class="text-h6 text-weight-bold">
{{ $t('mainProductTitle') }}
</div>
</div>
<AppBox
v-if="productMode === 'group' || productMode === 'type'"
bordered
class="q-mb-md"
>
<StatCard label-i18n :branch="stat" :dark="$q.dark.isActive" />
</AppBox>
<AppBox
v-if="productMode === 'group' || productMode === 'type'"
bordered
style="min-height: 80vh"
>
<div class="row justify-between">
<div
v-if="productMode === 'type'"
class="text-h6 text-weight-bold q-mb-md"
>
{{ $t('productAndServiceType') }}
</div>
<div
v-else-if="productMode === 'group'"
class="text-h6 text-weight-bold q-mb-md"
>
{{ $t('productAndServiceAll') }}
</div>
<div
v-if="productMode === 'group' || productMode === 'type'"
class="row q-px-md q-pb-md"
>
<q-input
style="width: 300px"
outlined
dense
:label="$t('search')"
class="q-mr-lg"
:bg-color="$q.dark.isActive ? 'dark' : 'white'"
v-model="inputSearch"
debounce="500"
>
<template v-slot:prepend>
<q-icon name="mdi-magnify" />
</template>
</q-input>
<q-btn
icon="mdi-tune-vertical-variant"
size="sm"
:color="$q.dark.isActive ? 'dark' : 'white'"
:text-color="$q.dark.isActive ? 'white' : 'dark'"
class="bordered rounded"
unelevated
>
<q-menu class="bordered">
<q-list v-close-popup dense>
<q-item
clickable
class="flex items-center"
@click="console.log('test')"
>
{{ $t('all') }}
</q-item>
<q-item
clickable
class="flex items-center"
@click="console.log('test')"
>
{{ $t('statusACTIVE') }}
</q-item>
<q-item
clickable
class="flex items-center"
@click="console.log('test')"
>
{{ $t('statusINACTIVE') }}
</q-item>
</q-list>
</q-menu>
</q-btn>
</div>
</div>
<div class="row q-col-gutter-lg">
<div
:class="`${$q.screen.gt.sm ? 'col-3' : $q.screen.gt.xs ? 'col-6' : 'col-12'}`"
v-for="(v, i) in productMode === 'type'
? productType
: productGroup"
:key="i"
>
<ProductCardComponent
v-if="productMode === 'type'"
:title="v.name"
:subtitle="v.code"
:date="new Date(v.updatedAt)"
:status="v.status"
color="var(--purple-11)"
@view-detail="
() => {
clearForm();
currentIdType = v.id;
assignFormData(v);
isEdit = false;
drawerInfo = true;
}
"
@on-click="
() => {
currentIdType = v.id;
productMode = 'service';
}
"
/>
<ProductCardComponent
v-else-if="productMode === 'group'"
:title="v.name"
:subtitle="v.code"
:date="new Date(v.updatedAt)"
:status="v.status"
color="var(--pink-6)"
@view-detail="
() => {
clearForm();
assignFormData(v);
isEdit = false;
currentId = v.id;
drawerInfo = true;
}
"
@on-click="
async () => {
currentId = v.id;
console.log(v.id);
productMode = 'type';
await fetchListType();
}
"
/>
</div>
<div
:class="`${$q.screen.gt.sm ? 'col-3' : $q.screen.gt.xs ? 'col-6' : 'col-12'}`"
>
<NewProductCardCompoent
v-if="productMode === 'type'"
:label="$t('productAndServiceType')"
:isType="true"
@on-click="
() => {
clearForm();
dialogInputForm = true;
}
"
/>
<NewProductCardCompoent
v-else-if="productMode === 'group'"
:label="$t('productAndService')"
:isType="false"
@on-click="
() => {
clearForm();
dialogInputForm = true;
}
"
/>
</div>
</div>
</AppBox>
<AppBox bordered v-else-if="productMode === 'service'" no-padding>
2024-06-11 16:52:35 +07:00
<div
2024-06-12 15:37:17 +07:00
class="row justify-center q-py-sm"
style="background-color: var(--surface-2)"
2024-06-11 16:52:35 +07:00
>
2024-06-10 16:42:59 +07:00
<q-input
2024-06-12 15:37:17 +07:00
style="width: 500px"
2024-06-10 16:42:59 +07:00
outlined
dense
:label="$t('search')"
2024-06-12 15:37:17 +07:00
class="q-mr-md"
2024-06-10 16:42:59 +07:00
:bg-color="$q.dark.isActive ? 'dark' : 'white'"
v-model="inputSearch"
debounce="500"
2024-06-11 16:52:35 +07:00
>
<template v-slot:prepend>
<q-icon name="mdi-magnify" />
</template>
</q-input>
2024-06-10 16:42:59 +07:00
<q-btn
2024-06-12 15:37:17 +07:00
icon="mdi-plus"
2024-06-10 16:42:59 +07:00
:color="$q.dark.isActive ? 'dark' : 'white'"
:text-color="$q.dark.isActive ? 'white' : 'dark'"
2024-06-12 15:37:17 +07:00
class="bordered rounded q-px-sm"
2024-06-10 16:42:59 +07:00
unelevated
2024-06-12 15:37:17 +07:00
@click="dialogProductServiceType = true"
/>
2024-06-12 15:37:17 +07:00
<div class="q-mx-lg">ปุ่มรวมสินค้าทั้งหมด >></div>
<q-btn
unelevated
@click="dialogTotalProduct = true"
class="bordered rounded q-px-sm"
icon="mdi-plus"
:color="$q.dark.isActive ? 'dark' : 'white'"
:text-color="$q.dark.isActive ? 'white' : 'dark'"
round
2024-06-10 16:42:59 +07:00
/>
</div>
2024-06-12 15:37:17 +07:00
<div class="flex justify-center items-center" style="min-height: 70vh">
asdasdasd
2024-06-10 17:42:37 +07:00
</div>
2024-06-12 15:37:17 +07:00
</AppBox>
</div>
2024-06-10 16:42:59 +07:00
</div>
<FormDialog
v-model:modal="dialogInputForm"
noAddress
2024-06-12 15:37:17 +07:00
:title="$t('addProduct')"
:submit="() => (productMode === 'type' ? submitType() : submitGroup())"
:close="() => {}"
>
<template #information>
<BasicInformation
dense
2024-06-11 16:52:35 +07:00
:isType="productMode === 'type'"
v-model:remark="formData.remark"
v-model:name="formData.name"
v-model:detail="formData.detail"
/>
</template>
</FormDialog>
<DrawerInfo
ref="formDialogRef"
v-model:drawerOpen="drawerInfo"
:title="'test'"
:undo="() => undoProductGroup()"
:isEdit="isEdit"
:editData="() => (isEdit = true)"
2024-06-11 16:52:35 +07:00
:submit="() => (productMode === 'type' ? submitType() : submitGroup())"
:delete-data="() => deleteProductById()"
:close="() => (drawerInfo = false)"
>
<template #info>
<AppBox class="q-ma-md" bordered>
<BasicInformation
dense
2024-06-11 16:52:35 +07:00
:isType="productMode === 'type'"
:readonly="!isEdit"
v-model:remark="formData.remark"
v-model:name="formData.name"
v-model:code="formData.code"
v-model:detail="formData.detail"
/>
</AppBox>
</template>
</DrawerInfo>
<FormDialog
v-model:modal="dialogProductServiceType"
:title="'สร้างสินค้าและบริการ'"
no-footer
no-app-box
:max-width="80"
>
<template #body>
<div class="row q-gutter-xl q-pa-sm">
<ItemCard
class="col"
v-for="i in itemCard"
changeColor
:key="i.text"
:icon="i.icon"
:text="i.text"
:color="i.color"
@trigger="
() => {
dialogProductServiceType = false;
console.log('test');
}
"
/>
</div>
</template>
</FormDialog>
<FormDialog
v-model:modal="dialogTotalProduct"
noAddress
noAppBox
title="รวมสินค้าทั้งหมด (2 ชิ้น)"
:submit="
() => {
console.log('submit');
}
"
:close="() => {}"
>
<TotalProductComponent />
</FormDialog>
2024-06-10 16:42:59 +07:00
</template>
<style scoped>
.hover-underline:hover {
cursor: pointer;
text-decoration: underline;
}
</style>