Merge branch 'refactor/customer' into develop

This commit is contained in:
Methapon2001 2024-08-06 09:26:11 +07:00
commit abb4932271
10 changed files with 174 additions and 31 deletions

View file

@ -34,7 +34,7 @@ const props = withDefaults(
employee?: boolean; employee?: boolean;
employeeOwnerOption?: CustomerBranch[]; employeeOwnerOption?: CustomerBranch[];
prefixId: string; prefixId: string;
showBtnSave: boolean; showBtnSave?: boolean;
}>(), }>(),
{ {
showBtnSave: false, showBtnSave: false,

View file

@ -29,13 +29,18 @@ defineProps<{
submit?: (...args: unknown[]) => void; submit?: (...args: unknown[]) => void;
close?: (...args: unknown[]) => void; close?: (...args: unknown[]) => void;
undo?: (...args: unknown[]) => void; undo?: (...args: unknown[]) => void;
beforeClose?: (...args: unknown[]) => boolean;
}>(); }>();
const modal = defineModel('modal', { default: false }); const modal = defineModel('modal', { default: false });
const currentTab = defineModel<string>('currentTab'); const currentTab = defineModel<string>('currentTab');
</script> </script>
<template> <template>
<q-dialog v-model="modal" @hide="close" @before-show="show"> <q-dialog
:model-value="modal"
@update:model-value="(v) => (modal = beforeClose ? beforeClose() : v)"
@before-show="show"
>
<div <div
class="surface-1" class="surface-1"
style="padding: 0; border-radius: var(--radius-2); height: 100%" style="padding: 0; border-radius: var(--radius-2); height: 100%"
@ -129,7 +134,12 @@ const currentTab = defineModel<string>('currentTab');
padding="xs" padding="xs"
class="close-btn" class="close-btn"
:class="{ dark: $q.dark.isActive }" :class="{ dark: $q.dark.isActive }"
@click="close" @click="
() => {
modal = beforeClose ? beforeClose() : !modal;
close?.();
}
"
/> />
</div> </div>
</div> </div>

View file

@ -99,11 +99,17 @@ export default {
invalid: 'Invalid value.', invalid: 'Invalid value.',
invalidCustomeMessage: 'Invalid value. {msg}', invalidCustomeMessage: 'Invalid value. {msg}',
}, },
warning: {
title: 'Warning {msg}',
unsave:
'You have unsaved changes. Are you sure you want to close this window?',
},
}, },
customer: { customer: {
form: { form: {
group: { group: {
basicInfo: 'Basic Information', basicInfo: 'Basic Information',
branch: 'Branch',
}, },
registeredBranch: 'Registered Branch', registeredBranch: 'Registered Branch',
customerName: 'Company Name', customerName: 'Company Name',

View file

@ -100,17 +100,26 @@ export default {
invalid: 'ค่าที่ไม่ถูกต้อง', invalid: 'ค่าที่ไม่ถูกต้อง',
invalidCustomeMessage: 'ค่าที่ไม่ถูกต้อง {msg}', invalidCustomeMessage: 'ค่าที่ไม่ถูกต้อง {msg}',
}, },
warning: {
title: 'แจ้งเตือน {msg}',
unsave:
'คุณมีการเปลี่ยนแปลงที่ยังไม่ได้บันทึก คุณต้องการปิดหน้าต่างนี้หรือไม่',
},
}, },
customer: { customer: {
form: { form: {
group: { group: {
basicInfo: 'ข้อมูลพื้นฐาน', basicInfo: 'ข้อมูลพื้นฐาน',
branch: 'ข้อมูลสาขา',
}, },
registeredBranch: 'สาขาที่ลงทะเบียน', registeredBranch: 'สาขาที่ลงทะเบียน',
customerName: 'ชื่อบริษัท', customerName: 'ชื่อบริษัท',
customerNameEN: 'ชื่อบริษัท (EN)', customerNameEN: 'ชื่อบริษัท (EN)',
personName: 'ชื่อลูกค้า', personName: 'ชื่อลูกค้า',
taxIdentificationNumber: 'หมายเลขประจำตัวผู้เสียภาษี', taxIdentificationNumber: 'หมายเลขประจำตัวผู้เสียภาษี',
branch: {
title: 'สาขาที่ {name}',
},
}, },
}, },
}; };

View file

@ -281,9 +281,11 @@ onMounted(async () => {
> >
{{ {{
item.text item.text
? $t(item.text, { ? item.i18n
...(item.argsi18n || {}), ? $t(item.text, {
}) ...(item.argsi18n || {}),
})
: item.text
: '' : ''
}} }}
</span> </span>

View file

@ -29,6 +29,7 @@ import SideMenu from 'src/components/SideMenu.vue';
import BasicInformation from 'src/components/03_customer-management/employee/BasicInformation.vue'; import BasicInformation from 'src/components/03_customer-management/employee/BasicInformation.vue';
import FormPerson from 'src/components/02_personnel-management/FormPerson.vue'; import FormPerson from 'src/components/02_personnel-management/FormPerson.vue';
import FormBasicInfo from './components/FormBasicInfo.vue'; import FormBasicInfo from './components/FormBasicInfo.vue';
import FormBranch from './components/FormBranch.vue';
import CustomerInfoComponent from './components/CustomerBranch.vue'; import CustomerInfoComponent from './components/CustomerBranch.vue';
import FormAddress from 'src/components/02_personnel-management/FormAddress.vue'; import FormAddress from 'src/components/02_personnel-management/FormAddress.vue';
@ -82,6 +83,7 @@ async function init() {
currentCustomer.value = _data; currentCustomer.value = _data;
utilsStore.currentTitle.path.push({ utilsStore.currentTitle.path.push({
text: currentCustomer.value.customerName, text: currentCustomer.value.customerName,
i18n: false,
}); });
} else { } else {
router.push('/customer-management'); router.push('/customer-management');
@ -398,6 +400,30 @@ async function editCustomerForm(id: string) {
customerFormState.value.editCustomerId = id; customerFormState.value.editCustomerId = id;
} }
function customerConfirmUnsave() {
dialog({
color: 'warning',
icon: 'mdi-alert',
title: t('form.warning.title'),
actionText: t('ok'),
persistent: true,
message: t('form.warning.unsave'),
action: () => {
customerFormStore.resetForm();
customerFormState.value.editReadonly = true;
},
cancel: () => {},
});
}
function customerFormUndo() {
if (customerFormStore.isFormDataDifferent()) {
return customerConfirmUnsave();
}
customerFormStore.resetForm();
customerFormState.value.editReadonly = true;
}
function createCustomerForm(customerType: 'CORP' | 'PERS') { function createCustomerForm(customerType: 'CORP' | 'PERS') {
customerFormState.value.dialogModal = true; customerFormState.value.dialogModal = true;
customerFormState.value.dialogType = 'create'; customerFormState.value.dialogType = 'create';
@ -1657,11 +1683,7 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
:title="$t('form.title.create', { name: 'Employer' })" :title="$t('form.title.create', { name: 'Employer' })"
:edit="customerFormState.dialogType === 'edit'" :edit="customerFormState.dialogType === 'edit'"
:isEdit="customerFormState.editReadonly === false" :isEdit="customerFormState.editReadonly === false"
:undo=" :undo="() => customerFormUndo()"
() => (
customerFormStore.resetForm(), (customerFormState.editReadonly = true)
)
"
:deleteData=" :deleteData="
() => () =>
customerFormState.editCustomerId && customerFormState.editCustomerId &&
@ -1669,8 +1691,8 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
" "
:editData="() => (customerFormState.editReadonly = false)" :editData="() => (customerFormState.editReadonly = false)"
:show=" :show="
async () => () =>
await fetchListOfOptionBranch().then(() => { fetchListOfOptionBranch().then(() => {
customerFormStore.resetForm( customerFormStore.resetForm(
customerFormState.dialogType === 'create', customerFormState.dialogType === 'create',
); );
@ -1682,7 +1704,15 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
await fetchListCustomer(); await fetchListCustomer();
} }
" "
:close="() => (customerFormState.dialogModal = false)" :before-close="
() => {
if (customerFormStore.isFormDataDifferent()) {
customerConfirmUnsave();
return true;
}
return false; // close
}
"
no-footer no-footer
> >
<div class="q-mx-lg q-mt-lg"> <div class="q-mx-lg q-mt-lg">
@ -1713,13 +1743,19 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
style="height: 100%; max-height: 100; overflow-y: auto" style="height: 100%; max-height: 100; overflow-y: auto"
v-if="$q.screen.gt.sm" v-if="$q.screen.gt.sm"
> >
<div class="q-py-md q-pl-md"> <div class="q-py-md q-pl-md q-pr-sm">
<SideMenu <SideMenu
:menu="[ :menu="[
{ {
name: $t('customer.form.group.basicInfo'), name: $t('customer.form.group.basicInfo'),
anchor: 'form-basic-info-customer', anchor: 'form-basic-info-customer',
}, },
...(customerFormData.customerBranch?.map((v) => ({
name: $t('customer.form.branch.title', {
name: v.branchNo || 0,
}),
anchor: `form-branch-customer-no-${v.branchNo}`,
})) || []),
]" ]"
background="transparent" background="transparent"
:active="{ :active="{
@ -1731,11 +1767,12 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
</div> </div>
</div> </div>
<div <div
class="col-12 col-md-10 q-pa-md" class="col-12 col-md-10 q-py-md q-pr-md q-pl-sm"
id="customer-form-content" id="customer-form-content"
style="height: 100%; max-height: 100%; overflow-y: auto" style="height: 100%; max-height: 100%; overflow-y: auto"
> >
<FormBasicInfo <FormBasicInfo
class="q-mb-xl"
:readonly=" :readonly="
customerFormState.dialogType === 'edit' && customerFormState.dialogType === 'edit' &&
customerFormState.editReadonly === true customerFormState.editReadonly === true
@ -1750,6 +1787,15 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
v-model:registered-branch-id="customerFormData.registeredBranchId" v-model:registered-branch-id="customerFormData.registeredBranchId"
v-model:branch-options="registerAbleBranchOption" v-model:branch-options="registerAbleBranchOption"
/> />
<FormBranch
id="form-branch-customer"
:editable="
customerFormState.dialogType === 'create' ||
customerFormState.editReadonly === false
"
@add-branch="customerFormStore.addCurrentCustomerBranch()"
v-model:customer-branch="customerFormData.customerBranch"
/>
</div> </div>
</div> </div>
@ -1791,18 +1837,26 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
: `${employeeFormState.currentEmployee.firstName} ${employeeFormState.currentEmployee.lastName}` : `${employeeFormState.currentEmployee.firstName} ${employeeFormState.currentEmployee.lastName}`
: '-' : '-'
" "
:badgeClass="
currentFromDataEmployee.gender === 'male'
? 'app-bg-male text-white'
: currentFromDataEmployee.gender === 'female'
? 'app-bg-female text-white'
: ''
"
> >
<div class="q-mx-lg q-mt-lg"> <div class="full-height full-width column">
<ProfileBanner <div class="q-mx-lg q-mt-lg">
active <ProfileBanner
hideFade active
:img="employeeFormState.profileUrl" hideFade
:menu="formMenuIconEmployee" :img="employeeFormState.profileUrl"
/> :menu="formMenuIconEmployee"
/>
</div>
<div <div
class="col surface-1 q-mt-lg rounded bordered scroll row" class="col surface-1 q-ma-lg rounded bordered scroll row"
id="personnel-form" id="employee-form"
> >
<div class="col"> <div class="col">
<div style="position: sticky; top: 0" class="q-pa-sm"> <div style="position: sticky; top: 0" class="q-pa-sm">
@ -1834,13 +1888,13 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
background: 'hsla(var(--blue-6-hsl) / .2)', background: 'hsla(var(--blue-6-hsl) / .2)',
foreground: 'var(--blue-6)', foreground: 'var(--blue-6)',
}" }"
scroll-element="#personnel-form" scroll-element="#employee-form"
/> />
</div> </div>
</div> </div>
<div class="col-10 q-pa-md q-gutter-y-xl"> <div class="col-10 q-pa-md q-gutter-y-xl">
<BasicInformation <BasicInformation
id="form-information"
prefix-id="drawer-info-employee" prefix-id="drawer-info-employee"
employee employee
dense dense
@ -1855,8 +1909,8 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
v-model:code="currentFromDataEmployee.code" v-model:code="currentFromDataEmployee.code"
@filter-owner-branch="employeeFormStore.employeeFilterOwnerBranch" @filter-owner-branch="employeeFormStore.employeeFilterOwnerBranch"
/> />
<FormPerson <FormPerson
id="form-personal"
prefix-id="drawer-info-employee" prefix-id="drawer-info-employee"
dense dense
outlined outlined
@ -1872,6 +1926,18 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
v-model:birthDate="currentFromDataEmployee.dateOfBirth" v-model:birthDate="currentFromDataEmployee.dateOfBirth"
v-model:nationality="currentFromDataEmployee.nationality" v-model:nationality="currentFromDataEmployee.nationality"
/> />
<FormAddress
id="form-personal-address"
v-model:address="currentFromDataEmployee.address"
v-model:addressEN="currentFromDataEmployee.addressEN"
v-model:provinceId="currentFromDataEmployee.provinceId"
v-model:districtId="currentFromDataEmployee.districtId"
v-model:subDistrictId="currentFromDataEmployee.subDistrictId"
v-model:zipCode="currentFromDataEmployee.zipCode"
:readonly="!employeeFormState.isEmployeeEdit"
prefix-id="drawer-info-personnel"
dense
/>
</div> </div>
</div> </div>
</div> </div>

View file

@ -54,7 +54,7 @@ watch(
</script> </script>
<template> <template>
<div class="row q-col-gutter-md"> <div class="row q-col-gutter-sm">
<div class="col-12 text-weight-bold text-body1 row items-center"> <div class="col-12 text-weight-bold text-body1 row items-center">
<q-icon <q-icon
flat flat

View file

@ -0,0 +1,48 @@
<script setup lang="ts">
import { CustomerCreate } from 'src/stores/customer/types';
const branch = defineModel<CustomerCreate['customerBranch']>('customerBranch', {
default: [],
});
defineProps<{
editable?: boolean;
}>();
</script>
<template>
<div class="row q-col-gutter-md">
<div class="col-12 text-weight-bold text-body1 row items-center">
<q-icon
flat
size="xs"
class="q-pa-sm rounded q-mr-xs"
color="info"
name="mdi-briefcase"
style="background-color: var(--surface-3)"
/>
<span>{{ $t('customer.form.group.branch') }}</span>
<q-btn
type="button"
rounded
flat
dense
unelevated
color="primary"
@click="$emit('addBranch')"
v-if="editable"
icon="mdi-plus"
class="q-ml-md"
/>
</div>
<template v-for="item in branch">
<span
class="col-12 text-weight-bold"
:id="`form-branch-customer-no-${item.branchNo}`"
>
{{ $t('customer.form.branch.title', { name: item.branchNo || 0 }) }}
</span>
</template>
</div>
</template>

View file

@ -139,7 +139,8 @@ export const useCustomerForm = defineStore('form-customer', () => {
currentFormData.value.customerBranch?.push({ currentFormData.value.customerBranch?.push({
id: '', id: '',
code: '', code: '',
branchNo: 1, branchNo:
(currentFormData.value.customerBranch?.at(-1)?.branchNo || 0) + 1,
address: '', address: '',
addressEN: '', addressEN: '',
provinceId: '', provinceId: '',

View file

@ -167,6 +167,7 @@ const useUtilsStore = defineStore('utilsStore', () => {
title: string; title: string;
path: { path: {
text: string; text: string;
i18n?: boolean;
argsi18n?: Record<string, string>; argsi18n?: Record<string, string>;
handler?: () => unknown; handler?: () => unknown;
}[]; }[];