discover.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <template>
  2. <view class="discover-page base-container">
  3. <view class="discover-top">
  4. <view class="home-search">
  5. <view class="search-wrap">
  6. <up-search placeholder="搜索品种" v-model="typeSearch"></up-search>
  7. </view>
  8. </view>
  9. <view class="type-wrap">
  10. <up-scroll-list indicatorColor="#FF770033" indicatorActiveColor="#FF7700" :indicatorWidth="30"
  11. :indicatorBarWidth="13">
  12. <view class="item-type" :class="{'active': activeType === 0}" @click="handleSelectType(null, 0)">
  13. <image class="type-img" :src="`${config.BASIC_IMG}home/type-icon.png`" alt="" />
  14. <view class="type-text">
  15. 全部
  16. </view>
  17. </view>
  18. <view class="item-type" v-for="(item, index) in typeList"
  19. :class="{'active': activeType === index+1}" :key="index" @click="handleSelectType(item.id, index+1)">
  20. <image class="type-img" :src="item.image" alt="" />
  21. <view class="type-text">
  22. {{item.name}}
  23. </view>
  24. </view>
  25. </up-scroll-list>
  26. </view>
  27. </view>
  28. <!-- 列表 -->
  29. <view class="discover-content">
  30. <view class="discover-filter">
  31. <view class="filter-item" :class="{'active': filterIndex === 0}" @click="selectFilter(0)">
  32. 综合
  33. </view>
  34. <view class="filter-item" :class="{'active': filterIndex === 1}" @click="selectFilter(1)">
  35. 价格
  36. </view>
  37. <view class="filter-item" :class="{'active': filterIndex === 2}" @click="selectFilter(2)">
  38. 销量
  39. </view>
  40. </view>
  41. <view class="discover-list">
  42. <view class="list-line">
  43. <view class="list-item" v-for="(item, index) in discoverData" :key="index">
  44. <image class="item-img" :src="item.img" mode="aspectFill"></image>
  45. <view class="item-desc">
  46. <view class="item-text">
  47. {{item.name}}
  48. </view>
  49. <view class="item-subtext">
  50. <text class="subtext-text">坏单包退</text>
  51. <text class="subtext-text">包邮</text>
  52. </view>
  53. <view class="info-price">
  54. <view class="price-text">
  55. <text class="price-unit">¥</text>{{item.price}}
  56. </view>
  57. <view class="info-sold">
  58. 已售{{item.salesVal}}
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </template>
  68. <script setup>
  69. import {
  70. onMounted,
  71. ref
  72. } from "vue";
  73. import config from "@/api/config.js"
  74. import HOME from "@/api/home.js"
  75. const typeSearch = ref(null)
  76. const filterIndex = ref(0)
  77. const activeType = ref(0)
  78. const discoverData = ref([])
  79. let sortObj = {
  80. 0: "id",
  81. 1: "price",
  82. 2: "salesVal"
  83. }
  84. function selectFilter(i) {
  85. filterIndex.value = i
  86. sort.value = sortObj[i]
  87. getGoodsList()
  88. }
  89. onMounted(() => {
  90. getTypeList()
  91. getGoodsList()
  92. })
  93. const typeList = ref([])
  94. function getTypeList() {
  95. HOME.fetchTypeList().then(({
  96. data
  97. }) => {
  98. typeList.value = data
  99. })
  100. }
  101. const sort = ref("id")
  102. function getGoodsList(param) {
  103. let params = {...param, sort: sort.value}
  104. HOME.fetchGoodsList(params).then(({
  105. data
  106. }) => {
  107. discoverData.value = data
  108. })
  109. }
  110. function handleSelectType(id, index) {
  111. activeType.value = index
  112. let params = {}
  113. if (id) {
  114. params = {
  115. categoryId: id
  116. }
  117. }
  118. getGoodsList(params)
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .discover-page {
  123. padding: 0;
  124. background: #F2F3F5;
  125. .discover-top {
  126. padding: 20rpx 24rpx;
  127. background: linear-gradient(#FFFFFF, #F2F3F5);
  128. .home-search {
  129. display: flex;
  130. align-items: center;
  131. width: 100%;
  132. border: 2rpx solid #FFD95E;
  133. border-radius: 40rpx;
  134. margin-bottom: 40rpx;
  135. .search-wrap {
  136. flex: 1;
  137. // padding-left: 22rpx;
  138. ::v-deep {
  139. .u-search {
  140. .u-search__content {
  141. background-color: transparent !important;
  142. .u-search__content__input {
  143. background-color: transparent !important;
  144. }
  145. }
  146. .u-search__action {
  147. text-align: center;
  148. line-height: 52rpx;
  149. border-radius: 40rpx;
  150. font-size: 28rpx;
  151. background-color: #FFD95E;
  152. margin: 6rpx 8rpx;
  153. width: 112rpx;
  154. height: 52rpx;
  155. }
  156. }
  157. }
  158. }
  159. .search-btn {
  160. text-align: center;
  161. line-height: 52rpx;
  162. border-radius: 40rpx;
  163. font-size: 28rpx;
  164. background-color: #FFD95E;
  165. margin: 6rpx 8rpx;
  166. width: 112rpx;
  167. height: 52rpx;
  168. }
  169. }
  170. .type-wrap {
  171. padding: 0 20rpx 20rpx;
  172. background-color: #fff;
  173. border-radius: 16rpx;
  174. height: 200rpx;
  175. box-sizing: border-box;
  176. .item-type {
  177. text-align: center;
  178. font-size: 24rpx;
  179. .type-img {
  180. width: 92rpx;
  181. height: 92rpx;
  182. }
  183. .type-text {
  184. line-height: 36rpx;
  185. }
  186. &.active {
  187. .type-text {
  188. background-color: #FFD95E;
  189. border-radius: 20rpx;
  190. }
  191. }
  192. }
  193. .item-type+.item-type {
  194. padding-left: 22rpx;
  195. }
  196. }
  197. }
  198. .discover-content {
  199. padding: 0rpx 24rpx 24rpx;
  200. .discover-filter {
  201. color: #A6A6A6;
  202. font-size: 28rpx;
  203. display: flex;
  204. align-items: center;
  205. .filter-item {
  206. padding: 12rpx 20rpx;
  207. &.active {
  208. color: #000000;
  209. }
  210. }
  211. }
  212. .discover-list {
  213. padding-top: 20rpx;
  214. .list-line {
  215. padding-bottom: 20rpx;
  216. display: flex;
  217. flex-wrap: wrap;
  218. .list-item {
  219. background-color: #FFFFFF;
  220. border-radius: 10rpx;
  221. width: calc(50% - 16rpx);
  222. margin-bottom: 20rpx;
  223. .item-img {
  224. width: 100%;
  225. height: 340rpx;
  226. object-fit: cover;
  227. border-radius: 10rpx 10rpx 0 0;
  228. }
  229. .item-desc {
  230. padding: 0 10rpx 10rpx;
  231. .item-text {
  232. width: calc(100% - 22rpx);
  233. overflow: hidden;
  234. text-overflow: ellipsis;
  235. color: #000000;
  236. font-size: 28rpx;
  237. line-height: 42rpx;
  238. font-weight: 600;
  239. white-space: nowrap;
  240. }
  241. .item-subtext {
  242. color: #AFAFAF;
  243. font-size: 24rpx;
  244. line-height: 36rpx;
  245. .subtext-text+.subtext-text {
  246. padding-left: 10rpx;
  247. }
  248. }
  249. .info-price {
  250. display: flex;
  251. align-items: baseline;
  252. justify-content: space-between;
  253. .price-text {
  254. color: #FF7700;
  255. font-size: 36rpx;
  256. .price-unit {
  257. font-size: 23rpx;
  258. }
  259. }
  260. .info-sold {
  261. font-size: 20rpx;
  262. color: #C4C4C4;
  263. }
  264. }
  265. }
  266. }
  267. .list-item:nth-child(2n) {
  268. margin-left: 20rpx;
  269. }
  270. }
  271. }
  272. }
  273. }
  274. </style>