saveMoney.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <template>
  2. <view class="save-money-container">
  3. <!-- 顶部渐变背景 -->
  4. <view class="top-bg"></view>
  5. <!-- 搜索栏 -->
  6. <view class="search-bar-wrap">
  7. <u-search
  8. placeholder="搜索商品"
  9. v-model="keyword"
  10. :showAction="false"
  11. actionText="搜索"
  12. bgColor="rgba(255, 255, 255,1)"
  13. height="32"
  14. searchIcon="search"
  15. searchIconSize="20"
  16. searchIconColor="#999"
  17. placeholderColor="#999"
  18. :inputStyle="{ fontSize: '28rpx' }"
  19. @search="onSearch"
  20. @custom="onSearch"
  21. @clear="onClearSearch"
  22. ></u-search>
  23. </view>
  24. <!-- Banner -->
  25. <!-- <view class="banner-wrap">
  26. <image class="banner-image" src="https://via.placeholder.com/710x240/FF5A5F/FFFFFF?text=Banner" mode="aspectFill"></image>
  27. </view> -->
  28. <!-- 消息通知栏 -->
  29. <!-- <view class="notice-bar-wrap">
  30. <view class="notice-left">
  31. <image class="notice-icon" src="@/static/image/points/icon_msg.png" mode="aspectFit"></image>
  32. <text class="notice-text">双十一活动已经开始,折扣享不停~</text>
  33. </view>
  34. <view class="notice-right">
  35. <image class="notice-more-icon" src="@/static/image/points/icon_msg_more.png" mode="aspectFit"></image>
  36. </view>
  37. </view> -->
  38. <!-- 主分类 Tabs -->
  39. <scroll-view class="main-tabs-scroll" scroll-x :show-scrollbar="false" :scroll-into-view="'main-tab-' + currentTab">
  40. <view class="main-tabs-inner">
  41. <view
  42. v-for="(item, index) in tabList"
  43. :key="index"
  44. :id="'main-tab-' + index"
  45. class="main-tab-item"
  46. :class="{ active: currentTab === index }"
  47. @click="onTabChange(index)"
  48. >
  49. {{ item.name }}
  50. </view>
  51. </view>
  52. </scroll-view>
  53. <!-- 子分类 Tabs (水平滚动) -->
  54. <scroll-view class="sub-tabs-scroll" scroll-x :show-scrollbar="false" :scroll-into-view="'sub-tab-' + currentSubTab">
  55. <view class="sub-tabs-inner">
  56. <view
  57. v-for="(item, index) in subTabList"
  58. :key="index"
  59. :id="'sub-tab-' + index"
  60. class="sub-tab-item"
  61. :class="{ active: currentSubTab === index }"
  62. @click="onSubTabChange(index)"
  63. >
  64. {{ item.name }}
  65. </view>
  66. </view>
  67. </scroll-view>
  68. <!-- 商品列表 -->
  69. <view class="goods-list">
  70. <template v-if="goodsList.length > 0">
  71. <view class="goods-item" v-for="(item, index) in goodsList" :key="index" @click="todetail(item.id)">
  72. <image class="goods-img" :src="item.imageUrl" mode="aspectFill"></image>
  73. <view class="goods-info">
  74. <view class="hot-tag">
  75. <image class="hot-icon" src="@/static/image/points/icon_tag_hot.png" mode="aspectFit"></image>
  76. <text class="hot-text">近2小时售出{{ item.monthlySales || 0 }}单</text>
  77. </view>
  78. <view class="goods-title">{{ item.title }}</view>
  79. <view class="goods-bottom">
  80. <view class="price-wrap">
  81. <text class="price-symbol">¥</text>
  82. <text class="price-main">{{ item.couponPrice || 0 }}</text>
  83. <text class="price-old" v-if="item.price">¥{{ item.price }}</text>
  84. </view>
  85. <view class="subsidy-tag">
  86. <image class="subsidy-bg" src="@/static/image/points/btn_price.png" mode="scaleToFill"></image>
  87. <view class="subsidy-content">
  88. <view class="subsidy-left">立享补贴</view>
  89. <view class="subsidy-right">¥{{ item.commissionAmount || 0 }}</view>
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. <!-- 加载更多 -->
  96. <u-loadmore :status="loadStatus" margin-top="20" margin-bottom="20" />
  97. </template>
  98. <!-- 空状态 -->
  99. <view class="empty-state" v-else-if="loadStatus === 'nomore' && goodsList.length === 0">
  100. <image class="empty-img" src="/pages_im/static/images/search_empty.png" mode="aspectFit"></image>
  101. <text class="empty-text">暂无更多</text>
  102. </view>
  103. </view>
  104. </view>
  105. </template>
  106. <script>
  107. import { getSaveCategory,getProductList } from "@/api/makeMoney.js"
  108. export default {
  109. name: "saveMoney",
  110. data() {
  111. return {
  112. keyword: "",
  113. currentTab: 0,
  114. tabList: [],
  115. currentSubTab: 0,
  116. subTabList: [],
  117. goodsList: [],
  118. page: 1,
  119. pageSize: 10,
  120. loadStatus: 'loadmore' // loadmore, loading, nomore
  121. }
  122. },
  123. mounted() {
  124. // 兼容可能不通过 swiper 切换直接显示的情况
  125. this.$nextTick(() => {
  126. if (this.tabList.length === 0) {
  127. this.initShow();
  128. }
  129. });
  130. },
  131. methods: {
  132. getSaveCategorys(){
  133. getSaveCategory().then(res=>{
  134. if(res.code==200){
  135. const platforms = res.data.platformCategory.map(item => ({
  136. name: item.platformName,
  137. platform: item.platform,
  138. channel: ''
  139. }));
  140. this.tabList = [
  141. { name: '精选好物', channel: 1, platform: '' },
  142. { name: '我的关注', channel: 2, platform: '' },
  143. ...platforms
  144. ];
  145. if (res.data.productCategory) {
  146. const products = res.data.productCategory.map(item => ({
  147. name: item.appCategoryName,
  148. appCategoryId: item.appCategoryId
  149. }));
  150. this.subTabList = [
  151. { name: '全部', appCategoryId: '' },
  152. ...products
  153. ];
  154. }
  155. // 获取完数据后重新渲染 u-tabs 以保证滚动位置正确
  156. this.currentTab = 0;
  157. this.currentSubTab = 0;
  158. this.$nextTick(() => {
  159. // 在获取完分类数据并且视图更新后,初始化商品列表
  160. if (this.goodsList.length === 0) {
  161. this.getProductLists();
  162. }
  163. });
  164. }else{
  165. uni.showToast({
  166. icon: 'none',
  167. title: res.msg,
  168. });
  169. }
  170. })
  171. },
  172. onTabChange(index) {
  173. this.currentTab = index;
  174. this.resetList();
  175. this.getProductLists();
  176. },
  177. onSubTabChange(index) {
  178. this.currentSubTab = index;
  179. this.resetList();
  180. this.getProductLists();
  181. },
  182. onSearch(value) {
  183. this.keyword = value || this.keyword;
  184. this.resetList();
  185. this.getProductLists();
  186. },
  187. onClearSearch() {
  188. this.keyword = '';
  189. this.resetList();
  190. this.getProductLists();
  191. },
  192. resetList() {
  193. this.page = 1;
  194. this.goodsList = [];
  195. this.loadStatus = 'loadmore';
  196. },
  197. getProductLists(){
  198. if (this.loadStatus === 'loading' || this.loadStatus === 'nomore') return;
  199. this.loadStatus = 'loading';
  200. const currentTabObj = this.tabList[this.currentTab];
  201. const currentSubTabObj = this.subTabList[this.currentSubTab];
  202. // 防御性判断,防止报错
  203. if (!currentTabObj) {
  204. this.loadStatus = 'loadmore';
  205. return;
  206. }
  207. const data={
  208. appCategoryId: currentSubTabObj ? currentSubTabObj.appCategoryId : '',
  209. channel: currentTabObj.channel,
  210. platform: currentTabObj.platform,
  211. page: this.page,
  212. pageSize: this.pageSize,
  213. title: this.keyword
  214. }
  215. getProductList(data).then(res=>{
  216. if(res.code==200){
  217. const list = res.data.list || [];
  218. this.goodsList = this.page === 1 ? list : this.goodsList.concat(list);
  219. this.loadStatus = list.length < this.pageSize ? 'nomore' : 'loadmore';
  220. }else{
  221. this.loadStatus = 'loadmore';
  222. uni.showToast({
  223. icon: 'none',
  224. title: res.msg,
  225. });
  226. }
  227. }).catch(() => {
  228. this.loadStatus = 'loadmore';
  229. })
  230. },
  231. scrolltolower() {
  232. if (this.loadStatus === 'loadmore') {
  233. this.page++;
  234. this.getProductLists();
  235. }
  236. },
  237. initShow() {
  238. // 当该组件所在的 swiper item 被激活时,触发该方法
  239. if (this.tabList.length === 0) {
  240. this.getSaveCategorys();
  241. } else {
  242. if (this.goodsList.length === 0) {
  243. this.getProductLists();
  244. }
  245. }
  246. },
  247. todetail(id){
  248. uni.navigateTo({
  249. url:'/pages/points/shopDetail?id='+id
  250. })
  251. }
  252. }
  253. };
  254. </script>
  255. <style lang="scss" scoped>
  256. .save-money-container {
  257. min-height: 100vh;
  258. position: relative;
  259. padding-bottom: 40rpx;
  260. }
  261. .top-bg {
  262. position: absolute;
  263. top: 0;
  264. left: 0;
  265. width: 100%;
  266. height: 360rpx;
  267. z-index: 0;
  268. }
  269. .search-bar-wrap {
  270. position: relative;
  271. z-index: 1;
  272. padding: 20rpx 30rpx;
  273. }
  274. .banner-wrap {
  275. position: relative;
  276. z-index: 1;
  277. padding: 0 30rpx;
  278. margin-top: 10rpx;
  279. }
  280. .banner-image {
  281. width: 100%;
  282. height: 240rpx;
  283. border-radius: 20rpx;
  284. background-color: #fff;
  285. }
  286. .notice-bar-wrap {
  287. position: relative;
  288. z-index: 1;
  289. margin: 20rpx 30rpx;
  290. background-color: #FFEADF;
  291. border-radius: 16rpx;
  292. display: flex;
  293. justify-content: space-between;
  294. align-items: center;
  295. padding: 16rpx 20rpx;
  296. }
  297. .notice-left {
  298. display: flex;
  299. align-items: center;
  300. }
  301. .notice-icon {
  302. width: 44rpx;
  303. height: 44rpx;
  304. }
  305. .notice-text {
  306. font-size: 26rpx;
  307. color: #E75932;
  308. margin-left: 16rpx;
  309. }
  310. .notice-right {
  311. display: flex;
  312. align-items: center;
  313. border-left: 1px dashed rgba(231, 89, 50, 0.3);
  314. padding-left: 20rpx;
  315. }
  316. .notice-more-icon {
  317. width: 44rpx;
  318. height: 44rpx;
  319. }
  320. .main-tabs-scroll {
  321. position: relative;
  322. z-index: 1;
  323. width: 100%;
  324. white-space: nowrap;
  325. padding: 10rpx 0 20rpx 0;
  326. background-color: transparent;
  327. }
  328. .main-tabs-inner {
  329. display: inline-flex;
  330. padding: 0 30rpx;
  331. }
  332. .main-tab-item {
  333. display: inline-block;
  334. font-size: 30rpx;
  335. color: #666;
  336. font-weight: 500;
  337. padding: 0 20rpx;
  338. height: 80rpx;
  339. line-height: 80rpx;
  340. }
  341. .main-tab-item.active {
  342. color: #FF5A1F;
  343. font-size: 34rpx;
  344. font-weight: bold;
  345. }
  346. .sub-tabs-scroll {
  347. position: relative;
  348. z-index: 1;
  349. width: 100%;
  350. white-space: nowrap;
  351. padding: 0 0 20rpx 0;
  352. }
  353. .sub-tabs-inner {
  354. display: inline-flex;
  355. padding: 0 30rpx;
  356. }
  357. .sub-tab-item {
  358. display: inline-block;
  359. padding: 8rpx 24rpx;
  360. background-color: #fff;
  361. border-radius: 26rpx;
  362. font-size: 26rpx;
  363. color: #666;
  364. margin-right: 20rpx;
  365. }
  366. .sub-tab-item.active {
  367. color: #FF5A1F;
  368. border: 1px solid #FF5A1F;
  369. background-color: rgba(255, 90, 31, 0.05);
  370. }
  371. .goods-list {
  372. position: relative;
  373. z-index: 1;
  374. padding: 0 30rpx;
  375. min-height: 400rpx;
  376. }
  377. .empty-state {
  378. display: flex;
  379. flex-direction: column;
  380. align-items: center;
  381. justify-content: center;
  382. padding: 100rpx 0;
  383. }
  384. .empty-img {
  385. width: 280rpx;
  386. height: 280rpx;
  387. margin-bottom: 20rpx;
  388. }
  389. .empty-text {
  390. font-size: 28rpx;
  391. color: #999;
  392. }
  393. .goods-item {
  394. display: flex;
  395. background-color: #fff;
  396. border-radius: 20rpx;
  397. padding: 20rpx;
  398. margin-bottom: 20rpx;
  399. }
  400. .goods-img {
  401. width: 220rpx;
  402. height: 220rpx;
  403. border-radius: 12rpx;
  404. background-color: #f5f5f5;
  405. flex-shrink: 0;
  406. }
  407. .goods-info {
  408. flex: 1;
  409. margin-left: 20rpx;
  410. display: flex;
  411. flex-direction: column;
  412. justify-content: space-between;
  413. }
  414. .hot-tag {
  415. display: inline-flex;
  416. align-items: center;
  417. background-color: #FFEFE5;
  418. border-radius: 8rpx;
  419. padding: 4rpx 10rpx;
  420. align-self: flex-start;
  421. }
  422. .hot-icon {
  423. width: 24rpx;
  424. height: 24rpx;
  425. }
  426. .hot-text {
  427. font-size: 22rpx;
  428. color: #FF5A1F;
  429. margin-left: 6rpx;
  430. }
  431. .goods-title {
  432. font-size: 28rpx;
  433. color: #333;
  434. line-height: 40rpx;
  435. font-weight: bold;
  436. margin-top: 10rpx;
  437. display: -webkit-box;
  438. -webkit-box-orient: vertical;
  439. -webkit-line-clamp: 2;
  440. overflow: hidden;
  441. }
  442. .goods-bottom {
  443. display: flex;
  444. justify-content: space-between;
  445. align-items: flex-end;
  446. margin-top: 16rpx;
  447. }
  448. .price-wrap {
  449. display: flex;
  450. align-items: baseline;
  451. }
  452. .price-symbol {
  453. font-size: 24rpx;
  454. color: #FF3B30;
  455. font-weight: bold;
  456. }
  457. .price-main {
  458. font-size: 36rpx;
  459. color: #FF3B30;
  460. font-weight: bold;
  461. }
  462. .price-old {
  463. font-size: 22rpx;
  464. color: #999;
  465. text-decoration: line-through;
  466. margin-left: 10rpx;
  467. }
  468. .subsidy-tag {
  469. position: relative;
  470. display: flex;
  471. height: 48rpx;
  472. width: 200rpx;
  473. }
  474. .subsidy-bg {
  475. position: absolute;
  476. top: 0;
  477. left: 0;
  478. width: 100%;
  479. height: 100%;
  480. z-index: 0;
  481. }
  482. .subsidy-content {
  483. position: relative;
  484. z-index: 1;
  485. display: flex;
  486. width: 100%;
  487. height: 100%;
  488. align-items: center;
  489. }
  490. .subsidy-left {
  491. flex: 1;
  492. color: #FF5A1F;
  493. font-size: 20rpx;
  494. text-align: center;
  495. padding-left: 10rpx;
  496. }
  497. .subsidy-right {
  498. flex: 1;
  499. color: #fff;
  500. font-size: 22rpx;
  501. text-align: center;
  502. font-weight: bold;
  503. }
  504. </style>