discover.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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 && typeList.length>5" indicatorColor="#FF770033" indicatorActiveColor="#FF7700" :indicatorWidth="30"
  11. :indicatorBarWidth="15">
  12. <view class="item-type" :class="{'active': activeType === 0}" @click="handleSelectType(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 === item.id}" :key="index" @click="handleSelectType(item.id)">
  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 class="no-data" v-if="!discoverData||!discoverData.length">
  76. 暂未上架商品,请耐心等候
  77. </view>
  78. </view>
  79. </view>
  80. </template>
  81. <script setup>
  82. import {
  83. onMounted,
  84. ref
  85. } from "vue";
  86. import config from "@/api/config.js"
  87. import HOME from "@/api/home.js"
  88. import { onShow } from "@dcloudio/uni-app"
  89. const typeSearch = ref(null)
  90. const filterIndex = ref(0)
  91. const activeType = ref(0)
  92. const orderType = ref(true)
  93. const discoverData = ref([])
  94. let sortObj = {
  95. 0: "id",
  96. 1: "price",
  97. 2: "salesVal"
  98. }
  99. function selectFilter(i) {
  100. if (filterIndex.value !== i) {
  101. orderType.value = false
  102. }
  103. filterIndex.value = i
  104. sort.value = sortObj[i]
  105. orderType.value = !orderType.value
  106. getGoodsList()
  107. }
  108. onShow(() => {
  109. const selectedType = uni.getStorageSync('selectedCategoryType');
  110. if (selectedType) {
  111. activeType.value = selectedType
  112. uni.setStorageSync('selectedCategoryType', 0);
  113. handleSelectType(selectedType||0)
  114. }
  115. })
  116. onMounted(() => {
  117. console.log('onMounted')
  118. getTypeList()
  119. getGoodsList()
  120. })
  121. const typeList = ref([])
  122. function getTypeList() {
  123. HOME.fetchTypeList().then(({
  124. data
  125. }) => {
  126. typeList.value = data
  127. })
  128. }
  129. const sort = ref("id")
  130. function getGoodsList(param) {
  131. let params = {...param, sort: sort.value}
  132. if (filterIndex.value !== 0) {
  133. params = {
  134. ...params,
  135. order: orderType.value ? "asc" : "desc"
  136. }
  137. }
  138. HOME.fetchGoodsList(params).then(({
  139. data
  140. }) => {
  141. discoverData.value = data
  142. })
  143. }
  144. function handleSelectType(id) {
  145. activeType.value = id
  146. let params = {}
  147. if (id) {
  148. params = {
  149. categoryId: id
  150. }
  151. }
  152. getGoodsList(params)
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .discover-page {
  157. padding: 0;
  158. background: #F2F3F5;
  159. height: 100vh;
  160. .discover-top {
  161. padding: 20rpx 24rpx;
  162. background: linear-gradient(#FFFFFF, #F2F3F5);
  163. .home-search {
  164. display: flex;
  165. align-items: center;
  166. width: 100%;
  167. border: 2rpx solid #FFD95E;
  168. border-radius: 40rpx;
  169. margin-bottom: 40rpx;
  170. .search-wrap {
  171. flex: 1;
  172. // padding-left: 22rpx;
  173. ::v-deep {
  174. .u-search {
  175. .u-search__content {
  176. background-color: transparent !important;
  177. .u-search__content__input {
  178. background-color: transparent !important;
  179. }
  180. }
  181. .u-search__action {
  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. }
  193. }
  194. .search-btn {
  195. text-align: center;
  196. line-height: 52rpx;
  197. border-radius: 40rpx;
  198. font-size: 28rpx;
  199. background-color: #FFD95E;
  200. margin: 6rpx 8rpx;
  201. width: 112rpx;
  202. height: 52rpx;
  203. }
  204. }
  205. .type-wrap {
  206. padding: 0 20rpx 0 20rpx;
  207. background-color: #fff;
  208. border-radius: 16rpx;
  209. height: 186rpx;
  210. box-sizing: border-box;
  211. // 覆盖 up-scroll-list 的默认样式,实现两端对齐
  212. :deep(.u-scroll-list__scroll-view__content) {
  213. display: flex;
  214. justify-content: space-between;
  215. align-items: center;
  216. width: 100%;
  217. min-width: 100%;
  218. }
  219. ::v-deep {
  220. .u-scroll-list__indicator {
  221. margin-top: 16rpx;
  222. }
  223. }
  224. .item-type {
  225. text-align: center;
  226. font-size: 24rpx;
  227. flex-shrink: 0;
  228. .type-img {
  229. width: 92rpx;
  230. height: 92rpx;
  231. }
  232. .type-text {
  233. line-height: 36rpx;
  234. }
  235. &.active {
  236. .type-text {
  237. background-color: #FFD95E;
  238. border-radius: 20rpx;
  239. }
  240. }
  241. }
  242. .item-type+.item-type {
  243. padding-left: 22rpx;
  244. }
  245. }
  246. }
  247. .discover-content {
  248. padding: 0rpx 24rpx 24rpx;
  249. height: calc(100% - 320rpx);
  250. overflow: auto;
  251. background: #F2F3F5;
  252. box-sizing: border-box;
  253. .no-data {
  254. text-align: center;
  255. color: rgba(0, 0, 0, 0.6);
  256. font-size: 28rpx;
  257. }
  258. .discover-filter {
  259. color: #A6A6A6;
  260. font-size: 28rpx;
  261. display: flex;
  262. align-items: center;
  263. .filter-item {
  264. padding: 12rpx 20rpx;
  265. display: flex;
  266. align-items: center;
  267. &.active {
  268. color: #000000;
  269. }
  270. .filter-icon {
  271. padding-left: 4rpx;
  272. }
  273. }
  274. }
  275. .discover-list {
  276. padding-top: 20rpx;
  277. .list-line {
  278. padding-bottom: 20rpx;
  279. display: flex;
  280. flex-wrap: wrap;
  281. .list-item {
  282. background-color: #FFFFFF;
  283. border-radius: 10rpx;
  284. width: calc(50% - 16rpx);
  285. margin-bottom: 20rpx;
  286. .item-img {
  287. width: 100%;
  288. height: 340rpx;
  289. object-fit: cover;
  290. border-radius: 10rpx 10rpx 0 0;
  291. }
  292. .item-desc {
  293. padding: 0 10rpx 10rpx;
  294. .item-text {
  295. width: calc(100% - 22rpx);
  296. overflow: hidden;
  297. text-overflow: ellipsis;
  298. color: #000000;
  299. font-size: 28rpx;
  300. line-height: 42rpx;
  301. font-weight: 600;
  302. white-space: nowrap;
  303. }
  304. .item-subtext {
  305. color: #AFAFAF;
  306. font-size: 24rpx;
  307. line-height: 36rpx;
  308. .subtext-text+.subtext-text {
  309. padding-left: 10rpx;
  310. }
  311. }
  312. .info-price {
  313. display: flex;
  314. align-items: baseline;
  315. justify-content: space-between;
  316. .price-text {
  317. color: #FF7700;
  318. font-size: 36rpx;
  319. .price-unit {
  320. font-size: 23rpx;
  321. }
  322. }
  323. .info-sold {
  324. font-size: 20rpx;
  325. color: #C4C4C4;
  326. }
  327. }
  328. }
  329. }
  330. .list-item:nth-child(2n) {
  331. margin-left: 20rpx;
  332. }
  333. }
  334. }
  335. }
  336. }
  337. </style>