feat(01): mock code branch
This commit is contained in:
parent
fddaf80f89
commit
88eb554e01
4 changed files with 73 additions and 19 deletions
|
|
@ -261,16 +261,18 @@ watch(
|
||||||
:readonly="readonly"
|
:readonly="readonly"
|
||||||
:label="$t('branch.form.bankAccountNumber')"
|
:label="$t('branch.form.bankAccountNumber')"
|
||||||
:maxlength="13"
|
: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"
|
:model-value="readonly ? book.accountNumber || '-' : book.accountNumber"
|
||||||
@update:model-value="
|
@update:model-value="
|
||||||
(v) => (typeof v === 'string' ? (book.accountNumber = v) : '')
|
(v) => (typeof v === 'string' ? (book.accountNumber = v) : '')
|
||||||
"
|
"
|
||||||
/>
|
/>
|
||||||
|
<!-- :rules="[
|
||||||
|
(val: string) =>
|
||||||
|
(val.length >= 7 && val.length <= 13) ||
|
||||||
|
$t('form.error.please', {
|
||||||
|
msg: $t('branch.form.bankAccountNumber'),
|
||||||
|
}),
|
||||||
|
]" -->
|
||||||
|
|
||||||
<q-input
|
<q-input
|
||||||
outlined
|
outlined
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const code = defineModel<string>('code');
|
const code = defineModel<string>('code');
|
||||||
|
const branchCount = defineModel<number>('branchCount', { default: 0 });
|
||||||
const codeSubBranch = defineModel<string>('codeSubBranch');
|
const codeSubBranch = defineModel<string>('codeSubBranch');
|
||||||
const taxNo = defineModel<string>('taxNo');
|
const taxNo = defineModel<string>('taxNo');
|
||||||
const name = defineModel<string>('name');
|
const name = defineModel<string>('name');
|
||||||
|
|
@ -13,12 +14,13 @@ defineProps<{
|
||||||
outlined?: boolean;
|
outlined?: boolean;
|
||||||
readonly?: boolean;
|
readonly?: boolean;
|
||||||
view?: boolean;
|
view?: boolean;
|
||||||
|
onCreate?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
function formatCode(input: string | undefined, type: 'code' | 'number') {
|
function formatCode(input: string | undefined, type: 'code' | 'number') {
|
||||||
if (!input) return;
|
if (!input) return;
|
||||||
const code = input.slice(0, -6);
|
const code = input.slice(0, -5);
|
||||||
const number = input.slice(-6);
|
const number = input.slice(-5);
|
||||||
if (type === 'code') return code;
|
if (type === 'code') return code;
|
||||||
if (type === 'number') return number;
|
if (type === 'number') return number;
|
||||||
}
|
}
|
||||||
|
|
@ -67,10 +69,22 @@ function formatCode(input: string | undefined, type: 'code' | 'number') {
|
||||||
class="col-md col-7"
|
class="col-md col-7"
|
||||||
:label="$t('branch.form.code')"
|
:label="$t('branch.form.code')"
|
||||||
for="input-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)"
|
@update:model-value="(v) => (code = v as string)"
|
||||||
/>
|
/>
|
||||||
<q-input
|
|
||||||
|
<!-- view ? `${formatCode(code, 'number')}${branchCount}` : code -->
|
||||||
|
<!-- <q-input
|
||||||
lazy-rules="ondemand"
|
lazy-rules="ondemand"
|
||||||
v-if="typeBranch !== 'headOffice'"
|
v-if="typeBranch !== 'headOffice'"
|
||||||
:dense="dense"
|
:dense="dense"
|
||||||
|
|
@ -85,7 +99,7 @@ function formatCode(input: string | undefined, type: 'code' | 'number') {
|
||||||
view ? formatCode(codeSubBranch, 'number') : codeSubBranch
|
view ? formatCode(codeSubBranch, 'number') : codeSubBranch
|
||||||
"
|
"
|
||||||
@update:model-value="(v) => (codeSubBranch = v as string)"
|
@update:model-value="(v) => (codeSubBranch = v as string)"
|
||||||
/>
|
/> -->
|
||||||
|
|
||||||
<q-input
|
<q-input
|
||||||
lazy-rules="ondemand"
|
lazy-rules="ondemand"
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ export default {
|
||||||
abbrev: 'ชื่อย่อ',
|
abbrev: 'ชื่อย่อ',
|
||||||
code: 'รหัสสำนักงานใหญ่',
|
code: 'รหัสสำนักงานใหญ่',
|
||||||
codeBranch: 'รหัสสาขา',
|
codeBranch: 'รหัสสาขา',
|
||||||
taxNo: 'เลขประจำตัวผู้เสียภาษี',
|
taxNo: 'ทะเบียนนิติบุคคลเลขที่',
|
||||||
contactName: 'ชื่อผู้ติดต่อ',
|
contactName: 'ชื่อผู้ติดต่อ',
|
||||||
contactTelephone: 'เบอร์ผู้ติดต่อ',
|
contactTelephone: 'เบอร์ผู้ติดต่อ',
|
||||||
branchName: 'ชื่อสาขา',
|
branchName: 'ชื่อสาขา',
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,7 @@ const imageDialog = ref(false);
|
||||||
|
|
||||||
const profileFile = ref<File | undefined>(undefined);
|
const profileFile = ref<File | undefined>(undefined);
|
||||||
const qrCodeimageUrl = ref<string | null>('');
|
const qrCodeimageUrl = ref<string | null>('');
|
||||||
|
const formBranchCount = ref<number>(0);
|
||||||
|
|
||||||
const inputFile = (() => {
|
const inputFile = (() => {
|
||||||
const element = document.createElement('input');
|
const element = document.createElement('input');
|
||||||
|
|
@ -295,8 +296,14 @@ const formDialogRef = ref();
|
||||||
|
|
||||||
const formType = ref<'create' | 'edit' | 'delete' | 'view'>('create');
|
const formType = ref<'create' | 'edit' | 'delete' | 'view'>('create');
|
||||||
const formTypeBranch = ref<'headOffice' | 'subBranch'>('headOffice');
|
const formTypeBranch = ref<'headOffice' | 'subBranch'>('headOffice');
|
||||||
const currentHq = ref<{ id: string; code: string }>({ id: '', code: '' });
|
const currentHq = ref<{ id: string; code: string; count?: number }>({
|
||||||
const currentEdit = ref<{ id: string; code: string }>({ id: '', code: '' });
|
id: '',
|
||||||
|
code: '',
|
||||||
|
});
|
||||||
|
const currentEdit = ref<{ id: string; code: string; count?: number }>({
|
||||||
|
id: '',
|
||||||
|
code: '',
|
||||||
|
});
|
||||||
const formData = ref<
|
const formData = ref<
|
||||||
Omit<BranchCreate & { codeHeadOffice?: string }, 'qrCodeImage' | 'imageUrl'>
|
Omit<BranchCreate & { codeHeadOffice?: string }, 'qrCodeImage' | 'imageUrl'>
|
||||||
>(structuredClone(defaultFormData));
|
>(structuredClone(defaultFormData));
|
||||||
|
|
@ -386,6 +393,7 @@ function triggerCreate(
|
||||||
type: 'headOffice' | 'subBranch',
|
type: 'headOffice' | 'subBranch',
|
||||||
id?: string,
|
id?: string,
|
||||||
code?: string,
|
code?: string,
|
||||||
|
count?: number,
|
||||||
) {
|
) {
|
||||||
clearData();
|
clearData();
|
||||||
|
|
||||||
|
|
@ -395,6 +403,7 @@ function triggerCreate(
|
||||||
currentHq.value = {
|
currentHq.value = {
|
||||||
id: id ?? '',
|
id: id ?? '',
|
||||||
code: code ?? '',
|
code: code ?? '',
|
||||||
|
count: count,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -403,6 +412,7 @@ function triggerCreate(
|
||||||
formData.value.headOfficeId = id;
|
formData.value.headOfficeId = id;
|
||||||
formData.value.code = code;
|
formData.value.code = code;
|
||||||
formData.value.codeHeadOffice = code;
|
formData.value.codeHeadOffice = code;
|
||||||
|
formBranchCount.value = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
formType.value = 'create';
|
formType.value = 'create';
|
||||||
|
|
@ -447,6 +457,7 @@ async function triggerEdit(
|
||||||
currentEdit.value = {
|
currentEdit.value = {
|
||||||
id: currentRecord.id,
|
id: currentRecord.id,
|
||||||
code: currentRecord.code,
|
code: currentRecord.code,
|
||||||
|
count: currentRecord._count,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (typeBranch === 'subBranch') {
|
if (typeBranch === 'subBranch') {
|
||||||
|
|
@ -459,6 +470,7 @@ async function triggerEdit(
|
||||||
if (currentRecordHead) {
|
if (currentRecordHead) {
|
||||||
currentHq.value.id = currentRecordHead.id;
|
currentHq.value.id = currentRecordHead.id;
|
||||||
currentHq.value.code = currentRecordHead.code;
|
currentHq.value.code = currentRecordHead.code;
|
||||||
|
currentHq.value.count = currentRecordHead._count.branch;
|
||||||
} else {
|
} else {
|
||||||
currentHq.value = currentEdit.value;
|
currentHq.value = currentEdit.value;
|
||||||
}
|
}
|
||||||
|
|
@ -577,7 +589,7 @@ async function onSubmit() {
|
||||||
);
|
);
|
||||||
|
|
||||||
formData.value.headOfficeId = currentRecord?.id;
|
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'];
|
delete formData.value['codeHeadOffice'];
|
||||||
await createBranch();
|
await createBranch();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -585,7 +597,7 @@ async function onSubmit() {
|
||||||
color: 'info',
|
color: 'info',
|
||||||
icon: 'mdi-message-processing-outline',
|
icon: 'mdi-message-processing-outline',
|
||||||
message: t('form.info.cantChange', {
|
message: t('form.info.cantChange', {
|
||||||
field: t('formDialogHqAbbreviation'),
|
field: t('branch.form.abbrev'),
|
||||||
name: formData.value.code,
|
name: formData.value.code,
|
||||||
}),
|
}),
|
||||||
actionText: t('agree'),
|
actionText: t('agree'),
|
||||||
|
|
@ -789,6 +801,7 @@ watch(currentHq, () => {
|
||||||
'subBranch',
|
'subBranch',
|
||||||
currentHq.id,
|
currentHq.id,
|
||||||
currentHq.code,
|
currentHq.code,
|
||||||
|
currentHq.count,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -843,6 +856,7 @@ watch(currentHq, () => {
|
||||||
currentHq = {
|
currentHq = {
|
||||||
id: v.id,
|
id: v.id,
|
||||||
code: v.code,
|
code: v.code,
|
||||||
|
count: v._count.branch,
|
||||||
};
|
};
|
||||||
beforeBranch = {
|
beforeBranch = {
|
||||||
id: '',
|
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="
|
@view="
|
||||||
(v) => {
|
(v) => {
|
||||||
if (v.isHeadOffice) {
|
if (v.isHeadOffice) {
|
||||||
|
|
@ -1100,6 +1122,7 @@ watch(currentHq, () => {
|
||||||
currentHq = {
|
currentHq = {
|
||||||
id: props.row.id,
|
id: props.row.id,
|
||||||
code: props.row.code,
|
code: props.row.code,
|
||||||
|
count: props.row._count.branch,
|
||||||
};
|
};
|
||||||
beforeBranch = {
|
beforeBranch = {
|
||||||
id: '',
|
id: '',
|
||||||
|
|
@ -1263,6 +1286,7 @@ watch(currentHq, () => {
|
||||||
currentHq = {
|
currentHq = {
|
||||||
id: props.row.id,
|
id: props.row.id,
|
||||||
code: props.row.code,
|
code: props.row.code,
|
||||||
|
count: props.row._count.branch,
|
||||||
};
|
};
|
||||||
beforeBranch = {
|
beforeBranch = {
|
||||||
id: '',
|
id: '',
|
||||||
|
|
@ -1386,6 +1410,7 @@ watch(currentHq, () => {
|
||||||
"
|
"
|
||||||
:close="
|
:close="
|
||||||
() => (
|
() => (
|
||||||
|
(formBranchCount = 0),
|
||||||
(modal = false),
|
(modal = false),
|
||||||
(profileFileImg = undefined),
|
(profileFileImg = undefined),
|
||||||
(isImageEdit = false),
|
(isImageEdit = false),
|
||||||
|
|
@ -1400,7 +1425,12 @@ watch(currentHq, () => {
|
||||||
active
|
active
|
||||||
useToggle
|
useToggle
|
||||||
:title="formData.name"
|
: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:toggle-status="formData.status"
|
||||||
v-model:cover-url="imageUrl"
|
v-model:cover-url="imageUrl"
|
||||||
:hideFade="imageUrl === '' || imageUrl === null"
|
:hideFade="imageUrl === '' || imageUrl === null"
|
||||||
|
|
@ -1479,6 +1509,7 @@ watch(currentHq, () => {
|
||||||
<div class="col-md-10 col-12 q-pa-md q-gutter-y-xl">
|
<div class="col-md-10 col-12 q-pa-md q-gutter-y-xl">
|
||||||
<FormBranchInformation
|
<FormBranchInformation
|
||||||
id="form-information"
|
id="form-information"
|
||||||
|
v-model:branchCount="formBranchCount"
|
||||||
v-model:abbreviation="formData.code"
|
v-model:abbreviation="formData.code"
|
||||||
v-model:code="formData.codeHeadOffice"
|
v-model:code="formData.codeHeadOffice"
|
||||||
v-model:code-sub-branch="currentEdit.code"
|
v-model:code-sub-branch="currentEdit.code"
|
||||||
|
|
@ -1489,8 +1520,9 @@ watch(currentHq, () => {
|
||||||
:dense="true"
|
:dense="true"
|
||||||
:outlined="true"
|
:outlined="true"
|
||||||
:readonly="formType === 'view'"
|
:readonly="formType === 'view'"
|
||||||
:view="isSubCreate"
|
|
||||||
title="form.field.basicInformation"
|
title="form.field.basicInformation"
|
||||||
|
:view="isSubCreate"
|
||||||
|
onCreate
|
||||||
/>
|
/>
|
||||||
<FormBranchContact
|
<FormBranchContact
|
||||||
id="form-contact"
|
id="form-contact"
|
||||||
|
|
@ -1583,6 +1615,7 @@ watch(currentHq, () => {
|
||||||
:active="formData.status !== 'INACTIVE'"
|
:active="formData.status !== 'INACTIVE'"
|
||||||
useToggle
|
useToggle
|
||||||
v-model:cover-url="imageUrl"
|
v-model:cover-url="imageUrl"
|
||||||
|
:toggleTitle="$t('status.title')"
|
||||||
:hideFade="imageUrl === '' || imageUrl === null"
|
:hideFade="imageUrl === '' || imageUrl === null"
|
||||||
:img="imageUrl || null"
|
:img="imageUrl || null"
|
||||||
:cover="imageUrl || null"
|
:cover="imageUrl || null"
|
||||||
|
|
@ -1810,7 +1843,12 @@ watch(currentHq, () => {
|
||||||
v-ripple
|
v-ripple
|
||||||
v-close-popup
|
v-close-popup
|
||||||
@click.stop="
|
@click.stop="
|
||||||
triggerCreate('subBranch', currentNode.id, currentNode.code)
|
triggerCreate(
|
||||||
|
'subBranch',
|
||||||
|
currentNode.id,
|
||||||
|
currentNode.code,
|
||||||
|
currentNode._count.branch,
|
||||||
|
)
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
<q-item-section avatar>
|
<q-item-section avatar>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue