Browse Source

[ADD] reactive grid when add a new item in suppliers and products

Gogs 7 years ago
parent
commit
a102aaf450
3 changed files with 36 additions and 4 deletions
  1. 4 4
      src/store/actions.js
  2. 16 0
      src/store/modules/product.js
  3. 16 0
      src/store/modules/supplier.js

+ 4 - 4
src/store/actions.js

@@ -42,7 +42,7 @@ const actions = {
      * @param {*} param0 
      * @param {*} payload 
      */
-    createSupplier({ commit }, payload) {
+    createSupplier({ commit, dispatch }, payload) {
         const data = {
             jsonrpc: '2.0',
             method: 'call',
@@ -52,7 +52,7 @@ const actions = {
         }
 
         return axios.post(createSupplierUrl, data).then(response => {
-            console.log(response)
+            dispatch('addSupplier', response.data.result)
         }).catch(error => {
             console.log(error)
         })
@@ -69,7 +69,7 @@ const actions = {
      * @param {*} param0 
      * @param {*} payload 
      */
-    createProduct({ commit }, payload) {
+    createProduct({ commit, dispatch }, payload) {
         const data = {
             jsonrpc: '2.0',
             method: 'call',
@@ -79,7 +79,7 @@ const actions = {
         }
 
         return axios.post(createProductUrl, data).then(response => {
-            console.log(response)
+            dispatch('addProduct', response.data.result)
         }).catch(error => {
             console.log(error)
         })

+ 16 - 0
src/store/modules/product.js

@@ -84,6 +84,14 @@ const mutations = {
      */
     setShowProductForm(state, payload) {
         state.showProductForm.value = !!payload
+    },
+    /**
+     * 
+     * @param {*} state 
+     * @param {*} payload 
+     */
+    addProduct(state, payload) {
+        state.products.values = [payload, ...state.products.values]
     }
 }
 
@@ -153,6 +161,14 @@ const actions = {
         }
 
         dispatch('hideProductForm')
+    },
+    /**
+     * 
+     * @param {*} param0 
+     * @param {*} payload 
+     */
+    addProduct({ commit }, payload) {
+        commit('addProduct', payload)
     }
 }
 

+ 16 - 0
src/store/modules/supplier.js

@@ -80,6 +80,14 @@ const mutations = {
      */
     setShowSupplierForm(state, payload) {
         state.showSupplierForm.value = !!payload
+    },
+    /**
+     * 
+     * @param {*} state 
+     * @param {*} payload 
+     */
+    addSupplier(state, payload) {
+        state.suppliers.values = [payload, ...state.suppliers.values]
     }
 }
 
@@ -129,6 +137,14 @@ const actions = {
         }
 
         dispatch('hideSupplierForm')
+    },
+    /**
+     * 
+     * @param {*} param0 
+     * @param {*} payload 
+     */
+    addSupplier({ commit }, payload) {
+        commit('addSupplier', payload)
     }
 }