refactor: add virtual

This commit is contained in:
Net 2024-09-03 18:15:45 +07:00
parent e8f6080aa0
commit 2e72cb3071

View file

@ -3,7 +3,7 @@ import { storeToRefs } from 'pinia';
import { ref, onMounted, computed, watch } from 'vue'; import { ref, onMounted, computed, watch } from 'vue';
import { Icon } from '@iconify/vue'; import { Icon } from '@iconify/vue';
import { BranchContact } from 'stores/branch-contact/types'; import { BranchContact } from 'stores/branch-contact/types';
import { useQuasar } from 'quasar'; import { colors, useQuasar } from 'quasar';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import type { QTableProps } from 'quasar'; import type { QTableProps } from 'quasar';
@ -16,6 +16,7 @@ import {
BankBook, BankBook,
} from 'stores/branch/types'; } from 'stores/branch/types';
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';
import TooltipComponent from 'components/TooltipComponent.vue'; import TooltipComponent from 'components/TooltipComponent.vue';
@ -49,7 +50,19 @@ const apiBaseUrl = import.meta.env.VITE_API_BASE_URL;
const $q = useQuasar(); const $q = useQuasar();
const { t } = useI18n(); const { t } = useI18n();
const utilsStore = useUtilsStore(); const utilsStore = useUtilsStore();
const modelCreateTypeBranch = ref<boolean>(false);
const typeBranchItem = [
{
icon: 'mdi-home-group',
text: 'Virtual Branch',
color: '#03A9F4',
},
{
icon: 'mdi-home-group',
text: 'Branch',
color: 'var(--purple-6)',
},
];
const holdDialog = ref(false); const holdDialog = ref(false);
const isSubCreate = ref(false); const isSubCreate = ref(false);
const columns = [ const columns = [
@ -292,6 +305,7 @@ const defaultFormData = {
provinceId: '', provinceId: '',
lineId: '', lineId: '',
webUrl: '', webUrl: '',
virtual: false,
}; };
const formDialogRef = ref(); const formDialogRef = ref();
@ -359,6 +373,7 @@ async function fetchBranchById(id: string) {
lineId: res.lineId, lineId: res.lineId,
status: res.status, status: res.status,
webUrl: res.webUrl, webUrl: res.webUrl,
virtual: res.virtual,
}; };
} }
} }
@ -392,13 +407,17 @@ async function undo() {
formData.value = prevFormData.value; formData.value = prevFormData.value;
} }
watch(modal, () => {
if (!modal.value) {
clearData();
}
});
function triggerCreate( function triggerCreate(
type: 'headOffice' | 'subBranch', type: 'headOffice' | 'subBranch',
id?: string, id?: string,
code?: string, code?: string,
) { ) {
clearData();
formTypeBranch.value = type; formTypeBranch.value = type;
if (type === 'headOffice') { if (type === 'headOffice') {
@ -606,15 +625,15 @@ async function onSubmit() {
fieldSelectedBranch.value.value = ''; fieldSelectedBranch.value.value = '';
inputSearch.value = ''; inputSearch.value = '';
currentHq.value = { currentHq.value = {
id: currentRecord.id, id: currentRecord?.id || '',
code: currentRecord.code, code: currentRecord?.code || '',
}; };
beforeBranch.value = { beforeBranch.value = {
id: '', id: '',
code: '', code: '',
}; };
expandedTree.value = []; expandedTree.value = [];
expandedTree.value.push(currentRecord.id); expandedTree.value.push(currentRecord?.id || '');
} else { } else {
dialog({ dialog({
color: 'info', color: 'info',
@ -786,7 +805,11 @@ watch(currentHq, () => {
<EmptyAddButton <EmptyAddButton
label="general.add" label="general.add"
:i18nArgs="{ text: $t('branch.form.title.branchLabel') }" :i18nArgs="{ text: $t('branch.form.title.branchLabel') }"
@trigger="() => triggerCreate('headOffice')" @trigger="
() => {
triggerCreate('headOffice');
}
"
/> />
</div> </div>
</div> </div>
@ -820,11 +843,7 @@ watch(currentHq, () => {
if (!currentHq.id) { if (!currentHq.id) {
triggerCreate('headOffice'); triggerCreate('headOffice');
} else { } else {
triggerCreate( modelCreateTypeBranch = true;
'subBranch',
currentHq.id,
currentHq.code,
);
} }
} }
" "
@ -886,7 +905,16 @@ watch(currentHq, () => {
} }
} }
" "
@create="(v) => triggerCreate('subBranch', v.id, v.code)" @create="
(v) => {
currentHq.id = v.id;
currentHq.code = v.code;
modelCreateTypeBranch = true;
}
// triggerCreate(v.virtual, 'subBranch', v.id, v.code)
"
@view=" @view="
(v) => { (v) => {
if (v.isHeadOffice) { if (v.isHeadOffice) {
@ -2010,6 +2038,40 @@ watch(currentHq, () => {
</div> </div>
</template> </template>
</ImageUploadDialog> </ImageUploadDialog>
<DialogForm
v-model:modal="modelCreateTypeBranch"
:title="$t('general.typeBranch')"
hide-footer
no-app-box
width="60vw"
height="300px"
:close="() => (modelCreateTypeBranch = false)"
>
<div class="full-height row q-pa-md">
<ItemCard
v-for="i in typeBranchItem"
class="col q-mx-sm -full-height"
:key="i.text"
:icon="i.icon"
:text="i.text"
:color="i.color"
@trigger="
() => {
modelCreateTypeBranch = false;
if (i.text === 'Virtual Branch') {
formData.virtual = true;
} else {
formData.virtual = false;
}
triggerCreate('subBranch', currentHq.id, currentHq.code);
}
"
/>
</div>
</DialogForm>
</template> </template>
<style scoped> <style scoped>