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
|
||||
}
|
||||
|
||||
function triggerQuotationDialog(statusDialog: 'info' | 'edit' | 'create') {
|
||||
function triggerQuotationDialog(
|
||||
statusDialog: 'info' | 'edit' | 'create',
|
||||
quotationId?: string,
|
||||
) {
|
||||
const url = new URL('/quotation/add-quotation', window.location.origin);
|
||||
url.searchParams.set('branchId', branchId.value);
|
||||
url.searchParams.set(
|
||||
|
|
@ -232,6 +235,10 @@ function triggerQuotationDialog(statusDialog: 'info' | 'edit' | 'create') {
|
|||
url.searchParams.set('special', special.value.toString());
|
||||
url.searchParams.set('statusDialog', statusDialog);
|
||||
|
||||
if (quotationId !== undefined) {
|
||||
url.searchParams.set('quotationId', quotationId);
|
||||
}
|
||||
|
||||
window.open(url.toString(), '_blank');
|
||||
}
|
||||
|
||||
|
|
@ -613,8 +620,12 @@ watch(() => pageState.currentTab, fetchQuotationList);
|
|||
"
|
||||
:reporter="v.actorName"
|
||||
:total-price="v.totalPrice"
|
||||
@view="quotationFormStore.assignFormData(v.id)"
|
||||
@edit="quotationFormStore.assignFormData(v.id, 'edit')"
|
||||
@view="
|
||||
() => {
|
||||
triggerQuotationDialog('info', v.id);
|
||||
}
|
||||
"
|
||||
@edit="triggerQuotationDialog('edit', v.id)"
|
||||
@link="console.log('link')"
|
||||
@upload="console.log('upload')"
|
||||
@delete="triggerDialogDeleteQuottaion(v.id)"
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ const {
|
|||
currentFormState: quotationFormState,
|
||||
newWorkerList,
|
||||
fileItemNewWorker,
|
||||
quotationFull,
|
||||
} = storeToRefs(quotationForm);
|
||||
|
||||
const refSelectZoneEmployee = ref<InstanceType<typeof SelectZone>>();
|
||||
|
|
@ -94,6 +95,7 @@ const selectedCustomer = ref('');
|
|||
const toggleWorker = ref(true);
|
||||
const rows = ref<Node[]>([]);
|
||||
const branchId = ref('');
|
||||
const currentQuotationId = ref<string | undefined>(undefined);
|
||||
const date = ref();
|
||||
|
||||
const preSelectedWorker = ref<Employee[]>([]);
|
||||
|
|
@ -317,7 +319,14 @@ function triggerProductServiceDialog() {
|
|||
|
||||
function toggleDeleteProduct(index: number) {
|
||||
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[]) {
|
||||
|
|
@ -432,6 +441,8 @@ onMounted(async () => {
|
|||
|
||||
date.value = Date.now();
|
||||
|
||||
currentQuotationId.value = urlParams.get('quotationId') || undefined;
|
||||
|
||||
quotationFormData.value.customerBranchId =
|
||||
urlParams.get('customerBranchId') || '';
|
||||
|
||||
|
|
@ -456,7 +467,18 @@ onMounted(async () => {
|
|||
const retEmp = await customerStore.fetchBranchEmployee(
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,11 @@ import { useI18n } from 'vue-i18n';
|
|||
import { ref } from 'vue';
|
||||
|
||||
// NOTE: Import types
|
||||
import { QuotationPayload, EmployeeWorker } from 'src/stores/quotations/types';
|
||||
import {
|
||||
QuotationPayload,
|
||||
EmployeeWorker,
|
||||
QuotationFull,
|
||||
} from 'src/stores/quotations/types';
|
||||
|
||||
// NOTE: Import stores
|
||||
import { useQuotationStore } from 'stores/quotations';
|
||||
|
|
@ -34,6 +38,7 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
|||
|
||||
const quotationStore = useQuotationStore();
|
||||
const employeeStore = useEmployeeStore();
|
||||
const quotationFull = ref<QuotationFull | undefined>(undefined);
|
||||
const newWorkerList = ref<
|
||||
(EmployeeWorker & {
|
||||
attachment?: {
|
||||
|
|
@ -91,10 +96,25 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
|||
|
||||
if (!data) return; // NOTE: Error should be handled globally by axios instance
|
||||
|
||||
quotationFull.value = data;
|
||||
resetFormData = Object.assign(data, {
|
||||
productServiceList: data.productServiceList.map((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) =>
|
||||
data.worker.findIndex((b) => b.employeeId === a.id),
|
||||
),
|
||||
|
|
@ -110,6 +130,7 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
|||
|
||||
currentFormData.value = structuredClone(resetFormData);
|
||||
|
||||
console.log('ทำงาน');
|
||||
currentFormState.value.mode = mode;
|
||||
}
|
||||
|
||||
|
|
@ -192,6 +213,7 @@ export const useQuotationForm = defineStore('form-quotation', () => {
|
|||
currentFormData,
|
||||
newWorkerList,
|
||||
fileItemNewWorker,
|
||||
quotationFull,
|
||||
|
||||
isFormDataDifferent,
|
||||
injectNewEmployee,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue