diff --git a/src/components/01_branch-management/FormBank.vue b/src/components/01_branch-management/FormBank.vue index 8d207d09..219c6f6a 100644 --- a/src/components/01_branch-management/FormBank.vue +++ b/src/components/01_branch-management/FormBank.vue @@ -261,16 +261,18 @@ watch( :readonly="readonly" :label="$t('branch.form.bankAccountNumber')" :maxlength="13" - :rules="[ - (val: string) => - (val.length >= 7 && val.length <= 13) || - $t('form.error.please', { msg: $t('accountNumber') }), - ]" :model-value="readonly ? book.accountNumber || '-' : book.accountNumber" @update:model-value=" (v) => (typeof v === 'string' ? (book.accountNumber = v) : '') " /> + const code = defineModel('code'); +const branchCount = defineModel('branchCount', { default: 0 }); const codeSubBranch = defineModel('codeSubBranch'); const taxNo = defineModel('taxNo'); const name = defineModel('name'); @@ -13,12 +14,13 @@ defineProps<{ outlined?: boolean; readonly?: boolean; view?: boolean; + onCreate?: boolean; }>(); function formatCode(input: string | undefined, type: 'code' | 'number') { if (!input) return; - const code = input.slice(0, -6); - const number = input.slice(-6); + const code = input.slice(0, -5); + const number = input.slice(-5); if (type === 'code') return code; if (type === 'number') return number; } @@ -67,10 +69,22 @@ function formatCode(input: string | undefined, type: 'code' | 'number') { class="col-md col-7" :label="$t('branch.form.code')" for="input-code" - :model-value="view ? formatCode(code, 'number') : code" + :model-value=" + typeBranch === 'headOffice' + ? view + ? formatCode(code, 'number') + : '00000' + : view + ? onCreate + ? (branchCount + 1).toString().padStart(5, '0') + : formatCode(codeSubBranch, 'number') + : codeSubBranch + " @update:model-value="(v) => (code = v as string)" /> - + (undefined); const qrCodeimageUrl = ref(''); +const formBranchCount = ref(0); const inputFile = (() => { const element = document.createElement('input'); @@ -295,8 +296,14 @@ const formDialogRef = ref(); const formType = ref<'create' | 'edit' | 'delete' | 'view'>('create'); const formTypeBranch = ref<'headOffice' | 'subBranch'>('headOffice'); -const currentHq = ref<{ id: string; code: string }>({ id: '', code: '' }); -const currentEdit = ref<{ id: string; code: string }>({ id: '', code: '' }); +const currentHq = ref<{ id: string; code: string; count?: number }>({ + id: '', + code: '', +}); +const currentEdit = ref<{ id: string; code: string; count?: number }>({ + id: '', + code: '', +}); const formData = ref< Omit >(structuredClone(defaultFormData)); @@ -386,6 +393,7 @@ function triggerCreate( type: 'headOffice' | 'subBranch', id?: string, code?: string, + count?: number, ) { clearData(); @@ -395,6 +403,7 @@ function triggerCreate( currentHq.value = { id: id ?? '', code: code ?? '', + count: count, }; } @@ -403,6 +412,7 @@ function triggerCreate( formData.value.headOfficeId = id; formData.value.code = code; formData.value.codeHeadOffice = code; + formBranchCount.value = count; } formType.value = 'create'; @@ -447,6 +457,7 @@ async function triggerEdit( currentEdit.value = { id: currentRecord.id, code: currentRecord.code, + count: currentRecord._count, }; if (typeBranch === 'subBranch') { @@ -459,6 +470,7 @@ async function triggerEdit( if (currentRecordHead) { currentHq.value.id = currentRecordHead.id; currentHq.value.code = currentRecordHead.code; + currentHq.value.count = currentRecordHead._count.branch; } else { currentHq.value = currentEdit.value; } @@ -577,7 +589,7 @@ async function onSubmit() { ); formData.value.headOfficeId = currentRecord?.id; - formData.value.code = formData.value.code?.slice(0, -6); + formData.value.code = formData.value.code?.slice(0, -5); delete formData.value['codeHeadOffice']; await createBranch(); } else { @@ -585,7 +597,7 @@ async function onSubmit() { color: 'info', icon: 'mdi-message-processing-outline', message: t('form.info.cantChange', { - field: t('formDialogHqAbbreviation'), + field: t('branch.form.abbrev'), name: formData.value.code, }), actionText: t('agree'), @@ -789,6 +801,7 @@ watch(currentHq, () => { 'subBranch', currentHq.id, currentHq.code, + currentHq.count, ); } } @@ -843,6 +856,7 @@ watch(currentHq, () => { currentHq = { id: v.id, code: v.code, + count: v._count.branch, }; beforeBranch = { id: '', @@ -851,7 +865,15 @@ watch(currentHq, () => { } } " - @create="(v) => triggerCreate('subBranch', v.id, v.code)" + @create=" + (v) => + triggerCreate( + 'subBranch', + v.id, + v.code, + v._count.branch, + ) + " @view=" (v) => { if (v.isHeadOffice) { @@ -1100,6 +1122,7 @@ watch(currentHq, () => { currentHq = { id: props.row.id, code: props.row.code, + count: props.row._count.branch, }; beforeBranch = { id: '', @@ -1263,6 +1286,7 @@ watch(currentHq, () => { currentHq = { id: props.row.id, code: props.row.code, + count: props.row._count.branch, }; beforeBranch = { id: '', @@ -1386,6 +1410,7 @@ watch(currentHq, () => { " :close=" () => ( + (formBranchCount = 0), (modal = false), (profileFileImg = undefined), (isImageEdit = false), @@ -1400,7 +1425,12 @@ watch(currentHq, () => { active useToggle :title="formData.name" - :caption="formData.codeHeadOffice" + :toggleTitle="$t('status.title')" + :caption=" + formTypeBranch === 'headOffice' + ? `${formData.code}00000` + : `${formData.code?.slice(0, -5)}${(formBranchCount + 1).toString().padStart(5, '0')}` + " v-model:toggle-status="formData.status" v-model:cover-url="imageUrl" :hideFade="imageUrl === '' || imageUrl === null" @@ -1479,6 +1509,7 @@ watch(currentHq, () => {
{ :dense="true" :outlined="true" :readonly="formType === 'view'" - :view="isSubCreate" title="form.field.basicInformation" + :view="isSubCreate" + onCreate /> { :active="formData.status !== 'INACTIVE'" useToggle v-model:cover-url="imageUrl" + :toggleTitle="$t('status.title')" :hideFade="imageUrl === '' || imageUrl === null" :img="imageUrl || null" :cover="imageUrl || null" @@ -1810,7 +1843,12 @@ watch(currentHq, () => { v-ripple v-close-popup @click.stop=" - triggerCreate('subBranch', currentNode.id, currentNode.code) + triggerCreate( + 'subBranch', + currentNode.id, + currentNode.code, + currentNode._count.branch, + ) " >