Тестовое задание про оптимальный розлив варенья по банкам
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

156 lines
3.9KB

  1. <template>
  2. <div class="tabs">
  3. <div class="tabs__buttons">
  4. <button
  5. @click="activeTab = 'Intro'"
  6. :class="activeTab === 'Intro' && 'active'"
  7. >
  8. Задача
  9. </button>
  10. <button
  11. @click="activeTab = 'Pots'"
  12. :class="activeTab === 'Pots' && 'active'"
  13. >
  14. Банки
  15. </button>
  16. <button
  17. @click="activeTab = 'Jams'"
  18. :class="activeTab === 'Jams' && 'active'"
  19. >
  20. Варенья
  21. </button>
  22. <button
  23. @click="activeTab = 'Result'"
  24. :class="activeTab === 'Result' && 'active'"
  25. >
  26. Разливаем
  27. </button>
  28. </div>
  29. <Intro v-show="activeTab === 'Intro'" class="tabs__body" />
  30. <Pots
  31. v-show="activeTab === 'Pots'"
  32. class="tabs__body"
  33. :pots="pots"
  34. @removePot="removePot"
  35. @addPot="addPot"
  36. />
  37. <Jams
  38. v-show="activeTab === 'Jams'"
  39. class="tabs__body"
  40. :jams="jams"
  41. @removeJam="removeJam"
  42. @addJam="addJam"
  43. />
  44. <Result v-show="activeTab === 'Result'" class="tabs__body" />
  45. </div>
  46. </template>
  47. <script>
  48. /* eslint-disable no-unused-vars */
  49. import Intro from "./components/Intro";
  50. import Pots from "./components/Pots";
  51. import Jams from "./components/Jams";
  52. import Result from "./components/Result";
  53. export default {
  54. name: "App",
  55. components: {
  56. Intro,
  57. Pots,
  58. Jams,
  59. Result,
  60. },
  61. data: function () {
  62. return {
  63. activeTab: "Intro",
  64. pots: [
  65. { id: "b1", vol: 3000 },
  66. { id: "b2", vol: 1000 },
  67. { id: "b3", vol: 100 },
  68. { id: "b4", vol: 850 },
  69. { id: "b5", vol: 500 },
  70. { id: "b6", vol: 750 },
  71. { id: "b7", vol: 500 },
  72. { id: "b8", vol: 450 },
  73. { id: "b9", vol: 450 },
  74. { id: "b10", vol: 300 },
  75. { id: "b11", vol: 350 },
  76. { id: "b12", vol: 100 },
  77. { id: "b13", vol: 150 },
  78. { id: "b14", vol: 100 },
  79. { id: "b15", vol: 50 },
  80. ],
  81. jams: [
  82. { id: "j1", vol: 3550 },
  83. { id: "j2", vol: 1700 },
  84. { id: "j3", vol: 2220 },
  85. ],
  86. };
  87. },
  88. methods: {
  89. removePot: function (index) {
  90. this.pots.splice(index, 1);
  91. },
  92. addPot: function (id, vol) {
  93. const f = this.pots.filter((p) => p.id === id);
  94. if (f.length > 0) {
  95. f[0].vol = +vol;
  96. } else {
  97. this.pots.push({ id, vol: +vol });
  98. }
  99. },
  100. removeJam: function (index) {
  101. this.jams.splice(index, 1);
  102. },
  103. addJam: function (id, vol) {
  104. const f = this.jams.filter((j) => j.id === id);
  105. if (f.length > 0) {
  106. f[0].vol = +vol;
  107. } else {
  108. this.jams.push({ id, vol: +vol });
  109. }
  110. },
  111. },
  112. };
  113. </script>
  114. <style lang="scss" scoped>
  115. #app {
  116. margin-top: 60px;
  117. }
  118. .tabs {
  119. max-width: 1440px;
  120. margin: 1rem;
  121. min-height: 75vh;
  122. display: flex;
  123. flex-direction: column;
  124. &__buttons {
  125. display: flex;
  126. flex-direction: row;
  127. button {
  128. appearance: none;
  129. border: none;
  130. padding: 1rem 2rem;
  131. font-size: 1.25rem;
  132. background: #ccc;
  133. border-bottom: 1px solid #ccc;
  134. &.active {
  135. background: #fff;
  136. border-bottom: 1px solid #fff;
  137. }
  138. }
  139. }
  140. &__body {
  141. background: #fff;
  142. flex-grow: 1;
  143. padding: 1rem 2rem;
  144. }
  145. }
  146. </style>