123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <template>
- <view class="navTabBox">
- <view class="longTab">
- <scroll-view scroll-x="true" style="white-space: nowrap; display: flex;" scroll-with-animation :scroll-left="tabLeft" show-scrollbar="true">
- <view
- class="longItem" :style='"width:"+isWidth+"px"'
- :data-index="index"
- :class="index===tabClick?'click':''"
- v-for="(item,index) in tabTitle"
- :key="index" :id="'id'+index"
- @click="longClick(tabClick,index)">
- <view>{{item.title}}</view>
- <!-- <view class="tab">{{item.content}}</view> -->
- <!-- <view class="lines"></view> -->
- </view>
-
- <view class="underlineBox" :style='"transform:translateX("+isLeft+"px);width:"+isWidth+"px"'>
- <view class="underline"></view>
- </view>
- </scroll-view>
- </view>
- <!--
- <view class="child-box" v-if="tabClick>0 && tabTitle[tabClick].children.length>0">
- <scroll-view scroll-x="true" style="white-space: nowrap; display: flex;align-items: center; height: 100%;" scroll-with-animation :scroll-left="tabLeft" show-scrollbar="false">
- <view class="wrapper">
- <view v-for="(item,index) in tabTitle[tabClick].children" class="child-item" :class="{on:index == childIndex}" @click="childTab(tabClick,index)">
- <image :src="item.pic" mode=""></image>
- <view class="txt">{{item.cate_name}}</view>
- </view>
- </view>
- </scroll-view>
- </view>-->
- </view>
- </template>
- <script>
- export default {
- name: 'navTab',
- props: {
- tabTitle: {
- type: Array,
- default: []
- }
- },
- data() {
- return {
- tabClick: 0, //导航栏被点击
- isLeft: 0, //导航栏下划线位置
- isWidth: 0, //每个导航栏占位
- tabLeft:0,
- swiperIndex:0,
- childIndex:0,
- childID:0
- };
- },
- created() {
-
- var that = this
- // 获取设备宽度
- uni.getSystemInfo({
- success(e) {
- that.isWidth = e.windowWidth /4
- }
- })
- },
- methods: {
- // 导航栏点击
- longClick(tabClick,index){
- this.childIndex = 0;
- if(this.tabTitle.length>5){
- var tempIndex = index - 2;
- tempIndex = tempIndex<=0 ? 0 : tempIndex;
- this.tabLeft = (index-2) * this.isWidth //设置下划线位置
- }
- this.tabClick = index //设置导航点击了哪一个
- this.isLeft = index * this.isWidth //设置下划线位置
- let obj = {
- type:'big', //大标题
- index:index
- }
- this.childTab(tabClick,index)
- //this.parentEmit(obj)
- // this.$parent.currentTab = index //设置swiper的第几页
- },
- // 导航子类点击
- childTab(tabClick,index){
- this.childIndex = index
- let obj = {
- parentIndex:tabClick,
- childIndex:index,
- type:'small' //小标题
- }
- this.parentEmit(obj)
- },
- parentEmit(data){
- this.$emit('changeTab', data);
- }
- }
- }
- </script>
- <style lang="scss">
- .navTabBox {
- width: 100%;
- color: #333333;
- .tab{
- width: 80%;
- overflow: hidden;
- margin: 0rpx auto;
- text-align: center;
- color: #b1b1b1;
- font-size: 26rpx;
- line-height: 44rpx;
- border-radius: 22rpx;
- }
- .click {
- color: #E83323;
- .tab{
- overflow: hidden;
- text-align: center;
- background: #E83323;
- line-height: 44rpx;
- border-radius: 22rpx;
- color: #fff;
- }
- }
- .longTab {
- width: 100%;
- padding-top: 12rpx;
- padding-bottom: 0rpx;
- background-color: #fff;
- // .longItem:nth-child(5){
- // margin-left: 30rpx;
- // }
- // .longItem:nth-child(6){
- // margin-left: 30rpx;
- // }
- .longItem{
- height: 77upx;
- display: inline-block;
- line-height: 77upx;
- text-align: center;
- font-size: 30rpx;
- position: relative;
-
- .lines{
- position: absolute;
- width: 2rpx;
- height: 60rpx;
- right: 2rpx;
- top: 18rpx;
- background: #333;
-
- }
- &.click{
-
- }
- }
- .underlineBox {
- height: 3px;
- width: 30%;
- display: flex;
- align-content: center;
- justify-content: center;
- transition: .5s;
- .underline {
- width: 33rpx;
- height: 4rpx;
- background-color: #E83323;
- }
- }
- // scroll-view ::-webkit-scrollbar {
- // width: 0;
- // height: 0;
- // background-color: transparent;
- // }
- }
- }
-
- .child-box{
- width: 100%;
- position: relative;
- // height: 152rpx;
- background-color: #fff;
- /* #ifdef H5 */
- box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.02);
- /* #endif */
- /* #ifdef MP */
- box-shadow: 0 2rpx 3rpx 1rpx #f9f9f9;
- /* #endif */
-
- .wrapper{
- display: flex;
- align-items: center;
- padding: 20rpx 0;
- background: #fff;
- /* #ifdef H5 */
- //box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.06);
- /* #endif */
- }
- .child-item{
- flex-shrink: 0;
- width:140rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- margin-left: 10rpx;
- image{
- width: 90rpx;
- height: 90rpx;
- border-radius: 50%;
- }
- .txt{
- font-size: 24rpx;
- color: #282828;
- text-align: center;
- margin-top: 10rpx;
- }
- &.on{
- image{
- border: 1px solid #e2e2e2;
- }
- .txt{
- color: #333;
- }
- }
- }
- }
- </style>
|