chore: order stylings; fix: compatibility with deprecated orders

This commit is contained in:
2024-05-30 15:34:03 +02:00
parent 28ba4045a0
commit af579f2cba
5 changed files with 115 additions and 48 deletions
+38 -31
View File
@@ -28,7 +28,8 @@ export default defineComponent({
orderType: this.store.chosenOrderType,
orderBody: this.store[this.store.chosenOrderType],
orderFooter: this.store.orderFooter,
createdAt: Date.now()
createdAt: Date.now(),
orderVersion: import.meta.env['VITE_APP_ORDER_VERSION'] || '1'
};
const headerInfo = orderObj['orderBody']['header'];
@@ -69,7 +70,8 @@ export default defineComponent({
orderType: this.store.chosenOrderType,
orderBody: this.store[this.store.chosenOrderType],
orderFooter: this.store.orderFooter,
updatedAt: Date.now()
updatedAt: Date.now(),
orderVersion: import.meta.env['VITE_APP_ORDER_VERSION'] || '1'
};
window.localStorage.setItem(this.store.chosenLocalOrderId, JSON.stringify(orderObj));
@@ -84,50 +86,55 @@ export default defineComponent({
// localStorage.setItem('orderCount', (Number(localStorage.getItem('orderCount')) - 1).toString());
},
selectLocalOrder(order: LocalStorageOrder) {
this.store.chosenOrderType = order.orderType;
this.store.chosenLocalOrderId = order.id;
selectLocalOrder(localOrder: LocalStorageOrder) {
// const localOrder = JSON.parse(JSON.stringify(order));
const { orderBody: localOrderBody, orderFooter: localOrderFooter } = localOrder;
const localOrder = JSON.parse(JSON.stringify(order));
const localOrderBody = localOrder['orderBody'];
const localOrderFooter = localOrder['orderFooter'];
this.store[localOrder.orderType].header.date = localOrderBody.header.date;
this.store[localOrder.orderType].header.orderNo = localOrderBody.header.orderNo;
this.store[localOrder.orderType].header.trainNo = localOrderBody.header.trainNo;
let storeOrderObj;
if (localOrder.orderType == 'orderN' || localOrder.orderType == 'orderS') {
const currentOrder = this.store[localOrder.orderType];
switch (order.orderType) {
case 'orderN':
case 'orderS':
storeOrderObj = this.store[order.orderType];
for (const orderKey in storeOrderObj) {
for (const propKey in (storeOrderObj as any)[orderKey]) {
(storeOrderObj as any)[orderKey][propKey] = localOrderBody[orderKey][propKey];
}
if (localOrderBody.rows.length != currentOrder.rows.length) {
alert(
'Zły format rozkazu! Może pochodzić z przestarzałej wersji lub został źle zapisany.'
);
console.warn('Zły format zapisanego rozkazu!');
return;
}
for (let rowIndex = 0; rowIndex < currentOrder.rows.length; rowIndex++) {
const row = currentOrder.rows[rowIndex];
for (const rowProp in row) {
(currentOrder.rows[rowIndex] as any)[rowProp] = localOrderBody.rows[rowIndex][rowProp];
}
}
}
break;
case 'orderO':
storeOrderObj = this.store[order.orderType];
if (localOrder.orderType == 'orderO') {
const currentOrder = this.store[localOrder.orderType];
storeOrderObj['other'] = localOrderBody['other'];
storeOrderObj['header']['date'] = localOrderBody['header']['date'];
storeOrderObj['header']['orderNo'] = localOrderBody['header']['orderNo'];
storeOrderObj['header']['trainNo'] = localOrderBody['header']['trainNo'];
for (let rowIndex = 0; rowIndex < currentOrder.orderList.length; rowIndex++) {
const row = currentOrder.orderList[rowIndex];
for (let i = 0; i < storeOrderObj['orderList'].length; i++) {
const orderItem = storeOrderObj['orderList'][i];
for (const prop in orderItem) {
(storeOrderObj['orderList'][i] as any)[prop] = localOrderBody['orderList'][i][prop];
}
for (const rowProp in row) {
(currentOrder.orderList[rowIndex] as any)[rowProp] =
localOrderBody.orderList[rowIndex][rowProp];
}
}
break;
currentOrder.other = localOrderBody.other;
}
for (const key in this.store.orderFooter) {
(this.store.orderFooter as any)[key] = localOrderFooter[key];
}
this.store.chosenOrderType = localOrder.orderType;
this.store.chosenLocalOrderId = localOrder.id;
this.store.orderMode = 'OrderMessage';
}
}