浏览代码

feat: store省份相关逻辑调整

cuiyalong 1 年之前
父节点
当前提交
5a0dd3d8a3

+ 1 - 1
src/assets/style/vant-custom-class.scss

@@ -22,7 +22,7 @@
 // 竖向的tab切换
 .van-tabs.column {
   display: flex;
-  max-height: 200px;
+  max-height: 300px;
   .van-tabs__nav {
     overflow-x: hidden;
     overflow-y: scroll;

+ 17 - 27
src/components/search/result/list/index.vue

@@ -108,9 +108,9 @@ export default {
       default: ''
     },
     area: {
-      type: Array,
+      type: Object,
       default() {
-        return []
+        return {}
       }
     }
   },
@@ -136,7 +136,7 @@ export default {
     }
   },
   computed: {
-    ...mapGetters('subscribe', ['subscribeArea']),
+    ...mapGetters('subscribe', ['subscribeArea', 'isPay', 'canSelectAreaCount']),
     showLoadingTips() {
       const t = this.listState.hasNextPage && !this.listState.finished
       return t
@@ -159,39 +159,29 @@ export default {
   },
   methods: {
     ...mapActions('subscribe', ['getSubscribeInfo']),
-    doSetArea (a = []) {
-      if (!Array.isArray(a)) {
+    doSetArea (a = {}) {
+      if (!a) {
         return
       }
-      if (a.length <= 0) {
-        return
-      }
-      const areaMap = {}
-      if (a.includes('全国')) {
-        // do nothing
-      } else {
-        a.forEach(item => {
-          areaMap[item] = []
-        })
-      }
+      const areaMap = a
       this.filters.area = areaMap
       this.$refs.filters.setDefaultFilters({
         area: areaMap
       })
     },
     beforeAreaChange(parent, child) {
-      // console.log(parent, child)
       let selectSubscribeArea = true
-      if (parent.value) {
-        // 非全国
-        selectSubscribeArea = this.subscribeArea.includes(parent.value)
-        // (已登陆)点击非订阅区域展示提示弹窗
-        if (!selectSubscribeArea) {
-          this.dialog.freeTip = true
-        }
-      } else {
-        // 全国
-        selectSubscribeArea = this.subscribeArea.includes('全国')
+      // console.log(parent, child)
+      if (this.isPay && this.canSelectAreaCount < 0) {
+        return selectSubscribeArea
+      }
+      const subscribeAreaList = Object.keys(this.subscribeArea)
+      const areaName = child.topName
+
+      selectSubscribeArea = subscribeAreaList.includes(areaName)
+      // (已登陆)点击非订阅区域展示提示弹窗
+      if (!selectSubscribeArea) {
+        this.dialog.freeTip = true
       }
       return selectSubscribeArea
     },

+ 2 - 15
src/pages/tabbar/box/index.vue

@@ -16,7 +16,7 @@
 <script>
 import boxItem from '@/ui/box-item'
 import Taro from "@tarojs/taro";
-import {mapActions, mapGetters, mapState} from "vuex";
+import {mapGetters} from "vuex";
 import adSingle from "@/components/common/Ad.vue";
 import {setTrackLog} from "@/track";
 import {ajaxGetBoxInfo} from "@/api/modules/common";
@@ -27,7 +27,6 @@ export default {
   },
   created () {
     this.$instance = Taro.getCurrentInstance()
-    this.getSubscribeInfo({ force: false })
   },
   onShow () {
     this.getBoxInfo()
@@ -41,22 +40,11 @@ export default {
     ...mapGetters('env', ['miniEnv']),
     ...mapGetters('box', ['list']),
     ...mapGetters('user', ['nowActiveArea']),
-    ...mapState({
-      subscribeInfo: (state) => state.subscribe.subscribeInfo
-    }),
-    areaSelectText() {
-      let tip = this.nowActiveArea
-      const { area } = this.subscribeInfo
-      if (Array.isArray(area) && area.length > 0) {
-        tip = area.join('、')
-      }
-      return tip
-    },
     formatBoxList () {
       const result = this.list.map((v, index) => {
         v.self = v.id === this.miniEnv.appId
         if (index === 0) {
-          v.tip = this.boxInfo?.Data || v.tip.replace('河南省', this.areaSelectText)
+          v.tip = this.boxInfo?.Data
         }
         if (v.self) {
           v.afterTitle = '您当前所在'
@@ -83,7 +71,6 @@ export default {
     }
   },
   methods: {
-    ...mapActions('subscribe', ['getSubscribeInfo']),
     getBoxInfo () {
       ajaxGetBoxInfo({
         Area: this.nowActiveArea

+ 9 - 5
src/pages/tabbar/home/index.vue

@@ -130,14 +130,18 @@ export default {
       return this.nowActiveArea.replace(/市|省/g, '')
     },
     defaultArea() {
-      if (this.subscribeArea.length > 0) {
-        if (this.subscribeArea.includes('全国')) {
-          return []
-        } else {
+      if (this.subscribeArea) {
+        if (Object.keys(this.subscribeArea).length > 0) {
+          // 非全国
           return this.subscribeArea
+        } else {
+          // 全国
+          return {}
         }
       } else {
-        return [this.showArea]
+        return {
+          [this.showArea]: []
+        }
       }
     },
   },

+ 18 - 2
src/store/modules/subscribe.js

@@ -4,7 +4,18 @@ export default {
   state: () => ({
     loaded: false,
     subscribeInfo: {
-      // area: ['河南'], // 订阅的省份
+      // area: { 河南: [] }, // 订阅的省份
+      // area: {
+      //   河南: {
+      //     郑州市: ['金水区'],
+      //     许昌市: []
+      //   },
+      //   北京: {
+      //     北京市: ['东城区']
+      //   },
+      //   澳门: {},
+      //   重庆: {},
+      // },
       // areaCount: 1, // 可选的省份数量,(-1购买了全国 1免费用户或者付费用户购买了1个省)
       // industry: [], // 订阅的业务类型
       // isPay: false, // 是否购买
@@ -40,12 +51,17 @@ export default {
     }
   },
   getters: {
+    // 订阅地区map
     subscribeArea(state) {
-      return state.subscribeInfo.area || []
+      return state.subscribeInfo.area
     },
+    // 可选多少个省份(免费用户为1(配置值)。付费用户为购买的区域数量,-1表示全国。该值任何情况下都不会为0)
     canSelectAreaCount(state) {
       return state.subscribeInfo.areaCount
     },
+    isPay(state) {
+      return state.subscribeInfo.isPay
+    },
     // 免费用户可修改次数
     lastModifyCount(state) {
       return state.subscribeInfo.residueNumber || 0

+ 1 - 1
src/store/modules/user.js

@@ -195,7 +195,7 @@ export default {
       return rootGetters['subscribe/subscribeArea']
     },
     hasArea (state, getters) {
-      if (getters.subscribeArea.length > 0) {
+      if (getters.subscribeArea) {
         return true
       } else {
         return Boolean(state.address.area)

+ 1 - 0
src/ui/drop-filter/index.vue

@@ -43,6 +43,7 @@
               :maxHeight="maxHeight"
               @cancel="onItemCancel(option, index)"
               @confirm="onItemConfirm(option, index)"
+              :class="'drop-filter--tab-content-layout-' + option.key"
             >
               <!-- @component 自定义组件, 自定义插槽提供 $index 索引  -->
               <Component