Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson8 #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions .idea/watcherTasks.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 96 additions & 0 deletions basket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
document.addEventListener('DOMContentLoaded', () => {

function filter(event){
let action = event.target.dataset.filter;
if (!action) return;
let catalog = document.getElementById('catalog');
if (action === 'all'){//если "Показать все товары"
catalog.innerHTML = '';
getCatalog();
return;
}
let products = catalog.querySelectorAll('.prod');//получаем все prod в каталоге
products.forEach(element => {//перебираем проды и удаляем лишние
if (element.dataset.type !== action) element.remove();
})
}

function getCatalog(){
for (let [key, value] of Object.entries(products)) {//Перебираю объект массивов с каталогом для вывода в DOM
let product = document.createElement('div');
product.className = 'prod';
product.dataset.id = key;
product.dataset.type = value.type;
let name = value.name;
let price = value.price;
product.innerHTML = `<p>Название:</p> <p>${name}</p><p>Цена: ${price}</p><button data-name="add" data-id="${key}">Добавить в корзину</button>`
catalog.append(product);
}
}

function price() {
sum = 0;
function getPrice (){
for (let i = 0; i < basket.length; i++) {
let a = basket[i].id;
sum += products[a].price * basket[i].amount;
} return sum
}getPrice();
}

function getBasket() {
let prodId = basket[basket.length - 1].id;
let cargo = document.createElement('p');
cargo.innerHTML = `<p>Название товара: <span>${products[prodId].name}</span>, цена: <span>${products[prodId].price}</span></p>`
cart.append(cargo);
}

function addToCart(event) {
let action = event.target.dataset.name;
if (!action) return;
let id = event.target.dataset.id;
let amount = 1;
basket.push({id, amount});
price();
cartText.innerHTML = `<p>Общая стоимость товаров составляет <span>${sum}</span></p>`;
getBasket();
}

let sum = 0;

let products = {
1: {
name: 'bike',
price: 300,
type: 'movable',
},
2: {
name: 'car',
price: 500,
type: 'movable',
},
3: {
name: 'ship',
price: 1000,
type: 'movable',
},
4: {
name: 'something',
price: 100,
type: 'immovables',
}
}

let basket = [];
let container = document.querySelector('#shop');
let cart = document.createElement('div');
cart.className = 'basket';
let cartText = document.createElement('p');
cartText.innerText = 'Корзина пуста';
container.append(cart);
cart.append(cartText);

getCatalog();
document.addEventListener('click', addToCart);
document.addEventListener('click', filter);
})
15 changes: 14 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Title</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<script src="main.js"></script>
<section class="content">
<h2>Корзина</h2>
<div id="shop" class="shop"></div>
</section>
<section class="container"><!--для каталога-->
<div id="catalog" class="catalog"></div>
</section>
<section class="filters">
<button class="filter" data-filter="movable">Движимое имущество</button>
<button class="filter" data-filter="immovables">Недвижимое имущество</button>
<button class="filter" data-filter="all">Показать все товары</button>
</section>
<script src="basket.js"></script>
</body>
</html>
59 changes: 59 additions & 0 deletions style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions style.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions style.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
button{
background-color: gray;
outline: 2px solid black;
}

.content{
display: flex;
margin-bottom: 20px;
h2{
text-align: center;
}
}

.container{
display: flex;
width: 100%;
justify-content: space-between;
}

.prod{
width: 150px;
height: 200px;
font-size: 22px;
text-align: center;
background-color: aqua;
outline: 1px solid black;
}

.catalog{
display: flex;
justify-content: space-between;
width: 100%;
}

.basket{
background-color: aquamarine;
outline: 2px solid black;
width: 100%;
display: flex;
flex-direction: column;
p{
margin: 0!important;
padding: 0!important;
font-size: 22px;
span{
color: red;
}
}
}

.content{
display: flex;
flex-direction: column;
}

.filters{
margin-top: 40px;
display: flex;
justify-content: space-around;
}

.filter {
background-color: cornflowerblue;
font-size: 22px;
cursor: pointer;

}
79 changes: 79 additions & 0 deletions tetris.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#score, #lines, #figures, #setting {
margin-top: 20px;
margin-left: 60px;
font-size: 40px;
}

.green{
background-color: green;
}

button{
font-size: 22px;
}

#board {
height: 30px;
width: 30px;
display: flex;
flex-wrap: wrap;
background-color: #dcd6bc;
margin-left: 50px;
margin-top: 20px;
border: 10px solid #dcd6bc;
user-select: none;
}

#board div {
height: 30px;
width: 30px;
font-size: 25px;
text-align: center;
vertical-align: center;
font-family: 'Roboto Mono', monospace;
font-weight: bold;
cursor: pointer;
box-sizing: border-box;
border: 5px solid;
border-color: #f5f3eb #bab7a9 #bab7a9 #fffd9b
}

.closed {
background-color: #dcd6bc;
}

.lFigure {
background-color: blue;
}

.jFigure {
background-color: green;
}

.zFigure {
background-color: red;
}

.sFigure {
background-color: orange;
}

.uFigure {
background-color: black;
}

.tFigure {
background-color: darkblue;
}

.oFigure {
background-color: darkred;
}

.iFigure {
background-color: darkgreen;
}

.yFigure {
background-color: crimson;
}
Loading