You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
3.6 KiB

2 years ago
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <link
  7. rel="stylesheet"
  8. href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css"
  9. />
  10. <script
  11. defer
  12. src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"
  13. ></script>
  14. <!-- Tailwind docs: https://tailwindcss.com/docs/installation/play-cdn -->
  15. <script src="https://cdn.tailwindcss.com"></script>
  16. <script>
  17. tailwind.config = {
  18. theme: {
  19. extend: {
  20. colors: {
  21. clifford: "#da373d",
  22. },
  23. },
  24. },
  25. };
  26. </script>
  27. </head>
  28. <body
  29. x-data="{
  30. formatter: new Intl.NumberFormat('fr-FR', {
  31. minimumFractionDigits: 2,
  32. maximumFractionDigits: 2,
  33. }),
  34. count: 0,
  35. taxChoice:0,
  36. taxes: [0, 8.5, 20],
  37. articles: [
  38. {
  39. id: 0,
  40. label: 'savon',
  41. price: 5,
  42. order: 0,
  43. },
  44. {
  45. id: 1,
  46. label: 'brosse',
  47. price: 10,
  48. order: 0,
  49. },
  50. {
  51. id: 2,
  52. label: 'lessive',
  53. price: 13,
  54. order: 0,
  55. }
  56. ],
  57. taxLabel: (entry)=> {
  58. switch (entry) {
  59. case 0: return 'exonéré';
  60. default: return entry+' %';
  61. }
  62. },
  63. order(id){
  64. this.articles[id].order++;
  65. },
  66. decrementOrder(id){
  67. this.articles[id].order--;
  68. },
  69. computePrice(){
  70. let sum=0;
  71. console.log(this.articles);
  72. for (item of this.articles) {
  73. sum += item.price * item.order;
  74. }
  75. return this.formatter.format(sum*(1+this.taxChoice/100));
  76. }
  77. }"
  78. class="p-8 bg-white dark:bg-slate-400"
  79. >
  80. <h1 class="text-3xl text-clifford">Articles</h1>
  81. <div class="flex space-x-4">
  82. <template x-for="article in articles" :key="article.id">
  83. <div>
  84. <span x-text="article.label"></span>
  85. <span x-show="article.order>0" x-text=" '('+article.order+')'"></span>
  86. <button
  87. @click="order(article.id)"
  88. class="flex items-center rounded bg-blue-100 px-5 py-2 text-slate-500 shadow-md"
  89. >
  90. <i class="mr-5 fa-solid fa-cart-plus"></i>
  91. Increment
  92. </button>
  93. <button
  94. x-show="article.order>0"
  95. @click="if (article.order>0) decrementOrder(article.id)"
  96. class="flex items-center rounded bg-blue-100 px-5 py-2 text-slate-500 shadow-md"
  97. >
  98. <i class="mr-5 fa-regular fa-square-minus"></i>
  99. Decrement
  100. </button>
  101. </div>
  102. </template>
  103. </div>
  104. <h2 class="text-2xl text-clifford">Taxes</h2>
  105. <template x-for="item in taxes" :key="item">
  106. <div>
  107. <input
  108. x-model="taxChoice"
  109. type="radio"
  110. name="taxChoice"
  111. :value="item"
  112. />
  113. <label x-text="taxLabel(item)"></label>
  114. </div>
  115. </template>
  116. <h2 class="text-2xl text-clifford mt-4">TOTAL TTC</h2>
  117. <span class="text-3xl" x-text="computePrice() + ' €'" />
  118. <div x-data="{ open: false }">
  119. <button
  120. @click="open = ! open"
  121. class="flex items-center rounded bg-orange-100 px-5 py-2 text-slate-500 shadow-md"
  122. >
  123. Voir C.G.U
  124. </button>
  125. <div
  126. x-transition.duration.500ms
  127. x-show="open"
  128. @click.outside="open = false"
  129. >
  130. Les conditions de vente standard s'appliquent à la date de la commande
  131. </div>
  132. </div>
  133. </body>
  134. </html>