Browse Source

H5-获取酒吧列表优化

panyong 3 năm trước cách đây
mục cha
commit
498639b61f

+ 3 - 0
htmldev/dashboard/src/App.vue

@@ -44,6 +44,9 @@ export default {
       immediate: true
     }
   },
+  async created () {
+    await this.$store.dispatch('common/fetchBarList')
+  },
   mounted () {
     const routeName = this.$route.name
     this.activeTab = ['PlaceList', 'PlaceReserve'].findIndex(item => item === routeName) > -1 ? routeName : ''

+ 40 - 2
htmldev/dashboard/src/store/modules/common.js

@@ -1,6 +1,11 @@
+import { apiBarList } from '../../views/place/list/api'
+import { Toast } from 'vant'
+
 const state = {
   phone: '', // 登录手机号
-  token: '' // APP登录
+  token: '', // APP登录
+  BarList: [], // 所有酒吧列表
+  objCurrentBarInfo: {} // 当前所在酒吧
 }
 
 const getters = {
@@ -9,6 +14,12 @@ const getters = {
   },
   token (state) {
     return state.token
+  },
+  BarList (state) {
+    return state.BarList
+  },
+  objCurrentBarInfo (state) {
+    return state.objCurrentBarInfo
   }
 }
 
@@ -18,6 +29,32 @@ const mutations = {
   },
   UPDATE_TOKEN (state, value) {
     state.token = value
+  },
+  UPDATE_BARLIST (state, value) {
+    state.BarList = value
+  },
+  UPDATE_OBJCURRENTBARINFO (state, value) {
+    state.objCurrentBarInfo = value
+  }
+}
+
+const actions = {
+  async fetchBarList ({ commit }) {
+    try {
+      const { data, status, msg } = await apiBarList()
+      if (status) {
+        if (data.length) {
+          commit('UPDATE_BARLIST', data)
+          commit('UPDATE_OBJCURRENTBARINFO', data[0])
+        } else {
+          Toast('门店不存在')
+        }
+      } else {
+        Toast(msg)
+      }
+    } catch (err) {
+      console.log(err)
+    }
   }
 }
 
@@ -25,5 +62,6 @@ export default {
   namespaced: true,
   state,
   getters,
-  mutations
+  mutations,
+  actions
 }

+ 21 - 29
htmldev/dashboard/src/views/place/list/index.vue

@@ -197,9 +197,10 @@
 
 <script>
 import { Tabs, Tab, Icon, Popup, Field, Toast, Button } from 'vant'
-import { apiBarList, apiPlaceList, apiPlacePreOrder } from './api'
+import { apiPlaceList, apiPlacePreOrder } from './api'
 import { getCookieValue } from '../../../utils'
 import { platform } from '../../../utils/platform'
+import { mapGetters } from 'vuex'
 
 export default {
   name: 'index',
@@ -214,8 +215,6 @@ export default {
   data () {
     return {
       platform: platform,
-      BarList: [], // 门店列表
-      objCurrentBarInfo: {}, // 当前门店信息
       placeList: [],
       objCurrentPlaceInfo: {}, // 当前座位信息
       active: 0,
@@ -232,6 +231,9 @@ export default {
     }
   },
   computed: {
+    ...mapGetters({
+      objCurrentBarInfo: 'common/objCurrentBarInfo'
+    }),
     phone () {
       return this.$store.getters['common/phone'] || getCookieValue('afhousephone')
     },
@@ -239,13 +241,21 @@ export default {
       return this.$store.getters['common/token'] || getCookieValue('afhousetoken')
     }
   },
-  created () {
+  watch: {
+    'objCurrentBarInfo.id': {
+      immediate: true,
+      handler: function () {
+        console.log(111)
+        this.fetchPlaceList()
+      }
+    }
+  },
+  async created () {
     if (platform.isWeixin) {
       this.order_pay_type = 1
     } else if (platform.isAlipay) {
       this.order_pay_type = 2
     }
-    this.fetchBarList()
   },
   async mounted () {
     await this.$nextTick()
@@ -253,34 +263,16 @@ export default {
   },
   methods: {
     handleChange () {},
-    // 获取门店列表
-    async fetchBarList () {
-      try {
-        const { data, status, msg } = await apiBarList()
-        if (status) {
-          this.BarList = data
-          if (this.BarList.length) {
-            // 暂时只有一家门店
-            const { id } = this.BarList[0]
-            this.bar_id = id
-            this.fetchPlaceList()
-          } else {
-            Toast('门店不存在')
-          }
-        } else {
-          Toast(msg)
-        }
-      } catch (err) {
-
-      }
-    },
     // 获取订座列表
     async fetchPlaceList () {
+      const { id } = this.objCurrentBarInfo
+      if (!id) {
+        return
+      }
       try {
-        const { data, status, msg } = await apiPlaceList(this.bar_id)
+        const { data, status, msg } = await apiPlaceList(id)
         if (status) {
-          const { bar, place } = data
-          this.objCurrentBarInfo = bar
+          const { place } = data
           this.placeList = place
         } else {
           Toast(msg)

+ 17 - 29
htmldev/dashboard/src/views/show/plan/index.vue

@@ -48,8 +48,9 @@
 </template>
 
 <script>
+import { mapGetters } from 'vuex'
 import { Tabs, Tab, Toast } from 'vant'
-import { apiBarList, apiShowPlanList } from './api'
+import { apiShowPlanList } from './api'
 import { getCookieValue } from '../../../utils'
 
 export default {
@@ -60,8 +61,6 @@ export default {
   },
   data () {
     return {
-      BarList: [], // 门店列表
-      objCurrentBarInfo: {}, // 当前门店信息
       showPlanList: [],
       active: 0,
       listData: [],
@@ -70,6 +69,9 @@ export default {
     }
   },
   computed: {
+    ...mapGetters({
+      objCurrentBarInfo: 'common/objCurrentBarInfo'
+    }),
     phone () {
       return this.$store.getters['common/phone'] || getCookieValue('afhousephone')
     },
@@ -77,40 +79,26 @@ export default {
       return this.$store.getters['common/token'] || getCookieValue('afhousetoken')
     }
   },
-  created () {
-    this.fetchBarList()
+  watch: {
+    'objCurrentBarInfo.id': {
+      immediate: true,
+      handler: function () {
+        this.fetchShowPlanList()
+      }
+    }
   },
   async mounted () {
     await this.$nextTick()
   },
   methods: {
     handleChange () {},
-    // 获取门店列表
-    async fetchBarList () {
-      try {
-        const { data, status, msg } = await apiBarList()
-        if (status) {
-          this.BarList = data
-          if (this.BarList.length) {
-            // 暂时只有一家门店
-            const { id } = this.BarList[0]
-            this.bar_id = id
-            this.objCurrentBarInfo = this.BarList[0]
-            this.fetchPlaceList()
-          } else {
-            Toast('门店不存在')
-          }
-        } else {
-          Toast(msg)
-        }
-      } catch (err) {
-
+    async fetchShowPlanList () {
+      const { id } = this.objCurrentBarInfo
+      if (!id) {
+        return
       }
-    },
-    // 获取订座列表
-    async fetchPlaceList () {
       try {
-        const { data, status, msg } = await apiShowPlanList(this.bar_id)
+        const { data, status, msg } = await apiShowPlanList(id)
         if (status) {
           this.showPlanList = data
         } else {