index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <div
  3. class="category-container">
  4. <transition name="fade">
  5. <div
  6. class="header-wrap"
  7. v-show="showHeader">
  8. <!--模拟搜索-->
  9. <div class="jump-search">
  10. <van-search
  11. :shape="'round'"
  12. v-model="searchValue"
  13. placeholder="搜索商品标题 领优惠券拿返现"/>
  14. <router-link
  15. :to="{name: 'Search'}">去搜索页
  16. </router-link>
  17. </div>
  18. <!--商家-->
  19. <div class="business-list">
  20. <van-tabs
  21. v-model="businessValue"
  22. :color="'#ee0a24'"
  23. :title-active-color="'#FFF'"
  24. :title-inactive-color="'#8A8A8A'"
  25. :background="'#fff'"
  26. @click="fetchCateList"
  27. ref="fbtBusinessList">
  28. <van-tab
  29. :name="item.value"
  30. v-for="item in sourceList"
  31. :key="item.value">
  32. <template #title>
  33. <i>{{ item.name }}</i>
  34. </template>
  35. </van-tab>
  36. </van-tabs>
  37. </div>
  38. <!--分类-->
  39. <div
  40. class="cate-header">
  41. <van-tabs
  42. v-model="catId"
  43. :color="'#F09E38'"
  44. :title-active-color="'#333333'"
  45. :title-inactive-color="'#515151'"
  46. :background="'#fff'"
  47. @click="selectCateId"
  48. ref="fbtCateList">
  49. <van-tab
  50. :name="item.id"
  51. v-for="item in cateList"
  52. :key="item.id">
  53. <template #title>{{ item.name }}</template>
  54. </van-tab>
  55. </van-tabs>
  56. <van-dropdown-menu
  57. class="fbt-van-dropdown-menu">
  58. <van-dropdown-item
  59. ref="fbtCateDropdownMenu">
  60. <template #title>
  61. <van-icon name="arrow-down"/>
  62. </template>
  63. <ul>
  64. <li
  65. :class="{'active': item.id === catId}"
  66. v-for="item in cateList"
  67. :key="item.id"
  68. @click="onConfirm(item)">{{ item.name }}
  69. </li>
  70. </ul>
  71. </van-dropdown-item>
  72. </van-dropdown-menu>
  73. </div>
  74. </div>
  75. </transition>
  76. <!--商品列表-->
  77. <Main
  78. :source="this.businessValue"
  79. :catId="catId"
  80. @setShowHeader="setShowHeader"
  81. ref="myMain"/>
  82. <!--回到顶部-->
  83. <BSScrollTop
  84. @handleScrollTop="handleScrollTop"
  85. v-show="!showHeader"/>
  86. </div>
  87. </template>
  88. <script>
  89. import { Tab, Tabs, DropdownMenu, DropdownItem, Icon, Toast, Search } from 'vant'
  90. import Main from './child/main'
  91. import BSScrollTop from '../../common/BSScrollTop'
  92. import { apiCateList } from './api/api'
  93. export default {
  94. name: 'index',
  95. components: {
  96. 'van-tabs': Tabs,
  97. 'van-tab': Tab,
  98. 'van-dropdown-menu': DropdownMenu,
  99. 'van-dropdown-item': DropdownItem,
  100. 'van-icon': Icon,
  101. 'van-search': Search,
  102. Main,
  103. BSScrollTop
  104. },
  105. data () {
  106. return {
  107. searchValue: '',
  108. sourceList: [
  109. {
  110. name: '京东',
  111. value: 'jd'
  112. },
  113. {
  114. name: '唯品会',
  115. value: 'vip'
  116. },
  117. {
  118. name: '拼多多',
  119. value: 'pdd'
  120. },
  121. {
  122. name: '考拉',
  123. value: 'kaola'
  124. },
  125. {
  126. name: '淘宝',
  127. value: 'taobao'
  128. }
  129. ], // 商家列表
  130. businessValue: 'jd',
  131. catId: '',
  132. cateList: [], // 分类列表
  133. numPositionY: 0, // BS纵轴坐标
  134. showHeader: true // 是否展示顶部模块:搜索、商家筛选、类别筛选
  135. }
  136. },
  137. activated () {
  138. if (!this.$route.meta.isUseCache) {
  139. this.searchValue = ''
  140. this.businessValue = this.sourceList[0].value
  141. this.catId = ''
  142. this.numPositionY = 0
  143. this.showHeader = true
  144. this.fetchCateList()
  145. } else {
  146. this.$nextTick(() => {
  147. if (this.$refs.myMain.scroll) {
  148. this.$refs.myMain.scroll.refresh()
  149. this.$refs.myMain.scroll.scrollTo(0, this.numPositionY)
  150. }
  151. })
  152. }
  153. setTimeout(() => {
  154. this.$refs.fbtBusinessList.resize()
  155. }, 500)
  156. this.$route.meta.isUseCache = false
  157. },
  158. methods: {
  159. async fetchCateList () {
  160. try {
  161. const { status, data, msg } = await apiCateList(this.businessValue)
  162. if (status) {
  163. this.cateList = data
  164. setTimeout(() => {
  165. this.$refs.fbtCateList.resize()
  166. this.$refs.myMain.init()
  167. }, 500)
  168. } else {
  169. Toast(msg)
  170. }
  171. } catch (e) {}
  172. },
  173. selectCateId () {
  174. this.$nextTick(() => {
  175. this.$refs.myMain.init()
  176. })
  177. },
  178. onConfirm (obj) {
  179. this.catId = obj.id
  180. this.$nextTick(() => {
  181. this.$refs.fbtCateDropdownMenu.toggle()
  182. this.$refs.myMain.init()
  183. })
  184. },
  185. setShowHeader (val) {
  186. this.showHeader = val
  187. },
  188. handleScrollTop () {
  189. this.$refs.myMain.scroll && this.$refs.myMain.scroll.scrollTo(0, 0)
  190. }
  191. },
  192. beforeRouteLeave (to, from, next) {
  193. if (['CategoryDetail'].findIndex(item => item === to.name) > -1) {
  194. from.meta.isUseCache = true
  195. }
  196. this.numPositionY = this.$refs.myMain.scroll ? this.$refs.myMain.scroll.y : 0
  197. next()
  198. }
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. .category-container {
  203. position: absolute;
  204. left: 0;
  205. top: 0;
  206. right: 0;
  207. bottom: 50px;
  208. width: 100%;
  209. }
  210. .fade-enter-active,
  211. .fade-leave-active {
  212. transition: all 0.6s;
  213. }
  214. .fade-enter,
  215. .fade-leave-to {
  216. transform: translate3d(0, -136px, 0);
  217. }
  218. .header-wrap {
  219. position: absolute;
  220. left: 0;
  221. top: 0;
  222. z-index: 10;
  223. width: 100%;
  224. }
  225. .jump-search {
  226. ::v-deep .van-search {
  227. padding-bottom: 0;
  228. input {
  229. &::-webkit-input-placeholder {
  230. -webkit-text-fill-color: #999;
  231. opacity: 1;
  232. color: #999;
  233. }
  234. }
  235. }
  236. position: relative;
  237. left: 0;
  238. top: 0;
  239. overflow: hidden;
  240. a {
  241. position: absolute;
  242. left: 12px;
  243. top: 10px;
  244. right: 12px;
  245. bottom: 0;
  246. opacity: 0;
  247. }
  248. }
  249. .business-list {
  250. position: relative;
  251. left: 0;
  252. top: 0;
  253. width: 100%;
  254. ::v-deep .van-tabs__nav--line {
  255. .van-tab {
  256. width: 75px;
  257. padding: 0;
  258. &--active {
  259. .van-tab__text {
  260. background: #EA483F !important;;
  261. }
  262. }
  263. .van-tab__text {
  264. display: flex;
  265. align-items: center;
  266. justify-content: center;
  267. width: 67px;
  268. height: 23px;
  269. padding: 0 12px;
  270. background: #F3F3F3;
  271. border-radius: 12px;
  272. img {
  273. width: 16px;
  274. height: 16px;
  275. margin-right: 3px;
  276. }
  277. i {
  278. font-size: 11px;
  279. color: inherit;
  280. white-space: nowrap;
  281. text-overflow: ellipsis;
  282. overflow: hidden;
  283. }
  284. }
  285. }
  286. .van-tabs__line {
  287. display: none;
  288. }
  289. }
  290. }
  291. .cate-header {
  292. position: relative;
  293. left: 0;
  294. top: 0;
  295. width: 100%;
  296. ::v-deep .van-tabs {
  297. width: calc(100% - 42px);
  298. .van-tabs__nav--line {
  299. .van-tab {
  300. &--active {
  301. .van-tab__text {
  302. font-size: 16px !important;
  303. font-weight: bold;
  304. }
  305. }
  306. .van-tab__text {
  307. font-size: 13px;
  308. }
  309. }
  310. }
  311. }
  312. .fbt-van-dropdown-menu {
  313. position: absolute;
  314. right: 0;
  315. top: 0;
  316. width: 42px;
  317. height: 100%;
  318. ::v-deep .van-dropdown-menu__bar {
  319. height: 100%;
  320. box-shadow: none;
  321. .van-dropdown-menu__title {
  322. &::after {
  323. visibility: hidden;
  324. }
  325. }
  326. }
  327. ul {
  328. display: flex;
  329. flex-flow: row wrap;
  330. align-content: flex-start;
  331. width: 375px;
  332. min-height: 177px;
  333. background: #F8F8F8;
  334. padding: 12px 0 2px;
  335. li {
  336. width: 75px;
  337. height: 24px;
  338. margin-left: 15px;
  339. margin-bottom: 10px;
  340. border-radius: 12px;
  341. color: #515151;
  342. background: #ECECEC;
  343. font-size: 12px;
  344. line-height: 24px;
  345. text-align: center;
  346. white-space: nowrap;
  347. text-overflow: ellipsis;
  348. overflow: hidden;
  349. &.active {
  350. color: #FFFFFF;
  351. background: #EA483F;
  352. }
  353. }
  354. }
  355. }
  356. }
  357. </style>