From ceca81dfbbfca70a6d6efb0131b49fc245de9267 Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Mon, 25 Nov 2019 20:30:49 +0300 Subject: [PATCH] PayInfo upd --- dist/public/js/bundle.js | 6 +++--- dist/views/assets/templates/modals/cart.pug | 19 +++++++++++++++---- src/js/index.js | 1 + src/js/modals/cart.modal.js | 14 ++++++++++---- src/js/templates/items.template.js | 4 ++-- src/js/templates/itemsOne.template.js | 4 ++-- 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/dist/public/js/bundle.js b/dist/public/js/bundle.js index 859c534..865cf44 100644 --- a/dist/public/js/bundle.js +++ b/dist/public/js/bundle.js @@ -4002,7 +4002,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _com /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"CartModal\", function() { return CartModal; });\n/* harmony import */ var _core_modal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/modal */ \"./src/js/core/modal.js\");\n/* harmony import */ var _other_counter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../other/counter */ \"./src/js/other/counter.js\");\n/* harmony import */ var _other_defaultColorBtn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../other/defaultColorBtn */ \"./src/js/other/defaultColorBtn.js\");\nfunction _typeof(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\n\n\n\nvar CartModal =\n/*#__PURE__*/\nfunction (_Modal) {\n _inherits(CartModal, _Modal);\n\n function CartModal(id, open, close, _ref) {\n var _this;\n\n var items = _ref.items;\n\n _classCallCheck(this, CartModal);\n\n _this = _possibleConstructorReturn(this, _getPrototypeOf(CartModal).call(this, id, open, close));\n _this.items = items;\n\n _this.open.addEventListener('click', _this.openHandler.bind(_assertThisInitialized(_this)));\n\n _this.close.addEventListener('click', _this.closeHandler.bind(_assertThisInitialized(_this)));\n\n _this.list = _this.$el.querySelector('#modalList');\n return _this;\n }\n\n _createClass(CartModal, [{\n key: \"closeHandler\",\n value: function closeHandler() {\n this.removeItem = null;\n this.makePay = null;\n }\n }, {\n key: \"openHandler\",\n value: function openHandler() {\n this.removeItem != null ? this.list.addEventListener('click', this.removeItem.bind(this)) : false;\n this.makePay != null ? this.$el.querySelector('#makePay').addEventListener('click', this.makePay.bind(this)) : false;\n this.list.innerHTML = '';\n this.insertItems(this.list);\n }\n }, {\n key: \"insertItems\",\n value: function insertItems(list) {\n var _this2 = this;\n\n if (localStorage.getItem('cart')) {\n var items = JSON.parse(localStorage.getItem('cart'));\n\n if (items.length == 0) {\n list.innerHTML = '

Вы не добавили ни один товар

';\n this.$el.querySelector('#makePay').classList.add('hide');\n } else {\n this.$el.querySelector('#makePay').classList.remove('hide');\n }\n\n items.forEach(function (item) {\n return _this2.list.innerHTML += \"
\").concat(item.title, \"
\\u0412 \\u043D\\u0430\\u043B\\u0438\\u0447\\u0438\\u0438: \").concat(item.count, \" (\\u0448\\u0442)
\").concat(parseFloat(item.price).toFixed(2), \"\\u20BD
close
\");\n });\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('modalCounter', this.items.cart);\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('counter', this.items.cart);\n this.insertTotalPrice('totalPrice', this.items.cart);\n }\n }\n }, {\n key: \"removeItem\",\n value: function removeItem(e) {\n if (e.target.id === 'removeItem') {\n var id = e.target.dataset.id;\n var index;\n this.items.cart.forEach(function (item, i) {\n return item.id === id ? index = i : false;\n });\n this.items.cart.splice(index, 1);\n localStorage.setItem('cart', JSON.stringify(this.items.cart));\n this.list.innerHTML = '';\n this.insertItems(this.list);\n Object(_other_defaultColorBtn__WEBPACK_IMPORTED_MODULE_2__[\"defaultBtnColor\"])(id, this.items.$el);\n }\n }\n }, {\n key: \"insertTotalPrice\",\n value: function insertTotalPrice(id, array) {\n var totalPrice = 0;\n array.forEach(function (item) {\n return totalPrice += parseFloat(item.price);\n });\n this.$el.querySelector(\"#\".concat(id)).innerHTML = \"\".concat(totalPrice.toFixed(2), \"\\u20BD\");\n }\n }, {\n key: \"makePay\",\n value: function makePay() {\n var payInfo = {\n items: this.items.cart.map(function (item) {\n return {\n id: item.id,\n title: item.title,\n price: parseFloat(item.price)\n };\n })\n };\n var totalPrice = 0;\n payInfo.items.forEach(function (item) {\n return totalPrice += parseFloat(item.price);\n });\n payInfo.totalPrice = Math.round(totalPrice * 100) / 100;\n console.log('Pay info:', payInfo);\n }\n }]);\n\n return CartModal;\n}(_core_modal__WEBPACK_IMPORTED_MODULE_0__[\"Modal\"]);\n\n//# sourceURL=webpack:///./src/js/modals/cart.modal.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"CartModal\", function() { return CartModal; });\n/* harmony import */ var _core_modal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/modal */ \"./src/js/core/modal.js\");\n/* harmony import */ var _other_counter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../other/counter */ \"./src/js/other/counter.js\");\n/* harmony import */ var _other_defaultColorBtn__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../other/defaultColorBtn */ \"./src/js/other/defaultColorBtn.js\");\nfunction _typeof(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\n\n\n\nvar CartModal =\n/*#__PURE__*/\nfunction (_Modal) {\n _inherits(CartModal, _Modal);\n\n function CartModal(id, open, close, _ref) {\n var _this;\n\n var items = _ref.items;\n\n _classCallCheck(this, CartModal);\n\n _this = _possibleConstructorReturn(this, _getPrototypeOf(CartModal).call(this, id, open, close));\n _this.items = items;\n\n _this.open.addEventListener('click', _this.openHandler.bind(_assertThisInitialized(_this)));\n\n _this.close.addEventListener('click', _this.closeHandler.bind(_assertThisInitialized(_this)));\n\n _this.list = _this.$el.querySelector('#modalList');\n return _this;\n }\n\n _createClass(CartModal, [{\n key: \"closeHandler\",\n value: function closeHandler() {\n this.removeItem = null;\n this.makePay = null;\n }\n }, {\n key: \"openHandler\",\n value: function openHandler() {\n this.removeItem != null ? this.list.addEventListener('click', this.removeItem.bind(this)) : false;\n this.makePay != null ? this.$el.querySelector('#purchaseInfo').addEventListener('submit', this.makePay.bind(this)) : false;\n this.list.innerHTML = '';\n this.insertItems(this.list);\n }\n }, {\n key: \"insertItems\",\n value: function insertItems(list) {\n var _this2 = this;\n\n if (localStorage.getItem('cart')) {\n var items = JSON.parse(localStorage.getItem('cart'));\n\n if (items.length == 0) {\n list.innerHTML = '

Вы не добавили ни один товар

';\n this.$el.querySelector('#purchaseInfo').classList.add('hide');\n } else {\n this.$el.querySelector('#purchaseInfo').classList.remove('hide');\n }\n\n items.forEach(function (item) {\n return _this2.list.innerHTML += \"
\").concat(item.title, \"
\\u0412 \\u043D\\u0430\\u043B\\u0438\\u0447\\u0438\\u0438: \").concat(item.count, \" (\\u0448\\u0442)
\").concat(parseFloat(item.price).toFixed(2), \"\\u20BD
close
\");\n });\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('modalCounter', this.items.cart);\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('counter', this.items.cart);\n this.insertTotalPrice('totalPrice', this.items.cart);\n } else {\n list.innerHTML = '

Вы не добавили ни один товар

';\n }\n }\n }, {\n key: \"removeItem\",\n value: function removeItem(e) {\n if (e.target.id === 'removeItem') {\n var id = e.target.dataset.id;\n var index;\n this.items.cart.forEach(function (item, i) {\n return item.id === id ? index = i : false;\n });\n this.items.cart.splice(index, 1);\n localStorage.setItem('cart', JSON.stringify(this.items.cart));\n this.list.innerHTML = '';\n this.insertItems(this.list);\n Object(_other_defaultColorBtn__WEBPACK_IMPORTED_MODULE_2__[\"defaultBtnColor\"])(id, this.items.$el);\n }\n }\n }, {\n key: \"insertTotalPrice\",\n value: function insertTotalPrice(id, array) {\n var totalPrice = 0;\n array.forEach(function (item) {\n return totalPrice += parseFloat(item.price);\n });\n this.$el.querySelector(\"#\".concat(id)).innerHTML = \"\".concat(totalPrice.toFixed(2), \"\\u20BD\");\n }\n }, {\n key: \"makePay\",\n value: function makePay(e) {\n e.preventDefault();\n var payInfo = {\n items: this.items.cart.map(function (item) {\n return {\n id: item.id,\n title: item.title,\n price: parseFloat(item.price)\n };\n })\n };\n var totalPrice = 0;\n payInfo.items.forEach(function (item) {\n return totalPrice += parseFloat(item.price);\n });\n payInfo.totalPrice = Math.round(totalPrice * 100) / 100;\n payInfo.payMethod = this.$el.querySelector('.payment-field select').value;\n payInfo.phone = this.$el.querySelector('.phone-field input').value;\n payInfo.email = this.$el.querySelector('.email-field input').value;\n console.log('Pay info:', payInfo);\n }\n }]);\n\n return CartModal;\n}(_core_modal__WEBPACK_IMPORTED_MODULE_0__[\"Modal\"]);\n\n//# sourceURL=webpack:///./src/js/modals/cart.modal.js?"); /***/ }), @@ -4050,7 +4050,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"renderItems\", function() { return renderItems; });\nfunction renderItems(categories, items) {\n var html = '';\n categories.forEach(function (category) {\n html += \"
\\n

\".concat(category, \"

\\n
\");\n items[category].forEach(function (item) {\n if (item && item._id != undefined) {\n html += \"\\n
\\n
\\n
\\n \\\"#\\\"\\n
\\n \\n
\\n
\\n
\\n \").concat(item.date, \"\\n
\\n
\\n \").concat(item.count, \" \\u0448\\u0442.\\n
\\n
\\n \\u0426\\u0435\\u043D\\u0430 \\u0437\\u0430 1 \\u0448\\u0442.\\n
\\n
\\n \").concat(item.price.toFixed(2), \"\\u20BD\\n
\\n
\\n \\n \\n
\\n
\\n
\\n \");\n } else {\n html += \"\\n
\\n
\\n
\\n \\u0412 \\u044D\\u0442\\u043E\\u0439 \\u043A\\u0430\\u0442\\u0435\\u0433\\u043E\\u0440\\u0438\\u0438 \\u043F\\u043E\\u043A\\u0430 \\u0447\\u0442\\u043E \\u043D\\u0435\\u0442\\u0443 \\u0442\\u043E\\u0432\\u0430\\u0440\\u043E\\u0432\\n
\\n
\\n
\\n \";\n }\n });\n });\n return html;\n}\n\n//# sourceURL=webpack:///./src/js/templates/items.template.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"renderItems\", function() { return renderItems; });\nfunction renderItems(categories, items) {\n var html = '';\n categories.forEach(function (category) {\n html += \"
\\n

\".concat(category, \"

\\n
\");\n items[category].forEach(function (item) {\n if (item && item._id != undefined) {\n html += \"\\n
\\n
\\n
\\n \\\"#\\\"\\n
\\n \\n
\\n
\\n
\\n \").concat(item.date, \"\\n
\\n
\\n \").concat(item.count, \" \\u0448\\u0442.\\n
\\n
\\n \\u0426\\u0435\\u043D\\u0430 \\u0437\\u0430 1 \\u0448\\u0442.\\n
\\n
\\n \").concat(item.price.toFixed(2), \"\\u20BD\\n
\\n
\\n \\n \\n
\\n
\\n
\\n \");\n } else {\n html += \"\\n
\\n
\\n
\\n \\u0412 \\u044D\\u0442\\u043E\\u0439 \\u043A\\u0430\\u0442\\u0435\\u0433\\u043E\\u0440\\u0438\\u0438 \\u043F\\u043E\\u043A\\u0430 \\u0447\\u0442\\u043E \\u043D\\u0435\\u0442\\u0443 \\u0442\\u043E\\u0432\\u0430\\u0440\\u043E\\u0432\\n
\\n
\\n
\\n \";\n }\n });\n });\n return html;\n}\n\n//# sourceURL=webpack:///./src/js/templates/items.template.js?"); /***/ }), @@ -4062,7 +4062,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"renderItemsOne\", function() { return renderItemsOne; });\nfunction renderItemsOne(category, items) {\n var html = '';\n html += \"
\\n

\".concat(category, \"

\\n
\");\n items.forEach(function (item) {\n if (item && item._id != undefined) {\n html += \"\\n
\\n
\\n
\\n \\\"#\\\"\\n
\\n \\n
\\n
\\n
\\n \").concat(item.date, \"\\n
\\n
\\n \").concat(item.count, \" \\u0448\\u0442.\\n
\\n
\\n \\u0426\\u0435\\u043D\\u0430 \\u0437\\u0430 1 \\u0448\\u0442.\\n
\\n
\\n \").concat(item.price.toFixed(2), \"\\u20BD\\n
\\n
\\n \\n \\n
\\n
\\n
\\n \");\n } else {\n html += \"\\n
\\n
\\n
\\n \\u0412 \\u044D\\u0442\\u043E\\u0439 \\u043A\\u0430\\u0442\\u0435\\u0433\\u043E\\u0440\\u0438\\u0438 \\u043F\\u043E\\u043A\\u0430 \\u0447\\u0442\\u043E \\u043D\\u0435\\u0442\\u0443 \\u0442\\u043E\\u0432\\u0430\\u0440\\u043E\\u0432\\n
\\n
\\n
\";\n }\n });\n return html;\n}\n\n//# sourceURL=webpack:///./src/js/templates/itemsOne.template.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"renderItemsOne\", function() { return renderItemsOne; });\nfunction renderItemsOne(category, items) {\n var html = '';\n html += \"
\\n

\".concat(category, \"

\\n
\");\n items.forEach(function (item) {\n if (item && item._id != undefined) {\n html += \"\\n
\\n
\\n
\\n \\\"#\\\"\\n
\\n \\n
\\n
\\n
\\n \").concat(item.date, \"\\n
\\n
\\n \").concat(item.count, \" \\u0448\\u0442.\\n
\\n
\\n \\u0426\\u0435\\u043D\\u0430 \\u0437\\u0430 1 \\u0448\\u0442.\\n
\\n
\\n \").concat(item.price.toFixed(2), \"\\u20BD\\n
\\n
\\n \\n \\n
\\n
\\n
\\n \");\n } else {\n html += \"\\n
\\n
\\n
\\n \\u0412 \\u044D\\u0442\\u043E\\u0439 \\u043A\\u0430\\u0442\\u0435\\u0433\\u043E\\u0440\\u0438\\u0438 \\u043F\\u043E\\u043A\\u0430 \\u0447\\u0442\\u043E \\u043D\\u0435\\u0442\\u0443 \\u0442\\u043E\\u0432\\u0430\\u0440\\u043E\\u0432\\n
\\n
\\n
\";\n }\n });\n return html;\n}\n\n//# sourceURL=webpack:///./src/js/templates/itemsOne.template.js?"); /***/ }), diff --git a/dist/views/assets/templates/modals/cart.pug b/dist/views/assets/templates/modals/cart.pug index 3219f17..12478aa 100644 --- a/dist/views/assets/templates/modals/cart.pug +++ b/dist/views/assets/templates/modals/cart.pug @@ -14,12 +14,23 @@ .modal-content__counter span Всего товаров в корзине span - b#modalCounter 1 + b#modalCounter 0 .modal-content__pay span b Сумма к оплате span - b#totalPrice 139.89 ₽ - .modal-content__purchase - button#makePay.purchase-btn.waves-effect.btn Перейти к оплате + b#totalPrice 0 ₽ + form#purchaseInfo.modal-content__purchase.hide + span Информация необходимая для оплаты + .email-field + label(for='email') Ваш E-mail + input#email(required='' type='text' name='email') + .phone-field + label(for="phone") Номер QIWI + input#phone(required='' type='text' name='phone') + .payment-field + label(for='payment') Способ оплаты + select#payment(name='payment') + option(value='qiwi' data-icon='../img/payments-icons/qiwi.svg') QIWI + button.purchase-btn.waves-effect.btn Перейти к оплате // Cart Modal END diff --git a/src/js/index.js b/src/js/index.js index 24a5fd6..afd0124 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -16,3 +16,4 @@ const filter = new FilterComponent('filter', {items}); const category = new CategoryComponent('category', {items}, {filter}); const breadcumb = new BreadcrumbComponent('breadcrumb'); const cart = new CartModal('cart', 'cartOpen', 'cartClose', {items}); + diff --git a/src/js/modals/cart.modal.js b/src/js/modals/cart.modal.js index 2f32b2e..198a68f 100644 --- a/src/js/modals/cart.modal.js +++ b/src/js/modals/cart.modal.js @@ -18,7 +18,7 @@ export class CartModal extends Modal { openHandler() { this.removeItem != null ? this.list.addEventListener('click', this.removeItem.bind(this)) : false - this.makePay != null ? this.$el.querySelector('#makePay').addEventListener('click', this.makePay.bind(this)) : false; + this.makePay != null ? this.$el.querySelector('#purchaseInfo').addEventListener('submit', this.makePay.bind(this)) : false; this.list.innerHTML = ''; this.insertItems(this.list); } @@ -29,15 +29,17 @@ export class CartModal extends Modal { if (items.length == 0) { list.innerHTML = '

Вы не добавили ни один товар

'; - this.$el.querySelector('#makePay').classList.add('hide'); + this.$el.querySelector('#purchaseInfo').classList.add('hide'); } else { - this.$el.querySelector('#makePay').classList.remove('hide'); + this.$el.querySelector('#purchaseInfo').classList.remove('hide'); } items.forEach(item => this.list.innerHTML += ``); insertCount('modalCounter', this.items.cart); insertCount('counter', this.items.cart); this.insertTotalPrice('totalPrice', this.items.cart); + } else { + list.innerHTML = '

Вы не добавили ни один товар

'; } } @@ -62,7 +64,8 @@ export class CartModal extends Modal { this.$el.querySelector(`#${id}`).innerHTML = `${totalPrice.toFixed(2)}₽`; } - makePay() { + makePay(e) { + e.preventDefault(); const payInfo = {items: this.items.cart.map(item => { return { id: item.id, @@ -73,6 +76,9 @@ export class CartModal extends Modal { let totalPrice = 0; payInfo.items.forEach(item => totalPrice += parseFloat(item.price)); payInfo.totalPrice = Math.round(totalPrice * 100) / 100; + payInfo.payMethod = this.$el.querySelector('.payment-field select').value; + payInfo.phone = this.$el.querySelector('.phone-field input').value; + payInfo.email = this.$el.querySelector('.email-field input').value; console.log('Pay info:', payInfo); } diff --git a/src/js/templates/items.template.js b/src/js/templates/items.template.js index 4fe59fe..80583ce 100644 --- a/src/js/templates/items.template.js +++ b/src/js/templates/items.template.js @@ -9,8 +9,8 @@ export function renderItems(categories, items) { items[category].forEach(item => { if (item && item._id != undefined) { html += ` -
-
+
+
#
diff --git a/src/js/templates/itemsOne.template.js b/src/js/templates/itemsOne.template.js index c67e18c..383e62b 100644 --- a/src/js/templates/itemsOne.template.js +++ b/src/js/templates/itemsOne.template.js @@ -8,8 +8,8 @@ export function renderItemsOne(category, items) { items.forEach(item => { if (item && item._id != undefined) { html += ` -
-
+
+
#