index.vue 8.1 KB

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