Browse Source

HW18 done

maryluis 4 years ago
parent
commit
566a520bc9
3 changed files with 86 additions and 1 deletions
  1. 78 0
      homework18/script.js
  2. 1 0
      homework18/shop.html
  3. 7 1
      homework18/style.css

+ 78 - 0
homework18/script.js

@@ -212,3 +212,81 @@ function oneGoodDescription(data, parentEl) {
 }
 
 
+function myOrder(parentEl) {
+    getGQL(gqlUrl) (
+        `query yourOrders {
+            OrderFind(query: "[{}]") {
+              _id
+              total
+              orderGoods {
+                count
+                good {
+                  name
+                  price
+                  images {
+                    url
+                  }
+                }
+              }
+              owner {
+                login
+              }
+            }
+          }
+          `
+    ).then((res) => {
+
+         parentEl.innerHTML = "";
+         parentEl.style = "justify-content: spase-around; ";
+        
+        var array = res.data.OrderFind;
+        for(let i = 0; i < array.length; i++) {
+            var oneOrder = array[i].orderGoods;
+            let icon = document.createElement("div");
+
+            for(let j = 0; j < oneOrder.length; j++) {
+
+                if(oneOrder[j].good !== null) {
+                    debugger
+                    icon.style = "margin: 30px; border: 2px solid black; padding:30px"
+                    parentEl.appendChild(icon);
+
+
+
+                    let goodInner = document.createElement("div");
+                    goodInner.style = "width: 250px; height: 200px;"
+                    icon.appendChild(goodInner);
+
+
+                    let goodImg = document.createElement("img");
+                    goodImg.setAttribute("src", `http://shop-roles.asmer.fs.a-level.com.ua/${oneOrder[j].good.images[0].url}`);
+                    goodImg.style = "width: 70px; height: 70px;"
+                    goodInner.appendChild(goodImg);
+
+                    let goodName = document.createElement("h4");
+                    goodName.innerText = oneOrder[j].good.name;
+                    goodInner.appendChild(goodName);
+
+                    let goodCount = document.createElement("span");
+                    goodCount.innerText = `${oneOrder[j].count} шт    `;
+                    goodInner.appendChild(goodCount)
+
+                    let goodPrice = document.createElement("span");
+                    goodPrice.innerText = `${oneOrder[j].good.price} грн`;
+                    goodInner.appendChild(goodPrice);
+                    console.log(oneOrder)
+
+                }
+            }
+
+            let totalOrder = document.createElement("h3");
+            totalOrder.innerText = `${array[i].total} грн`;
+            icon.appendChild(totalOrder);
+
+        }
+        console.log(array);
+    });
+
+}
+const orders = document.getElementById("orders");
+orders.onclick = () => myOrder(goodsDiv)

+ 1 - 0
homework18/shop.html

@@ -9,6 +9,7 @@
 <body>
     <header id="header">
         <div id="loginForm"></div>
+        <h3 id="orders">Предыдущие заказы</h3>
     </header>
 
     <main>

+ 7 - 1
homework18/style.css

@@ -1,3 +1,9 @@
+header {
+    display:flex;
+    justify-content: space-between;
+    background-color: orangered;
+    padding: 0px 30px;
+}
 #categories {
     background-color: olivedrab;
     /* position: absolute; */
@@ -18,6 +24,6 @@ main {
     flex-wrap: wrap;
 }
 #loginForm {
-    background-color: orangered;
+
     margin: 0%;
 }