Gennadysht пре 2 година
родитељ
комит
bae03216e3
1 измењених фајлова са 25 додато и 6 уклоњено
  1. 25 6
      js/HW_13_kiosk/index.html

+ 25 - 6
js/HW_13_kiosk/index.html

@@ -2,6 +2,7 @@
 
 <body>
     <script>
+
         const addCell = (row, value) => {
             let cell = document.createElement("td");
             cell.innerText = value;
@@ -22,10 +23,9 @@
                 let item = state[itemKey];
                 let row = document.createElement("tr");
                 table.append(row);
-                addCell(row, itemKey);
 
+                addCell(row, itemKey);
                 addCell(row, item.price);
-
                 let amountVal = addCell(row, item.amount);
 
                 store.subscribe(() => {
@@ -38,6 +38,13 @@
             }
             return table;
         }
+        const addLabel = (element, value) => {
+            let label = document.createElement("label");
+            label.htmlFor = element.id;
+            label.innerText = value + ": ";
+            element.parentElement.insertBefore(label, element);
+        }
+        const addBr = (element) => element.append(document.createElement("br"));
 
         const createSale = (store) => {
             let state = store.getState();
@@ -55,16 +62,28 @@
             select.onchange = () => {
                 priceDiv.innerText = state[select.value].price;
             }
-
-            let priceDiv = document.createElement("div");
+            addLabel(select, "NAME");
+            addBr(resDiv);
+            let priceDiv = document.createElement("a");
             priceDiv.innerText = state[select.value].price;
+            priceDiv.id = "priceId";
+
             resDiv.append(priceDiv);
+            addLabel(priceDiv, "price");
+            addBr(resDiv);
             let amountInp = document.createElement("input");
+            amountInp.id = "amountId";
             amountInp.value = 0;
+
             resDiv.append(amountInp);
+            addLabel(amountInp, "amount");
+            addBr(resDiv);
             let cashInp = document.createElement("input");
+            cashInp.id = "cashId";
             cashInp.value = 0;
             resDiv.append(cashInp);
+            addLabel(cashInp, "cash");
+            addBr(resDiv);
             let buyBtn = document.createElement("button");
             buyBtn.innerText = "BUY";
             buyBtn.onclick = () => {
@@ -123,7 +142,7 @@
                     cashbox: state.cashbox + amount * state[item].price,
                 }
             }
-            if (type === 'SUPPLY' &&
+           /* if (type === 'SUPPLY' &&
                 typeof amount == "number" && amount > 0) {
                 let newState = { ...state };
                 let currItem = newState[item];
@@ -136,7 +155,7 @@
                     return state;
                 newState[item] = { amount: newState[item].amount + amount, price: newState[item].price };  //и уменьшаем то, что покупается на количество
                 return newState;
-            }
+            }*/
             return state;
         }
         let store = createStore(seller);