refactor: assign worker to selectedWorker
This commit is contained in:
parent
4e736a2c96
commit
d5c8ce85b6
3 changed files with 62 additions and 7 deletions
|
|
@ -221,7 +221,10 @@ function triggerAddQuotationDialog() {
|
||||||
// TODO: form and state controll
|
// TODO: form and state controll
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerQuotationDialog(statusDialog: 'info' | 'edit' | 'create') {
|
function triggerQuotationDialog(
|
||||||
|
statusDialog: 'info' | 'edit' | 'create',
|
||||||
|
quotationId?: string,
|
||||||
|
) {
|
||||||
const url = new URL('/quotation/add-quotation', window.location.origin);
|
const url = new URL('/quotation/add-quotation', window.location.origin);
|
||||||
url.searchParams.set('branchId', branchId.value);
|
url.searchParams.set('branchId', branchId.value);
|
||||||
url.searchParams.set(
|
url.searchParams.set(
|
||||||
|
|
@ -232,6 +235,10 @@ function triggerQuotationDialog(statusDialog: 'info' | 'edit' | 'create') {
|
||||||
url.searchParams.set('special', special.value.toString());
|
url.searchParams.set('special', special.value.toString());
|
||||||
url.searchParams.set('statusDialog', statusDialog);
|
url.searchParams.set('statusDialog', statusDialog);
|
||||||
|
|
||||||
|
if (quotationId !== undefined) {
|
||||||
|
url.searchParams.set('quotationId', quotationId);
|
||||||
|
}
|
||||||
|
|
||||||
window.open(url.toString(), '_blank');
|
window.open(url.toString(), '_blank');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -613,8 +620,12 @@ watch(() => pageState.currentTab, fetchQuotationList);
|
||||||
"
|
"
|
||||||
:reporter="v.actorName"
|
:reporter="v.actorName"
|
||||||
:total-price="v.totalPrice"
|
:total-price="v.totalPrice"
|
||||||
@view="quotationFormStore.assignFormData(v.id)"
|
@view="
|
||||||
@edit="quotationFormStore.assignFormData(v.id, 'edit')"
|
() => {
|
||||||
|
triggerQuotationDialog('info', v.id);
|
||||||
|
}
|
||||||
|
"
|
||||||
|
@edit="triggerQuotationDialog('edit', v.id)"
|
||||||
@link="console.log('link')"
|
@link="console.log('link')"
|
||||||
@upload="console.log('upload')"
|
@upload="console.log('upload')"
|
||||||
@delete="triggerDialogDeleteQuottaion(v.id)"
|
@delete="triggerDialogDeleteQuottaion(v.id)"
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ const {
|
||||||
currentFormState: quotationFormState,
|
currentFormState: quotationFormState,
|
||||||
newWorkerList,
|
newWorkerList,
|
||||||
fileItemNewWorker,
|
fileItemNewWorker,
|
||||||
|
quotationFull,
|
||||||
} = storeToRefs(quotationForm);
|
} = storeToRefs(quotationForm);
|
||||||
|
|
||||||
const refSelectZoneEmployee = ref<InstanceType<typeof SelectZone>>();
|
const refSelectZoneEmployee = ref<InstanceType<typeof SelectZone>>();
|
||||||
|
|
@ -94,6 +95,7 @@ const selectedCustomer = ref('');
|
||||||
const toggleWorker = ref(true);
|
const toggleWorker = ref(true);
|
||||||
const rows = ref<Node[]>([]);
|
const rows = ref<Node[]>([]);
|
||||||
const branchId = ref('');
|
const branchId = ref('');
|
||||||
|
const currentQuotationId = ref<string | undefined>(undefined);
|
||||||
const date = ref();
|
const date = ref();
|
||||||
|
|
||||||
const preSelectedWorker = ref<Employee[]>([]);
|
const preSelectedWorker = ref<Employee[]>([]);
|
||||||
|
|
@ -317,7 +319,14 @@ function triggerProductServiceDialog() {
|
||||||
|
|
||||||
function toggleDeleteProduct(index: number) {
|
function toggleDeleteProduct(index: number) {
|
||||||
deleteItem(productServiceList.value, index);
|
deleteItem(productServiceList.value, index);
|
||||||
console.log(index);
|
}
|
||||||
|
async function assignWorkerToSelectedWorker() {
|
||||||
|
quotationFormData.value.worker.forEach((value, i) => {
|
||||||
|
const tempValue: Employee | undefined = workerList.value.find(
|
||||||
|
(v) => v.id === value.id,
|
||||||
|
);
|
||||||
|
if (tempValue !== undefined) selectedWorker.value.push(tempValue);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertToTable(nodes: Node[]) {
|
function convertToTable(nodes: Node[]) {
|
||||||
|
|
@ -432,6 +441,8 @@ onMounted(async () => {
|
||||||
|
|
||||||
date.value = Date.now();
|
date.value = Date.now();
|
||||||
|
|
||||||
|
currentQuotationId.value = urlParams.get('quotationId') || undefined;
|
||||||
|
|
||||||
quotationFormData.value.customerBranchId =
|
quotationFormData.value.customerBranchId =
|
||||||
urlParams.get('customerBranchId') || '';
|
urlParams.get('customerBranchId') || '';
|
||||||
|
|
||||||
|
|
@ -456,7 +467,18 @@ onMounted(async () => {
|
||||||
const retEmp = await customerStore.fetchBranchEmployee(
|
const retEmp = await customerStore.fetchBranchEmployee(
|
||||||
quotationFormData.value.customerBranchId,
|
quotationFormData.value.customerBranchId,
|
||||||
);
|
);
|
||||||
if (retEmp) workerList.value = workerList.value = retEmp.data.result;
|
if (retEmp) workerList.value = retEmp.data.result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
currentQuotationId.value !== undefined &&
|
||||||
|
quotationFormState.value.mode !== 'create'
|
||||||
|
) {
|
||||||
|
await quotationForm.assignFormData(
|
||||||
|
currentQuotationId.value,
|
||||||
|
quotationFormState.value.mode,
|
||||||
|
);
|
||||||
|
await assignWorkerToSelectedWorker();
|
||||||
}
|
}
|
||||||
|
|
||||||
pageState.isLoaded = true;
|
pageState.isLoaded = true;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,11 @@ import { useI18n } from 'vue-i18n';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
// NOTE: Import types
|
// NOTE: Import types
|
||||||
import { QuotationPayload, EmployeeWorker } from 'src/stores/quotations/types';
|
import {
|
||||||
|
QuotationPayload,
|
||||||
|
EmployeeWorker,
|
||||||
|
QuotationFull,
|
||||||
|
} from 'src/stores/quotations/types';
|
||||||
|
|
||||||
// NOTE: Import stores
|
// NOTE: Import stores
|
||||||
import { useQuotationStore } from 'stores/quotations';
|
import { useQuotationStore } from 'stores/quotations';
|
||||||
|
|
@ -34,6 +38,7 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
||||||
|
|
||||||
const quotationStore = useQuotationStore();
|
const quotationStore = useQuotationStore();
|
||||||
const employeeStore = useEmployeeStore();
|
const employeeStore = useEmployeeStore();
|
||||||
|
const quotationFull = ref<QuotationFull | undefined>(undefined);
|
||||||
const newWorkerList = ref<
|
const newWorkerList = ref<
|
||||||
(EmployeeWorker & {
|
(EmployeeWorker & {
|
||||||
attachment?: {
|
attachment?: {
|
||||||
|
|
@ -91,10 +96,25 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
||||||
|
|
||||||
if (!data) return; // NOTE: Error should be handled globally by axios instance
|
if (!data) return; // NOTE: Error should be handled globally by axios instance
|
||||||
|
|
||||||
|
quotationFull.value = data;
|
||||||
resetFormData = Object.assign(data, {
|
resetFormData = Object.assign(data, {
|
||||||
productServiceList: data.productServiceList.map((v) => ({
|
productServiceList: data.productServiceList.map((v) => ({
|
||||||
...v,
|
...v,
|
||||||
worker: undefined,
|
worker: v.worker.map((value, index) => ({
|
||||||
|
// passportNo: obj.data.passportNo, wait api add
|
||||||
|
//documentExpireDate: obj.data.documentExpireDate,
|
||||||
|
id: value.id,
|
||||||
|
lastNameEN: value.lastNameEN,
|
||||||
|
lastName: value.lastName,
|
||||||
|
middleNameEN: value.middleNameEN,
|
||||||
|
middleName: value.middleName,
|
||||||
|
firstNameEN: value.firstNameEN,
|
||||||
|
firstName: value.firstName,
|
||||||
|
namePrefix: value.namePrefix,
|
||||||
|
nationality: value.nationality,
|
||||||
|
gender: value.gender,
|
||||||
|
dateOfBirth: value.dateOfBirth,
|
||||||
|
})),
|
||||||
workerIndex: v.worker.map((a) =>
|
workerIndex: v.worker.map((a) =>
|
||||||
data.worker.findIndex((b) => b.employeeId === a.id),
|
data.worker.findIndex((b) => b.employeeId === a.id),
|
||||||
),
|
),
|
||||||
|
|
@ -110,6 +130,7 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
||||||
|
|
||||||
currentFormData.value = structuredClone(resetFormData);
|
currentFormData.value = structuredClone(resetFormData);
|
||||||
|
|
||||||
|
console.log('ทำงาน');
|
||||||
currentFormState.value.mode = mode;
|
currentFormState.value.mode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,6 +213,7 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
||||||
currentFormData,
|
currentFormData,
|
||||||
newWorkerList,
|
newWorkerList,
|
||||||
fileItemNewWorker,
|
fileItemNewWorker,
|
||||||
|
quotationFull,
|
||||||
|
|
||||||
isFormDataDifferent,
|
isFormDataDifferent,
|
||||||
injectNewEmployee,
|
injectNewEmployee,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue