Advertisement
EBALO_GOVNA

Untitled

May 13th, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.61 KB | None | 0 0
  1. index.html
  2.  
  3. <!DOCTYPE html>
  4. <html lang="en">
  5. <head>
  6. <title>Смерть русским!</title>
  7. <meta charset="UTF-8"/>
  8. <meta name="viewport" content="width=device-width,initial-scale=1"/>
  9.  
  10. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"
  11. integrity="sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A=="
  12. crossorigin="anonymous" referrerpolicy="no-referrer"/>
  13.  
  14. <script src="https://cdn.tailwindcss.com"></script>
  15. </head>
  16. <body>
  17. <main id="app">
  18. <template id="service-template">
  19. <li class="service border border-black p-2 mt-2 first:mt-0 relative">
  20. <i class="fa-solid fa-xmark absolute top-2 right-2 service-remove" onclick="removeService(this)"></i>
  21.  
  22. <h3>Услуга:</h3>
  23.  
  24. <div class="grid grid-cols-2 gap-3 mt-2">
  25. <select class="service-select border border-black outline-none" onchange="onSelectService(this)">
  26. <option data-name="Ретушь" data-price="50">Ретушь - $50</option>
  27. <option data-name="Фото на паспорт" data-price="100">Фото на паспорт - $100</option>
  28. <option data-name="Проявка пленки" data-price="10">Проявка пленки - $10</option>
  29. </select>
  30.  
  31. <input type="number" value="1" class="border border-black outline-none" onchange="onServiceCount(this)">
  32. </div>
  33.  
  34. <div class="service-codes mt-2 p-4 border-t border-black hidden">
  35. <div>
  36. <input type="text" class="add-service-input border border-black outline-none">
  37. <button class="add-service border border-black px-2 duration-100 hover:bg-slate-200"
  38. onclick="addCode(this)">Add
  39. </button>
  40. </div>
  41. <div class="mt-2 border-t border-black">
  42. <h3>Codes: </h3>
  43. <ul class="mt-2">
  44. <li>Item 1</li>
  45. <li>Item 2</li>
  46. <li>Item 3</li>
  47. </ul>
  48. </div>
  49. </div>
  50. </li>
  51. </template>
  52.  
  53. <div class="w-full min-h-screen bg-blue-200 flex justify-center py-20">
  54. <form class="w-thousand max-w-[90%] bg-slate-50 rounded-lg p-5">
  55. <header>
  56. <h1 class="text-center text-4xl pt-10 font-bold">Форма добавления заказа</h1>
  57. </header>
  58.  
  59. <!-- Выбор клиента -->
  60. <div class="mt-10">
  61. <h3>Выбор клиента:</h3>
  62.  
  63. <select class="mt-2 border border-black outline-none client-select" onchange="onSelectClient(this)">
  64. <option>Option 1</option>
  65. <option>Option 2</option>
  66. <option>Option 3</option>
  67. </select>
  68.  
  69. <div class="mt-2">
  70. <input type="checkbox" onchange="onCheckboxClient(this)">
  71. <span class="ml-2">Срочный заказ</span>
  72. </div>
  73. </div>
  74.  
  75. <!-- Выбор услуг-->
  76. <div class="mt-10">
  77. <header>
  78. <h3>Выбор услуг</h3>
  79. </header>
  80.  
  81. <ul class="mt-2 services-list">
  82. <li class="border border-black p-2 mt-2 first:mt-0 relative hidden">
  83. <i class="fa-solid fa-xmark absolute top-2 right-2"></i>
  84.  
  85. <h3>Услуга:</h3>
  86.  
  87. <div class="grid grid-cols-2 gap-3 mt-2">
  88. <select class="border border-black outline-none">
  89. <option>Проявка плёнки - $10</option>
  90. <option>Фото на паспорт - $100</option>
  91. <option>Проявка плёнки - $10</option>
  92. </select>
  93.  
  94. <input type="number" value="1" class="border border-black outline-none">
  95. </div>
  96.  
  97. <div class="service-films mt-2 p-4 border-t border-black">
  98. <ul class="service-films__list">
  99. <li class="mt-2 first:mt-0">
  100. <h3>Код плёнки (1):</h3>
  101. <input type="text" class="border border-black px-2 mt-2 outline-none"
  102. placeholder="ee72921">
  103. </li>
  104. <li class="mt-2 first:mt-0">
  105. <h3>Код плёнки (2):</h3>
  106. <input type="text" class="border border-black px-2 mt-2 outline-none"
  107. placeholder="ee72921">
  108. </li>
  109. </ul>
  110. </div>
  111. </li>
  112. </ul>
  113.  
  114. <div class="mt-2">
  115. <button
  116. onclick="createService()"
  117. type="button"
  118. class="add-service border border-black px-2 duration-100 hover:bg-slate-200">Добавить услугу
  119. </button>
  120. </div>
  121. </div>
  122.  
  123. <!-- Печать фотографий -->
  124. <div class="mt-10 hidden">
  125. <header>
  126. <h3>Печать фотографий</h3>
  127. </header>
  128.  
  129. <ul class="mt-2">
  130. <li class="border border-black p-2 mt-2 first:mt-0 relative">
  131. <i class="fa-solid fa-xmark absolute top-2 right-2"></i>
  132.  
  133. <div class="flex items-center">
  134. <h3>Копии:</h3>
  135. <input type="number" value="1" class="border border-black outline-none ml-2">
  136. </div>
  137.  
  138. <div class="mt-2 grid grid-cols-3 gap-3">
  139. <input type="text" placeholder="Плёнка" class="border border-black outline-none">
  140. <input type="text" placeholder="Кадр" class="border border-black outline-none">
  141.  
  142. <select class="border border-black outline-none">
  143. <option>Холст - А2</option>
  144. <option>Матовая - А2</option>
  145. <option>Глянцевая - А2</option>
  146. </select>
  147. </div>
  148. </li>
  149. </ul>
  150.  
  151. <div class="mt-2">
  152. <button class="border border-black px-2 duration-100 hover:bg-slate-200">Добавить услугу</button>
  153. </div>
  154. </div>
  155.  
  156. <!-- Продажа товаров -->
  157. <div class="mt-10 hidden">
  158. <header>
  159. <h3>Продажа товаров</h3>
  160. </header>
  161.  
  162. <ul class="mt-2">
  163. <li class="border border-black p-2 mt-2 first:mt-0 relative">
  164. <div class="grid grid-cols-2 gap-3">
  165. <select class="border border-black outline-none">
  166. <option>Проявка плёнки - $10</option>
  167. <option>Фото на паспорт - $100</option>
  168. <option>Проявка плёнки - $10</option>
  169. </select>
  170.  
  171. <input type="number" value="1" class="border border-black outline-none">
  172. </div>
  173.  
  174. <div class="mt-2 p-4 border-t border-black">
  175. <ul>
  176. <li class="mt-2 first:mt-0">
  177. <h3>Код плёнки (1):</h3>
  178. <input type="text" class="border border-black px-2 mt-2 outline-none"
  179. placeholder="ee72921">
  180. </li>
  181. <li class="mt-2 first:mt-0">
  182. <h3>Код плёнки (2):</h3>
  183. <input type="text" class="border border-black px-2 mt-2 outline-none"
  184. placeholder="ee72921">
  185. </li>
  186. </ul>
  187. </div>
  188. </li>
  189. </ul>
  190.  
  191. <div class="mt-2">
  192. <button class="border border-black px-2 duration-100 hover:bg-slate-200">Добавить услугу</button>
  193. </div>
  194. </div>
  195.  
  196. <button type="submit" class="submit-btn mt-10 border border-black px-2 duration-100 hover:bg-slate-200">
  197. Добавить заказ
  198. </button>
  199. </form>
  200. </div>
  201. </main>
  202.  
  203. <!-- libs-->
  204. <script src="https://cdnjs.cloudflare.com/ajax/libs/uuid/8.3.2/uuid.min.js" referrerpolicy="no-referrer"></script>
  205.  
  206. <script src="/js/tailwind.js"></script>
  207. <script src="/js/index.js"></script>
  208. </body>
  209. </html>
  210.  
  211. index.js
  212.  
  213. // order
  214. const submit = document.querySelector('.submit-btn');
  215.  
  216. const order = {
  217. services: [],
  218. }
  219. const DEFAULT_SERVICE = {
  220. name: "Ретушь",
  221. price: 50,
  222. count: 0,
  223. }
  224.  
  225. // Choose a client
  226. const onSelectClient = (select) => {
  227. order.name = select.value;
  228.  
  229. printOrder();
  230. }
  231. const onCheckboxClient = (input) => {
  232. order.isUrgent = input.checked;
  233.  
  234. printOrder();
  235. }
  236.  
  237. // Services
  238. const serviceTemplate = document.querySelector('#service-template');
  239.  
  240. const servicesList = document.querySelector('.services-list');
  241.  
  242. const createService = () => {
  243. const cloneNode = serviceTemplate.content.cloneNode(true);
  244.  
  245. servicesList.appendChild(cloneNode)
  246.  
  247. const latestService = servicesList.lastElementChild;
  248.  
  249. updateServices();
  250.  
  251. order.services.push({uuid: latestService.getAttribute('data-uuid'), ...DEFAULT_SERVICE});
  252.  
  253. printOrder()
  254. }
  255. const updateServices = () => {
  256. Object.values(servicesList.children).forEach((it) => {
  257. if (!it.hasAttribute('data-uuid')) {
  258. it.setAttribute('data-uuid', uuid.v4())
  259. }
  260. })
  261. }
  262. const removeService = (html) => {
  263. const parent = html.closest('.service');
  264. const uuid = parent.getAttribute('data-uuid');
  265.  
  266. order.services = order.services.filter((it) => it.uuid !== uuid);
  267.  
  268. servicesList.removeChild(parent);
  269. printOrder();
  270. }
  271. const onSelectService = (html) => {
  272. const option = html.options[html.selectedIndex];
  273. const uuid = html.closest('.service').getAttribute('data-uuid');
  274.  
  275. order.services = order.services.map((it) => {
  276. if (it.uuid === uuid) {
  277. it.name = option.getAttribute('data-name');
  278. it.price = option.getAttribute('data-price');
  279. }
  280.  
  281. return it;
  282. })
  283.  
  284. if (option.getAttribute('data-name') === "Проявка пленки") {
  285. onServiceFilm(html);
  286. }
  287.  
  288. printOrder()
  289. }
  290. const onServiceFilm = (html) => {
  291. const parent = html.closest('.service');
  292. const codes = parent.querySelector('.service-codes');
  293. const uuid = parent.getAttribute('data-uuid');
  294.  
  295. codes.classList.remove("hidden");
  296. }
  297. const onServiceCount = (html) => {
  298. const uuid = html.closest('.service').getAttribute('data-uuid');
  299.  
  300. order.services = order.services.map((it) => {
  301. if (it.uuid === uuid) {
  302. it.count = parseInt(html.value);
  303. }
  304.  
  305. return it;
  306. })
  307.  
  308. onServiceFilm(html);
  309. printOrder()
  310. }
  311. const addCode = (html) => {
  312. const parent = html.closest('.service');
  313. const uuid = parent.getAttribute('data-uuid');
  314. const inputCode = parent.querySelector('.add-service-input');
  315.  
  316. console.log(inputCode.value, uuid, parent);
  317. }
  318.  
  319. // Order
  320. const onSubmit = (e) => {
  321. e.preventDefault()
  322.  
  323. console.log('[onSubmit]: ')
  324. }
  325.  
  326. // Other
  327. const printOrder = () => {
  328. console.log("Order: ", order);
  329. }
  330. const getServiceByUUID = (uuid) => {
  331. return order.services.filter((it) => it.uuid === uuid);
  332. }
  333.  
  334. // Events
  335. submit.addEventListener("click", onSubmit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement