index.vue 4.5 KB

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