index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <template>
  2. <view :style="viewColor">
  3. <view class="navTabBox">
  4. <view class="longTab">
  5. <scroll-view scroll-x="true" style="white-space: nowrap; display: flex;height: 60rpx;" scroll-with-animation :scroll-left="tabLeft"
  6. show-scrollbar="true">
  7. <view class="longItem" :style='"width:"+isWidth+"px"' :data-index="index" :class="index===tabClick?'click':''"
  8. v-for="(item,index) in tabTitle" :key="index" :id="'id'+index" @click="longClick(index,item.store_category_id)">{{item.cate_name}}
  9. </view>
  10. <view class="underlineBox" :style='"transform:translateX("+isLeft+"px);width:"+isWidth+"px"'>
  11. <view class="underline bg-color-white"></view>
  12. </view>
  13. </scroll-view>
  14. <view class='iconfont icon-xiangxia' style="padding: 8rpx 0 0 8rpx;" @click="tabsOpen = true"></view>
  15. </view>
  16. <view class="tabs-box" v-if="tabsOpen">
  17. <view class="box-top">
  18. <view class="">
  19. 切换分类
  20. </view>
  21. <view class="">
  22. <view class='iconfont icon-xiangshang' @click="tabsOpen = false"></view>
  23. </view>
  24. </view>
  25. <view class="all-tabs">
  26. <view class="tabs-style" :class="index===tabClick?'active':''" v-for="(tab,index) in tabTitle" :key='index' @click="longClick(index,tab.store_category_id)">
  27. <text class="line1">{{tab.cate_name}}</text>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <view class='mask' v-if="tabsOpen" @click="tabsOpen = false"></view>
  33. </view>
  34. </template>
  35. <script>
  36. // +----------------------------------------------------------------------
  37. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  38. // +----------------------------------------------------------------------
  39. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  40. // +----------------------------------------------------------------------
  41. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  42. // +----------------------------------------------------------------------
  43. // | Author: CRMEB Team <admin@crmeb.com>
  44. // +----------------------------------------------------------------------
  45. import { mapGetters } from "vuex";
  46. let app = getApp();
  47. export default {
  48. name: 'navTab',
  49. props: {
  50. tabTitle: {
  51. type: Array,
  52. default: () => {
  53. []
  54. }
  55. }
  56. },
  57. computed: mapGetters(['viewColor']),
  58. data() {
  59. return {
  60. tabClick: 0, //导航栏被点击
  61. isLeft: 0, //导航栏下划线位置
  62. isWidth: 0, //每个导航栏占位
  63. tabLeft: 0,
  64. swiperIndex: 0,
  65. childIndex: 0,
  66. childID: 0,
  67. window: false,
  68. tabsOpen: false
  69. };
  70. },
  71. created() {
  72. var that = this
  73. // 获取设备宽度
  74. uni.getSystemInfo({
  75. success(e) {
  76. that.isWidth = e.windowWidth / 5
  77. }
  78. })
  79. },
  80. methods: {
  81. // 导航栏点击
  82. longClick(index, id) {
  83. this.childIndex = 0;
  84. if (this.tabTitle.length > 5) {
  85. var tempIndex = index - 2;
  86. tempIndex = tempIndex <= 0 ? 0 : tempIndex;
  87. this.tabLeft = (index - 2) * this.isWidth //设置下划线位置
  88. }
  89. this.tabClick = index //设置导航点击了哪一个
  90. this.isLeft = index * this.isWidth //设置下划线位置
  91. let obj = {
  92. index: index,
  93. pid: id
  94. }
  95. this.parentEmit(obj);
  96. this.tabsOpen = false
  97. },
  98. parentEmit(obj) {
  99. this.$emit('changeTab', obj);
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss">
  105. @keyframes bounce-in {
  106. 0% {
  107. opacity: 0;
  108. }
  109. 100% {
  110. opacity: 1;
  111. }
  112. }
  113. .navTabBox {
  114. width: 750rpx;
  115. box-sizing: border-box;
  116. padding: 0 40rpx;
  117. color: rgba(255, 255, 255, 1);
  118. position: relative;
  119. .tabs-box {
  120. position: absolute;
  121. top: 0;
  122. display: flex;
  123. flex-direction: column;
  124. width: 90%;
  125. background-color: #FFFFFF;
  126. border-radius: 24rpx;
  127. z-index: 999;
  128. animation: bounce-in .3s;
  129. .box-top {
  130. padding: 30rpx 20rpx 10rpx 20rpx;
  131. display: flex;
  132. justify-content: space-between;
  133. color: #666;
  134. font-size: 28rpx;
  135. }
  136. .all-tabs {
  137. display: flex;
  138. flex-wrap: wrap;
  139. padding: 20rpx 0;
  140. font-size: 24rpx;
  141. .tabs-style {
  142. display: flex;
  143. justify-content: center;
  144. background: #F2F2F2;
  145. border-radius: 29px;
  146. color: #282828;
  147. width: 22%;
  148. padding: 10rpx 20rpx;
  149. white-space: nowrap;
  150. border-radius: 30px;
  151. margin: 10rpx;
  152. }
  153. .active {
  154. background: var(--view-minorColor);
  155. color: var(--view-theme);
  156. border: 1px solid var(--view-theme);
  157. }
  158. }
  159. }
  160. .nav_toggle {
  161. position: absolute;
  162. top: 8rpx;
  163. right: 20rpx;
  164. }
  165. .click {
  166. color: white;
  167. }
  168. .longTab {
  169. display: flex;
  170. width: 95%;
  171. /* #ifdef H5 */
  172. padding-bottom: 20rpx;
  173. /* #endif */
  174. /* #ifdef MP */
  175. padding-top: 12rpx;
  176. padding-bottom: 12rpx;
  177. /* #endif */
  178. .longItem {
  179. height: 50upx;
  180. display: inline-block;
  181. line-height: 50upx;
  182. text-align: center;
  183. font-size: 30rpx;
  184. color: rgba(255, 255, 255, .8);
  185. max-width: 160rpx;
  186. white-space: nowrap;
  187. overflow: hidden;
  188. text-overflow: ellipsis;
  189. overflow-x: scroll;
  190. overflow-y: hidden;
  191. /*解决ios上滑动不流畅*/
  192. -webkit-overflow-scrolling: touch;
  193. &.click {
  194. font-weight: bold;
  195. font-size: 30rpx;
  196. color: #FFFFFF;
  197. }
  198. }
  199. .underlineBox {
  200. height: 3px;
  201. width: 20%;
  202. display: flex;
  203. align-content: center;
  204. justify-content: center;
  205. transition: .5s;
  206. .underline {
  207. width: 60rpx;
  208. height: 4rpx;
  209. }
  210. }
  211. }
  212. }
  213. .bg-color-white {
  214. background-color: #fff;
  215. }
  216. .child-box {
  217. width: 100%;
  218. position: relative;
  219. background-color: #fff;
  220. /* #ifdef H5 */
  221. box-shadow: 0 2px 5px 1px rgba(0, 0, 0, 0.02);
  222. /* #endif */
  223. /* #ifdef MP */
  224. box-shadow: 0 2rpx 3rpx 1rpx #f9f9f9;
  225. /* #endif */
  226. .wrapper {
  227. display: flex;
  228. align-items: center;
  229. padding: 20rpx 0;
  230. background: #fff;
  231. }
  232. .child-item {
  233. flex-shrink: 0;
  234. width: 140rpx;
  235. display: flex;
  236. flex-direction: column;
  237. align-items: center;
  238. justify-content: center;
  239. margin-left: 10rpx;
  240. image {
  241. width: 90rpx;
  242. height: 90rpx;
  243. border-radius: 50%;
  244. }
  245. .txt {
  246. font-size: 24rpx;
  247. color: #282828;
  248. text-align: center;
  249. margin-top: 10rpx;
  250. }
  251. &.on {
  252. image {
  253. border: 1px solid $theme-color-opacity;
  254. }
  255. .txt {
  256. color: $theme-color;
  257. }
  258. }
  259. }
  260. }
  261. .brand-wrapper {
  262. flex: 1;
  263. overflow: hidden;
  264. width: 690rpx;
  265. margin: 0 auto;
  266. background: #ffffff;
  267. border-radius: 12rpx;
  268. padding: 25rpx;
  269. .wrapper {
  270. display: flex;
  271. flex-wrap: wrap;
  272. padding-bottom: 20rpx;
  273. }
  274. .item {
  275. display: block;
  276. width: 146rpx;
  277. height: 58rpx;
  278. line-height: 58rpx;
  279. text-align: center;
  280. background: rgba(242, 242, 242, 1);
  281. border-radius: 28rpx;
  282. margin-top: 25rpx;
  283. padding: 0 10rpx;
  284. margin-right: 19rpx;
  285. color: #282828;
  286. font-size: 24rpx;
  287. &:nth-child(4n) {
  288. margin-right: 0;
  289. }
  290. &.on {
  291. background: rgba(255, 244, 243, 1);
  292. border: 1px solid rgba(233, 51, 35, 1);
  293. color: rgba(233, 51, 35, 1);
  294. }
  295. }
  296. .btns {
  297. display: flex;
  298. align-items: center;
  299. justify-content: center;
  300. padding-top: 10rpx;
  301. font-size: 22rpx;
  302. color: #999;
  303. .iconfont {
  304. margin-left: 10rpx;
  305. margin-top: 5rpx;
  306. font-size: 20rpx;
  307. }
  308. }
  309. .mask {
  310. z-index: 300 !important;
  311. }
  312. .icon-xiangxia {
  313. font-size: 20px;
  314. }
  315. }
  316. </style>