Zapisywanie rozkazów

This commit is contained in:
2022-07-22 01:53:22 +02:00
parent 667987bdb6
commit 3ab273e2ba
6 changed files with 84 additions and 37 deletions
+52 -1
View File
@@ -12,7 +12,8 @@ export default defineComponent({
methods: {
saveOrderToStorage() {
let orderObj: LocalStorageOrder = {
orderType: this.store.chosenOrderType ,
id: '',
orderType: this.store.chosenOrderType,
orderBody: {},
orderFooter: this.store.orderFooter,
createdAt: Date.now(),
@@ -50,10 +51,60 @@ export default defineComponent({
}
const nextOrderCount = Number(localOrderCount) + 1;
orderObj['id'] = `order-${nextOrderCount}`;
localStorage.setItem('orderCount', `${nextOrderCount}`);
localStorage.setItem(`order-${nextOrderCount}`, JSON.stringify(orderObj));
return 1;
},
removeLocalOrder(order: LocalStorageOrder) {
localStorage.removeItem(order.id);
localStorage.setItem('orderCount', (Number(localStorage.getItem('orderCount')) - 1).toString());
},
selectLocalOrder(order: LocalStorageOrder) {
this.store.chosenOrderType = order.orderType;
const localOrder = JSON.parse(JSON.stringify(order));
const localOrderBody = localOrder['orderBody'];
const localOrderFooter = localOrder['orderFooter'];
let storeOrderObj;
switch (order.orderType) {
case 'orderN':
case 'orderS':
storeOrderObj = this.store[order.orderType];
for (let orderKey in storeOrderObj) {
for (let propKey in (storeOrderObj as any)[orderKey]) {
(storeOrderObj as any)[orderKey][propKey] = localOrderBody[orderKey][propKey];
}
}
break;
case 'orderO':
storeOrderObj = this.store[order.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 i = 0; i < storeOrderObj['orderList'].length; i++) {
const orderItem = storeOrderObj['orderList'][i];
for (let prop in orderItem) {
(storeOrderObj['orderList'][i] as any)[prop] = localOrderBody['orderList'][i][prop];
}
}
break;
}
for (let key in this.store.orderFooter) {
(this.store.orderFooter as any)[key] = localOrderFooter[key];
}
},
},
});