DetailHeader.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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:['navid'],
  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. },
  62. mounted () {
  63. // #ifdef MP-WEIXIN
  64. this.navHeight = uni.getMenuButtonBoundingClientRect().height
  65. // #endif
  66. var pages = getCurrentPages()
  67. var page = pages[pages.length - 1]
  68. this.currentUrl=env.H5_HOST + page.route+(page.options?('?'+urlencode(page.options)):'')
  69. this.changeIndex(0)
  70. this.saveNumber(1)
  71. if(this.isOnline){
  72. getChatCount().then(res=>{
  73. if(res.result){
  74. if(!this.showDot){
  75. this.showDot={}
  76. }
  77. this.showDot['chat']=true
  78. }
  79. })
  80. }
  81. },
  82. methods: {
  83. ...mapMutations({
  84. changeIndex: 'changeIndex',
  85. saveNumber: 'saveNumber'
  86. }),
  87. popupMore () {
  88. if (!this.popupVisible) {
  89. this.popupVisible = true
  90. } else {
  91. this.popupVisible = false
  92. }
  93. },
  94. changeEvent (index) {
  95. this.changeIndex(index)
  96. },
  97. goanchor(id){
  98. if(id == '#goods-swipe'){
  99. this.navbaractive = 1
  100. }else if(id == '#review'){
  101. this.navbaractive = 2
  102. }else if(id == '#mbBody'){
  103. this.navbaractive = 3
  104. }
  105. this.$emit('setnav',id);
  106. },
  107. goBack () {
  108. uni.navigateBack({delta:1})
  109. }
  110. },
  111. watch:{
  112. navid: {
  113. handler (newName, oldName) {
  114. this.navbaractive = newName
  115. },
  116. immediate: true
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .ui-detail-header-wrapper{
  123. position: fixed;
  124. top:0;
  125. padding-top: var(--status-bar-height);
  126. background: rgba(255, 255, 255, 1);
  127. left: 0;
  128. right: 0;
  129. z-index: 10;
  130. }
  131. .dot{position:absolute;width:.5rem;height:.5rem;background:red;border-radius:50%;top:.2rem;right:0;}
  132. .ui-detail-header {
  133. padding: 0 0.45rem;
  134. // height:3.2rem;
  135. color: #55595f;
  136. font-size:$h2;
  137. width: auto;
  138. display: flex;
  139. justify-content: center;
  140. align-content: center;
  141. align-items: center;
  142. flex-basis: auto;
  143. .iconfont {
  144. width: 1.2rem;
  145. font-size:$h2;
  146. height: $headerHeight;
  147. line-height:$headerHeight;
  148. cursor: pointer;
  149. position: absolute;
  150. left: 0.45rem;
  151. bottom: 0;
  152. }
  153. .iconfont.right{left:auto;right:0.45rem}
  154. .div.navbar-wrapper {
  155. line-height: $headerHeight;
  156. height: $headerHeight;
  157. .div {
  158. // line-height: 2.1rem;
  159. border-bottom: 0;
  160. display: inline-block;
  161. margin-right:2.4rem;
  162. color: #55595f;
  163. background-color: #fff;
  164. position: relative;
  165. &.navbar_active {
  166. color: $primaryColor;
  167. &::after{content:'';display: block;height: .1rem;width: 1rem;position: absolute;bottom:0;left:50%;margin-left:-.5rem;background: $primaryColor}
  168. }
  169. &:last-child {
  170. margin-right: 0;
  171. }
  172. &:focus {
  173. outline: none;
  174. }
  175. }
  176. }
  177. }
  178. </style>