tabNav.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <view>
  3. <!-- #ifdef MP || APP-PLUS -->
  4. <view style="visibility: hidden;" :style="{ height: navHeight + 'rpx' }" v-if="isFixed"></view>
  5. <!-- #endif -->
  6. <view class="navTabBox tabNav" :class="{isFixed:isFixed}" :style="'background: '+ bgColor +';margin-top:'+mbConfig+'rpx;color:'+txtColor+';top:'+isTop">
  7. <view class="longTab" :style='"width:"+mainWidth+"px"'>
  8. <scroll-view scroll-x="true" style="white-space: nowrap; display: flex;" scroll-with-animation :scroll-left="tabLeft" show-scrollbar="true">
  9. <view class="longItem" :style="'width:'+isWidth+'px;color:' + (index===tabClick ? activeColor : txtColor)" :data-index="index" :class="index===tabClick?'click':''" v-for="(item,index) in tabTitle" :key="index" :id="'id'+index" @click="longClick(index,item.store_category_id,item.pid)">{{item.cate_name}}</view>
  10. <view class="underlineBox" :style='"transform:translateX("+isLeft+"px);width:"+isWidth+"px"'>
  11. <view class="underline" :style="'background-color:'+activeColor"></view>
  12. </view>
  13. </scroll-view>
  14. </view>
  15. <navigator v-if="merId" :url="'/pages/store/home/index?id='+merId+'&type=2'" class="category" hover-class="none" :style="'background-color:'+bgColor+';color:'+txtColor">
  16. <text class="iconfont icon-fenlei3"></text>分类
  17. </navigator>
  18. <navigator v-else open-type='switchTab' url="/pages/goods_cate/goods_cate" class="category" hover-class="none" :style="'background-color:'+bgColor+';color:'+txtColor">
  19. <text class="iconfont icon-fenlei3"></text>分类
  20. </navigator>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. // +----------------------------------------------------------------------
  26. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  27. // +----------------------------------------------------------------------
  28. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  29. // +----------------------------------------------------------------------
  30. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  31. // +----------------------------------------------------------------------
  32. // | Author: CRMEB Team <admin@crmeb.com>
  33. // +----------------------------------------------------------------------
  34. let app = getApp();
  35. export default {
  36. name: 'navTab',
  37. props: {
  38. tabTitle: {
  39. type: Array,
  40. default: []
  41. },
  42. dataConfig: {
  43. type: Object,
  44. default: () => {}
  45. },
  46. isFixed: {
  47. type: Boolean,
  48. default: false
  49. },
  50. merId: {
  51. type: String || Number,
  52. default: ''
  53. }
  54. },
  55. data() {
  56. return {
  57. tabClick: 0, //导航栏被点击
  58. isLeft: 0, //导航栏下划线位置
  59. isWidth: 0, //每个导航栏占位
  60. mainWidth: 0,
  61. tabLeft:0,
  62. swiperIndex:0,
  63. childIndex:0,
  64. childID:0,
  65. bgColor:this.dataConfig.bgColor.color[0].item,
  66. mbConfig:this.dataConfig.mbConfig.val * 2,
  67. txtColor:this.dataConfig.txtColor.color[0].item,
  68. activeColor: this.dataConfig.activeColor.color[0].item,
  69. fixedTop: 0,
  70. isTop: 0,
  71. navHeight: 0,
  72. };
  73. },
  74. created() {
  75. var that = this
  76. // 获取设备宽度
  77. uni.getSystemInfo({
  78. success(e) {
  79. that.mainWidth = e.windowWidth
  80. that.isWidth = (e.windowWidth-65) / 4
  81. }
  82. })
  83. setTimeout((e) => {
  84. const query = uni.createSelectorQuery().in(this);
  85. query.select('.navTabBox').boundingClientRect(data => {
  86. that.navHeight = data.height * 2
  87. that.$emit('bindHeight', data)
  88. }).exec();
  89. }, 200)
  90. // #ifdef MP || APP-PLUS
  91. this.isTop = (uni.getSystemInfoSync().statusBarHeight + 43) + 'px'
  92. // #endif
  93. // #ifdef H5
  94. this.isTop = 0
  95. // #endif
  96. },
  97. methods: {
  98. // 导航栏点击
  99. longClick(index,id,fid){
  100. app.globalData.fid = fid;
  101. this.childIndex = 0;
  102. if(this.tabTitle.length>3){
  103. var tempIndex = index - 2;
  104. tempIndex = tempIndex<=0 ? 0 : tempIndex;
  105. this.tabLeft = (index-2) * this.isWidth //设置下划线位置
  106. }
  107. this.tabClick = index //设置导航点击了哪一个
  108. this.isLeft = index * this.isWidth //设置下划线位置
  109. let obj = {
  110. index:index,
  111. pid:id//自己的id
  112. }
  113. if(!this.merId){
  114. this.parentEmit(obj);
  115. }else{
  116. if(id){
  117. uni.navigateTo({
  118. url: '/pages/store/list/index?id='+id+'&mer_id='+this.merId
  119. });
  120. }else{
  121. uni.navigateTo({
  122. url: '/pages/store/home/index?id='+this.merId
  123. });
  124. }
  125. }
  126. },
  127. parentEmit(obj){
  128. this.$emit('changeTab', obj);
  129. }
  130. }
  131. }
  132. </script>
  133. <style lang="scss">
  134. .tabNav {
  135. padding-top: 10rpx;
  136. }
  137. .navTabBox {
  138. width: 100%;
  139. color: rgba(255, 255, 255, 1);
  140. position: relative;
  141. padding-bottom: 10rpx;
  142. &.isFixed {
  143. z-index: 10;
  144. position: fixed;
  145. left: 0;
  146. width: 100%;
  147. /* #ifdef H5 */
  148. top: 0;
  149. /* #endif */
  150. }
  151. .click {
  152. color: white;
  153. }
  154. .longTab {
  155. .longItem{
  156. height: 50upx;
  157. display: inline-block;
  158. line-height: 50upx;
  159. text-align: center;
  160. font-size: 28rpx;
  161. color: #333333;
  162. max-width: 160rpx;
  163. white-space: nowrap;
  164. overflow: hidden;
  165. text-overflow: ellipsis;
  166. &.click{
  167. font-weight: bold;
  168. font-size: 30rpx;
  169. color: #E93323;
  170. }
  171. }
  172. .underlineBox {
  173. height: 3px;
  174. width: 20%;
  175. display: flex;
  176. align-content: center;
  177. justify-content: center;
  178. transition: .5s;
  179. .underline {
  180. width: 33rpx;
  181. height: 4rpx;
  182. }
  183. }
  184. }
  185. .category{
  186. position: absolute;
  187. right: 0;
  188. top: 10rpx;
  189. /* #ifdef H5 */
  190. width: 132rpx;
  191. /* #endif */
  192. /* #ifdef MP || APP-PLUS */
  193. width: 130rpx;
  194. /* #endif */
  195. height: 50upx;
  196. line-height: 50upx;
  197. z-index: 3;
  198. padding: 0 15rpx 0 25rpx;
  199. .iconfont{
  200. font-size: 30rpx;
  201. margin-right:6rpx;
  202. }
  203. }
  204. }
  205. .child-box{
  206. width: 100%;
  207. position: relative;
  208. // height: 152rpx;
  209. background-color: #fff;
  210. /* #ifdef H5 */
  211. box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.02);
  212. /* #endif */
  213. /* #ifdef MP */
  214. box-shadow: 0 2rpx 3rpx 1rpx #f9f9f9;
  215. /* #endif */
  216. .wrapper{
  217. display: flex;
  218. align-items: center;
  219. padding: 20rpx 0;
  220. background: #fff;
  221. /* #ifdef H5 */
  222. //box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.06);
  223. /* #endif */
  224. }
  225. .child-item{
  226. flex-shrink: 0;
  227. width:140rpx;
  228. display: flex;
  229. flex-direction: column;
  230. align-items: center;
  231. justify-content: center;
  232. margin-left: 10rpx;
  233. image{
  234. width: 90rpx;
  235. height: 90rpx;
  236. border-radius: 50%;
  237. }
  238. .txt{
  239. font-size: 24rpx;
  240. color: #282828;
  241. text-align: center;
  242. margin-top: 10rpx;
  243. }
  244. &.on{
  245. image{
  246. border: 1px solid $theme-color-opacity;
  247. }
  248. .txt{
  249. color: $theme-color;
  250. }
  251. }
  252. }
  253. }
  254. </style>