-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprice_adjustment.js
104 lines (90 loc) · 4.28 KB
/
price_adjustment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { World } from './World.js';
World.getInstance().events.subscribe('load_pricelist_scene', () => {
World.getInstance().events.emit('stop_game'); World.getInstance().events.emit('stop_game');
function renderApp() {
document.getElementById('html-content').innerHTML = ''; // Reset content
const appHTML = `
<h2>Verkaufspreise anpassen</h2>
<table id="product-table" class="table">
<thead>
<tr>
<th>Emoji</th>
<th>Name</th>
<th>Besonderheit</th>
<th>Haltbarkeit</th>
<th>Qualität</th>
<th>Geschmack</th>
<th>Bestand</th>
<th>Aktueller Preis (€)</th>
<th>Neuer Preis (€)</th>
</tr>
</thead>
<tbody>
<!-- Produkte werden hier dynamisch hinzugefügt -->
</tbody>
</table>
<button id="set-prices-button" class="btn-green">Preise setzen</button>
<button id="back-button" class="btn-blue">Zurück</button>
`;
document.getElementById('html-content').innerHTML = appHTML;
const productTableBody = document.querySelector('#product-table tbody');
const setPricesButton = document.getElementById('set-prices-button');
const backButton = document.getElementById('back-button');
const inputs = {}; // Eingabe-Elemente sammeln
// Produkte anzeigen
function renderProducts() {
const inventory = World.getInstance().getFoodStall().getPos().listInventory();
productTableBody.innerHTML = '';
inventory.forEach(product => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${product.emoji}</td>
<td>${product.name}</td>
<td>${product.attributeIds.join(',')}</td>
<td>${product.expiryDate}</td>
<td>${product.quality}</td>
<td>${product.taste}</td>
<td>${product.stock}</td>
<td>${product.purchasePrice} €</td>
<td><input type="number" class="price-input" min="0.01" step="0.01" value="${product.purchasePrice}" id="price-${product.id}"></td>
`;
productTableBody.appendChild(row);
inputs[product.id] = document.getElementById(`price-${product.id}`);
});
}
// Preise anwenden
function applyPrices() {
Object.keys(inputs).forEach(productId => {
const inputElement = inputs[productId];
const newPrice = parseFloat(inputElement.value);
if (!isNaN(newPrice) && newPrice > 0) {
console.log(`Preis für Produkt ${productId} auf ${newPrice.toFixed(2)} € gesetzt.`);
World.getInstance().getFoodStall().getPos().updateSellPrice(productId, newPrice);
inputElement.style.borderColor = '';
} else {
console.warn(`Ungültiger Preis für Produkt ${productId} ignoriert.`);
inputElement.style.borderColor = 'red';
}
});
// Erfolgsmeldung anzeigen
const successMessage = document.createElement('p');
successMessage.textContent = 'Preise erfolgreich aktualisiert!';
successMessage.style.color = 'green';
document.getElementById('html-content').appendChild(successMessage);
setTimeout(() => successMessage.remove(), 3000);
}
// Event-Listener für Buttons
setPricesButton.addEventListener('click', () => {
applyPrices();
World.getInstance().events.emit('start_game')
});
// backButton.addEventListener('click', () => {
// game.scene.start('MainScene');
// document.getElementById('game-container').style.display = 'block';
// document.getElementById('html-content').style.display = 'none';
// });
// Initiale Anzeige
renderProducts();
}
renderApp();
});