refactor: by value inputFileQrCode
This commit is contained in:
parent
fb1c7c077d
commit
95b0cd9c93
1 changed files with 116 additions and 36 deletions
|
|
@ -9,7 +9,6 @@ import type { QTableProps } from 'quasar';
|
||||||
import { resetScrollBar } from 'src/stores/utils';
|
import { resetScrollBar } from 'src/stores/utils';
|
||||||
import useBranchStore from 'stores/branch';
|
import useBranchStore from 'stores/branch';
|
||||||
import useFlowStore from 'stores/flow';
|
import useFlowStore from 'stores/flow';
|
||||||
import { isRoleInclude } from 'src/stores/utils';
|
|
||||||
import {
|
import {
|
||||||
BranchWithChildren,
|
BranchWithChildren,
|
||||||
BranchCreate,
|
BranchCreate,
|
||||||
|
|
@ -17,6 +16,7 @@ import {
|
||||||
BankBook,
|
BankBook,
|
||||||
} from 'stores/branch/types';
|
} from 'stores/branch/types';
|
||||||
|
|
||||||
|
import QrCodeUploadDialog from 'src/components/QrCodeUploadDialog.vue';
|
||||||
import ItemCard from 'src/components/ItemCard.vue';
|
import ItemCard from 'src/components/ItemCard.vue';
|
||||||
import useUtilsStore, { dialog, baseUrl } from 'stores/utils';
|
import useUtilsStore, { dialog, baseUrl } from 'stores/utils';
|
||||||
import EmptyAddButton from 'components/AddButton.vue';
|
import EmptyAddButton from 'components/AddButton.vue';
|
||||||
|
|
@ -145,41 +145,32 @@ const formBankBook = ref<BankBook[]>([
|
||||||
accountName: '',
|
accountName: '',
|
||||||
accountType: '',
|
accountType: '',
|
||||||
currentlyUse: true,
|
currentlyUse: true,
|
||||||
|
bankUrl: '',
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const statusQrCodeFile = ref<File | undefined>(undefined);
|
||||||
|
const statusQrCodeUrl = ref<string>('');
|
||||||
|
const statusDeletsQrCode = ref<boolean>(false);
|
||||||
|
|
||||||
|
const deletsStatusQrCodeImag = ref(false);
|
||||||
|
const deletsStatusQrCodeBankImag = ref<number[]>([]);
|
||||||
|
const currentIndexQrCodeBank = ref<number>(-1);
|
||||||
|
const refQrCodeUpload = ref();
|
||||||
const refImageUpload = ref();
|
const refImageUpload = ref();
|
||||||
const isImageEdit = ref(false);
|
const isImageEdit = ref(false);
|
||||||
|
const isQrCodeEdit = ref(false);
|
||||||
const profileFile = ref<File | undefined>(undefined);
|
const profileFile = ref<File | undefined>(undefined);
|
||||||
|
const qrCodeFile = ref<File | undefined>(undefined);
|
||||||
const imageUrl = ref<string>('');
|
const imageUrl = ref<string>('');
|
||||||
const prevImageUrl = ref<string>('');
|
const prevImageUrl = ref<string>('');
|
||||||
const currentNode = ref<BranchWithChildren>();
|
const currentNode = ref<BranchWithChildren>();
|
||||||
const imageDialog = ref(false);
|
const imageDialog = ref(false);
|
||||||
|
const qrCodeDialog = ref(false);
|
||||||
|
|
||||||
const qrFile = ref<File | undefined>(undefined);
|
const qrCodeimageUrl = ref<string>('');
|
||||||
const qrCodeimageUrl = ref<string | null>('');
|
|
||||||
const formLastSubBranch = ref<number>(0);
|
const formLastSubBranch = ref<number>(0);
|
||||||
|
|
||||||
const inputFile = (() => {
|
|
||||||
const element = document.createElement('input');
|
|
||||||
element.type = 'file';
|
|
||||||
element.accept = 'image/*';
|
|
||||||
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.addEventListener('load', () => {
|
|
||||||
if (typeof reader.result === 'string') qrCodeimageUrl.value = reader.result;
|
|
||||||
});
|
|
||||||
|
|
||||||
element.addEventListener('change', () => {
|
|
||||||
qrFile.value = element.files?.[0];
|
|
||||||
if (qrFile.value) {
|
|
||||||
reader.readAsDataURL(qrFile.value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return element;
|
|
||||||
})();
|
|
||||||
|
|
||||||
const branchStore = useBranchStore();
|
const branchStore = useBranchStore();
|
||||||
const flowStore = useFlowStore();
|
const flowStore = useFlowStore();
|
||||||
const { locale } = useI18n();
|
const { locale } = useI18n();
|
||||||
|
|
@ -372,13 +363,19 @@ function openDialog() {
|
||||||
|
|
||||||
async function fetchBranchById(id: string) {
|
async function fetchBranchById(id: string) {
|
||||||
const res = await branchStore.fetchById(id, { includeContact: true });
|
const res = await branchStore.fetchById(id, { includeContact: true });
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
qrCodeimageUrl.value = `${apiBaseUrl}/branch/${res.id}/line-image`;
|
qrCodeimageUrl.value = `${apiBaseUrl}/branch/${res.id}/line-image?ts=${Date.now()}`;
|
||||||
imageUrl.value = `${apiBaseUrl}/branch/${res.id}/branch-image`;
|
imageUrl.value = `${apiBaseUrl}/branch/${res.id}/branch-image`;
|
||||||
prevImageUrl.value = res.imageUrl;
|
prevImageUrl.value = res.imageUrl;
|
||||||
formBankBook.value = res.bank;
|
formBankBook.value = res.bank;
|
||||||
|
|
||||||
|
formBankBook.value = formBankBook.value.map((v) => {
|
||||||
|
return {
|
||||||
|
...v,
|
||||||
|
bankUrl: `${apiBaseUrl}/branch/${res.id}/bank-qr/${v.id}?ts=${Date.now()}`,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
formData.value = {
|
formData.value = {
|
||||||
code: res.code,
|
code: res.code,
|
||||||
headOfficeId: res.headOfficeId,
|
headOfficeId: res.headOfficeId,
|
||||||
|
|
@ -408,12 +405,12 @@ async function fetchBranchById(id: string) {
|
||||||
function clearData() {
|
function clearData() {
|
||||||
formData.value = structuredClone(defaultFormData);
|
formData.value = structuredClone(defaultFormData);
|
||||||
imageUrl.value = '';
|
imageUrl.value = '';
|
||||||
qrCodeimageUrl.value = null;
|
qrCodeimageUrl.value = '';
|
||||||
currentEdit.value = {
|
currentEdit.value = {
|
||||||
id: '',
|
id: '',
|
||||||
code: '',
|
code: '',
|
||||||
};
|
};
|
||||||
qrFile.value = undefined;
|
qrCodeFile.value = undefined;
|
||||||
|
|
||||||
formBankBook.value = [
|
formBankBook.value = [
|
||||||
{
|
{
|
||||||
|
|
@ -428,6 +425,7 @@ function clearData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function undo() {
|
async function undo() {
|
||||||
|
isQrCodeEdit.value = false;
|
||||||
isImageEdit.value = false;
|
isImageEdit.value = false;
|
||||||
formType.value = 'view';
|
formType.value = 'view';
|
||||||
imageUrl.value = prevImageUrl.value;
|
imageUrl.value = prevImageUrl.value;
|
||||||
|
|
@ -481,6 +479,7 @@ function findLastSub(code: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawerEdit() {
|
function drawerEdit() {
|
||||||
|
isQrCodeEdit.value = true;
|
||||||
isImageEdit.value = true;
|
isImageEdit.value = true;
|
||||||
formType.value = 'edit';
|
formType.value = 'edit';
|
||||||
prevFormData.value = {
|
prevFormData.value = {
|
||||||
|
|
@ -579,6 +578,40 @@ function triggerDelete(id: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function triggerEditQrCodeLine(opts?: { save?: boolean }) {
|
||||||
|
if (opts?.save === undefined) {
|
||||||
|
qrCodeDialog.value = true;
|
||||||
|
statusDeletsQrCode.value = false;
|
||||||
|
deletsStatusQrCodeImag.value = false;
|
||||||
|
statusQrCodeUrl.value = qrCodeimageUrl.value;
|
||||||
|
} else {
|
||||||
|
qrCodeimageUrl.value = statusQrCodeUrl.value;
|
||||||
|
qrCodeFile.value = statusQrCodeFile.value;
|
||||||
|
deletsStatusQrCodeImag.value = statusDeletsQrCode.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function triggerEditQrCodeBank(opts?: { save?: boolean }) {
|
||||||
|
if (opts?.save === undefined) {
|
||||||
|
qrCodeDialog.value = true;
|
||||||
|
statusDeletsQrCode.value = false;
|
||||||
|
statusQrCodeUrl.value =
|
||||||
|
formBankBook.value[currentIndexQrCodeBank.value].bankUrl || '';
|
||||||
|
statusDeletsQrCode.value = false;
|
||||||
|
} else {
|
||||||
|
formBankBook.value[currentIndexQrCodeBank.value].bankUrl =
|
||||||
|
statusQrCodeUrl.value;
|
||||||
|
|
||||||
|
formBankBook.value[currentIndexQrCodeBank.value].bankQr =
|
||||||
|
statusQrCodeFile.value;
|
||||||
|
|
||||||
|
if (statusDeletsQrCode.value) {
|
||||||
|
deletsStatusQrCodeBankImag.value.push(currentIndexQrCodeBank.value);
|
||||||
|
}
|
||||||
|
currentIndexQrCodeBank.value = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function triggerChangeStatus(
|
async function triggerChangeStatus(
|
||||||
id: string,
|
id: string,
|
||||||
status: string,
|
status: string,
|
||||||
|
|
@ -617,9 +650,13 @@ async function onSubmit() {
|
||||||
...formData.value,
|
...formData.value,
|
||||||
status: undefined,
|
status: undefined,
|
||||||
},
|
},
|
||||||
qrFile.value,
|
qrCodeFile.value,
|
||||||
profileFile.value,
|
profileFile.value,
|
||||||
formBankBook.value,
|
formBankBook.value,
|
||||||
|
{
|
||||||
|
deleteQrCodeImage: deletsStatusQrCodeImag.value,
|
||||||
|
indexDeleteQrCodeBank: deletsStatusQrCodeBankImag.value,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
await branchStore.fetchList({ pageSize: 99999 });
|
await branchStore.fetchList({ pageSize: 99999 });
|
||||||
|
|
@ -632,7 +669,7 @@ async function onSubmit() {
|
||||||
await branchStore.create(
|
await branchStore.create(
|
||||||
{
|
{
|
||||||
...formData.value,
|
...formData.value,
|
||||||
qrCodeImage: qrFile.value,
|
qrCodeImage: qrCodeFile.value,
|
||||||
imageUrl: profileFile.value,
|
imageUrl: profileFile.value,
|
||||||
},
|
},
|
||||||
formBankBook.value,
|
formBankBook.value,
|
||||||
|
|
@ -735,6 +772,13 @@ watch(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => qrCodeFile.value,
|
||||||
|
() => {
|
||||||
|
if (qrCodeFile !== null) isQrCodeEdit.value = true;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
watch(locale, () => {
|
watch(locale, () => {
|
||||||
fieldSelectedBranch.value = {
|
fieldSelectedBranch.value = {
|
||||||
label: t(`${fieldSelectedBranch.value.label}`),
|
label: t(`${fieldSelectedBranch.value.label}`),
|
||||||
|
|
@ -1653,11 +1697,6 @@ watch(currentHq, () => {
|
||||||
:separator="true"
|
:separator="true"
|
||||||
:qr="qrCodeimageUrl"
|
:qr="qrCodeimageUrl"
|
||||||
:readonly="formType === 'view'"
|
:readonly="formType === 'view'"
|
||||||
@upload="
|
|
||||||
() => {
|
|
||||||
inputFile.click();
|
|
||||||
}
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
<FormBank
|
<FormBank
|
||||||
id="form-bank"
|
id="form-bank"
|
||||||
|
|
@ -1915,11 +1954,12 @@ watch(currentHq, () => {
|
||||||
title="QR Code"
|
title="QR Code"
|
||||||
:separator="true"
|
:separator="true"
|
||||||
:qr="qrCodeimageUrl"
|
:qr="qrCodeimageUrl"
|
||||||
@upload="
|
@view-qr="
|
||||||
() => {
|
() => {
|
||||||
inputFile.click();
|
triggerEditQrCodeLine();
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
|
@edit-qr="() => refQrCodeUpload && refQrCodeUpload.browse()"
|
||||||
class="q-mb-xl"
|
class="q-mb-xl"
|
||||||
/>
|
/>
|
||||||
<FormBank
|
<FormBank
|
||||||
|
|
@ -1929,6 +1969,17 @@ watch(currentHq, () => {
|
||||||
dense
|
dense
|
||||||
v-model:bank-book-list="formBankBook"
|
v-model:bank-book-list="formBankBook"
|
||||||
class="q-mb-xl"
|
class="q-mb-xl"
|
||||||
|
@view-qr="
|
||||||
|
(i) => {
|
||||||
|
currentIndexQrCodeBank = i;
|
||||||
|
triggerEditQrCodeBank();
|
||||||
|
}
|
||||||
|
"
|
||||||
|
@edit-qr="
|
||||||
|
(i) => {
|
||||||
|
currentIndexQrCodeBank = i;
|
||||||
|
}
|
||||||
|
"
|
||||||
/>
|
/>
|
||||||
<FormBranchAdmin
|
<FormBranchAdmin
|
||||||
id="info-branch-admin-view"
|
id="info-branch-admin-view"
|
||||||
|
|
@ -2073,6 +2124,35 @@ watch(currentHq, () => {
|
||||||
</div>
|
</div>
|
||||||
</q-dialog>
|
</q-dialog>
|
||||||
|
|
||||||
|
<QrCodeUploadDialog
|
||||||
|
ref="refQrCodeUpload"
|
||||||
|
v-model:dialogState="qrCodeDialog"
|
||||||
|
v-model:file="statusQrCodeFile as File"
|
||||||
|
v-model:image-url="statusQrCodeUrl"
|
||||||
|
@save="
|
||||||
|
() => {
|
||||||
|
qrCodeDialog = false;
|
||||||
|
if (currentIndexQrCodeBank === -1) {
|
||||||
|
triggerEditQrCodeLine({ save: true });
|
||||||
|
}
|
||||||
|
if (currentIndexQrCodeBank !== -1) {
|
||||||
|
triggerEditQrCodeBank({ save: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"
|
||||||
|
@clear="statusDeletsQrCode = true"
|
||||||
|
clearButton
|
||||||
|
>
|
||||||
|
<template #error>
|
||||||
|
<div
|
||||||
|
class="full-width full-height flex items-center justify-center"
|
||||||
|
style="color: gray"
|
||||||
|
>
|
||||||
|
<q-icon size="15rem" name="mdi-qrcode" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</QrCodeUploadDialog>
|
||||||
|
|
||||||
<ImageUploadDialog
|
<ImageUploadDialog
|
||||||
ref="refImageUpload"
|
ref="refImageUpload"
|
||||||
v-model:dialogState="imageDialog"
|
v-model:dialogState="imageDialog"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue