feat: check tab before add
This commit is contained in:
parent
2c9f7ba02d
commit
be397112f6
5 changed files with 103 additions and 62 deletions
|
|
@ -8,7 +8,7 @@ import useAddressStore, {
|
||||||
} from 'src/stores/address';
|
} from 'src/stores/address';
|
||||||
import { EmployeeCheckupCreate } from 'src/stores/employee/types';
|
import { EmployeeCheckupCreate } from 'src/stores/employee/types';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { selectFilterOptionRefMod } from 'src/stores/utils';
|
import { checkTabBeforeAdd, selectFilterOptionRefMod } from 'src/stores/utils';
|
||||||
import { QSelect } from 'quasar';
|
import { QSelect } from 'quasar';
|
||||||
|
|
||||||
const { locale } = useI18n();
|
const { locale } = useI18n();
|
||||||
|
|
@ -63,19 +63,22 @@ async function fetchProvince() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addData() {
|
function addData() {
|
||||||
employeeCheckup.value?.push({
|
const canAdd = checkTabBeforeAdd(employeeCheckup.value || []);
|
||||||
coverageExpireDate: null,
|
if (canAdd) {
|
||||||
coverageStartDate: null,
|
employeeCheckup.value?.push({
|
||||||
insuranceCompany: '',
|
coverageExpireDate: null,
|
||||||
medicalBenefitScheme: '',
|
coverageStartDate: null,
|
||||||
remark: '',
|
insuranceCompany: '',
|
||||||
hospitalName: '',
|
medicalBenefitScheme: '',
|
||||||
provinceId: '',
|
remark: '',
|
||||||
checkupResult: '',
|
hospitalName: '',
|
||||||
checkupType: '',
|
provinceId: '',
|
||||||
});
|
checkupResult: '',
|
||||||
if (employeeCheckup.value)
|
checkupType: '',
|
||||||
tab.value = `tab${employeeCheckup.value.length - 1}`;
|
});
|
||||||
|
if (employeeCheckup.value)
|
||||||
|
tab.value = `tab${employeeCheckup.value.length - 1}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeData(index: number) {
|
function removeData(index: number) {
|
||||||
|
|
@ -132,7 +135,7 @@ const insuranceCompanyFilter = selectFilterOptionRefMod(
|
||||||
style="background-color: var(--_body-bg); min-width: 40px"
|
style="background-color: var(--_body-bg); min-width: 40px"
|
||||||
icon="mdi-plus"
|
icon="mdi-plus"
|
||||||
padding="8px 8px"
|
padding="8px 8px"
|
||||||
:disable="readonly"
|
:disable="readonly || !checkTabBeforeAdd(employeeCheckup || [])"
|
||||||
:color="$q.dark.isActive ? 'primary' : ''"
|
:color="$q.dark.isActive ? 'primary' : ''"
|
||||||
:class="tab !== 'tab0' ? 'bordered-r' : ''"
|
:class="tab !== 'tab0' ? 'bordered-r' : ''"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { onMounted, ref } from 'vue';
|
||||||
import { dateFormat, parseAndFormatDate } from 'src/utils/datetime';
|
import { dateFormat, parseAndFormatDate } from 'src/utils/datetime';
|
||||||
import { EmployeeWorkCreate } from 'src/stores/employee/types';
|
import { EmployeeWorkCreate } from 'src/stores/employee/types';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { selectFilterOptionRefMod } from 'src/stores/utils';
|
import { checkTabBeforeAdd, selectFilterOptionRefMod } from 'src/stores/utils';
|
||||||
|
|
||||||
const { locale } = useI18n();
|
const { locale } = useI18n();
|
||||||
|
|
||||||
|
|
@ -33,18 +33,21 @@ defineProps<{
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
function addData() {
|
function addData() {
|
||||||
employeeWork.value?.push({
|
const canAdd = checkTabBeforeAdd(employeeWork.value || []);
|
||||||
workEndDate: null,
|
if (canAdd) {
|
||||||
workPermitExpireDate: null,
|
employeeWork.value?.push({
|
||||||
workPermitIssuDate: null,
|
workEndDate: null,
|
||||||
workPermitNo: '',
|
workPermitExpireDate: null,
|
||||||
workplace: '',
|
workPermitIssuDate: null,
|
||||||
jobType: '',
|
workPermitNo: '',
|
||||||
positionName: '',
|
workplace: '',
|
||||||
ownerName: '',
|
jobType: '',
|
||||||
remark: '',
|
positionName: '',
|
||||||
});
|
ownerName: '',
|
||||||
if (employeeWork.value) tab.value = `tab${employeeWork.value.length - 1}`;
|
remark: '',
|
||||||
|
});
|
||||||
|
if (employeeWork.value) tab.value = `tab${employeeWork.value.length - 1}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeData(index: number) {
|
function removeData(index: number) {
|
||||||
|
|
@ -94,7 +97,7 @@ const workplaceFilter = selectFilterOptionRefMod(
|
||||||
style="background-color: var(--_body-bg); min-width: 40px"
|
style="background-color: var(--_body-bg); min-width: 40px"
|
||||||
icon="mdi-plus"
|
icon="mdi-plus"
|
||||||
padding="8px 8px"
|
padding="8px 8px"
|
||||||
:disable="readonly"
|
:disable="readonly || !checkTabBeforeAdd(employeeWork || [])"
|
||||||
:color="$q.dark.isActive ? 'primary' : ''"
|
:color="$q.dark.isActive ? 'primary' : ''"
|
||||||
:class="tab !== 'tab0' ? 'bordered-r' : ''"
|
:class="tab !== 'tab0' ? 'bordered-r' : ''"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { CustomerBranchCreate } from 'stores/customer/types';
|
import { CustomerBranchCreate } from 'stores/customer/types';
|
||||||
import { onMounted } from 'vue';
|
import { onMounted } from 'vue';
|
||||||
|
import { checkTabBeforeAdd } from 'src/stores/utils';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
readonly?: boolean;
|
readonly?: boolean;
|
||||||
|
|
@ -20,38 +21,47 @@ const statBranchNo = defineModel<number>('statBranchNo', {
|
||||||
const tab = defineModel<number>('tabIndex', { required: true });
|
const tab = defineModel<number>('tabIndex', { required: true });
|
||||||
|
|
||||||
function addData() {
|
function addData() {
|
||||||
const currentNo = (customerBranch.value.at(-1)?.branchNo || 0) + 1;
|
const canAdd = checkTabBeforeAdd(customerBranch.value || [], [
|
||||||
customerBranch.value.push({
|
'branchNo',
|
||||||
code: '',
|
'payDate',
|
||||||
branchNo: currentNo,
|
'registerDate',
|
||||||
address: '',
|
'status',
|
||||||
addressEN: '',
|
'wageRate',
|
||||||
provinceId: '',
|
]);
|
||||||
districtId: '',
|
if (canAdd) {
|
||||||
subDistrictId: '',
|
const currentNo = (customerBranch.value.at(-1)?.branchNo || 0) + 1;
|
||||||
zipCode: '',
|
customerBranch.value.push({
|
||||||
email: '',
|
code: '',
|
||||||
telephoneNo: '',
|
branchNo: currentNo,
|
||||||
name: '',
|
address: '',
|
||||||
status: 'CREATED',
|
addressEN: '',
|
||||||
taxNo: '',
|
provinceId: '',
|
||||||
nameEN: '',
|
districtId: '',
|
||||||
legalPersonNo: '',
|
subDistrictId: '',
|
||||||
registerName: '',
|
zipCode: '',
|
||||||
registerDate: new Date(),
|
email: '',
|
||||||
authorizedCapital: '',
|
telephoneNo: '',
|
||||||
employmentOffice: '',
|
name: '',
|
||||||
bussinessType: '',
|
status: 'CREATED',
|
||||||
bussinessTypeEN: '',
|
taxNo: '',
|
||||||
jobPosition: '',
|
nameEN: '',
|
||||||
jobPositionEN: '',
|
legalPersonNo: '',
|
||||||
jobDescription: '',
|
registerName: '',
|
||||||
saleEmployee: '',
|
registerDate: new Date(),
|
||||||
payDate: new Date(),
|
authorizedCapital: '',
|
||||||
wageRate: 0,
|
employmentOffice: '',
|
||||||
});
|
bussinessType: '',
|
||||||
|
bussinessTypeEN: '',
|
||||||
|
jobPosition: '',
|
||||||
|
jobPositionEN: '',
|
||||||
|
jobDescription: '',
|
||||||
|
saleEmployee: '',
|
||||||
|
payDate: new Date(),
|
||||||
|
wageRate: 0,
|
||||||
|
});
|
||||||
|
|
||||||
tab.value = customerBranch.value.length - 1;
|
tab.value = customerBranch.value.length - 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function close(index: number) {
|
function close(index: number) {
|
||||||
|
|
@ -85,7 +95,16 @@ onMounted(() => {
|
||||||
style="background-color: var(--_body-bg)"
|
style="background-color: var(--_body-bg)"
|
||||||
@click="addData()"
|
@click="addData()"
|
||||||
icon="mdi-plus"
|
icon="mdi-plus"
|
||||||
:disable="readonly"
|
:disable="
|
||||||
|
readonly ||
|
||||||
|
!checkTabBeforeAdd(customerBranch || [], [
|
||||||
|
'branchNo',
|
||||||
|
'payDate',
|
||||||
|
'registerDate',
|
||||||
|
'status',
|
||||||
|
'wageRate',
|
||||||
|
])
|
||||||
|
"
|
||||||
></q-btn>
|
></q-btn>
|
||||||
<q-tabs
|
<q-tabs
|
||||||
:active-bg-color="$q.dark.isActive ? 'dark' : 'white'"
|
:active-bg-color="$q.dark.isActive ? 'dark' : 'white'"
|
||||||
|
|
|
||||||
|
|
@ -994,7 +994,6 @@ async function fetchListEmployee() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function triggerChangeStatus(id: string, status: string) {
|
async function triggerChangeStatus(id: string, status: string) {
|
||||||
console.log('asd');
|
|
||||||
return await new Promise((resolve, reject) => {
|
return await new Promise((resolve, reject) => {
|
||||||
dialog({
|
dialog({
|
||||||
color: status !== 'INACTIVE' ? 'warning' : 'info',
|
color: status !== 'INACTIVE' ? 'warning' : 'info',
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,23 @@ export function selectOptionFilter(
|
||||||
return { options, filter };
|
return { options, filter };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function checkTabBeforeAdd(data: unknown[], except?: string[]) {
|
||||||
|
if (!data) return;
|
||||||
|
const lastData = data[data.length - 1];
|
||||||
|
|
||||||
|
if (typeof lastData !== 'object') return false;
|
||||||
|
|
||||||
|
let canAdd = false;
|
||||||
|
for (const [key, val] of Object.entries(
|
||||||
|
lastData as Record<string, unknown>,
|
||||||
|
)) {
|
||||||
|
if (except?.includes(key)) continue;
|
||||||
|
canAdd = val !== '' && val !== null;
|
||||||
|
if (canAdd) break;
|
||||||
|
}
|
||||||
|
return canAdd;
|
||||||
|
}
|
||||||
|
|
||||||
const useUtilsStore = defineStore('utilsStore', () => {
|
const useUtilsStore = defineStore('utilsStore', () => {
|
||||||
const currentTitle = ref<{
|
const currentTitle = ref<{
|
||||||
title: string;
|
title: string;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue