Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. App.Vue
  2.  
  3. <template>
  4. <v-app>
  5. <v-app-bar app>
  6. <v-toolbar-items>
  7. <v-btn text to="/">Home</v-btn>
  8. <v-btn text to="/about">About</v-btn>
  9. <v-btn text to="/product_list">Product List</v-btn>
  10. <v-btn text to="/stock_inventory">Stock Inventory</v-btn>
  11. </v-toolbar-items>
  12.  
  13. <v-spacer></v-spacer>
  14. <v-toolbar-title class="headline text-uppercase">
  15. <span class="font-weight-light">Vue App</span>
  16. </v-toolbar-title>
  17. </v-app-bar>
  18. <v-content style="margin-top: 10px">
  19. <router-view/>
  20. </v-content>
  21. </v-app>
  22. </template>
  23.  
  24. <script>
  25. import HelloWorld from "./components/HelloWorld";
  26.  
  27. export default {
  28. name: "App",
  29. components: {
  30. HelloWorld
  31. },
  32. data: () => ({})
  33. };
  34. </script>
  35.  
  36.  
  37. ProductList
  38.  
  39. <template>
  40. <div style="margin-left: 10px">
  41. <!-- Los estilos Son temporales -->
  42. <h1>Odoo Product List</h1>
  43.  
  44. <v-alert v-if="errors && errors.length" type="error">
  45. <p v-for="error of errors">{{errors}}</p>
  46. </v-alert>
  47.  
  48. <v-simple-table v-if="products && products.length">
  49. <thead>
  50. <tr>
  51. <th class="text-left">Producto</th>
  52. <th class="text-left">Precio</th>
  53. <th class="text-left">Cantidad</th>
  54. <th class="text-left"></th>
  55. </tr>
  56. </thead>
  57. <tbody>
  58. <tr v-for="(product, index) in products" :key="index">
  59. <td>{{ product.product_id[1] }}</td>
  60. <td>{{ currencyFormat(product)}}</td>
  61. <td>{{product.product_qty}}</td>
  62. <td>
  63. <div class="text-center">
  64. <v-btn text small color="primary" @click="detailDialog(product.id)">
  65. <v-icon>open_in_new</v-icon>
  66. </v-btn>
  67. </div>
  68. </td>
  69. </tr>
  70. </tbody>
  71. </v-simple-table>
  72. </div>
  73. </template>
  74.  
  75.  
  76. <script>
  77. import axios from "axios";
  78. var _ = require("lodash");
  79. export default {
  80. data() {
  81. return {
  82. search: "",
  83. products: [],
  84. errors: [],
  85. stockInventoryId: 0
  86. };
  87. },
  88. watch: {
  89. search: function() {
  90. // this.getResults(this.search); // Nada mas tengo que traer el input dentro de la funcion
  91. // this.debouncedGetAnswer;
  92. }
  93. },
  94. computed: {},
  95. created() {
  96. this.stockInventoryId = this.$route.params.id;
  97. this.productList(this.stockInventoryId);
  98. this.debouncedGetAnswer = this.lodash.debounce(this.getResults, 500);
  99. },
  100. methods: {
  101. detailDialog(id) {
  102. alert(`${id}`);
  103. },
  104. getResults: function(term) {
  105. axios
  106. .get(
  107. `http://192.168.100.59:3000/stock-inventory/stock-details/get-product-by-filters?value=${term}`
  108. )
  109. .then(response => {
  110. this.products = response.data;
  111. })
  112. .catch(e => {
  113. this.errors.push(e);
  114. });
  115. },
  116. productList(stockInventoryId) {
  117. axios
  118. .get(
  119. `http://192.168.100.59:3000/stock-inventory/stock-details?inventory_id=${stockInventoryId}`
  120. )
  121. .then(response => {
  122. this.products = response.data;
  123. })
  124. .catch(e => {
  125. this.errors.push(e);
  126. });
  127. },
  128. // This methods helps to handle the Currency Format in Price List
  129. currencyFormat: function(product) {
  130. return (
  131. "$" +
  132. product.products[0].list_price
  133. .toFixed(2)
  134. .replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
  135. );
  136. }
  137. }
  138. };
  139. </script>
  140.  
  141. StockInventory.Vue
  142.  
  143. <template>
  144. <div>
  145. <v-simple-table>
  146. <tbody>
  147. <tr v-for="(item, index) in stockInventories" :key="index">
  148. <td>{{ item.name }}</td>
  149. <td>{{ item.date }}</td>
  150. <td>{{ item.state}}</td>
  151. <td>
  152. <div class="text-center">
  153. <v-btn text small color="primary" @click="goToStockInventoryDetail(item.id)">
  154. <v-icon>open_in_new</v-icon>
  155. </v-btn>
  156. </div>
  157. </td>
  158. </tr>
  159. </tbody>
  160. </v-simple-table>
  161. </div>
  162. </template>
  163. <script>
  164. import axios from "axios";
  165.  
  166. export default {
  167. data() {
  168. return {
  169. stockInventories: []
  170. };
  171. },
  172. created() {
  173. this.stockInventoryList();
  174. },
  175. methods: {
  176. goToStockInventoryDetail(id) {
  177. this.$router.push({ path: `/product_list/${id}` });
  178. },
  179. stockInventoryList() {
  180. axios
  181. .get(`http://192.168.100.59:3000/stock-inventory?offset=0&limit=10`)
  182. .then(response => {
  183. console.log("This is the response");
  184. this.stockInventories = response.data;
  185. })
  186. .catch(e => {
  187. this.errors.push(e);
  188. });
  189. // .then(response => {
  190. // this.products = response.data;
  191. // })
  192. // .catch(e => {
  193. // this.errors.push(e);
  194. // });
  195. }
  196. }
  197. };
  198. </script>
  199.  
  200. <style lang="stylus"></style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement