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

517 lines
14 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';
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';
import { dialog } from 'src/stores/utils';
2024-06-11 15:04:01 +07:00
import useProductServiceStore from 'src/stores/product-service';
import {
ProductGroup,
ProductGroupCreate,
ProductGroupUpdate,
2024-06-11 15:04:01 +07:00
} from 'src/stores/product-service/types';
const productServiceStore = useProductServiceStore();
const {
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;
color: 'pink' | 'purple' | 'green';
}[]
>([
{ count: 5, label: 'branchHQLabel', color: 'pink' },
{ count: 4, label: 'branchLabel', color: 'purple' },
{ count: 12, label: 'branchLabel', color: 'green' },
]);
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-11 15:04:01 +07:00
const productGroup = ref<ProductGroup[]>();
const previousValue = ref();
2024-06-11 15:04:01 +07:00
const formData = ref<ProductGroupCreate>({
remark: '',
detail: '',
name: '',
code: '',
});
const currentId = ref<string>('');
async function submitType() {
console.log(formData.value);
}
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
} else {
// Product Group
await deleteProductService(currentId.value);
await fetchListGroups();
}
console.log('deleted');
drawerInfo.value = false;
},
cancel: () => {},
});
}
2024-06-11 15:04:01 +07:00
function undoProductGroup() {
console.log('dasd');
formData.value = {
remark: previousValue.value.remark,
detail: previousValue.value.detail,
name: previousValue.value.name,
code: previousValue.value.code,
};
isEdit.value = false;
}
function assignFormData(data: ProductGroup) {
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 {
await createProductService(formData.value);
}
2024-06-11 15:04:01 +07:00
await fetchListGroups();
2024-06-11 15:04:01 +07:00
clearForm();
}
async function fetchListGroups() {
2024-06-11 15:04:01 +07:00
const res = await fetchListProductService();
if (res) {
productGroup.value = res;
}
}
onMounted(async () => {
await fetchListGroups();
2024-06-11 15:04:01 +07:00
});
2024-06-10 16:42:59 +07:00
</script>
<template>
<div v class="column q-pb-lg">
2024-06-11 16:52:35 +07:00
<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
2024-06-11 16:52:35 +07:00
@click="productMode = 'group'"
class="q-mr-md"
/>
2024-06-11 16:52:35 +07:00
<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 text-weight-bold">
{{ $t('ProductAndServiceType') }}
</div>
</div>
2024-06-11 16:52:35 +07:00
<div v-else-if="productMode === 'service'" class="row items-center q-mb-md">
<q-btn
round
2024-06-11 16:52:35 +07:00
icon="mdi-arrow-left"
flat
dense
@click="productMode = 'type'"
class="q-mr-md"
/>
2024-06-11 16:52:35 +07:00
<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">
{{ 'บริการพิสูจน์สัญชาติ' }}
</div>
<div class="text-h6 app-text-muted q-mx-sm">/</div>
<div class="text-h6 text-weight-bold">
{{ $t('mainProductTitle') }}
</div>
</div>
2024-06-11 16:52:35 +07:00
<AppBox
v-if="productMode === 'group' || productMode === 'type'"
bordered
class="q-mb-md"
>
2024-06-10 16:42:59 +07:00
<StatCard label-i18n :branch="stat" :dark="$q.dark.isActive" />
</AppBox>
2024-06-11 16:52:35 +07:00
<AppBox
v-if="productMode === 'group' || productMode === 'type'"
bordered
style="min-height: 80vh"
>
2024-06-10 16:42:59 +07:00
<div class="row justify-between">
2024-06-11 16:52:35 +07:00
<div
v-if="productMode === 'type'"
class="text-h6 text-weight-bold q-mb-md"
>
{{ $t('ProductAndServiceType') }}
</div>
2024-06-11 16:52:35 +07:00
<div
v-else-if="productMode === 'group'"
class="text-h6 text-weight-bold q-mb-md"
>
{{ $t('ProductAndServiceAll') }}
2024-06-10 16:42:59 +07:00
</div>
2024-06-11 16:52:35 +07:00
<div
v-if="productMode === 'group' || productMode === 'type'"
class="row q-px-md q-pb-md"
>
2024-06-10 16:42:59 +07:00
<q-input
2024-06-11 16:52:35 +07:00
style="width: 300px"
2024-06-10 16:42:59 +07:00
outlined
dense
:label="$t('search')"
class="q-mr-lg"
: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
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'}`"
2024-06-11 16:52:35 +07:00
v-for="(v, i) in productMode ? productGroup : productGroup"
:key="i"
>
2024-06-10 16:42:59 +07:00
<ProductCardComponent
2024-06-11 16:52:35 +07:00
v-if="productMode === 'type'"
:title="cardTypeData.title"
:subtitle="cardTypeData.subtitle"
:date="cardTypeData.date"
2024-06-11 15:04:40 +07:00
:status="v.status"
:color="cardTypeData.color"
@view-detail="
() => {
currentId = v.id;
drawerInfo = true;
}
"
2024-06-11 15:04:40 +07:00
@on-click="
() => {
currentId = v.id;
2024-06-11 16:52:35 +07:00
productMode = 'service';
2024-06-11 15:04:40 +07:00
}
"
/>
<ProductCardComponent
2024-06-11 16:52:35 +07:00
v-else-if="productMode === 'group'"
2024-06-11 15:04:40 +07:00
:title="v.name"
:subtitle="v.code"
:date="new Date(v.updatedAt)"
:status="v.status"
color="var(--pink-6)"
@view-detail="
() => {
assignFormData(v);
currentId = v.id;
drawerInfo = true;
}
"
2024-06-11 15:04:40 +07:00
@on-click="
() => {
currentId = v.id;
2024-06-11 16:52:35 +07:00
productMode = 'type';
2024-06-11 15:04:40 +07:00
}
"
2024-06-10 16:42:59 +07:00
/>
</div>
<div
:class="`${$q.screen.gt.sm ? 'col-3' : $q.screen.gt.xs ? 'col-6' : 'col-12'}`"
>
2024-06-10 17:42:37 +07:00
<NewProductCardCompoent
2024-06-11 16:52:35 +07:00
v-if="productMode === 'type'"
:label="$t('ProductAndServiceType')"
:isType="true"
@on-click="() => (dialogInputForm = true)"
/>
<NewProductCardCompoent
2024-06-11 16:52:35 +07:00
v-else-if="productMode === 'group'"
:label="$t('ProductAndService')"
2024-06-10 17:42:37 +07:00
:isType="false"
@on-click="() => (dialogInputForm = true)"
2024-06-10 17:42:37 +07:00
/>
</div>
2024-06-10 16:42:59 +07:00
</div>
</AppBox>
2024-06-11 16:52:35 +07:00
<AppBox bordered v-else-if="productMode === 'service'" no-padding>
<div
class="row justify-center q-py-sm"
style="background-color: var(--surface-2)"
>
<q-input
style="width: 500px"
outlined
dense
:label="$t('search')"
class="q-mr-md"
: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-plus"
:color="$q.dark.isActive ? 'dark' : 'white'"
:text-color="$q.dark.isActive ? 'white' : 'dark'"
class="bordered rounded q-px-sm"
unelevated
@click="dialogProductServiceType = true"
/>
<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
/>
</div>
<div class="flex justify-center items-center" style="min-height: 70vh">
asdasdasd
</div>
</AppBox>
2024-06-10 16:42:59 +07:00
</div>
<FormDialog
v-model:modal="dialogInputForm"
noAddress
:title="$t('customerEmployerAdd')"
:submit="
() => {
2024-06-11 15:04:01 +07:00
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>