DetailHeader.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <!-- DetailHeader.vue -->
  2. <template>
  3. <view class="div ui-detail-header-wrapper">
  4. <title-header />
  5. <view class="div ui-detail-header">
  6. <text class="span iconfont" @click="goBack()">&#xe6ee;</text>
  7. <!-- <view class="div navbar-wrapper">
  8. <view class="div"
  9. v-for="(item, key) in data"
  10. :key="key"
  11. v-bind:class="{ navbar_active: key == index }"
  12. v-on:click="changeEvent(key)"
  13. >
  14. {{ item.name }}
  15. </view>
  16. </view> -->
  17. <view class="div navbar-wrapper">
  18. <view class="div" :class="{'navbar_active':navbaractive ==1}"><text @click="goanchor('#goods-swipe')">商品</text></view>
  19. <view class="div" :class="{'navbar_active':navbaractive ==2}"><text @click="goanchor('#review')">评论</text></view>
  20. <view class="div" :class="{'navbar_active':navbaractive ==3}"><text @click="goanchor('#mbBody')">详情</text></view>
  21. </view>
  22. <text class="span iconfont right" @click="popupMore">&#xe680;<view v-if="showDot" class="div dot"></view></text>
  23. </view>
  24. <header-more v-if="share_info" :goods_id="goods_id" :share_info="share_info" v-show="popupVisible" :showDot="showDot"></header-more>
  25. </view>
  26. </template>
  27. <script>
  28. import TitleHeader from '../../TitleHeader'
  29. import { header } from './static'
  30. import { getChatCount } from '../../../api/memberInstantMessage'
  31. import { mapState, mapMutations } from 'vuex'
  32. import HeaderMore from '../../HeaderMore'
  33. import { env } from '@/static/config'
  34. import { urlencode } from '@/util/common'
  35. export default {
  36. data () {
  37. return {
  38. navHeight: 0,
  39. currentUrl:'',
  40. data: header,
  41. popupVisible: false,
  42. showDot:false,
  43. navbaractive:1,
  44. }
  45. },
  46. props:['mbBodytop','reviewtop'],
  47. components: {
  48. HeaderMore,
  49. TitleHeader
  50. },
  51. computed: {
  52. ...mapState({
  53. detailInfo: state => state.goodsdetail.detailInfo,
  54. goods_id: state => state.goodsdetail.currentProductId,
  55. index: state => state.goodsdetail.index,
  56. isOnline:state => state.member.isOnline,
  57. }),
  58. share_info: function () {
  59. return this.detailInfo?{ title: this.detailInfo.goods_name, link: this.currentUrl, imgUrl: this.detailInfo.photos[0], desc: this.detailInfo.goods_advword }:false
  60. },
  61. listenChange(){
  62. let mbBodytop = this.mbBodytop
  63. let reviewtop = this.reviewtop
  64. return { mbBodytop, reviewtop}
  65. }
  66. },
  67. mounted () {
  68. // #ifdef MP-WEIXIN
  69. this.navHeight = uni.getMenuButtonBoundingClientRect().top
  70. // #endif
  71. var pages = getCurrentPages()
  72. var page = pages[pages.length - 1]
  73. this.currentUrl=env.H5_HOST + page.route+(page.options?('?'+urlencode(page.options)):'')
  74. this.changeIndex(0)
  75. this.saveNumber(1)
  76. if(this.isOnline){
  77. getChatCount().then(res=>{
  78. if(res.result){
  79. if(!this.showDot){
  80. this.showDot={}
  81. }
  82. this.showDot['chat']=true
  83. }
  84. })
  85. }
  86. },
  87. methods: {
  88. ...mapMutations({
  89. changeIndex: 'changeIndex',
  90. saveNumber: 'saveNumber'
  91. }),
  92. popupMore () {
  93. if (!this.popupVisible) {
  94. this.popupVisible = true
  95. } else {
  96. this.popupVisible = false
  97. }
  98. },
  99. changeEvent (index) {
  100. this.changeIndex(index)
  101. },
  102. goanchor(id){
  103. document.querySelector(id).scrollIntoView({
  104. behavior:"smooth"
  105. });
  106. },
  107. goBack () {
  108. uni.navigateBack({delta:1})
  109. }
  110. },
  111. watch:{
  112. listenChange(val){
  113. val.mbBodytop = val.mbBodytop - 100
  114. val.reviewtop = val.reviewtop - 100
  115. if(val.mbBodytop > 0 && val.reviewtop >0){
  116. this.navbaractive = 1
  117. }else if(val.reviewtop < 0 && val.mbBodytop > 0){
  118. this.navbaractive = 2
  119. }else if(val.reviewtop < 0 && val.mbBodytop < 0){
  120. this.navbaractive = 3
  121. }
  122. }
  123. }
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. .ui-detail-header-wrapper{
  128. position: fixed;
  129. top:0;
  130. padding-top: var(--status-bar-height);
  131. background: rgba(255, 255, 255, 1);
  132. left: 0;
  133. right: 0;
  134. z-index: 10;
  135. }
  136. .dot{position:absolute;width:.5rem;height:.5rem;background:red;border-radius:50%;top:.2rem;right:0;}
  137. .ui-detail-header {
  138. padding: 0 0.45rem;
  139. // height:3.2rem;
  140. color: #55595f;
  141. font-size:$h2;
  142. width: auto;
  143. display: flex;
  144. justify-content: center;
  145. align-content: center;
  146. align-items: center;
  147. flex-basis: auto;
  148. .iconfont {
  149. width: 1.2rem;
  150. font-size:$h2;
  151. height: $headerHeight;
  152. line-height:$headerHeight;
  153. cursor: pointer;
  154. position: absolute;
  155. left: 0.45rem;
  156. bottom: 0;
  157. }
  158. .iconfont.right{left:auto;right:0.45rem}
  159. .div.navbar-wrapper {
  160. line-height: $headerHeight;
  161. height: $headerHeight;
  162. .div {
  163. // line-height: 2.1rem;
  164. border-bottom: 0;
  165. display: inline-block;
  166. margin-right:2.4rem;
  167. color: #55595f;
  168. background-color: #fff;
  169. position: relative;
  170. &.navbar_active {
  171. color: $primaryColor;
  172. &::after{content:'';display: block;height: .1rem;width: 1rem;position: absolute;bottom:0;left:50%;margin-left:-.5rem;background: $primaryColor}
  173. }
  174. &:last-child {
  175. margin-right: 0;
  176. }
  177. &:focus {
  178. outline: none;
  179. }
  180. }
  181. }
  182. }
  183. </style>