feat: detect unsave and confirmation
This commit is contained in:
parent
64a9df2613
commit
71d8b8b06c
5 changed files with 115 additions and 10 deletions
|
|
@ -99,6 +99,11 @@ export default {
|
||||||
invalid: 'Invalid value.',
|
invalid: 'Invalid value.',
|
||||||
invalidCustomeMessage: 'Invalid value. {msg}',
|
invalidCustomeMessage: 'Invalid value. {msg}',
|
||||||
},
|
},
|
||||||
|
warning: {
|
||||||
|
title: 'Warning {msg}',
|
||||||
|
unsave:
|
||||||
|
'You have unsaved changes. Are you sure you want to close this window?',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
customer: {
|
customer: {
|
||||||
form: {
|
form: {
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,11 @@ export default {
|
||||||
invalid: 'ค่าที่ไม่ถูกต้อง',
|
invalid: 'ค่าที่ไม่ถูกต้อง',
|
||||||
invalidCustomeMessage: 'ค่าที่ไม่ถูกต้อง {msg}',
|
invalidCustomeMessage: 'ค่าที่ไม่ถูกต้อง {msg}',
|
||||||
},
|
},
|
||||||
|
warning: {
|
||||||
|
title: 'แจ้งเตือน {msg}',
|
||||||
|
unsave:
|
||||||
|
'คุณมีการเปลี่ยนแปลงที่ยังไม่ได้บันทึก คุณต้องการปิดหน้าต่างนี้หรือไม่',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
customer: {
|
customer: {
|
||||||
form: {
|
form: {
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import SideMenu from 'src/components/SideMenu.vue';
|
||||||
import BasicInformation from 'src/components/03_customer-management/employee/BasicInformation.vue';
|
import BasicInformation from 'src/components/03_customer-management/employee/BasicInformation.vue';
|
||||||
import FormPerson from 'src/components/02_personnel-management/FormPerson.vue';
|
import FormPerson from 'src/components/02_personnel-management/FormPerson.vue';
|
||||||
import FormBasicInfo from './components/FormBasicInfo.vue';
|
import FormBasicInfo from './components/FormBasicInfo.vue';
|
||||||
|
import FormBranch from './components/FormBranch.vue';
|
||||||
import CustomerInfoComponent from './components/CustomerBranch.vue';
|
import CustomerInfoComponent from './components/CustomerBranch.vue';
|
||||||
import FormAddress from 'src/components/02_personnel-management/FormAddress.vue';
|
import FormAddress from 'src/components/02_personnel-management/FormAddress.vue';
|
||||||
|
|
||||||
|
|
@ -82,6 +83,7 @@ async function init() {
|
||||||
currentCustomer.value = _data;
|
currentCustomer.value = _data;
|
||||||
utilsStore.currentTitle.path.push({
|
utilsStore.currentTitle.path.push({
|
||||||
text: currentCustomer.value.customerName,
|
text: currentCustomer.value.customerName,
|
||||||
|
i18n: false,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
router.push('/customer-management');
|
router.push('/customer-management');
|
||||||
|
|
@ -398,6 +400,30 @@ async function editCustomerForm(id: string) {
|
||||||
customerFormState.value.editCustomerId = id;
|
customerFormState.value.editCustomerId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function customerConfirmUnsave() {
|
||||||
|
dialog({
|
||||||
|
color: 'warning',
|
||||||
|
icon: 'mdi-alert',
|
||||||
|
title: t('form.warning.title'),
|
||||||
|
actionText: t('ok'),
|
||||||
|
persistent: true,
|
||||||
|
message: t('form.warning.unsave'),
|
||||||
|
action: () => {
|
||||||
|
customerFormStore.resetForm();
|
||||||
|
customerFormState.value.editReadonly = true;
|
||||||
|
},
|
||||||
|
cancel: () => {},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function customerFormUndo() {
|
||||||
|
if (customerFormStore.isFormDataDifferent()) {
|
||||||
|
return customerConfirmUnsave();
|
||||||
|
}
|
||||||
|
customerFormStore.resetForm();
|
||||||
|
customerFormState.value.editReadonly = true;
|
||||||
|
}
|
||||||
|
|
||||||
function createCustomerForm(customerType: 'CORP' | 'PERS') {
|
function createCustomerForm(customerType: 'CORP' | 'PERS') {
|
||||||
customerFormState.value.dialogModal = true;
|
customerFormState.value.dialogModal = true;
|
||||||
customerFormState.value.dialogType = 'create';
|
customerFormState.value.dialogType = 'create';
|
||||||
|
|
@ -1657,11 +1683,7 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
|
||||||
:title="$t('form.title.create', { name: 'Employer' })"
|
:title="$t('form.title.create', { name: 'Employer' })"
|
||||||
:edit="customerFormState.dialogType === 'edit'"
|
:edit="customerFormState.dialogType === 'edit'"
|
||||||
:isEdit="customerFormState.editReadonly === false"
|
:isEdit="customerFormState.editReadonly === false"
|
||||||
:undo="
|
:undo="() => customerFormUndo()"
|
||||||
() => (
|
|
||||||
customerFormStore.resetForm(), (customerFormState.editReadonly = true)
|
|
||||||
)
|
|
||||||
"
|
|
||||||
:deleteData="
|
:deleteData="
|
||||||
() =>
|
() =>
|
||||||
customerFormState.editCustomerId &&
|
customerFormState.editCustomerId &&
|
||||||
|
|
@ -1669,8 +1691,8 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
|
||||||
"
|
"
|
||||||
:editData="() => (customerFormState.editReadonly = false)"
|
:editData="() => (customerFormState.editReadonly = false)"
|
||||||
:show="
|
:show="
|
||||||
async () =>
|
() =>
|
||||||
await fetchListOfOptionBranch().then(() => {
|
fetchListOfOptionBranch().then(() => {
|
||||||
customerFormStore.resetForm(
|
customerFormStore.resetForm(
|
||||||
customerFormState.dialogType === 'create',
|
customerFormState.dialogType === 'create',
|
||||||
);
|
);
|
||||||
|
|
@ -1682,7 +1704,15 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
|
||||||
await fetchListCustomer();
|
await fetchListCustomer();
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
:close="() => (customerFormState.dialogModal = false)"
|
:before-close="
|
||||||
|
() => {
|
||||||
|
if (customerFormStore.isFormDataDifferent()) {
|
||||||
|
customerConfirmUnsave();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false; // close
|
||||||
|
}
|
||||||
|
"
|
||||||
no-footer
|
no-footer
|
||||||
>
|
>
|
||||||
<div class="q-mx-lg q-mt-lg">
|
<div class="q-mx-lg q-mt-lg">
|
||||||
|
|
@ -1713,13 +1743,19 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
|
||||||
style="height: 100%; max-height: 100; overflow-y: auto"
|
style="height: 100%; max-height: 100; overflow-y: auto"
|
||||||
v-if="$q.screen.gt.sm"
|
v-if="$q.screen.gt.sm"
|
||||||
>
|
>
|
||||||
<div class="q-py-md q-pl-md">
|
<div class="q-py-md q-pl-md q-pr-sm">
|
||||||
<SideMenu
|
<SideMenu
|
||||||
:menu="[
|
:menu="[
|
||||||
{
|
{
|
||||||
name: $t('customer.form.group.basicInfo'),
|
name: $t('customer.form.group.basicInfo'),
|
||||||
anchor: 'form-basic-info-customer',
|
anchor: 'form-basic-info-customer',
|
||||||
},
|
},
|
||||||
|
...(customerFormData.customerBranch?.map((v) => ({
|
||||||
|
name: $t('customer.form.branch.title', {
|
||||||
|
name: v.branchNo || 0,
|
||||||
|
}),
|
||||||
|
anchor: `form-branch-customer-no-${v.branchNo}`,
|
||||||
|
})) || []),
|
||||||
]"
|
]"
|
||||||
background="transparent"
|
background="transparent"
|
||||||
:active="{
|
:active="{
|
||||||
|
|
@ -1731,11 +1767,12 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="col-12 col-md-10 q-pa-md"
|
class="col-12 col-md-10 q-py-md q-pr-md q-pl-sm"
|
||||||
id="customer-form-content"
|
id="customer-form-content"
|
||||||
style="height: 100%; max-height: 100%; overflow-y: auto"
|
style="height: 100%; max-height: 100%; overflow-y: auto"
|
||||||
>
|
>
|
||||||
<FormBasicInfo
|
<FormBasicInfo
|
||||||
|
class="q-mb-xl"
|
||||||
:readonly="
|
:readonly="
|
||||||
customerFormState.dialogType === 'edit' &&
|
customerFormState.dialogType === 'edit' &&
|
||||||
customerFormState.editReadonly === true
|
customerFormState.editReadonly === true
|
||||||
|
|
@ -1750,6 +1787,15 @@ function createCustomerForm(customerType: 'CORP' | 'PERS') {
|
||||||
v-model:registered-branch-id="customerFormData.registeredBranchId"
|
v-model:registered-branch-id="customerFormData.registeredBranchId"
|
||||||
v-model:branch-options="registerAbleBranchOption"
|
v-model:branch-options="registerAbleBranchOption"
|
||||||
/>
|
/>
|
||||||
|
<FormBranch
|
||||||
|
id="form-branch-customer"
|
||||||
|
:editable="
|
||||||
|
customerFormState.dialogType === 'create' ||
|
||||||
|
customerFormState.editReadonly === false
|
||||||
|
"
|
||||||
|
@add-branch="customerFormStore.addCurrentCustomerBranch()"
|
||||||
|
v-model:customer-branch="customerFormData.customerBranch"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
48
src/pages/03_customer-management/components/FormBranch.vue
Normal file
48
src/pages/03_customer-management/components/FormBranch.vue
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { CustomerCreate } from 'src/stores/customer/types';
|
||||||
|
|
||||||
|
const branch = defineModel<CustomerCreate['customerBranch']>('customerBranch', {
|
||||||
|
default: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
editable?: boolean;
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="row q-col-gutter-md">
|
||||||
|
<div class="col-12 text-weight-bold text-body1 row items-center">
|
||||||
|
<q-icon
|
||||||
|
flat
|
||||||
|
size="xs"
|
||||||
|
class="q-pa-sm rounded q-mr-xs"
|
||||||
|
color="info"
|
||||||
|
name="mdi-briefcase"
|
||||||
|
style="background-color: var(--surface-3)"
|
||||||
|
/>
|
||||||
|
<span>{{ $t('customer.form.group.branch') }}</span>
|
||||||
|
<q-btn
|
||||||
|
type="button"
|
||||||
|
rounded
|
||||||
|
flat
|
||||||
|
dense
|
||||||
|
unelevated
|
||||||
|
color="primary"
|
||||||
|
@click="$emit('addBranch')"
|
||||||
|
v-if="editable"
|
||||||
|
icon="mdi-plus"
|
||||||
|
class="q-ml-md"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-for="item in branch">
|
||||||
|
<span
|
||||||
|
class="col-12 text-weight-bold"
|
||||||
|
:id="`form-branch-customer-no-${item.branchNo}`"
|
||||||
|
>
|
||||||
|
{{ $t('customer.form.branch.title', { name: item.branchNo || 0 }) }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
@ -167,6 +167,7 @@ const useUtilsStore = defineStore('utilsStore', () => {
|
||||||
title: string;
|
title: string;
|
||||||
path: {
|
path: {
|
||||||
text: string;
|
text: string;
|
||||||
|
i18n?: boolean;
|
||||||
argsi18n?: Record<string, string>;
|
argsi18n?: Record<string, string>;
|
||||||
handler?: () => unknown;
|
handler?: () => unknown;
|
||||||
}[];
|
}[];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue