refactor: customer

This commit is contained in:
puriphatt 2024-09-17 10:00:35 +07:00
parent 2ab96dc816
commit 234b03c7fa
12 changed files with 372 additions and 978 deletions

View file

@ -289,6 +289,7 @@ watch(districtId, fetchSubDistrict);
hide-bottom-space hide-bottom-space
class="col-3" class="col-3"
v-model="homeCode" v-model="homeCode"
mask="###########"
:dense="dense" :dense="dense"
:label="$t('customer.form.homeCode')" :label="$t('customer.form.homeCode')"
:readonly="readonly || sameWithEmployer" :readonly="readonly || sameWithEmployer"
@ -365,7 +366,7 @@ watch(districtId, fetchSubDistrict);
outlined outlined
hide-bottom-space hide-bottom-space
class="col-md-1 col-4" class="col-md-1 col-4"
v-model="moo" :model-value="readonly ? moo || '-' : moo"
:dense="dense" :dense="dense"
:label="$t('form.moo')" :label="$t('form.moo')"
:readonly="readonly || sameWithEmployer" :readonly="readonly || sameWithEmployer"
@ -375,7 +376,7 @@ watch(districtId, fetchSubDistrict);
outlined outlined
hide-bottom-space hide-bottom-space
class="col-md-3 col-6" class="col-md-3 col-6"
v-model="soi" :model-value="readonly ? soi || '-' : soi"
:dense="dense" :dense="dense"
:label="$t('form.soi')" :label="$t('form.soi')"
:readonly="readonly || sameWithEmployer" :readonly="readonly || sameWithEmployer"
@ -385,7 +386,7 @@ watch(districtId, fetchSubDistrict);
outlined outlined
hide-bottom-space hide-bottom-space
class="col-md-3 col-6" class="col-md-3 col-6"
v-model="street" :model-value="readonly ? street || '-' : street"
:dense="dense" :dense="dense"
:label="$t('form.street')" :label="$t('form.street')"
:readonly="readonly || sameWithEmployer" :readonly="readonly || sameWithEmployer"
@ -593,7 +594,7 @@ watch(districtId, fetchSubDistrict);
outlined outlined
hide-bottom-space hide-bottom-space
class="col-md-1 col-4" class="col-md-1 col-4"
v-model="mooEN" :model-value="readonly ? mooEN || '-' : mooEN"
:dense="dense" :dense="dense"
label="Moo" label="Moo"
:readonly="readonly || sameWithEmployer" :readonly="readonly || sameWithEmployer"
@ -603,7 +604,7 @@ watch(districtId, fetchSubDistrict);
outlined outlined
hide-bottom-space hide-bottom-space
class="col-md-3 col-6" class="col-md-3 col-6"
v-model="soiEN" :model-value="readonly ? soiEN || '-' : soiEN"
:dense="dense" :dense="dense"
label="Soi" label="Soi"
:readonly="readonly || sameWithEmployer" :readonly="readonly || sameWithEmployer"
@ -613,7 +614,7 @@ watch(districtId, fetchSubDistrict);
outlined outlined
hide-bottom-space hide-bottom-space
class="col-md-3 col-6" class="col-md-3 col-6"
v-model="streetEN" :model-value="readonly ? streetEN || '-' : streetEN"
:dense="dense" :dense="dense"
label="Street" label="Street"
:readonly="readonly || sameWithEmployer" :readonly="readonly || sameWithEmployer"

View file

@ -155,6 +155,7 @@ export default {
invalidCustomeMessage: 'Invalid value. {msg}', invalidCustomeMessage: 'Invalid value. {msg}',
letterOnly: 'Only letters are allowed', letterOnly: 'Only letters are allowed',
letterAndNumOnly: 'Only letters and number are allowed', letterAndNumOnly: 'Only letters and number are allowed',
numOnly: 'Only number are allowed',
requireLength: 'Please enter {msg} character', requireLength: 'Please enter {msg} character',
}, },
warning: { warning: {

View file

@ -155,6 +155,7 @@ export default {
invalidCustomeMessage: 'ข้อมูลไม่ถูกต้อง {msg}', invalidCustomeMessage: 'ข้อมูลไม่ถูกต้อง {msg}',
letterOnly: 'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น', letterOnly: 'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษเท่านั้น',
letterAndNumOnly: 'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษและตัวเลขเท่านั้น', letterAndNumOnly: 'โปรดใช้เฉพาะตัวอักษรภาษาอังกฤษและตัวเลขเท่านั้น',
numOnly: 'โปรดใช้เฉพาะตัวเลขเท่านั้น',
requireLength: 'กรุณากรอกให้ครบ {msg} หลัก', requireLength: 'กรุณากรอกให้ครบ {msg} หลัก',
}, },
warning: { warning: {

View file

@ -718,25 +718,25 @@ watch([customerId, inputSearch, currentStatus], async () => {
</div> </div>
</div> </div>
<EmployerFormAbout <EmployerFormAbout
:index="customerBranchFormData.code?.slice(-2) || '00'" :index="customerBranchFormData.code"
class="q-mb-xl"
:customer-type="customerType" :customer-type="customerType"
:customer-name="currentCustomerName"
:readonly="customerBranchFormState.dialogType === 'info'"
v-model:citizen-id="customerBranchFormData.citizenId" v-model:citizen-id="customerBranchFormData.citizenId"
v-model:id="customerBranchFormData.id" v-model:prefixName="customerBranchFormData.namePrefix"
v-model:legal-person-no="customerBranchFormData.legalPersonNo" v-model:firstName="customerBranchFormData.firstName"
v-model:branch-code="customerBranchFormData.code" v-model:lastName="customerBranchFormData.lastName"
v-model:customer-code="customerBranchFormData.code" v-model:firstNameEN="customerBranchFormData.firstNameEN"
v-model:register-company-name=" v-model:lastNameEN="customerBranchFormData.lastNameEN"
customerBranchFormData.registerCompanyName v-model:gender="customerBranchFormData.gender"
" v-model:birthDate="customerBranchFormData.birthDate"
v-model:register-name="customerBranchFormData.registerName" v-model:customerName="customerBranchFormData.customerName"
v-model:register-name-en="customerBranchFormData.registerNameEN" v-model:legalPersonNo="customerBranchFormData.legalPersonNo"
v-model:register-date="customerBranchFormData.registerDate" v-model:branchCode="customerBranchFormData.code"
v-model:authorized-capital=" v-model:registerName="customerBranchFormData.registerName"
customerBranchFormData.authorizedCapital v-model:registerNameEN="customerBranchFormData.registerNameEN"
" v-model:registerDate="customerBranchFormData.registerDate"
v-model:authorizedCapital="customerBranchFormData.authorizedCapital"
v-model:telephoneNo="customerBranchFormData.telephoneNo"
v-model:codeCustomer="customerBranchFormData.codeCustomer"
/> />
<div class="row q-col-gutter-sm q-mb-sm" id="employer-branch-address"> <div class="row q-col-gutter-sm q-mb-sm" id="employer-branch-address">
<div class="col-12 text-weight-bold text-body1 row items-center"> <div class="col-12 text-weight-bold text-body1 row items-center">

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch, onMounted } from 'vue'; import { ref, watch, onMounted, computed } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useQuasar } from 'quasar'; import { useQuasar } from 'quasar';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
@ -121,7 +121,13 @@ async function init() {
if (_data) { if (_data) {
currentCustomer.value = _data; currentCustomer.value = _data;
utilsStore.currentTitle.path.push({ utilsStore.currentTitle.path.push({
text: `${currentCustomer.value.firstName || '-'} ${currentCustomer.value.lastName || ''}`, text: `${
_data.customerType === 'CORP'
? _data.branch[0].registerName
: locale.value === 'eng'
? _data.branch[0].firstNameEN + ' ' + _data.branch[0].lastNameEN
: _data.branch[0].firstName + ' ' + _data.branch[0].lastName
}`,
i18n: false, i18n: false,
}); });
} else { } else {
@ -154,6 +160,13 @@ const customerTypeSelected = ref<{
value: 'all', value: 'all',
}); });
const customerNameInfo = computed(() => {
const name =
locale.value === 'eng'
? `${customerFormData.value.customerBranch[0].firstNameEN} ${customerFormData.value.customerBranch[0].lastNameEN}`
: `${customerFormData.value.customerBranch[0].firstName} ${customerFormData.value.customerBranch[0].lastName}`;
return name || '-';
});
const currentBtnOpen = ref<boolean[]>([]); const currentBtnOpen = ref<boolean[]>([]);
const employeeStats = ref(0); const employeeStats = ref(0);
const gridView = ref(false); const gridView = ref(false);
@ -482,7 +495,7 @@ async function openHistory(id: string) {
employeeHistoryDialog.value = true; employeeHistoryDialog.value = true;
} }
async function editCustomerForm(id: string) { async function editCustomerForm(id: string, view?: boolean) {
await customerFormStore.assignFormData(id); await customerFormStore.assignFormData(id);
await fetchListOfOptionBranch(); await fetchListOfOptionBranch();
await fetchImageList( await fetchImageList(
@ -490,6 +503,7 @@ async function editCustomerForm(id: string) {
customerFormData.value.selectedImage || '', customerFormData.value.selectedImage || '',
'customer', 'customer',
); );
customerFormState.value.branchIndex = -1;
customerFormState.value.dialogType = 'edit'; customerFormState.value.dialogType = 'edit';
customerFormState.value.drawerModal = true; customerFormState.value.drawerModal = true;
customerFormState.value.editCustomerId = id; customerFormState.value.editCustomerId = id;
@ -1212,7 +1226,7 @@ const emptyCreateDialog = ref(false);
> >
<template #error> <template #error>
<q-img <q-img
:src="`${props.row.customerType === 'CORP' ? `/images/customer-CORP-avartar-${props.row.gender}.png` : `/images/customer-PERS-avartar-${props.row.gender}.png`}`" :src="`/images/customer-${props.row.customerType}-avartar-${props.row.customerType === 'PERS' ? props.row.branch[0].gender : 'male'}.png`"
/> />
</template> </template>
</q-img> </q-img>
@ -1222,12 +1236,22 @@ const emptyCreateDialog = ref(false);
</div> </div>
<div class="col"> <div class="col">
<div class="col"> <div class="col">
{{ props.row.firstName }} {{
{{ props.row.lastName }} props.row.customerType === 'CORP'
? props.row.branch[0].registerName || '-'
: props.row.branch[0].firstName +
' ' +
props.row.branch[0].lastName || '-'
}}
</div> </div>
<div class="col app-text-muted"> <div class="col app-text-muted">
{{ props.row.firstNameEN || '-' }} {{
{{ props.row.lastNameEN || '-' }} props.row.customerType === 'CORP'
? props.row.branch[0].registerNameEN || '-'
: props.row.branch[0].firstNameEN +
' ' +
props.row.branch[0].lastNameEN || '-'
}}
</div> </div>
</div> </div>
</div> </div>
@ -1236,7 +1260,9 @@ const emptyCreateDialog = ref(false);
{{ {{
props.row.branch.length !== 0 props.row.branch.length !== 0
? props.row.branch[0].businessType !== null ? props.row.branch[0].businessType !== null
? props.row.branch[0].businessType ? optionStore.mapOption(
props.row.branch[0].businessType,
)
: '' : ''
: '-' : '-'
}} }}
@ -1327,7 +1353,7 @@ const emptyCreateDialog = ref(false);
dense dense
round round
flat flat
@click.stop="editCustomerForm(props.row.id)" @click.stop="editCustomerForm(props.row.id, true)"
/> />
<KebabAction <KebabAction
@ -1337,7 +1363,7 @@ const emptyCreateDialog = ref(false);
() => { () => {
const { branch, ...payload } = props.row; const { branch, ...payload } = props.row;
currentCustomer = payload; currentCustomer = payload;
editCustomerForm(props.row.id); editCustomerForm(props.row.id, true);
} }
" "
@edit=" @edit="
@ -1420,10 +1446,18 @@ const emptyCreateDialog = ref(false);
code: props.row.code, code: props.row.code,
name: name:
$i18n.locale === 'eng' $i18n.locale === 'eng'
? `${props.row.firstNameEN} ${props.row.lastNameEN} `.trim() ? props.row.customerType === 'CORP'
: `${props.row.firstName} ${props.row.lastName} `.trim(), ? props.row.branch[0].registerNameEN || '-'
: props.row.branch[0].firstNameEN +
' ' +
props.row.branch[0].lastNameEN || '-'
: props.row.customerType === 'CORP'
? props.row.branch[0].registerName || '-'
: props.row.branch[0].firstName +
' ' +
props.row.branch[0].lastName || '-',
img: `${baseUrl}/customer/${props.row.id}/image/${props.row.selectedImage}`, img: `${baseUrl}/customer/${props.row.id}/image/${props.row.selectedImage}`,
fallbackImg: `/images/customer-${props.row.customerType}-avartar-${props.row.gender}.png`, fallbackImg: `/images/customer-${props.row.customerType}-avartar-${props.row.customerType === 'PERS' ? props.row.branch[0].gender : 'male'}.png`,
male: undefined, male: undefined,
female: undefined, female: undefined,
detail: [ detail: [
@ -1469,7 +1503,7 @@ const emptyCreateDialog = ref(false);
() => { () => {
const { branch, ...payload } = props.row; const { branch, ...payload } = props.row;
currentCustomer = payload; currentCustomer = payload;
editCustomerForm(props.row.id); editCustomerForm(props.row.id, true);
} }
" "
@delete-card="deleteCustomerById(props.row.id)" @delete-card="deleteCustomerById(props.row.id)"
@ -1766,6 +1800,7 @@ const emptyCreateDialog = ref(false);
async () => { async () => {
customerFormStore.resetForm(customerFormState.dialogType === 'create'); customerFormStore.resetForm(customerFormState.dialogType === 'create');
onCreateImageList = { selectedImage: '', list: [] }; onCreateImageList = { selectedImage: '', list: [] };
customerFormState.customerImageUrl = '';
await fetchListOfOptionBranch(); await fetchListOfOptionBranch();
await customerFormStore.addCurrentCustomerBranch(); await customerFormStore.addCurrentCustomerBranch();
} }
@ -1805,11 +1840,8 @@ const emptyCreateDialog = ref(false);
active active
hide-fade hide-fade
:fallback-cover="`/images/customer-${customerFormData.customerType}-banner-bg.jpg`" :fallback-cover="`/images/customer-${customerFormData.customerType}-banner-bg.jpg`"
:img=" :img="customerFormState.customerImageUrl || null"
customerFormState.customerImageUrl || :fallbackImg="`/images/customer-PERS-avartar-male.png`"
`/images/customer-${customerFormData.customerType}-avartar-${customerFormData.gender}.png`
"
:fallbackImg="`/images/customer-${customerFormData.customerType}-avartar-${customerFormData.gender}.png`"
:color="`hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/1)`" :color="`hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/1)`"
:bg-color="`hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/0.1)`" :bg-color="`hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/0.1)`"
:icon=" :icon="
@ -1875,19 +1907,6 @@ const emptyCreateDialog = ref(false);
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"
> >
<q-form
@submit.prevent="
async () => {
console.log(customerFormData);
// await customerFormStore.submitFormCustomer(onCreateImageList);
// customerFormState.readonly = true;
notify('create', $t('general.success'));
// await fetchListCustomer();
}
"
greedy
>
<!-- :create="customerFormState.dialogType === 'create'" -->
<EmployerFormBasicInfo <EmployerFormBasicInfo
class="q-mb-xl" class="q-mb-xl"
:readonly=" :readonly="
@ -1897,7 +1916,7 @@ const emptyCreateDialog = ref(false);
" "
:action-disabled="customerFormState.branchIndex !== -1" :action-disabled="customerFormState.branchIndex !== -1"
id="form-basic-info-customer" id="form-basic-info-customer"
:create="false" :onCreate="customerFormState.dialogType === 'create'"
@edit=" @edit="
(customerFormState.dialogType = 'edit'), (customerFormState.dialogType = 'edit'),
(customerFormState.readonly = false) (customerFormState.readonly = false)
@ -1918,7 +1937,6 @@ const emptyCreateDialog = ref(false);
v-mode:telephoneNo="customerFormData.telephoneNo" v-mode:telephoneNo="customerFormData.telephoneNo"
v-model:branch-options="registerAbleBranchOption" v-model:branch-options="registerAbleBranchOption"
/> />
</q-form>
<div class="row q-col-gutter-sm" id="form-branch-customer-branch"> <div class="row q-col-gutter-sm" id="form-branch-customer-branch">
<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
@ -2062,6 +2080,7 @@ const emptyCreateDialog = ref(false);
:index="idx" :index="idx"
v-model:customer="customerFormData" v-model:customer="customerFormData"
v-model:customer-branch="customerFormData.customerBranch[idx]" v-model:customer-branch="customerFormData.customerBranch[idx]"
:onCreate="customerFormState.dialogType === 'create'"
:customer-type="customerFormData.customerType" :customer-type="customerFormData.customerType"
:customer-name="`${customerFormData.firstName} ${customerFormData.lastName}`" :customer-name="`${customerFormData.firstName} ${customerFormData.lastName}`"
:readonly="customerFormState.branchIndex !== idx" :readonly="customerFormState.branchIndex !== idx"
@ -2962,8 +2981,8 @@ const emptyCreateDialog = ref(false);
return false; return false;
} else { } else {
fetchListCustomer(); fetchListCustomer();
customerFormStore.resetForm(true);
customerFormState.branchIndex = -1; customerFormState.branchIndex = -1;
customerFormStore.resetForm(true);
} }
return false; return false;
} }
@ -2980,7 +2999,7 @@ const emptyCreateDialog = ref(false);
refreshImageState ? `?ts=${Date.now()}` : '', refreshImageState ? `?ts=${Date.now()}` : '',
) || null ) || null
" "
:fallbackImg="`/images/customer-${customerFormData.customerType}-avartar-${customerFormData.gender}.png`" :fallbackImg="`/images/customer-${customerFormData.customerType}-avartar-${customerFormData.customerType === 'PERS' ? customerFormData.customerBranch[0]?.gender : 'male'}.png`"
:color="`hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/1)`" :color="`hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/1)`"
:bg-color="`hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/0.1)`" :bg-color="`hsla(var(--${customerFormData.customerType === 'PERS' ? 'teal-10-hsl' : 'violet-11-hsl'})/0.1)`"
:icon=" :icon="
@ -3050,6 +3069,7 @@ const emptyCreateDialog = ref(false);
style="height: 100%; max-height: 100%; overflow-y: auto" style="height: 100%; max-height: 100%; overflow-y: auto"
> >
<EmployerFormBasicInfo <EmployerFormBasicInfo
v-if="customerFormData.customerBranch.length > 0"
:readonly=" :readonly="
(customerFormState.dialogType === 'edit' && (customerFormState.dialogType === 'edit' &&
customerFormState.readonly === true) || customerFormState.readonly === true) ||
@ -3058,7 +3078,7 @@ const emptyCreateDialog = ref(false);
:hide-action="customerFormData.status === 'INACTIVE'" :hide-action="customerFormData.status === 'INACTIVE'"
:action-disabled="customerFormState.branchIndex !== -1" :action-disabled="customerFormState.branchIndex !== -1"
id="form-basic-info-customer" id="form-basic-info-customer"
:create="customerFormState.dialogType === 'create'" :onCreate="customerFormState.dialogType === 'create'"
@edit=" @edit="
(customerFormState.dialogType = 'edit'), (customerFormState.dialogType = 'edit'),
(customerFormState.readonly = false) (customerFormState.readonly = false)
@ -3069,16 +3089,25 @@ const emptyCreateDialog = ref(false);
deleteCustomerById(customerFormState.editCustomerId) deleteCustomerById(customerFormState.editCustomerId)
" "
:customer-type="customerFormData.customerType" :customer-type="customerFormData.customerType"
v-model:code="customerFormData.code"
v-model:registered-branch-id="customerFormData.registeredBranchId" v-model:registered-branch-id="customerFormData.registeredBranchId"
v-model:customerName="customerNameInfo"
v-model:registerName="
customerFormData.customerBranch[0].registerName
"
v-model:citizenId="customerFormData.customerBranch[0].citizenId"
v-model:legalPersonNo="
customerFormData.customerBranch[0].legalPersonNo
"
v-model:businessType="
customerFormData.customerBranch[0].businessType
"
v-model:jobPosition="
customerFormData.customerBranch[0].jobPosition
"
v-model:telephoneNo="
customerFormData.customerBranch[0].telephoneNo
"
v-model:branch-options="registerAbleBranchOption" v-model:branch-options="registerAbleBranchOption"
v-model:first-name="customerFormData.firstName"
v-model:last-name="customerFormData.lastName"
v-model:first-name-en="customerFormData.firstNameEN"
v-model:last-name-en="customerFormData.lastNameEN"
v-model:name-prefix="customerFormData.namePrefix"
v-model:gender="customerFormData.gender"
v-model:birth-date="customerFormData.birthDate"
/> />
<!-- <div class="row q-col-gutter-sm q-mb-xl"> <!-- <div class="row q-col-gutter-sm q-mb-xl">
@ -3096,11 +3125,7 @@ const emptyCreateDialog = ref(false);
<div class="row q-col-gutter-sm" id="form-branch-customer-branch"> <div class="row q-col-gutter-sm" id="form-branch-customer-branch">
<div <div
class="col-12 text-weight-bold text-body1 row items-center" class="col-12 text-weight-bold text-body1 row items-center q-mt-lg"
:style="{
opacity:
customerFormState.branchIndex !== -1 ? '0.5' : undefined,
}"
> >
<q-icon <q-icon
flat flat

View file

@ -50,7 +50,7 @@ const authorizedCapital = defineModel<string>('authorizedCapital', {
// both // both
const telephoneNo = defineModel<string>('telephoneNo'); const telephoneNo = defineModel<string>('telephoneNo');
const customerCode = defineModel<string | undefined>('customerCode', { const codeCustomer = defineModel<string | undefined>('codeCustomer', {
required: true, required: true,
}); });
@ -130,6 +130,15 @@ watch(
:label="$t('customer.form.legalPersonCode')" :label="$t('customer.form.legalPersonCode')"
for="input-legal-person-code" for="input-legal-person-code"
v-model="legalPersonNo" v-model="legalPersonNo"
mask="#############"
:rules="[
(val) => (val && val.length > 0) || $t('form.error.required'),
(val) =>
(val && val.length === 13 && /[0-9]+/.test(val)) ||
$t('form.error.invalidCustomeMessage', {
msg: $t('form.error.requireLength', { msg: 13 }),
}),
]"
/> />
<q-input <q-input
@ -141,7 +150,7 @@ watch(
:disable="!readonly" :disable="!readonly"
:readonly="readonly" :readonly="readonly"
:label="$t('customer.form.customerCode')" :label="$t('customer.form.customerCode')"
:model-value="customerCode" :model-value="legalPersonNo"
/> />
<q-input <q-input
@ -153,7 +162,7 @@ watch(
:label="$t('customer.form.branchCode')" :label="$t('customer.form.branchCode')"
:disable="!readonly" :disable="!readonly"
:readonly="readonly" :readonly="readonly"
:model-value="`${branchCode?.slice(0, -2) || '-'}${index.toString().padStart(2, '0')}`" :model-value="branchCode"
/> />
</div> </div>
@ -182,7 +191,7 @@ watch(
:rules="[ :rules="[
(val: string) => !!val || $t('form.error.required'), (val: string) => !!val || $t('form.error.required'),
(val: string) => (val: string) =>
/^[A-Za-z]+$/.test(val) || $t('form.error.letterOnly'), /^[A-Za-z\s.,]+$/.test(val) || $t('form.error.letterOnly'),
]" ]"
/> />
</div> </div>
@ -249,7 +258,7 @@ watch(
:disable="!readonly" :disable="!readonly"
:readonly="readonly" :readonly="readonly"
:label="$t('customer.form.customerCode')" :label="$t('customer.form.customerCode')"
:model-value="customerCode" :model-value="codeCustomer"
/> />
<q-input <q-input
@ -262,6 +271,15 @@ watch(
:label="$t('customer.form.cardNumber')" :label="$t('customer.form.cardNumber')"
for="input-legal-person-no" for="input-legal-person-no"
v-model="citizenId" v-model="citizenId"
mask="#############"
:rules="[
(val) => (val && val.length > 0) || $t('form.error.required'),
(val) =>
(val && val.length === 13 && /[0-9]+/.test(val)) ||
$t('form.error.invalidCustomeMessage', {
msg: $t('form.error.requireLength', { msg: 13 }),
}),
]"
/> />
</div> </div>

View file

@ -18,7 +18,7 @@ withDefaults(
prefixId?: string; prefixId?: string;
outlined?: boolean; outlined?: boolean;
readonly?: boolean; readonly?: boolean;
create?: boolean; onCreate?: boolean;
actionDisabled?: boolean; actionDisabled?: boolean;
customerType?: 'CORP' | 'PERS'; customerType?: 'CORP' | 'PERS';
hideAction?: boolean; hideAction?: boolean;
@ -78,60 +78,6 @@ watch(
); );
}, },
); );
// const prefixNameOptions = ref<Record<string, unknown>[]>([]);
// let prefixNameFilter: (
// value: string,
// update: (callbackFn: () => void, afterFn?: (ref: QSelect) => void) => void,
// ) => void;
// const genderOptions = ref<Record<string, unknown>[]>([]);
// let genderFilter: (
// value: string,
// update: (callbackFn: () => void, afterFn?: (ref: QSelect) => void) => void,
// ) => void;
// onMounted(() => {
// prefixNameFilter = selectFilterOptionRefMod(
// ref(optionStore.globalOption?.prefix),
// prefixNameOptions,
// 'label',
// );
// genderFilter = selectFilterOptionRefMod(
// ref(optionStore.globalOption?.gender),
// genderOptions,
// 'label',
// );
// });
// watch(
// () => optionStore.globalOption,
// () => {
// prefixNameFilter = selectFilterOptionRefMod(
// ref(optionStore.globalOption.prefix),
// prefixNameOptions,
// 'label',
// );
// genderFilter = selectFilterOptionRefMod(
// ref(optionStore.globalOption.gender),
// genderOptions,
// 'label',
// );
// },
// );
// watch(
// () => namePrefix.value,
// (v) => {
// if (v === 'mr') gender.value = 'male';
// else gender.value = 'female';
// },
// );
// function formatCode(input: string | undefined, type: 'code' | 'number') {
// if (!input) return;
// return input.slice(...(type === 'code' ? [0, -6] : [-6]));
// }
</script> </script>
<template> <template>
@ -239,7 +185,7 @@ watch(
</div> </div>
<div <div
v-if="customerType === 'CORP' && !create" v-if="customerType === 'CORP' && !onCreate"
class="row col-12 q-col-gutter-sm" class="row col-12 q-col-gutter-sm"
> >
<q-input <q-input
@ -270,12 +216,12 @@ watch(
class="col-6 col-md-3" class="col-6 col-md-3"
:label="$t('customer.table.businessTypePure')" :label="$t('customer.table.businessTypePure')"
for="input-first-name-en" for="input-first-name-en"
v-model="businessType" :model-value="optionStore.mapOption(businessType)"
/> />
</div> </div>
<div <div
v-if="customerType === 'PERS' && !create" v-if="customerType === 'PERS' && !onCreate"
class="row col-12 q-col-gutter-sm" class="row col-12 q-col-gutter-sm"
> >
<q-input <q-input
@ -307,11 +253,11 @@ watch(
class="col-6 col-md-3" class="col-6 col-md-3"
:label="$t('customer.table.businessTypePure')" :label="$t('customer.table.businessTypePure')"
for="input-first-name-en" for="input-first-name-en"
v-model="businessType" :model-value="optionStore.mapOption(businessType)"
/> />
</div> </div>
<div v-if="!create" class="row col-12 q-col-gutter-sm"> <div v-if="!onCreate" class="row col-12 q-col-gutter-sm">
<q-input <q-input
dense dense
outlined outlined
@ -320,7 +266,7 @@ watch(
class="col-6 col-md-5" class="col-6 col-md-5"
:label="$t('customer.form.jobPosition')" :label="$t('customer.form.jobPosition')"
for="input-first-name-en" for="input-first-name-en"
v-model="jobPosition" :model-value="optionStore.mapOption(jobPosition)"
/> />
<q-input <q-input
dense dense
@ -343,671 +289,5 @@ watch(
</q-input> </q-input>
</div> </div>
</div> </div>
<!-- <div v-if="customerType === 'CORP'" class="col-12 row q-col-gutter-sm">
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-12 col-md-6"
:label="$t('customer.form.customerName')"
for="input-first-name"
v-model="customerName"
:rules="[(val: string) => !!val || $t('form.error.required')]"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-12 col-md-6"
:label="$t('customer.form.customerNameEN')"
for="input-first-name-en"
v-model="customerNameEN"
:rules="[
(val: string) => !!val || $t('form.error.required'),
(val: string) =>
/^[A-Za-z]+$/.test(val) || $t('form.error.letterOnly'),
]"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-6 col-md-3"
:label="$t('general.taxNo')"
for="input-first-name-en"
v-model="taxNo"
mask="#############"
:rules="[
(val) => (val && val.length > 0) || $t('form.error.required'),
(val) =>
(val && val.length === 13 && /[0-9]+/.test(val)) ||
$t('form.error.invalidCustomeMessage', {
msg: $t('form.error.requireLength', { msg: 13 }),
}),
]"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-6 col-md-3"
:label="$t('customer.table.businessTypePure')"
for="input-first-name-en"
v-model="businessType"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-6 col-md-3"
:label="$t('customer.form.jobPosition')"
for="input-first-name-en"
v-model="jobPosition"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-6 col-md-3"
:label="$t('customer.form.headQuarters.telephoneNo')"
for="input-first-name-en"
v-model="telephoneNo"
>
<template #prepend>
<q-icon
size="xs"
name="mdi-phone-outline"
class="cursor-pointer"
color="primary"
/>
</template>
</q-input>
</div>
<div v-if="customerType === 'PERS'" class="col-12 row q-col-gutter-sm">
<div class="col-9 row q-col-gutter-sm">
<q-select
outlined
clearable
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
dense
class="col-12"
option-value="id"
input-debounce="0"
option-label="name"
v-model="registeredBranchId"
:readonly="readonly"
:options="filteredBranchOptions"
:hide-dropdown-icon="readonly"
:label="$t('customer.form.registeredBranch')"
:for="`${prefixId}-input-source-nationality`"
:rules="[
(val) => {
const roles = getRole() || [];
return (
['admin', 'system', 'head_of_admin'].some((v) =>
roles.includes(v),
) ||
!!val ||
$t('form.error.required')
);
},
]"
@filter="branchFilter"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('general.noData') }}
</q-item-section>
</q-item>
</template>
</q-select>
<q-select
outlined
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
input-debounce="0"
option-label="label"
option-value="value"
hide-dropdown-icon
class="col-12 col-md-2"
dense
:readonly="readonly"
:options="prefixNameOptions"
:for="`${prefixId}-select-prefix-name`"
:label="$t('form.prefixName')"
@filter="prefixNameFilter"
:model-value="readonly ? namePrefix || '-' : namePrefix"
@update:model-value="
(v) => {
typeof v === 'string' ? (namePrefix = v) : '';
}
"
@clear="namePrefix = ''"
:rules="[
(val) => {
const roles = getRole() || [];
return !!val || $t('form.error.required');
},
]"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('general.noData') }}
</q-item-section>
</q-item>
</template>
</q-select>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-12 col-md-5"
:label="$t('customer.form.firstName')"
for="input-first-name"
v-model="firstName"
:rules="[
(val) => {
const roles = getRole() || [];
return !!val || $t('form.error.required');
},
]"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-12 col-md-5"
:label="$t('customer.form.lastName')"
for="input-last-name"
v-model="lastName"
:rules="[
(val) => {
const roles = getRole() || [];
return !!val || $t('form.error.required');
},
]"
/>
<q-input
dense
outlined
:disable="!readonly"
readonly
hide-bottom-space
class="col-12 col-md-2"
label="Title"
for="input-prefix-name-en"
:model-value="
readonly
? capitalize(namePrefix || '') || '-'
: capitalize(namePrefix || '')
"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-12 col-md-5"
label="Name"
for="input-first-name-en"
v-model="firstNameEN"
:rules="[
(val: string) => !!val || $t('form.error.required'),
(val: string) =>
/^[A-Za-z]+$/.test(val) || $t('form.error.letterOnly'),
]"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-12 col-md-5"
label="Surname"
for="input-last-name-en"
v-model="lastNameEN"
:rules="[
(val: string) => !!val || $t('form.error.required'),
(val: string) =>
/^[A-Za-z]+$/.test(val) || $t('form.error.letterOnly'),
]"
/>
<q-input
outlined
class="col-md-5 col-12"
hide-bottom-space
v-model="lastNameEN"
mask="#############"
:readonly="readonly"
dense
:label="$t('personnel.form.citizenId')"
:rules="[
(val) => (val && val.length > 0) || $t('form.error.required'),
(val) =>
(val && val.length === 13 && /[0-9]+/.test(val)) ||
$t('form.error.invalidCustomeMessage', {
msg: $t('form.error.requireLength', { msg: 13 }),
}),
]"
for="input-citizen-id"
/>
<q-select
outlined
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
input-debounce="0"
option-label="label"
option-value="value"
class="col-md-2 col-6"
dense
:readonly="readonly"
:options="genderOptions"
:hide-dropdown-icon="readonly"
:for="`${prefixId}-select-gender`"
:label="$t('form.gender')"
@filter="genderFilter"
:model-value="readonly ? gender || '-' : gender"
@update:model-value="
(v) => (typeof v === 'string' ? (gender = v) : '')
"
@clear="gender = ''"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('general.noData') }}
</q-item-section>
</q-item>
</template>
</q-select>
<DatePicker
v-model="birthDate"
class="col-md col-6"
:id="`${prefixId}-input-birth-date`"
:readonly="readonly"
:label="$t('form.birthDate')"
:disabled-dates="disabledAfterToday"
:rules="[
(val: string) =>
!!val ||
$t('form.error.selectField', { field: $t('form.birthDate') }),
]"
/>
<q-input
:for="`${prefixId}-input-age`"
:id="`${prefixId}-input-age`"
dense
outlined
:label="$t('personnel.age')"
class="col-md col-12"
:model-value="
birthDate?.toString() === 'Invalid Date' ||
birthDate?.toString() === undefined
? ''
: calculateAge(birthDate)
"
/>
</div>
<div class="row col-12 q-col-gutter-sm">
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-6 col-md"
:label="$t('customer.table.businessTypePure')"
for="input-first-name-en"
v-model="firstNameEN"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-6 col-md"
:label="$t('customer.form.jobPosition')"
for="input-first-name-en"
v-model="firstNameEN"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-6 col-md-3"
:label="$t('customer.form.headQuarters.telephoneNo')"
for="input-first-name-en"
v-model="firstNameEN"
>
<template #prepend>
<q-icon
size="xs"
name="mdi-phone-outline"
class="cursor-pointer"
color="primary"
/>
</template>
</q-input>
</div>
</div> -->
<!-- <div class="col-12 row q-col-gutter-sm">
<q-select
outlined
clearable
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
dense
class="col-12 col-md-7"
option-value="id"
input-debounce="0"
option-label="name"
v-model="registeredBranchId"
:readonly="readonly"
:options="filteredBranchOptions"
:hide-dropdown-icon="readonly"
:label="$t('customer.form.registeredBranch')"
:for="`${prefixId}-input-source-nationality`"
:rules="[
(val) => {
const roles = getRole() || [];
return (
['admin', 'system', 'head_of_admin'].some((v) =>
roles.includes(v),
) ||
!!val ||
$t('form.error.required')
);
},
]"
@filter="branchFilter"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('general.noData') }}
</q-item-section>
</q-item>
</template>
</q-select>
</div>
<div class="col-12 row q-col-gutter-sm">
<q-select
outlined
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
input-debounce="0"
option-label="label"
option-value="value"
hide-dropdown-icon
class="col-12 col-md-2"
dense
:readonly="readonly"
:options="prefixNameOptions"
:for="`${prefixId}-select-prefix-name`"
:label="$t('form.prefixName')"
@filter="prefixNameFilter"
:model-value="readonly ? namePrefix || '-' : namePrefix"
@update:model-value="
(v) => {
typeof v === 'string' ? (namePrefix = v) : '';
}
"
@clear="namePrefix = ''"
:rules="[
(val) => {
const roles = getRole() || [];
return !!val || $t('form.error.required');
},
]"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('general.noData') }}
</q-item-section>
</q-item>
</template>
</q-select>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-12 col-md-5"
:label="$t('customer.form.firstName')"
for="input-first-name"
v-model="firstName"
:rules="[
(val) => {
const roles = getRole() || [];
return !!val || $t('form.error.required');
},
]"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-12 col-md-5"
:label="$t('customer.form.lastName')"
for="input-last-name"
v-model="lastName"
:rules="[
(val) => {
const roles = getRole() || [];
return !!val || $t('form.error.required');
},
]"
/>
</div>
<div class="col-12 row q-col-gutter-sm">
<q-input
dense
outlined
:disable="!readonly"
readonly
hide-bottom-space
class="col-12 col-md-2"
:label="$t('customer.form.prefixName')"
for="input-prefix-name"
:model-value="
readonly
? capitalize(namePrefix || '') || '-'
: capitalize(namePrefix || '')
"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-12 col-md-5"
:label="$t('customer.form.firstNameEN')"
for="input-first-name-en"
v-model="firstNameEN"
:rules="[
(val: string) => !!val || $t('form.error.required'),
(val: string) =>
/^[A-Za-z]+$/.test(val) || $t('form.error.letterOnly'),
]"
/>
<q-input
dense
outlined
:readonly="readonly"
hide-bottom-space
class="col-12 col-md-5"
:label="$t('customer.form.lastNameEN')"
for="input-last-name-en"
v-model="lastNameEN"
:rules="[
(val: string) => !!val || $t('form.error.required'),
(val: string) =>
/^[A-Za-z]+$/.test(val) || $t('form.error.letterOnly'),
]"
/>
</div>
<div class="col-12 row q-col-gutter-sm">
<q-select
outlined
use-input
fill-input
emit-value
map-options
hide-selected
hide-bottom-space
input-debounce="0"
option-label="label"
option-value="value"
class="col-12 col-md-2"
dense
:readonly="readonly"
:options="genderOptions"
:hide-dropdown-icon="readonly"
:for="`${prefixId}-select-gender`"
:label="$t('form.gender')"
@filter="genderFilter"
:model-value="readonly ? gender || '-' : gender"
@update:model-value="(v) => (typeof v === 'string' ? (gender = v) : '')"
@clear="gender = ''"
:rules="[
(val) => {
const roles = getRole() || [];
return !!val || $t('form.error.required');
},
]"
>
<template v-slot:no-option>
<q-item>
<q-item-section class="text-grey">
{{ $t('general.noData') }}
</q-item-section>
</q-item>
</template>
</q-select>
<VueDatePicker
:id="`${prefixId}-input-birth-date`"
:for="`${prefixId}-input-birth-date`"
utc
autoApply
v-model="birthDate"
:disabled-dates="disabledAfterToday"
:teleport="true"
:dark="$q.dark.isActive"
:locale="$i18n.locale === 'tha' ? 'th' : 'en'"
:enableTimePicker="false"
:disabled="readonly"
class="col-12 col-md-3"
>
<template #year="{ value }">
{{ $i18n.locale === 'tha' ? value + 543 : value }}
</template>
<template #year-overlay-value="{ value }">
{{ $i18n.locale === 'tha' ? value + 543 : value }}
</template>
<template #trigger>
<q-input
:for="`${prefixId}-input-birth-date`"
hide-bottom-space
placeholder="DD/MM/YYYY"
:label="$t('form.birthDate')"
dense
outlined
:readonly="readonly"
:rules="[
(val: string) =>
!!val || $t('selectValidate') + $t('form.birthDate'),
]"
:mask="readonly ? '' : '##/##/####'"
:model-value="
birthDate && readonly
? dateFormat(birthDate)
: dateFormat(birthDate, false, false, true)
"
@update:model-value="
(v) => {
if (v && v.toString().length === 10) {
const today = new Date();
const date = parseAndFormatDate(v, locale);
birthDate = date && date > today ? today : date;
}
}
"
>
<template v-slot:prepend>
<q-icon
size="xs"
name="mdi-calendar-blank-outline"
class="cursor-pointer"
color="primary"
/>
</template>
</q-input>
</template>
</VueDatePicker>
<q-input
:for="`${prefixId}-input-age`"
:id="`${prefixId}-input-age`"
dense
outlined
readonly
:label="$t('general.age')"
class="col-12 col-md-2"
:model-value="
birthDate?.toString() === 'Invalid Date' ||
birthDate?.toString() === undefined
? ''
: calculateAge(birthDate)
"
/>
</div> -->
</div> </div>
</template> </template>

View file

@ -47,6 +47,7 @@ withDefaults(
customerName: string; customerName: string;
readonly?: boolean; readonly?: boolean;
prefixId?: string; prefixId?: string;
onCreate?: boolean;
actionDisabled?: boolean; actionDisabled?: boolean;
customerType?: 'CORP' | 'PERS'; customerType?: 'CORP' | 'PERS';
hideAction?: boolean; hideAction?: boolean;
@ -69,7 +70,8 @@ withDefaults(
? $t('customer.form.headQuarters.title') ? $t('customer.form.headQuarters.title')
: $t('customer.form.branch.title', { name: index || 0 }) : $t('customer.form.branch.title', { name: index || 0 })
}} }}
<!-- <EditButton <div class="q-ml-auto row no-warp">
<EditButton
icon-only icon-only
v-if="readonly" v-if="readonly"
@click="$emit('edit')" @click="$emit('edit')"
@ -86,20 +88,19 @@ withDefaults(
/> />
<UndoButton <UndoButton
icon-only icon-only
v-if="!readonly" v-if="!readonly && !onCreate"
@click="$emit('cancel')" @click="$emit('cancel')"
type="button" type="button"
class="q-ml-auto"
:disabled="actionDisabled" :disabled="actionDisabled"
/> --> />
<!-- v-if="!readonly" -->
<SaveButton <SaveButton
v-if="!readonly"
icon-only icon-only
@click="$emit('save')" @click="$emit('save')"
class="q-ml-auto"
type="submit" type="submit"
:disabled="actionDisabled" :disabled="actionDisabled"
/> />
</div>
</span> </span>
<div class="col-12" :style="{ opacity: actionDisabled ? '.5' : undefined }"> <div class="col-12" :style="{ opacity: actionDisabled ? '.5' : undefined }">
@ -140,13 +141,13 @@ withDefaults(
v-model:birthDate="item.birthDate" v-model:birthDate="item.birthDate"
v-model:customerName="item.customerName" v-model:customerName="item.customerName"
v-model:legalPersonNo="item.legalPersonNo" v-model:legalPersonNo="item.legalPersonNo"
v-model:branchCode="item.branchCode" v-model:branchCode="item.code"
v-model:registerName="item.registerName" v-model:registerName="item.registerName"
v-model:registerNameEN="item.registerNameEN" v-model:registerNameEN="item.registerNameEN"
v-model:registerDate="item.registerDate" v-model:registerDate="item.registerDate"
v-model:authorizedCapital="item.authorizedCapital" v-model:authorizedCapital="item.authorizedCapital"
v-model:telephoneNo="item.telephoneNo" v-model:telephoneNo="item.telephoneNo"
v-model:customerCode="item.customerCode" v-model:codeCustomer="item.codeCustomer"
/> />
</q-tab-panel> </q-tab-panel>
<q-tab-panel name="business"> <q-tab-panel name="business">

View file

@ -110,6 +110,7 @@ let jobPositionENFilter = selectFilterOptionRefMod(
map-options map-options
hide-selected hide-selected
hide-bottom-space hide-bottom-space
hide-dropdown-icon
input-debounce="0" input-debounce="0"
option-value="value" option-value="value"
option-label="label" option-label="label"
@ -142,6 +143,7 @@ let jobPositionENFilter = selectFilterOptionRefMod(
map-options map-options
hide-selected hide-selected
hide-bottom-space hide-bottom-space
hide-dropdown-icon
input-debounce="0" input-debounce="0"
option-value="value" option-value="value"
option-label="label" option-label="label"
@ -170,6 +172,7 @@ let jobPositionENFilter = selectFilterOptionRefMod(
map-options map-options
hide-selected hide-selected
hide-bottom-space hide-bottom-space
hide-dropdown-icon
input-debounce="0" input-debounce="0"
option-value="value" option-value="value"
option-label="label" option-label="label"
@ -200,6 +203,7 @@ let jobPositionENFilter = selectFilterOptionRefMod(
map-options map-options
hide-selected hide-selected
hide-bottom-space hide-bottom-space
hide-dropdown-icon
input-debounce="0" input-debounce="0"
option-value="value" option-value="value"
option-label="label" option-label="label"

View file

@ -140,28 +140,21 @@ export const useCustomerForm = defineStore('form-customer', () => {
resetFormData.registeredBranchId = data.registeredBranchId; resetFormData.registeredBranchId = data.registeredBranchId;
resetFormData.status = data.status; resetFormData.status = data.status;
resetFormData.customerType = data.customerType; resetFormData.customerType = data.customerType;
resetFormData.code = data.code || '';
resetFormData.namePrefix = data.namePrefix;
resetFormData.firstName = data.firstName;
resetFormData.lastName = data.lastName;
resetFormData.firstNameEN = data.firstNameEN;
resetFormData.lastNameEN = data.lastNameEN;
resetFormData.gender = data.gender;
resetFormData.birthDate = new Date(data.birthDate);
resetFormData.image = null; resetFormData.image = null;
resetFormData.selectedImage = data.selectedImage; resetFormData.selectedImage = data.selectedImage;
resetFormData.customerBranch = await Promise.all( resetFormData.customerBranch = await Promise.all(
data.branch.map(async (v) => ({ data.branch.map(async (v) => ({
id: v.id, firstName: v.firstName,
code: v.code || '', firstNameEN: v.firstNameEN,
customerCode: '', lastName: v.lastName,
provinceId: v.provinceId, lastNameEN: v.lastNameEN,
districtId: v.districtId, gender: v.gender,
subDistrictId: v.subDistrictId, birthDate: v.birthDate,
namePrefix: v.namePrefix,
wageRate: v.wageRate, wageRate: v.wageRate,
payDate: v.payDate, // Convert the string to a Date object wageRateText: v.wageRateText,
payDateEN: v.payDateEN, payDate: v.payDate,
saleEmployee: v.saleEmployee, saleEmployee: v.saleEmployee,
jobDescription: v.jobDescription, jobDescription: v.jobDescription,
jobPositionEN: v.jobPositionEN, jobPositionEN: v.jobPositionEN,
@ -169,23 +162,49 @@ export const useCustomerForm = defineStore('form-customer', () => {
businessTypeEN: v.businessTypeEN, businessTypeEN: v.businessTypeEN,
businessType: v.businessType, businessType: v.businessType,
employmentOffice: v.employmentOffice, employmentOffice: v.employmentOffice,
employmentOfficeEN: v.employmentOfficeEN,
telephoneNo: v.telephoneNo, telephoneNo: v.telephoneNo,
contactName: v.contactName,
email: v.email, email: v.email,
subDistrictId: v.subDistrictId,
districtId: v.districtId,
provinceId: v.provinceId,
streetEN: v.streetEN,
street: v.street,
mooEN: v.mooEN,
moo: v.moo,
soiEN: v.soiEN,
soi: v.soi,
addressEN: v.addressEN, addressEN: v.addressEN,
address: v.address, address: v.address,
workplaceEN: v.workplaceEN, workplaceEN: v.workplaceEN,
workplace: v.workplace, workplace: v.workplace,
authorizedCapital: v.authorizedCapital,
registerDate: v.registerDate,
registerNameEN: v.registerNameEN,
registerName: v.registerName,
legalPersonNo: v.legalPersonNo,
citizenId: v.citizenId,
codeCustomer: v.codeCustomer,
updatedByUserId: v.updatedByUserId,
updatedAt: v.updatedAt,
createdByUserId: v.createdByUserId,
createdAt: v.createdAt,
code: v.code,
statusOrder: v.statusOrder,
status: v.status, status: v.status,
customerId: v.customerId, customerId: v.customerId,
citizenId: v.citizenId || '', id: v.id,
authorizedCapital: v.authorizedCapital || '', homeCode: v.homeCode,
registerDate: new Date(v.registerDate), // Convert the string to a Date object contactTel: v.contactTel,
registerNameEN: v.registerNameEN || '', officeTel: v.officeTel,
registerName: v.registerName || '', agent: v.agent,
legalPersonNo: v.legalPersonNo || '', customerName: v.customerName,
registerCompanyName: '', authorizedName: v.authorizedName,
authorizedNameEN: v.authorizedNameEN,
payDateEN: v.payDateEN,
statusSave: true, statusSave: true,
contactName: v.contactName || '',
file: await customerStore.listAttachment(v.id).then(async (r) => { file: await customerStore.listAttachment(v.id).then(async (r) => {
if (r) { if (r) {
return await Promise.all( return await Promise.all(
@ -220,7 +239,7 @@ export const useCustomerForm = defineStore('form-customer', () => {
? '' ? ''
: currentFormData.value.customerBranch?.[0].branchCode : currentFormData.value.customerBranch?.[0].branchCode
: '', : '',
customerCode: '', codeCustomer: '',
legalPersonNo: legalPersonNo:
currentFormData.value.customerBranch.length !== 0 currentFormData.value.customerBranch.length !== 0
@ -373,7 +392,6 @@ export const useCustomerBranchForm = defineStore('form-customer-branch', () => {
registerNameEN: '', registerNameEN: '',
registerName: '', registerName: '',
legalPersonNo: '', legalPersonNo: '',
registerCompanyName: '',
statusSave: false, statusSave: false,
contactName: '', contactName: '',
file: [], file: [],
@ -441,7 +459,6 @@ export const useCustomerBranchForm = defineStore('form-customer-branch', () => {
registerName: _data.registerName, registerName: _data.registerName,
legalPersonNo: _data.legalPersonNo, legalPersonNo: _data.legalPersonNo,
contactName: _data.contactName, contactName: _data.contactName,
registerCompanyName: '',
statusSave: false, statusSave: false,
file: [], file: [],
}; };

View file

@ -335,7 +335,6 @@ const useCustomerStore = defineStore('api-customer', () => {
) { ) {
if (data.customerBranch) { if (data.customerBranch) {
if (data.customerBranch[0].citizenId) { if (data.customerBranch[0].citizenId) {
console.log('1');
delete data.customerBranch[0]['authorizedNameEN']; delete data.customerBranch[0]['authorizedNameEN'];
delete data.customerBranch[0]['authorizedName']; delete data.customerBranch[0]['authorizedName'];
delete data.customerBranch[0]['authorizedCapital']; delete data.customerBranch[0]['authorizedCapital'];
@ -368,7 +367,7 @@ const useCustomerStore = defineStore('api-customer', () => {
branchCode: undefined, branchCode: undefined,
id: undefined, id: undefined,
customerId: undefined, customerId: undefined,
customerCode: undefined, codeCustomer: undefined,
})), })),
selectedImage: imgList.selectedImage, selectedImage: imgList.selectedImage,
}, },
@ -404,18 +403,6 @@ const useCustomerStore = defineStore('api-customer', () => {
}, },
) { ) {
const { customerBranch, image, ...payload } = data; const { customerBranch, image, ...payload } = data;
// const attachment = payload.customerBranch?.map((v) => v.file);
// payload.customerBranch = payload.customerBranch?.map((v) => {
// const { code: _code, ...rest } = v;
// return { ...rest };
// });
// if (payload.customerBranch?.length) {
// for (let i = 0; i < payload.customerBranch?.length; i++) {
// delete payload.customerBranch[i].file;
// }
// }
const res = await api.put< const res = await api.put<
Customer & { Customer & {
@ -423,28 +410,32 @@ const useCustomerStore = defineStore('api-customer', () => {
imageUrl: string; imageUrl: string;
imageUploadUrl: string; imageUploadUrl: string;
} }
>(`/customer/${id}`, payload, { >(
`/customer/${id}`,
{
...payload,
branch: data.customerBranch?.map((v) => ({
...v,
file: undefined,
branchCode: undefined,
id: undefined,
customerId: undefined,
codeCustomer: undefined,
createAt: undefined,
createdByUserId: undefined,
statusOrder: undefined,
updatedAt: undefined,
updatedByUserId: undefined,
})),
},
{
headers: { headers: {
'X-Session-Id': flow?.sessionId, 'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Rtid': flow?.refTransactionId || flowStore.rtid,
'X-Tid': flow?.transactionId, 'X-Tid': flow?.transactionId,
}, },
}); },
);
// await Promise.allSettled([
// ...res.data.branch.map(async (v, i) => {
// const fileList = attachment?.[i];
// if (fileList)
// return await addBranchAttachment(v.id, { file: fileList });
// }),
// image &&
// (await axios
// .put(res.data.imageUploadUrl, image, {
// headers: { 'Content-Type': image.type },
// onUploadProgress: (e) => console.log(e),
// })
// .catch((e) => console.error(e)));
// ]);
if (!res) return false; if (!res) return false;
@ -494,30 +485,35 @@ const useCustomerStore = defineStore('api-customer', () => {
} }
async function createBranch( async function createBranch(
data: CustomerBranchCreate & { id?: string; customerId: string }, data: CustomerBranchCreate & {
id?: string;
customerId: string;
codeCustomer: string;
},
flow?: { flow?: {
sessionId?: string; sessionId?: string;
refTransactionId?: string; refTransactionId?: string;
transactionId?: string; transactionId?: string;
}, },
) { ) {
const { const { codeCustomer, statusSave, code, file, birthDate, ...payload } =
customerCode, data;
registerCompanyName,
statusSave,
code,
file,
...payload
} = data;
if (!!payload.citizenId) { if (data.citizenId) {
delete payload['registerDate']; delete data['authorizedNameEN'];
delete payload['registerName']; delete data['authorizedName'];
delete payload['registerNameEN']; delete data['registerDate'];
delete payload['authorizedCapital']; delete data['authorizedCapital'];
delete payload['legalPersonNo']; delete data['registerNameEN'];
delete data['registerName'];
delete data['legalPersonNo'];
} else { } else {
delete payload['citizenId']; delete data['citizenId'];
}
console.log(data.birthDate);
console.log(!data.birthDate);
if (!data.birthDate) {
delete data['birthDate'];
} }
const res = await api.post<CustomerBranch>('/customer-branch', payload, { const res = await api.post<CustomerBranch>('/customer-branch', payload, {
@ -536,20 +532,44 @@ const useCustomerStore = defineStore('api-customer', () => {
async function editBranchById( async function editBranchById(
id: string, id: string,
data: Partial<CustomerBranchCreate & { id?: string; customerId: string }>, data: Partial<
CustomerBranch & {
id?: string;
customerId: string;
codeCustomer: string;
}
>,
flow?: { flow?: {
sessionId?: string; sessionId?: string;
refTransactionId?: string; refTransactionId?: string;
transactionId?: string; transactionId?: string;
}, },
) { ) {
if (data.citizenId) {
delete data['authorizedNameEN'];
delete data['authorizedName'];
delete data['registerDate'];
delete data['authorizedCapital'];
delete data['registerNameEN'];
delete data['registerName'];
delete data['legalPersonNo'];
} else {
delete data['citizenId'];
}
if (!data.birthDate) delete data['birthDate'];
const { const {
customerCode,
registerCompanyName,
statusSave,
code, code,
status, status,
codeCustomer,
createdAt,
createdByUserId,
statusOrder,
updatedAt,
updatedByUserId,
file, file,
registerCompanyName,
statusSave,
...payload ...payload
} = data; } = data;

View file

@ -30,33 +30,57 @@ export type Customer = {
}; };
export type CustomerBranch = { export type CustomerBranch = {
customerId: string; customerCode?: string;
contactName: string; wageRateText: 'string';
wageRate: number; wageRate: 0;
payDate: string; payDateEN: 'string';
payDateEN: string; payDate: 'string';
jobDescription: string; jobDescription: 'string';
jobPosition: string; jobPosition: 'string';
businessType: string; businessType: 'string';
employmentOffice: string; agent: 'string';
authorizedCapital: string; contactName: 'string';
registerDate: Date | null; officeTel: 'string';
registerNameEN: string; contactTel: 'string';
registerName: string; email: 'string';
legalPersonNo?: string; subDistrictId: 'string';
citizenId: string; districtId: 'string';
updatedByUserId: string; provinceId: 'string';
createdByUserId: string; streetEN: 'string';
statusOrder: number; street: 'string';
telephoneNo: string; mooEN: 'string';
email: string; moo: 'string';
subDistrictId: string; soiEN: 'string';
districtId: string; soi: 'string';
provinceId: string; addressEN: 'string';
addressEN: string; address: 'string';
address: string; employmentOfficeEN: 'string';
code: string; employmentOffice: 'string';
id: string; homeCode: 'string';
authorizedNameEN: 'string';
authorizedName: 'string';
authorizedCapital: 'string';
registerDate: '2024-09-16T07:52:42.627Z';
registerNameEN: 'string';
registerName: 'string';
legalPersonNo: 'string';
citizenId: 'string';
birthDate: '2024-09-16T07:52:42.627Z';
gender: 'string';
lastNameEN: 'string';
lastName: 'string';
firstNameEN: 'string';
firstName: 'string';
namePrefix: 'string';
telephoneNo: 'string';
codeCustomer: 'string';
customerName: 'string';
updatedByUserId: 'string';
createdByUserId: 'string';
code: 'string';
statusOrder: 0;
customerId: 'string';
id: 'string';
status: Status; status: Status;
createdBy: string | null; createdBy: string | null;
@ -72,6 +96,7 @@ export type CustomerBranch = {
}; };
export type CustomerBranchCreate = { export type CustomerBranchCreate = {
customerCode?: string;
customerId: string; customerId: string;
legalPersonNo?: string; legalPersonNo?: string;
citizenId?: string; citizenId?: string;
@ -117,6 +142,7 @@ export type CustomerBranchCreate = {
authorizedCapital?: string; authorizedCapital?: string;
authorizedName?: string; authorizedName?: string;
authorizedNameEN?: string; authorizedNameEN?: string;
code?: 'string';
file?: { file?: {
name?: string; name?: string;
group?: string; group?: string;
@ -129,7 +155,7 @@ export type CustomerCreate = {
customerBranch?: (CustomerBranchCreate & { customerBranch?: (CustomerBranchCreate & {
id?: string; id?: string;
branchCode?: string; branchCode?: string;
customerCode?: string; codeCustomer?: string;
})[]; })[];
selectedImage?: string; selectedImage?: string;
status?: Status; status?: Status;
@ -145,7 +171,7 @@ export type CustomerUpdate = {
customerBranch?: (CustomerBranchCreate & { customerBranch?: (CustomerBranchCreate & {
id?: string; id?: string;
branchCode?: string; branchCode?: string;
customerCode?: string; codeCustomer?: string;
})[]; })[];
image?: File; image?: File;
registeredBranchId: string; registeredBranchId: string;