index.vue 6.3 KB

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