tabNav.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view class="navTabBox">
  3. <view class="longTab">
  4. <scroll-view scroll-x="true" style="white-space: nowrap; display: flex;" scroll-with-animation :scroll-left="tabLeft" show-scrollbar="true">
  5. <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(index,item.store_category_id,item.pid)">{{item.cate_name}}</view>
  6. <view class="underlineBox" :style='"transform:translateX("+isLeft+"px);width:"+isWidth+"px"'>
  7. <view class="underline bg-color-red"></view>
  8. </view>
  9. </scroll-view>
  10. </view>
  11. <!-- <view class="child-box" v-if="tabClick>0 && tabTitle[tabClick].children.length>0">
  12. <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">
  13. <view class="wrapper">
  14. <view v-for="(item,index) in tabTitle[tabClick].children" class="child-item" :class="{on:index == childIndex}" @click="childTab(tabClick,index)">
  15. <image :src="item.pic" mode=""></image>
  16. <view class="txt">{{item.cate_name}}</view>
  17. </view>
  18. </view>
  19. </scroll-view>
  20. </view> -->
  21. </view>
  22. </template>
  23. <script>
  24. let app = getApp();
  25. export default {
  26. name: 'navTab',
  27. props: {
  28. tabTitle: {
  29. type: Array,
  30. default: []
  31. }
  32. },
  33. data() {
  34. return {
  35. tabClick: 0, //导航栏被点击
  36. isLeft: 0, //导航栏下划线位置
  37. isWidth: 0, //每个导航栏占位
  38. tabLeft:0,
  39. swiperIndex:0,
  40. childIndex:0,
  41. childID:0
  42. };
  43. },
  44. created() {
  45. var that = this
  46. // 获取设备宽度
  47. uni.getSystemInfo({
  48. success(e) {
  49. that.isWidth = e.windowWidth / 5
  50. }
  51. })
  52. },
  53. methods: {
  54. // 导航栏点击
  55. longClick(index,id,fid){
  56. app.globalData.fid = fid;
  57. this.childIndex = 0;
  58. if(this.tabTitle.length>5){
  59. var tempIndex = index - 2;
  60. tempIndex = tempIndex<=0 ? 0 : tempIndex;
  61. this.tabLeft = (index-2) * this.isWidth //设置下划线位置
  62. }
  63. this.tabClick = index //设置导航点击了哪一个
  64. this.isLeft = index * this.isWidth //设置下划线位置
  65. // let obj = {
  66. // type:'big', //大标题
  67. // index:index
  68. // }
  69. let obj = {
  70. index:index,
  71. pid:id//自己的id
  72. }
  73. this.parentEmit(obj);
  74. // this.$parent.currentTab = index //设置swiper的第几页
  75. },
  76. // 导航子类点击
  77. // childTab(tabClick,index){
  78. // this.childIndex = index
  79. // let obj = {
  80. // parentIndex:tabClick,
  81. // childIndex:index,
  82. // type:'small' //小标题
  83. // }
  84. // this.parentEmit(obj)
  85. // }
  86. parentEmit(obj){
  87. this.$emit('changeTab', obj);
  88. }
  89. }
  90. }
  91. </script>
  92. <style lang="scss">
  93. .navTabBox {
  94. width: 100%;
  95. color: rgba(255, 255, 255, 1);
  96. .click {
  97. color: white;
  98. }
  99. .longTab {
  100. width: 100%;
  101. /* #ifdef H5 */
  102. padding-bottom: 20rpx;
  103. /* #endif */
  104. /* #ifdef MP */
  105. padding-top: 12rpx;
  106. padding-bottom: 12rpx;
  107. /* #endif */
  108. .longItem{
  109. height: 50upx;
  110. display: inline-block;
  111. line-height: 50upx;
  112. text-align: center;
  113. font-size: 28rpx;
  114. color: #333333;
  115. max-width: 160rpx;
  116. white-space: nowrap;
  117. overflow: hidden;
  118. text-overflow: ellipsis;
  119. &.click{
  120. font-weight: bold;
  121. font-size: 30rpx;
  122. color: #E93323;
  123. }
  124. }
  125. .underlineBox {
  126. height: 3px;
  127. width: 20%;
  128. display: flex;
  129. align-content: center;
  130. justify-content: center;
  131. transition: .5s;
  132. .underline {
  133. width: 33rpx;
  134. height: 4rpx;
  135. }
  136. }
  137. }
  138. }
  139. .child-box{
  140. width: 100%;
  141. position: relative;
  142. // height: 152rpx;
  143. background-color: #fff;
  144. /* #ifdef H5 */
  145. box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.02);
  146. /* #endif */
  147. /* #ifdef MP */
  148. box-shadow: 0 2rpx 3rpx 1rpx #f9f9f9;
  149. /* #endif */
  150. .wrapper{
  151. display: flex;
  152. align-items: center;
  153. padding: 20rpx 0;
  154. background: #fff;
  155. /* #ifdef H5 */
  156. //box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.06);
  157. /* #endif */
  158. }
  159. .child-item{
  160. flex-shrink: 0;
  161. width:140rpx;
  162. display: flex;
  163. flex-direction: column;
  164. align-items: center;
  165. justify-content: center;
  166. margin-left: 10rpx;
  167. image{
  168. width: 90rpx;
  169. height: 90rpx;
  170. border-radius: 50%;
  171. }
  172. .txt{
  173. font-size: 24rpx;
  174. color: #282828;
  175. text-align: center;
  176. margin-top: 10rpx;
  177. }
  178. &.on{
  179. image{
  180. border: 1px solid $theme-color-opacity;
  181. }
  182. .txt{
  183. color: $theme-color;
  184. }
  185. }
  186. }
  187. }
  188. </style>