Prechádzať zdrojové kódy

管理后台-获取门店列表、商品分类列表、商品附加列表优化

panyong 3 rokov pred
rodič
commit
0c585dc243

+ 40 - 11
htmldev/manage/src/layout/components/Navbar.vue

@@ -7,10 +7,25 @@
     <div class="right-menu">
       <el-dropdown class="avatar-container" trigger="click">
         <div class="avatar-wrapper">
-          <img src="https://pic.rmb.bdstatic.com/bjh/840702eef7eb4f6196853a99323c87cb.png" class="user-avatar">
+          <p>当前所属门店:</p>
           <i class="el-icon-caret-bottom"/>
         </div>
-        <el-dropdown-menu slot="dropdown" class="user-dropdown">
+        <el-dropdown-menu slot="dropdown">
+          <el-dropdown-item
+            v-for="item in outletList"
+            :key="item.id"
+            @click.native="handleSelectOutlet(item)">
+            <span style="display:block;">{{ item.bar_name }}</span>
+          </el-dropdown-item>
+        </el-dropdown-menu>
+      </el-dropdown>
+      <i style="margin-right: 30px;"></i>
+      <el-dropdown class="avatar-container" trigger="click">
+        <div class="avatar-wrapper">
+          <p>{{ name }}</p>
+          <i class="el-icon-caret-bottom"/>
+        </div>
+        <el-dropdown-menu slot="dropdown">
           <router-link to="/">
             <el-dropdown-item>
               主页
@@ -44,7 +59,9 @@ export default {
   computed: {
     ...mapGetters([
       'sidebar',
-      'avatar'
+      'avatar',
+      'name',
+      'outletList'
     ])
   },
   data () {
@@ -54,6 +71,11 @@ export default {
       }
     }
   },
+  created () {
+    this.$store.dispatch('common/fetchOutletList')
+    this.$store.dispatch('common/fetchCategory')
+    this.$store.dispatch('common/fetchGoodsAttr')
+  },
   methods: {
     modPassword () {
       this.modPasswordDialog.show = true
@@ -64,6 +86,20 @@ export default {
     async logout () {
       await this.$store.dispatch('user/logout')
       this.$router.push(`/login`)
+    },
+    // TODO 切换门店接口
+    handleSelectOutlet (item) {
+      this.$confirm('确定要切换门店吗', '确认', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(async () => {
+        const data = await this.$fetch('', { id: item.id }, 'get')
+        if (data.code === 200) {
+          this.$message.success('切换成功成功')
+          this.logout()
+        }
+      }).catch(() => {})
     }
   }
 }
@@ -128,18 +164,11 @@ export default {
         margin-top: 5px;
         position: relative;
 
-        .user-avatar {
-          cursor: pointer;
-          width: 40px;
-          height: 40px;
-          border-radius: 10px;
-        }
-
         .el-icon-caret-bottom {
           cursor: pointer;
           position: absolute;
           right: -20px;
-          top: 25px;
+          top: 20px;
           font-size: 12px;
         }
       }

+ 0 - 1
htmldev/manage/src/mixin/page.js

@@ -31,7 +31,6 @@ export default {
         this.tableData = data.data || data.list
         this.totalCount = Number(data.total)
         if (this.tableUrl === '/v1/user/song/list') {
-          console.log(111)
           this.user_song_name = data.user_song_name
         }
       }

+ 4 - 1
htmldev/manage/src/store/getters.js

@@ -18,6 +18,9 @@ const getters = {
     return state.common.projectArr
   },
   departmentArr: state => state.common.departmentArr,
-  roleArr: state => state.common.roleArr
+  roleArr: state => state.common.roleArr,
+  outletList: state => state.common.outletList,
+  categoryArr: state => state.common.categoryArr,
+  goodsAttrArr: state => state.common.goodsAttrArr
 }
 export default getters

+ 34 - 1
htmldev/manage/src/store/modules/common.js

@@ -4,7 +4,10 @@ import { getToken } from '@/utils/auth'
 const state = {
   projectArr: [],   // 项目
   departmentArr: [],    // 部门
-  roleArr: []   // 角色
+  roleArr: [],   // 角色
+  outletList: [], // 门店列表
+  categoryArr: [], // 商品分类列表
+  goodsAttrArr: [] // 获取规格列表
 }
 
 const mutations = {
@@ -16,6 +19,15 @@ const mutations = {
   },
   SET_ROLEARR: (state, arr) => {
     state.roleArr = arr
+  },
+  SET_OUTLETLIST: (state, val) => {
+    state.outletList = val
+  },
+  SET_CATEGORYARR: (state, val) => {
+    state.categoryArr = val
+  },
+  SET_GOODSATTRARR: (state, val) => {
+    state.goodsAttrArr = val
   }
 }
 
@@ -38,6 +50,27 @@ const actions = {
     if (data.code === 200) {
       commit('SET_ROLEARR', data.data)
     }
+  },
+  // 获取门店列表
+  async fetchOutletList ({ commit }) {
+    const { code, data } = await fetch('/api/admin/v1/bar/list?page=1&page_size=10000', {}, 'get')
+    if (code === 200) {
+      commit('SET_OUTLETLIST', data.list)
+    }
+  },
+  // 获取商品分类列表
+  async fetchCategory ({ commit }) {
+    const { code, data } = await fetch('/v1/bar/product/category/list?page=1&page_size=10000', {}, 'get')
+    if (code === 200) {
+      commit('SET_CATEGORYARR', data.list)
+    }
+  },
+  // 获取规格列表
+  async fetchGoodsAttr ({ commit }) {
+    const { code, data } = await fetch('/v1/bar/product/attach/list?page=1&page_size=10000', {}, 'get')
+    if (code === 200) {
+      commit('SET_GOODSATTRARR', data.list)
+    }
   }
 }
 

+ 1 - 0
htmldev/manage/src/views/business/outlet/list/details.vue

@@ -149,6 +149,7 @@ export default {
           if (data.code === 200) {
             this.$message.success('提交成功')
             this.$emit('success')
+            this.$store.dispatch('common/fetchOutletList')
             this.dialog = false
           }
         }

+ 1 - 0
htmldev/manage/src/views/business/pms/category/details.vue

@@ -79,6 +79,7 @@ export default {
           if (data.code === 200) {
             this.$message.success('提交成功')
             this.$emit('success')
+            this.$store.dispatch('common/fetchCategory')
             this.dialog = false
           }
         }

+ 1 - 0
htmldev/manage/src/views/business/pms/category/index.vue

@@ -103,6 +103,7 @@ export default {
         if (data.code === 200) {
           this.$message.success('删除成功')
           this.init()
+          this.$store.dispatch('common/fetchCategory')
         }
       }).catch(() => {})
     }

+ 10 - 29
htmldev/manage/src/views/business/pms/goods/index.vue

@@ -153,8 +153,8 @@
     <detail v-if="detailsDialog.show"
             v-model="detailsDialog.show"
             :exData="detailsDialog.exData"
-            :categoryData="categoryData"
-            :goodsAttrData="goodsAttrData"
+            :categoryData="categoryArr"
+            :goodsAttrData="goodsAttrArr"
             @success="init"></detail>
   </div>
 </template>
@@ -162,6 +162,7 @@
 <script>
 import page from '@/mixin/page'
 import detail from './details'
+import { mapGetters } from 'vuex'
 
 export default {
   mixins: [page],
@@ -176,11 +177,15 @@ export default {
       },
       searchForm: {},
       tableData: [],
-      tableUrl: '/v1/bar/product/list',
-      categoryData: [],
-      goodsAttrData: []
+      tableUrl: '/v1/bar/product/list'
     }
   },
+  computed: {
+    ...mapGetters([
+      'categoryArr',
+      'goodsAttrArr'
+    ])
+  },
   methods: {
     add () {
       this.detailsDialog.exData = {}
@@ -202,34 +207,10 @@ export default {
           this.init()
         }
       }).catch(() => {})
-    },
-    // todo 优化,放在全局 获取商品分类列表
-    async fetchCategory () {
-      const api = '/v1/bar/product/category/list'
-      const { code, data } = await this.$fetch(api, {
-        page: 1,
-        page_size: 10000
-      }, 'get')
-      if (this.tableData && (data.data || data.list) && code === 200) {
-        this.categoryData = data.data || data.list
-      }
-    },
-    // todo 优化,放在全局 获取规格列表
-    async fetchGoodsAttr () {
-      const api = '/v1/bar/product/attach/list'
-      const { code, data } = await this.$fetch(api, {
-        page: 1,
-        page_size: 10000
-      }, 'get')
-      if (this.tableData && (data.data || data.list) && code === 200) {
-        this.goodsAttrData = data.data || data.list
-      }
     }
   },
   mounted () {
     this.init()
-    this.fetchCategory()
-    this.fetchGoodsAttr()
   }
 }
 </script>

+ 1 - 0
htmldev/manage/src/views/business/pms/goodsAttr/details.vue

@@ -97,6 +97,7 @@ export default {
           if (data.code === 200) {
             this.$message.success('提交成功')
             this.$emit('success')
+            this.$store.dispatch('common/fetchGoodsAttr')
             this.dialog = false
           }
         }

+ 1 - 0
htmldev/manage/src/views/business/pms/goodsAttr/index.vue

@@ -99,6 +99,7 @@ export default {
         if (data.code === 200) {
           this.$message.success('删除成功')
           this.init()
+          this.$store.dispatch('common/fetchGoodsAttr')
         }
       }).catch(() => {})
     }