Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.85 KB | None | 0 0
  1. <template>
  2. <div id="ordering">
  3. <section class="leftSection">
  4. <div id="menuButtons">
  5. <button v-on:click="switchLang()">{{ uiLabels.language }}</button>
  6. <button v-on:click="changeCategory(1); showBurger(true); showOrder(true)"><img src="@/assets/hamburger.png" width=200></button>
  7.  
  8. <div class="hamburgerIngredients" v-if="hamburgerButtons">
  9. <button v-on:click="changeCategory(1)"> KÖTT </button>
  10. <button v-on:click="changeCategory(2)"> PÅLÄGG </button>
  11. <button v-on:click="changeCategory(3)"> SÅS </button>
  12. <button v-on:click="changeCategory(4)"> BRÖD </button>
  13. </div>
  14. <button v-on:click="changeCategory(5); showBurger(false); showOrder(true)"><img src="@/assets/fries.png" width=200></button>
  15. <button v-on:click="changeCategory(6); showBurger(false); showOrder(true)"><img src="@/assets/drink.png" width=200></button>
  16. </div>
  17. </section>
  18.  
  19. <section class="middleSection" >
  20. <div v-if="displayOrder">
  21. <h1>{{ uiLabels.ingredients }}</h1>
  22. <Ingredient
  23. ref="ingredient"
  24. v-for= "item in ingredients"
  25. v-show="item.category==currentCategory"
  26. v-on:increment="createBurger(item)"
  27. :item="item"
  28. :lang="lang"
  29. :key="item.ingredient_id">
  30. </Ingredient>
  31. <div v-if="hamburgerButtons">
  32. <h1>{{ uiLabels.order }}</h1>
  33. {{ burgerIngredients.map(item => item["ingredient_"+lang]).join(', ') }}, {{ price }} kr
  34. </div>
  35. <div id="addOrderButton">
  36. <button v-on:click="addToOrder(); showOrder(false)" style="float: right;"><img src="@/assets/cart.png" width = 40> {{ uiLabels.addOrder }}</button>
  37. </div>
  38. </div>
  39.  
  40. <div v-if="displayOrder == false">
  41. <h1>{{ uiLabels.order }}</h1>
  42. <div v-for="ab in outputOrderText">
  43. {{ab}}
  44. <button> delete </button>
  45. <br>
  46.  
  47. </div>
  48. <button v-on:click="placeOrder()">{{ uiLabels.placeOrder }}</button>
  49. </div>
  50. </section>
  51. <section class="rightSection">
  52. <h1>{{ uiLabels.ordersInQueue }}</h1>
  53. <div>
  54. <OrderItem
  55. v-for="(order, key) in orders"
  56. v-if="order.status !== 'done'"
  57. :order-id="key"
  58. :order="order"
  59. :ui-labels="uiLabels"
  60. :lang="lang"
  61. :key="key">
  62. </OrderItem>
  63. </div>
  64. </section>
  65. </div>
  66. </template>
  67. <script>
  68.  
  69. //import the components that are used in the template, the name that you
  70. //use for importing will be used in the template above and also below in
  71. //components
  72. import Ingredient from '@/components/Ingredient.vue'
  73. import OrderItem from '@/components/OrderItem.vue'
  74.  
  75. //import methods and data that are shared between ordering and kitchen views
  76. import sharedVueStuff from '@/components/sharedVueStuff.js'
  77.  
  78. /* instead of defining a Vue instance, export default allows the only
  79. necessary Vue instance (found in main.js) to import your data and methods */
  80. export default {
  81. name: 'Ordering',
  82. components: {
  83. Ingredient,
  84. OrderItem
  85. },
  86. mixins: [sharedVueStuff], // include stuff that is used in both
  87. // the ordering system and the kitchen
  88. data: function() { //Not that data is a function!
  89. return {
  90. chosenIngredients: [],
  91. burgerIngredients: [],
  92. drinksAndExtras: [],
  93. outputOrderText: [],
  94. tempFoodObjekt:"",
  95. price: 0,
  96. orderNumber: "",
  97. currentCategory: 1,
  98. hamburgerButtons: false,
  99. displayOrder: false,
  100. isburger: false,
  101. aBurger: {
  102. bread: null,
  103. meat: [],
  104. additionals:[],
  105. sauce: []
  106. },
  107. aDrinkOrExtra: {
  108. size: "Small",
  109. name: {}
  110. }
  111. }
  112. },
  113. created: function () {
  114. this.$store.state.socket.on('orderNumber', function (data) {
  115. this.orderNumber = data;
  116. }.bind(this));
  117. },
  118. methods: {
  119. createBurger: function (item) {
  120. if (this.currentCategory<=4){
  121. this.burgerIngredients.push(item);
  122. this.price += +item.selling_price;
  123. }
  124. else if (this.currentCategory>=5) {
  125. this.drinksAndExtras.push(item);
  126. this.price += +item.selling_price;
  127. }
  128.  
  129. },
  130. addToOrder: function () {
  131. this.addToBurger();
  132. this.addToDrinkOrExtra();
  133. this.createOutputOrderText();
  134. //this.chosenIngredients = this.chosenIngredients.concat(this.burgerIngredients).concat(this.drinksAndExtras);
  135. this.burgerIngredients = [];
  136. this.drinksAndExtras = []
  137. },
  138. addToBurger: function(){
  139. var i;
  140. for (i=0; i < this.burgerIngredients.length; i++){
  141. if (this.burgerIngredients[i].category == 1) {
  142. this.aBurger.meat.push(this.burgerIngredients[i]);
  143. }
  144. else if (this.burgerIngredients[i].category == 2) {
  145. this.aBurger.additionals.push(this.burgerIngredients[i]);
  146. }
  147. else if (this.burgerIngredients[i].category == 3) {
  148. this.aBurger.sauce.push(this.burgerIngredients[i]);
  149. }
  150. else if (this.burgerIngredients[i].category == 4)
  151. { this.isBurger=true;
  152. this.aBurger.bread = this.burgerIngredients[i];
  153. }
  154. }
  155. if(this.isBurger){
  156. this.chosenIngredients.push(this.aBurger);
  157. this.isBurger=false;
  158. }
  159. //this.chosenIngredients.push(this.aBurger);
  160. },
  161. addToDrinkOrExtra: function(){
  162. var j;
  163. for (j=0; j< this.drinksAndExtras.length; j++){
  164. if (this.drinksAndExtras[j].category >= 5){
  165. this.aDrinkOrExtra.name = this.drinksAndExtras[j]
  166. this.chosenIngredients.push(this.aDrinkOrExtra);
  167. }
  168. }
  169. },
  170. placeOrder: function () {
  171. var i,
  172. //Wrap the order in an object
  173. order = {
  174. ingredients: this.chosenIngredients,
  175. price: this.price
  176. };
  177. // make use of socket.io's magic to send the stuff to the kitchen via the server (app.js)
  178. this.$store.state.socket.emit('order', {order: order});
  179. //set all counters to 0. Notice the use of $refs
  180. for (i = 0; i < this.$refs.ingredient.length; i += 1) {
  181. this.$refs.ingredient[i].resetCounter();
  182. }
  183. this.price = 0;
  184. this.chosenIngredients = [];
  185. },
  186.  
  187. createOutputOrderText: function(){
  188. var i
  189. var j
  190. this.outputOrderText=[];
  191. for (i=0; i <this.chosenIngredients.length; i++){
  192. if(this.chosenIngredients[i].bread != null){
  193. this.tempFoodObjekt= i +": " + this.chosenIngredients[i].bread["ingredient_" + this.lang]
  194. for (j=0; j < this.chosenIngredients[i].meat.length; j++){
  195. this.tempFoodObjekt=this.tempFoodObjekt + ", " + this.chosenIngredients[i].meat[j]["ingredient_" + this.lang]
  196. }
  197. for (j=0; j < this.chosenIngredients[i].additionals.length; j++){
  198. this.tempFoodObjekt=this.tempFoodObjekt + ", " + this.chosenIngredients[i].additionals[j]["ingredient_" + this.lang]
  199. }
  200. for (j=0; j < this.chosenIngredients[i].sauce.length; j++){
  201. this.tempFoodObjekt=this.tempFoodObjekt + ", " + this.chosenIngredients[i].sauce[j]["ingredient_" + this.lang]
  202. }
  203. this.outputOrderText.push(this.tempFoodObjekt);
  204. this.tempFoodObjekt = "";
  205. }
  206. else {
  207. console.log(this.chosenIngredients)
  208. console.log(this.chosenIngredients[i].name["ingredient_" + this.lang])
  209. this.tempFoodObjekt=this.chosenIngredients[i].name["ingredient_" + this.lang] + ", " + this.chosenIngredients[i].size
  210. this.outputOrderText.push(this.tempFoodObjekt);
  211. this.tempFoodObjekt = "";
  212. }
  213. }
  214. console.log(this.outputOrderText);
  215. },
  216. changeCategory: function(int) {
  217. this.currentCategory = int;
  218. },
  219.  
  220. showBurger: function(boolean) {
  221. this.hamburgerButtons = boolean;
  222. },
  223. showOrder: function(boolean) {
  224. this.displayOrder = boolean;
  225. },
  226. removeitem: function(){
  227.  
  228. }
  229. }
  230. }
  231. </script>
  232. <style scoped>
  233. /* scoped in the style tag means that these rules will only apply to elements, classes and ids in this template and no other templates. */
  234. #ordering {
  235. display: grid;
  236. grid-gap: 5px;
  237. grid-template-columns: 20% 45% 35%;
  238. margin-left: 40px;
  239. }
  240. .leftSection{
  241. grid-column: 1;
  242. }
  243. .middleSection{
  244. grid-column: 2;
  245. }
  246. .rightSection{
  247. grid-column: 3;
  248. }
  249. #menuButtons{
  250. display: grid;
  251. grid-gap: 2px;
  252. grid-template-columns: repeat(1, 1fr);
  253. }
  254.  
  255. #menuButtons button{
  256. width: 100%;
  257. }
  258.  
  259. #addOrderButton {
  260. font-size: 50em;
  261. }
  262.  
  263. .hamburgerIngredients button:focus {
  264. background-color: black;
  265. color: white;
  266. }
  267.  
  268. .example-panel {
  269. position: fixed;
  270. left:0;
  271. top:0;
  272. z-index: -2;
  273. }
  274. .ingredient {
  275. border: 1px solid #ccd;
  276. padding: 1em;
  277. }
  278. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement