Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

restaurantMenuItem.vue 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div>
  3. <div class="container">
  4. <div class="container">
  5. <div class="row">
  6. <div class="col-md-12 col-lg-8">
  7. <div class="title-box-d">
  8. <br />
  9. <h1 class="title-d" style="text-align:left; font-size: 250%">Menu Item</h1>
  10. </div>
  11. </div>
  12. </div>
  13. </div>
  14. </div>
  15. <div class="container" v-if="!showOption">
  16. <div class="row" style="text-align:left">
  17. <div class="col-md-6" style="margin-bottom: 1em">
  18. <label>Category</label>
  19. <div class="input-group-prepend">
  20. <span class="input-group-text">
  21. <eva-icon name="edit-2-outline" fill="#6c757d"></eva-icon>
  22. </span>
  23. <select class="form-control" v-model="menuItem.category">
  24. <option v-for="(cat, i) in categories" :key="i">{{ cat.description }}</option>
  25. </select>
  26. </div>
  27. </div>
  28. </div>
  29. <div class="row" style="text-align:left">
  30. <div class="col-md-6" style="margin-bottom: 1em">
  31. <label>Name</label>
  32. <div class="input-group-prepend">
  33. <span class="input-group-text">
  34. <eva-icon name="edit-2-outline" fill="#6c757d"></eva-icon>
  35. </span>
  36. <input class="form-control" type="text" v-model="menuItem.name" />
  37. </div>
  38. </div>
  39. </div>
  40. <div class="row" style="text-align:left">
  41. <div class="col-md-6" style="margin-bottom: 1em">
  42. <label>Description</label>
  43. <div class="input-group-prepend">
  44. <span class="input-group-text">
  45. <eva-icon name="edit-2-outline" fill="#6c757d"></eva-icon>
  46. </span>
  47. <input class="form-control" type="text" v-model="menuItem.description" />
  48. </div>
  49. </div>
  50. </div>
  51. <div class="row" style="text-align:left">
  52. <div class="col-md-6" style="margin-bottom: 1em">
  53. <label>Price</label>
  54. <div class="input-group-prepend">
  55. <span class="input-group-text" style="color:#6c757d">
  56. <b>R</b>
  57. </span>
  58. <input class="form-control" type="number" v-model="menuItem.price" />
  59. </div>
  60. </div>
  61. </div>
  62. <div v-if="!menuItem.image" class="row" style="text-align:left">
  63. <div class="col-md-6" style="margin-bottom: 1em">
  64. <label>Image</label>
  65. <div class="input-group-prepend">
  66. <image-uploader
  67. :preview="true"
  68. :className="['fileinput', { 'fileinput--loaded': hasImage }]"
  69. capture="environment"
  70. :debug="1"
  71. doNotResize="gif"
  72. :autoRotate="true"
  73. outputFormat="verbose"
  74. @input="setImage"
  75. >
  76. <label for="fileInput" slot="upload-label">
  77. <figure>
  78. <path
  79. class="path1"
  80. d="M9.5 19c0 3.59 2.91 6.5 6.5 6.5s6.5-2.91 6.5-6.5-2.91-6.5-6.5-6.5-6.5 2.91-6.5 6.5zM30 8h-7c-0.5-2-1-4-3-4h-8c-2 0-2.5 2-3 4h-7c-1.1 0-2 0.9-2 2v18c0 1.1 0.9 2 2 2h28c1.1 0 2-0.9 2-2v-18c0-1.1-0.9-2-2-2zM16 27.875c-4.902 0-8.875-3.973-8.875-8.875s3.973-8.875 8.875-8.875c4.902 0 8.875 3.973 8.875 8.875s-3.973 8.875-8.875 8.875zM30 14h-4v-2h4v2z"
  81. ></path>
  82. </figure>
  83. </label>
  84. </image-uploader>
  85. </div>
  86. </div>
  87. </div>
  88. <div v-else class="row" style="text-align:left">
  89. <div class="col-md-6" style="margin-bottom: 1em">
  90. <img :src="menuItem.image" style="height:100px; width:100px; object-fit: cover;" />
  91. <br />
  92. <span class="input-group-text" align="center" style="width:100px" @click="removeImage()">
  93. <eva-icon name="trash-2-outline" fill="#6c757d"></eva-icon>Delete
  94. </span>
  95. </div>
  96. </div>
  97. <div class="row" style="text-align:left" v-if="1 === 2">
  98. <div class="col-md-12" style="margin-bottom: 1em">
  99. <div class="custom-control custom-switch">
  100. <label>Override Options</label>
  101. <input
  102. style="margin-left: 1px"
  103. type="checkbox"
  104. class="custom-control-input"
  105. id="thCloseSwitch"
  106. :checked="menuItem.overrideOptions"
  107. @change="selectionChanged"
  108. />
  109. <label class="custom-control-label" for="thCloseSwitch" style="margin-left: 40px">
  110. {{
  111. menuItem.overrideOptions
  112. ? "Yes - This will override any menu options set on the category"
  113. : "No - This will append category options to the below options"
  114. }}
  115. </label>
  116. </div>
  117. </div>
  118. </div>
  119. <div class="row" style="text-align:left" v-if="1 === 2">
  120. <div class="col-md-12" style="margin-bottomL 1em">
  121. <label>Options</label>
  122. <ListView
  123. :items="menuItem.options"
  124. @onEdit="OptionEdit"
  125. @onDelete="OptionDelete"
  126. @onNew="OptionNew"
  127. />
  128. </div>
  129. </div>
  130. <div class="row"></div>
  131. <div class="row">
  132. <div class="col-md-12" style="margin-bottomL 1em">
  133. <div class="row offset-md-5">
  134. <div class="col-md-2">
  135. <b-button class="mt-2" @click="Save()">Save</b-button>
  136. </div>
  137. <div class="col-md-2">
  138. <b-button class="mt-2" @click="Close()">Close</b-button>
  139. </div>
  140. </div>
  141. </div>
  142. </div>
  143. <div v-if="wait" id="preloader"></div>
  144. </div>
  145. <div v-else class="containers">
  146. <ItemOption @Close="CloseOptions" :menuOption="CurrentOption" />
  147. </div>
  148. </div>
  149. </template>
  150. <script>
  151. import { mapState, mapActions } from "vuex";
  152. import Log from "../../assets/Log";
  153. import ImageUploader from "vue-image-upload-resize";
  154. import ListView from "../shared/listView";
  155. import ItemOption from "./restaurantMenuItemOptions";
  156. export default {
  157. name: "MenuItem",
  158. components: {
  159. ImageUploader,
  160. ListView,
  161. ItemOption,
  162. },
  163. data() {
  164. return {
  165. wait: false,
  166. hasImage: false,
  167. restaurantId: Log.restaurantId(),
  168. showOption: false,
  169. menuOption: {},
  170. };
  171. },
  172. methods: {
  173. ...mapActions("menuCategories", ["getCategories"]),
  174. ...mapActions("menu", ["getMenuItem", "insertMenuItem", "updateMenuItem"]),
  175. Save() {
  176. //this.wait = true;
  177. this.menuItem.restaurantId = this.restaurantId;
  178. if (this.menuItem.category !== "") {
  179. var category = this.categories.find(
  180. (c) => c.description === this.menuItem.category
  181. );
  182. this.menuItem.categoryId = category.id;
  183. }
  184. console.log(JSON.stringify(this.menuItem));
  185. this.insertMenuItem(this.menuItem).then((fulfilled) => {
  186. this.$router.push("/RestaurantMenu");
  187. });
  188. },
  189. Close() {
  190. this.$router.push("/RestaurantMenu");
  191. },
  192. setImage: function (output) {
  193. this.hasImage = true;
  194. this.menuItem.image = output.dataUrl;
  195. },
  196. removeImage() {
  197. this.hasImage = false;
  198. this.menuItem.image = null;
  199. },
  200. selectionChanged() {
  201. this.menuItem.overrideOptions = !this.menuItem.overrideOptions;
  202. },
  203. OptionNew() {
  204. //new
  205. this.menuOption = {};
  206. this.menuOption.options = [];
  207. this.showOption = true;
  208. },
  209. OptionEdit(item) {
  210. //edit
  211. },
  212. OptionDelete(item) {
  213. //delete
  214. },
  215. CloseOptions(item) {
  216. if (item) {
  217. this.showOption = false;
  218. }
  219. },
  220. },
  221. computed: {
  222. ...mapState("menuCategories", ["categories"]),
  223. ...mapState("menu", ["menuItem"]),
  224. CurrentOption() {
  225. return this.menuOption;
  226. },
  227. },
  228. mounted() {
  229. this.wait = true;
  230. this.getCategories(this.restaurantId);
  231. this.getMenuItem(this.$route.params.itemid);
  232. this.wait = false;
  233. },
  234. };
  235. </script>