index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <div>
  3. <form
  4. class="fbt-form"
  5. action="/">
  6. <van-search
  7. v-model.trim="keyword"
  8. show-action
  9. :shape="'round'"
  10. placeholder="搜索商品标题 领优惠券拿返现"
  11. @search="onSearch">
  12. <template #action>
  13. <div
  14. class="btn"
  15. @click="onSearch">搜索
  16. </div>
  17. </template>
  18. </van-search>
  19. </form>
  20. <!--商家-->
  21. <div
  22. class="business-list">
  23. <van-tabs
  24. v-model="source"
  25. :color="'#F09E38'"
  26. :title-active-color="'#333333'"
  27. :title-inactive-color="'#515151'"
  28. :background="'#fff'"
  29. @click="fetchGoodsList"
  30. ref="fbtCateList">
  31. <van-tab
  32. :name="item.value"
  33. v-for="item in sourceList"
  34. :key="item.value">
  35. <template #title>{{ item.name }}</template>
  36. </van-tab>
  37. </van-tabs>
  38. </div>
  39. <ul
  40. class="filter-wrap border-top-1px"
  41. v-show="booGoodsWrap">
  42. <li
  43. :class="{'active': sort === item.value}"
  44. v-for="item in filterList"
  45. :key="item.value"
  46. @click="selectSortType(item)">{{ item.name }}
  47. </li>
  48. </ul>
  49. <!--商品列表-->
  50. <Main
  51. :keyword="keyword"
  52. :source="source"
  53. :sort="sort"
  54. ref="myMain"
  55. v-show="booGoodsWrap"/>
  56. </div>
  57. </template>
  58. <script>
  59. import { Search, Tabs, Tab, Toast } from 'vant'
  60. import Main from './child/main'
  61. export default {
  62. name: 'index',
  63. components: {
  64. 'van-search': Search,
  65. 'van-tabs': Tabs,
  66. 'van-tab': Tab,
  67. Main
  68. },
  69. data () {
  70. return {
  71. keyword: '',
  72. sourceList: [
  73. {
  74. name: '京东',
  75. value: 'jd'
  76. },
  77. {
  78. name: '唯品会',
  79. value: 'vip'
  80. },
  81. {
  82. name: '拼多多',
  83. value: 'pdd'
  84. },
  85. {
  86. name: '考拉',
  87. value: 'kaola'
  88. },
  89. {
  90. name: '淘宝',
  91. value: 'taobao'
  92. }
  93. ], // 商家列表
  94. // 1-综合排序,2-价格升序,3-销量降序 默认1
  95. filterList: [
  96. {
  97. name: '综合',
  98. value: 1
  99. },
  100. {
  101. name: '销量',
  102. value: 2
  103. },
  104. {
  105. name: '价格',
  106. value: 3
  107. }
  108. ],
  109. source: 'jd',
  110. sort: 1,
  111. booGoodsWrap: false
  112. }
  113. },
  114. activated () {
  115. if (!this.$route.meta.isUseCache) {
  116. } else {}
  117. setTimeout(() => {
  118. this.$refs.fbtCateList.resize()
  119. }, 500)
  120. this.$route.meta.isUseCache = false
  121. },
  122. methods: {
  123. onSearch () {
  124. if (!this.keyword) {
  125. Toast('搜索内容不能为空')
  126. return
  127. }
  128. if (!this.booGoodsWrap) {
  129. this.booGoodsWrap = true
  130. }
  131. this.$nextTick(() => {
  132. this.$refs.myMain.init()
  133. })
  134. },
  135. fetchGoodsList () {
  136. if (!this.keyword) {
  137. return
  138. }
  139. this.$nextTick(() => {
  140. this.$refs.myMain.init()
  141. })
  142. },
  143. selectSortType (item) {
  144. this.sort = item.value
  145. if (!this.keyword) {
  146. return
  147. }
  148. this.$nextTick(() => {
  149. this.$refs.myMain.init()
  150. })
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .fbt-form {
  157. ::v-deep .van-search {
  158. padding-bottom: 0;
  159. .van-cell {
  160. align-items: center;
  161. input {
  162. color: #333;
  163. -webkit-text-fill-color: #333;
  164. opacity: 1;
  165. &::-webkit-input-placeholder {
  166. -webkit-text-fill-color: #999;
  167. opacity: 1;
  168. color: #999;
  169. }
  170. }
  171. }
  172. }
  173. .btn {
  174. font-size: 16px;
  175. color: #333;
  176. }
  177. }
  178. .cate-header {
  179. position: relative;
  180. left: 0;
  181. top: 0;
  182. width: 100%;
  183. ::v-deep .van-tabs {
  184. width: calc(100% - 42px);
  185. .van-tabs__nav--line {
  186. .van-tab {
  187. &--active {
  188. .van-tab__text {
  189. font-size: 16px !important;
  190. font-weight: bold;
  191. }
  192. }
  193. .van-tab__text {
  194. font-size: 13px;
  195. }
  196. }
  197. }
  198. }
  199. }
  200. .filter-wrap {
  201. display: flex;
  202. align-items: center;
  203. background: #fff;
  204. @include border-top-1px(#eee);
  205. li {
  206. flex: 1;
  207. line-height: 40px;
  208. font-size: 14px;
  209. color: #999;
  210. text-align: center;
  211. &.active {
  212. font-weight: bolder;
  213. color: #333;
  214. }
  215. }
  216. }
  217. </style>