index.vue 8.0 KB

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