Parcourir la source

fix: 大会员自定义分析报告新增锚点跳转功能

cuiyalong il y a 3 ans
Parent
commit
25e8323c08

+ 34 - 0
src/jfw/modules/app/src/web/staticres/jyapp/big-member/css/report_analysis.css

@@ -254,6 +254,9 @@
   display: none;
 }
 
+.search-result {
+  position: relative;
+}
 .search-result .filters-list .van-cell__title {
   color: #161826;
   font-size: .4rem;
@@ -277,6 +280,32 @@
   padding: .12rem 0;
 }
 
+.fixed-bottom-right {
+  position: absolute;
+  bottom: 15%;
+  right: .32rem;
+}
+.scroll-to-top {
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  width: .8rem;
+  height: .8rem;
+  font-size: .4rem;
+  border-radius: 50%;
+  background-color: #fff;
+  box-shadow: rgb(54,147,79,20%) 0 0 30px 5px;
+}
+
+.section-sticky {
+  width: 100%;
+}
+.van-sticky {
+  padding: 0 .32rem;
+  width: 100%;
+  background-color: #fff;
+}
+
 .section .section-tip-text {
   font-size: .22rem;
   line-height: .3rem;
@@ -288,6 +317,11 @@
   display: flex;
   flex-direction: column;
   align-items: center;
+  width: 100%;
+  height: 2.4rem;
+}
+.search-result .dimension > div {
+  width: 100%;
 }
 .search-result .dimension .section-title {
   font-size: .28rem;

+ 88 - 7
src/jfw/modules/app/src/web/staticres/jyapp/big-member/js/report_analysis.js

@@ -93,16 +93,19 @@ var vm = new Vue({
       {
         id: 'market',
         name: '市场规模',
+        top: 0,
         anchor: 'market-overview'
       },
       {
         id: 'buyer',
         name: '采购单位',
+        top: 0,
         anchor: 'buyerclass-scatter'
       },
       {
         id: 'bidder',
         name: '中标单位',
+        top: 0,
         anchor: 'winner-scatter'
       },
     ],
@@ -226,10 +229,18 @@ var vm = new Vue({
         projectAmountTop3: null
       }
     },
+    stickyOffset: 0,
     notSetKey: false, // 未设置关键词
     isSubCount: false // 是否子账号
   },
   computed: {
+    anchorTopList: function () {
+      var arr = []
+      this.dimensionList.forEach(function (item) {
+        arr.push(item.top)
+      })
+      return arr
+    },
     // 报告详情筛选条件只有一个省份
     // 此时不显示地区分布chart
     oneAreaFilter () {
@@ -270,6 +281,13 @@ var vm = new Vue({
       return total
     }
   },
+  watch: {
+    filtersPageShow (newVal) {
+      if (!newVal) {
+        this.calcStickyOffset()
+      }
+    }
+  },
   created () {
     this.calcLastTimeText()
     this.getPower()
@@ -288,6 +306,7 @@ var vm = new Vue({
         }
       }
     }, 0)
+    this.addEventListeners()
     utils.iosBackRefresh()
   },
   methods: {
@@ -320,6 +339,66 @@ var vm = new Vue({
       }
       return this.$dialog.confirm(defaultConf)
     },
+    calcOffsetTop: function () {
+      this.dimensionList.forEach(function (item) {
+        var anchor = $('.' + item.anchor)
+        var offsetTop = 0
+        if (anchor.length) {
+          offsetTop = parseInt(anchor.offset().top)
+        }
+        item.top = offsetTop
+      })
+    },
+    addEventListeners: function () {
+      this.scrollToTop()
+    },
+    scrollToTop: function () {
+      var $scrollDOM = $('.j-container.search-result > .j-main')
+      // 1. 检查当前高度是否满足显示快速滚动到顶部
+      this.checkScrollTopButtonShow()
+      // 2. 具体逻辑
+      $scrollDOM.on('scroll', this.checkScrollTopButtonShow)
+      setTimeout(function () {
+        // 5s后绑定(尽可能保证top能够被计算完)
+        $scrollDOM.on('scroll', this.checkAnchorItemActive)
+      }.bind(this), 2000)
+
+      $('.scroll-to-top').on('click', function () {
+        $scrollDOM.animate({ scrollTop: 0 })
+      })
+    },
+    checkAnchorItemActive: function () {
+      var $scrollDOM = $('.j-container.search-result > .j-main')
+      var anchorTopList = this.anchorTopList
+      var scrollTop = $scrollDOM.scrollTop()
+      var i = 0
+      if (scrollTop > anchorTopList[1] && scrollTop <= anchorTopList[2]) {
+        i = 1
+      } else if (scrollTop >= anchorTopList[2]) {
+        i = 2
+      } else {
+        i = 0
+      }
+      this.activeDimension = this.dimensionList[i].id
+    },
+    checkScrollTopButtonShow: function () {
+      var showButtonHeight = 300
+      var $scrollDOM = $('.j-container.search-result > .j-main')
+      var button = $('.scroll-to-top')
+      var scrollTop = $scrollDOM.scrollTop()
+      if (scrollTop > showButtonHeight) {
+        button.show()
+      } else {
+        button.hide()
+      }
+    },
+    calcStickyOffset: function () {
+      setTimeout(function () {
+        var headerHeight = $('.jy-app-header')[0].clientHeight
+        var tabHeight = $('.analysis-tab')[0].clientHeight
+        this.stickyOffset = headerHeight + tabHeight - 5
+      }.bind(this), 0)
+    },
     setScrollTop: function (scrollTop) {
       this.$nextTick(function () {
         var wrapper = document.querySelector('.j-container.search-result > .j-main')
@@ -738,6 +817,8 @@ var vm = new Vue({
         // 中标单位分析
         this.sortWinnerData(data)
       }
+
+      this.$nextTick(this.calcOffsetTop)
     },
     formatSelectTime (value) {
       if (!value) return '-'
@@ -1335,7 +1416,7 @@ var vm = new Vue({
       if (Array.isArray(countTop3)) {
         countTop3.forEach((item, index) => {
           item.name = item.name
-          item.subInfo1 = `项目金额:${item.total}个`
+          item.subInfo1 = `项目数量:${item.total}个`
           item.subInfo2 = item.prop ? `全部占比:${utils.formatMoney(item.prop * 100, undefined, true)}%` : 0
           item.actionText = `中标单位 TOP3`
           item.childrenShow = true
@@ -1623,14 +1704,14 @@ var vm = new Vue({
       }
     },
     anchorTo (item) {
-      if (!item.anchor) return
-      var anchor = item.anchor
-      var offset = $('.' + anchor).offset()
+      if (!item.top) return
+      var offsetTop = item.top || 0
       var headerHeight = $('.jy-app-header')[0].clientHeight
       var tabHeight = $('#analysis .van-tabs')[0].clientHeight
-      if (offset) {
-        $('.search-result > .j-main').animate({ scrollTop: offset.top - headerHeight - tabHeight })
-      }
+      var stickyHeight = $('.dimension-list')[0].clientHeight
+      var sTop = offsetTop - headerHeight - tabHeight - stickyHeight
+      this.activeDimension = item.id
+      $('.search-result > .j-main').animate({ scrollTop: sTop })
     },
     showSetKeyTip: function () {
       this.notSetKey = true

+ 3 - 1
src/jfw/modules/app/src/web/staticres/jyapp/js/historypush.js

@@ -643,7 +643,9 @@ var vm = new Vue({
         var count = data.count
         this.selectAreaList = areaCityRes
         if (!areaCityRes || Object.keys(areaCityRes).length === 0) {
-
+          this.area = ''
+          this.city = ''
+          $('.areaText').html('地区')
         } else {
           var obj = {
             p: [], // 省份全选

+ 12 - 6
src/jfw/modules/app/src/web/templates/big-member/page_report_analysis.html

@@ -27,6 +27,7 @@
     <div class="j-main" id="analysis" v-cloak>
         <div class="j-container">
             <van-tabs
+                class="analysis-tab"
                 :title-active-color="tabConf.titleActiveColor"
                 :title-inactive-color="tabConf.titleInactiveColor"
                 :line-width="tabConf.lineWidth"
@@ -78,8 +79,9 @@
                         </van-cell-group>
                         <div class="height8" v-show="false"></div>
                         <section class="section bg-white pd-16 dimension">
-                                <div class="section-title"> - 分析维度 -</div>
-                                <div class="section-content dimension-list">
+                            <div class="section-title"> - 分析维度 -</div>
+                            <van-sticky class="section-sticky" z-index="99999999" :offset-top="stickyOffset">
+                                <div class="section-content dimension-list bg-white">
                                     <div
                                         class="j-button j-button-item dimension-item"
                                         v-for="(item, index) in dimensionList"
@@ -89,10 +91,11 @@
                                         @click="anchorTo(item)"
                                     ></div>
                                 </div>
-                                <div class="section-footer section-tip-text">
-                                    <span>数据统计范围:</span>
-                                    <span v-text="formatSelectTime(reportFilters.selectTime)"></span>
-                                </div>
+                            </van-sticky>
+                            <div class="section-footer section-tip-text">
+                                <span>数据统计范围:</span>
+                                <span v-text="formatSelectTime(reportFilters.selectTime)"></span>
+                            </div>
                         </section>
                         <!-- 市场概况 -->
                         <section class="section bg-white market-overview">
@@ -300,6 +303,9 @@
                             </div>
                         </div>
                     </div>
+                    <div class="fixed-bottom-right clickable scroll-to-top" style="display: none;">
+                        <van-icon name="arrow-up"></van-icon>
+                    </div>
                 </div>
             </section>
         </div>

+ 3 - 1
src/web/staticres/vipsubscribe/js/historypush.js

@@ -418,7 +418,9 @@ var vm = new Vue({
         var count = data.count
         this.selectAreaList = areaCityRes
         if (!areaCityRes || Object.keys(areaCityRes).length === 0) {
-          
+          this.area = ''
+          this.city = ''
+          $('.areaText').html('地区')
         } else {
           var obj = {
             p: [], // 省份全选