refactor: add isEdit

This commit is contained in:
Net 2024-09-19 11:33:22 +07:00
parent b61d0aeb3e
commit 1da17c7ce8
2 changed files with 62 additions and 8 deletions

View file

@ -1,12 +1,13 @@
<script setup lang="ts"> <script setup lang="ts">
import { QTableProps } from 'quasar'; import { QTableProps } from 'quasar';
import { ref, toRaw } from 'vue'; import { ref, toRaw, onMounted } from 'vue';
import { dialog } from 'stores/utils'; import { dialog } from 'stores/utils';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import TableComponents from 'src/components/TableComponents.vue'; import TableComponents from 'src/components/TableComponents.vue';
import ShowAttachent from 'src/components/ShowAttachent.vue'; import ShowAttachent from 'src/components/ShowAttachent.vue';
import DialogForm from 'components/DialogForm.vue'; import DialogForm from 'components/DialogForm.vue';
const isEdit = ref(false);
const { t } = useI18n(); const { t } = useI18n();
const obj = defineModel< const obj = defineModel<
{ {
@ -30,6 +31,7 @@ const props = defineProps<{
ocr?: (group: any, file: File) => void | Promise<void>; ocr?: (group: any, file: File) => void | Promise<void>;
getFileList?: (group: any) => Promise<typeof obj.value>; getFileList?: (group: any) => Promise<typeof obj.value>;
deleteItem?: (obj: any) => void | Promise<boolean>; deleteItem?: (obj: any) => void | Promise<boolean>;
download?: (obj: any) => void;
save?: ( save?: (
group: any, group: any,
meta: any, meta: any,
@ -138,6 +140,7 @@ defineEmits<{
v-close-popup v-close-popup
@click=" @click="
() => { () => {
isEdit = true;
selectedMenu = menu?.[i]; selectedMenu = menu?.[i];
currentIndex = obj.length; currentIndex = obj.length;
@ -190,6 +193,11 @@ defineEmits<{
<div class="full-height full-width q-pa-md"> <div class="full-height full-width q-pa-md">
<TableComponents <TableComponents
buttomDownload buttomDownload
@download="
(index) => {
download?.(obj[index]);
}
"
@delete=" @delete="
async (index) => { async (index) => {
await triggerDelete(obj[index]); await triggerDelete(obj[index]);
@ -197,6 +205,14 @@ defineEmits<{
" "
@view=" @view="
(index) => { (index) => {
isEdit = false;
currentIndex = index;
modalDialog = true;
}
"
@edit="
(index) => {
isEdit = true;
currentIndex = index; currentIndex = index;
modalDialog = true; modalDialog = true;
} }
@ -211,6 +227,7 @@ defineEmits<{
}) })
.map((v, index) => { .map((v, index) => {
return { return {
id: v._meta?.id,
branchNo: index + 1, branchNo: index + 1,
attachmentName: v.file?.name || v.name, attachmentName: v.file?.name || v.name,
uploadDate: '', uploadDate: '',
@ -225,6 +242,9 @@ defineEmits<{
</div> </div>
</div> </div>
<DialogForm <DialogForm
edit
hideDelete
:is-edit="isEdit"
style="position: absolute" style="position: absolute"
height="100vh" height="100vh"
weight="90%" weight="90%"
@ -232,6 +252,16 @@ defineEmits<{
title="ดูตัวอย่าง" title="ดูตัวอย่าง"
hideCloseEvent hideCloseEvent
v-if="obj.length > 0" v-if="obj.length > 0"
:undo="
() => {
isEdit = false;
}
"
:edit-data="
() => {
isEdit = !isEdit;
}
"
:close=" :close="
() => { () => {
if (!autoSave || !obj[currentIndex]?._meta?.hasOwnProperty('id')) { if (!autoSave || !obj[currentIndex]?._meta?.hasOwnProperty('id')) {
@ -244,7 +274,6 @@ defineEmits<{
async () => { async () => {
modalDialog = false; modalDialog = false;
if (autoSave === true) { if (autoSave === true) {
console.log(autoSave);
const statusSave = await save?.( const statusSave = await save?.(
obj[currentIndex].group, obj[currentIndex].group,
obj[currentIndex]._meta, obj[currentIndex]._meta,
@ -275,6 +304,7 @@ defineEmits<{
name="form" name="form"
:mode="obj[currentIndex].group" :mode="obj[currentIndex].group"
:meta="obj[currentIndex]._meta" :meta="obj[currentIndex]._meta"
:isEdit="isEdit"
/> />
</div> </div>
</template> </template>

View file

@ -67,6 +67,8 @@ import FormEmployeeOther from 'components/03_customer-management/FormEmployeeOth
import useOptionStore from 'stores/options'; import useOptionStore from 'stores/options';
import { DialogContainer, DialogHeader } from 'components/dialog'; import { DialogContainer, DialogHeader } from 'components/dialog';
import KebabAction from 'src/components/shared/KebabAction.vue'; import KebabAction from 'src/components/shared/KebabAction.vue';
import { group } from 'node:console';
import { readonly } from 'vue';
const currentSelectedMenu = ref<{ label: string; value: string }>({ const currentSelectedMenu = ref<{ label: string; value: string }>({
label: '', label: '',
@ -2499,6 +2501,15 @@ const emptyCreateDialog = ref(false);
:menu="uploadFileListEmployee" :menu="uploadFileListEmployee"
:columns="columnsAttachment" :columns="columnsAttachment"
:auto-save="currentFromDataEmployee.id !== ''" :auto-save="currentFromDataEmployee.id !== ''"
:download="
(obj) => {
employeeStore.getFile({
parentId: currentFromDataEmployee.id || '',
group: obj.group,
fileId: obj._meta.id,
});
}
"
:delete-item=" :delete-item="
async (obj) => { async (obj) => {
const res = await employeeStore.delMeta({ const res = await employeeStore.delMeta({
@ -2589,10 +2600,12 @@ const emptyCreateDialog = ref(false);
} }
" "
> >
<template #form="{ mode, meta }"> <template #form="{ mode, meta, isEdit }">
<FormCitizen <FormCitizen
v-if="mode === 'citizen' && meta" v-if="mode === 'citizen' && meta"
orc orc
ra
:readonly="!isEdit"
v-model:citizen-id="meta.citizenId" v-model:citizen-id="meta.citizenId"
v-model:birth-date="meta.birthDate" v-model:birth-date="meta.birthDate"
v-model:first-name="meta.firstName" v-model:first-name="meta.firstName"
@ -2610,7 +2623,7 @@ const emptyCreateDialog = ref(false);
separator separator
ocr ocr
:title="$t('customerEmployee.form.group.passport')" :title="$t('customerEmployee.form.group.passport')"
:readonly="!employeeFormState.isEmployeeEdit" :readonly="!isEdit"
v-model:passport-type="meta.type" v-model:passport-type="meta.type"
v-model:passport-number="meta.number" v-model:passport-number="meta.number"
v-model:passport-issue-date="meta.issueDate" v-model:passport-issue-date="meta.issueDate"
@ -2626,7 +2639,7 @@ const emptyCreateDialog = ref(false);
dense dense
outlined outlined
title="customerEmployee.form.group.visa" title="customerEmployee.form.group.visa"
:readonly="!employeeFormState.isEmployeeEdit" :readonly="!isEdit"
v-model:visa-type="meta.type" v-model:visa-type="meta.type"
v-model:visa-number="meta.number" v-model:visa-number="meta.number"
v-model:visa-issue-date="meta.issueDate" v-model:visa-issue-date="meta.issueDate"
@ -3689,6 +3702,16 @@ const emptyCreateDialog = ref(false);
:menu="uploadFileListEmployee" :menu="uploadFileListEmployee"
:columns="columnsAttachment" :columns="columnsAttachment"
auto-save auto-save
:download="
(obj) => {
employeeStore.getFile({
parentId: currentFromDataEmployee.id || '',
group: obj.group,
fileId: obj._meta.id,
download: true,
});
}
"
:delete-item=" :delete-item="
async (obj) => { async (obj) => {
const res = await employeeStore.delMeta({ const res = await employeeStore.delMeta({
@ -3779,10 +3802,11 @@ const emptyCreateDialog = ref(false);
} }
" "
> >
<template #form="{ mode, meta }"> <template #form="{ mode, meta, isEdit }">
<FormCitizen <FormCitizen
v-if="mode === 'citizen' && meta" v-if="mode === 'citizen' && meta"
orc orc
:readonly="!isEdit"
v-model:citizen-id="meta.citizenId" v-model:citizen-id="meta.citizenId"
v-model:birth-date="meta.birthDate" v-model:birth-date="meta.birthDate"
v-model:first-name="meta.firstName" v-model:first-name="meta.firstName"
@ -3800,7 +3824,7 @@ const emptyCreateDialog = ref(false);
separator separator
ocr ocr
:title="$t('customerEmployee.form.group.passport')" :title="$t('customerEmployee.form.group.passport')"
:readonly="!employeeFormState.isEmployeeEdit" :readonly="!isEdit"
v-model:passport-type="meta.type" v-model:passport-type="meta.type"
v-model:passport-number="meta.number" v-model:passport-number="meta.number"
v-model:passport-issue-date="meta.issueDate" v-model:passport-issue-date="meta.issueDate"
@ -3816,7 +3840,7 @@ const emptyCreateDialog = ref(false);
dense dense
outlined outlined
title="customerEmployee.form.group.visa" title="customerEmployee.form.group.visa"
:readonly="!employeeFormState.isEmployeeEdit" :readonly="!isEdit"
v-model:visa-type="meta.type" v-model:visa-type="meta.type"
v-model:visa-number="meta.number" v-model:visa-number="meta.number"
v-model:visa-issue-date="meta.issueDate" v-model:visa-issue-date="meta.issueDate"