refactor: use session storage instead
This commit is contained in:
parent
d165d3bb81
commit
425fd71d2c
2 changed files with 66 additions and 49 deletions
|
|
@ -187,21 +187,18 @@ function triggerQuotationDialog(opts: {
|
||||||
branchId?: string;
|
branchId?: 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',
|
|
||||||
opts.branchId !== undefined ? opts.branchId : branchId.value,
|
|
||||||
);
|
|
||||||
url.searchParams.set(
|
|
||||||
'customerBranchId',
|
|
||||||
quotationFormData.value.customerBranchId,
|
|
||||||
);
|
|
||||||
url.searchParams.set('agentPrice', agentPrice.value.toString());
|
|
||||||
url.searchParams.set('special', special.value.toString());
|
|
||||||
url.searchParams.set('statusDialog', opts.statusDialog);
|
|
||||||
|
|
||||||
if (opts.quotationId !== undefined) {
|
localStorage.setItem(
|
||||||
url.searchParams.set('quotationId', opts.quotationId);
|
'new-quotation',
|
||||||
}
|
JSON.stringify({
|
||||||
|
customerBranchId: quotationFormData.value.customerBranchId,
|
||||||
|
branchId: opts.branchId ?? branchId.value,
|
||||||
|
agentPrice: agentPrice.value,
|
||||||
|
special: special.value,
|
||||||
|
statusDialog: opts.statusDialog,
|
||||||
|
quotationId: opts.quotationId,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
window.open(url.toString(), '_blank');
|
window.open(url.toString(), '_blank');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -511,6 +511,8 @@ function changeMode(mode: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sessionData = ref<Record<string, any>>();
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await configStore.getConfig();
|
await configStore.getConfig();
|
||||||
// get language
|
// get language
|
||||||
|
|
@ -536,25 +538,57 @@ onMounted(async () => {
|
||||||
changeMode('light');
|
changeMode('light');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sessionStorage.setItem(
|
||||||
|
'new-quotation',
|
||||||
|
localStorage.getItem('new-quotation') ||
|
||||||
|
sessionStorage.getItem('new-quotation') ||
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
|
||||||
|
localStorage.removeItem('new-quotation');
|
||||||
|
const payload = sessionStorage.getItem('new-quotation');
|
||||||
|
|
||||||
|
if (!!payload) {
|
||||||
|
const parsed = JSON.parse(payload);
|
||||||
|
date.value = Date.now();
|
||||||
|
quotationFormState.value.mode = parsed.statusDialog;
|
||||||
|
quotationFormData.value.registeredBranchId = parsed.branchId;
|
||||||
|
quotationFormData.value.customerBranchId = parsed.customerBranchId;
|
||||||
|
currentQuotationId.value = parsed.quotationId;
|
||||||
|
agentPrice.value = parsed.agentPrice;
|
||||||
|
if (
|
||||||
|
currentQuotationId.value !== undefined &&
|
||||||
|
quotationFormState.value.mode &&
|
||||||
|
quotationFormState.value.mode !== 'create'
|
||||||
|
) {
|
||||||
|
await quotationForm.assignFormData(
|
||||||
|
currentQuotationId.value,
|
||||||
|
quotationFormState.value.mode,
|
||||||
|
);
|
||||||
|
await assignWorkerToSelectedWorker();
|
||||||
|
}
|
||||||
|
sessionData.value = parsed;
|
||||||
|
}
|
||||||
|
|
||||||
// get query string
|
// get query string
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
// const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
//
|
||||||
const price = urlParams.get('agentPrice');
|
// const price = urlParams.get('agentPrice');
|
||||||
agentPrice.value = price === 'true' ? true : false;
|
// agentPrice.value = price === 'true' ? true : false;
|
||||||
|
//
|
||||||
date.value = Date.now();
|
// date.value = Date.now();
|
||||||
|
//
|
||||||
currentQuotationId.value = urlParams.get('quotationId') || undefined;
|
// currentQuotationId.value = urlParams.get('quotationId') || undefined;
|
||||||
|
//
|
||||||
quotationFormData.value.registeredBranchId = urlParams.get('branchId') || '';
|
// quotationFormData.value.registeredBranchId = urlParams.get('branchId') || '';
|
||||||
|
//
|
||||||
quotationFormData.value.customerBranchId =
|
// quotationFormData.value.customerBranchId =
|
||||||
urlParams.get('customerBranchId') || '';
|
// urlParams.get('customerBranchId') || '';
|
||||||
|
//
|
||||||
quotationFormState.value.mode = urlParams.get('statusDialog') as
|
// quotationFormState.value.mode = urlParams.get('statusDialog') as
|
||||||
| 'info'
|
// | 'info'
|
||||||
| 'edit'
|
// | 'edit'
|
||||||
| 'create';
|
// | 'create';
|
||||||
|
|
||||||
// fetch option
|
// fetch option
|
||||||
const resultOption = await fetch('/option/option.json');
|
const resultOption = await fetch('/option/option.json');
|
||||||
|
|
@ -562,16 +596,6 @@ onMounted(async () => {
|
||||||
if (locale.value === 'eng') optionStore.globalOption = rawOption.eng;
|
if (locale.value === 'eng') optionStore.globalOption = rawOption.eng;
|
||||||
if (locale.value === 'tha') optionStore.globalOption = rawOption.tha;
|
if (locale.value === 'tha') optionStore.globalOption = rawOption.tha;
|
||||||
|
|
||||||
if (
|
|
||||||
currentQuotationId.value !== undefined &&
|
|
||||||
quotationFormState.value.mode !== 'create'
|
|
||||||
) {
|
|
||||||
await quotationForm.assignFormData(
|
|
||||||
currentQuotationId.value,
|
|
||||||
quotationFormState.value.mode,
|
|
||||||
);
|
|
||||||
await assignWorkerToSelectedWorker();
|
|
||||||
}
|
|
||||||
await assignToProductServiceList();
|
await assignToProductServiceList();
|
||||||
|
|
||||||
pageState.isLoaded = true;
|
pageState.isLoaded = true;
|
||||||
|
|
@ -580,17 +604,13 @@ onMounted(async () => {
|
||||||
watch(
|
watch(
|
||||||
() => quotationFormData.value.customerBranchId,
|
() => quotationFormData.value.customerBranchId,
|
||||||
async (v) => {
|
async (v) => {
|
||||||
const url = new URL(window.location.href);
|
|
||||||
url.searchParams.set('customerBranchId', v);
|
|
||||||
history.pushState({}, '', url.toString());
|
|
||||||
|
|
||||||
if (!v) return;
|
if (!v) return;
|
||||||
|
|
||||||
const retEmp = await customerStore.fetchBranchEmployee(v, {
|
const retEmp = await customerStore.fetchBranchEmployee(v, {
|
||||||
passport: true,
|
passport: true,
|
||||||
});
|
});
|
||||||
if (retEmp) {
|
|
||||||
workerList.value = retEmp.data.result;
|
if (retEmp) workerList.value = retEmp.data.result;
|
||||||
}
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue