discover.vue 8.2 KB

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