index.vue 7.1 KB

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