home.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template>
  2. <view class="home-container">
  3. <!-- 头部搜索与标题 -->
  4. <view class="custom-header" :style="{paddingTop: statusBarHeight + 'px'}">
  5. <view class="title-bar">
  6. <view class="back-btn" @click="goBack">
  7. <u-icon name="arrow-left" color="#fff" size="20"></u-icon>
  8. </view>
  9. <text class="title">商城</text>
  10. <view class="right-info">
  11. <text class="coin-badge">福币:{{integral}}</text>
  12. </view>
  13. </view>
  14. <view class="search-section">
  15. <u-search placeholder="搜索您想要的内容" :show-action="false" v-model="keyword" bg-color="#fff" color="#333"
  16. placeholder-color="#999" @search="refreshList" @clear="refreshList"></u-search>
  17. </view>
  18. </view>
  19. <!-- 滚动内容区 -->
  20. <scroll-view scroll-y class="scroll-content" @scrolltolower="scrolltolower">
  21. <!-- Banner -->
  22. <view class="banner-section" v-if="false">
  23. <view class="banner-wrapper">
  24. <view class="banner-icon">
  25. <u-icon name="volume-fill" color="#fff" size="24"></u-icon>
  26. </view>
  27. <view class="banner-content">
  28. <text class="banner-title">快递停运通知</text>
  29. <text class="banner-sub">春节期间快递服务调整,请提前安排下单</text>
  30. </view>
  31. <view class="banner-action">
  32. <text>查看</text>
  33. <u-icon name="arrow-right" color="#fff" size="12"></u-icon>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 金刚区导航 -->
  38. <view class="nav-grid">
  39. <view class="nav-item" @click="navTo('/pages_mall/newArrival')">
  40. <view class="icon-box icon-new">
  41. <u-icon name="star-fill" color="#fff" size="24"></u-icon>
  42. </view>
  43. <text>新品推荐</text>
  44. </view>
  45. <view class="nav-item" @click="switchTab(1)">
  46. <view class="icon-box icon-cate">
  47. <u-icon name="grid-fill" color="#fff" size="24"></u-icon>
  48. </view>
  49. <text>商品分类</text>
  50. </view>
  51. <view class="nav-item" @click="navTo('/pages_mall/exchange')">
  52. <view class="icon-box icon-mall">
  53. <u-icon name="bag-fill" color="#fff" size="24"></u-icon>
  54. </view>
  55. <text>福币商城</text>
  56. </view>
  57. <view class="nav-item" @click="switchTab(3)">
  58. <view class="icon-box icon-user">
  59. <u-icon name="account-fill" color="#fff" size="24"></u-icon>
  60. </view>
  61. <text>个人中心</text>
  62. </view>
  63. </view>
  64. <!-- 商品列表 -->
  65. <view class="goods-section">
  66. <!-- <view class="goods-item"
  67. @click="navTo('/pages/user/integral/integralGoodsDetails?goodsId=' + item.goodsId)" -->
  68. <view class="goods-item" @click="navTo('/pages_mall/productDetails?productId='+item.productId)"
  69. v-for="(item,index) in dataList" :key="index">
  70. <image :src="item.image || item.imgUrl" mode="aspectFill" class="goods-img"></image>
  71. <view class="goods-info">
  72. <text class="goods-title ellipsis2">{{item.productName || item.goodsName}}</text>
  73. <view class="goods-price">
  74. <text class="price es-mr-10">¥{{item.otPrice ? item.otPrice.toFixed(2) : item.price}}</text>
  75. <text class="es-fs-24">已售{{item.sales || 0}}件</text>
  76. <!-- <text class="org-price" v-if="item.price">¥{{item.price}}</text> -->
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. <view class="loading-more" v-if="dataList.length > 0">
  82. <u-loadmore :status="isMore ? 'loading' : 'nomore'" />
  83. </view>
  84. <view class="empty-box" v-if="dataList.length == 0">
  85. <u-empty mode="data" text="暂无商品数据"></u-empty>
  86. </view>
  87. </scroll-view>
  88. </view>
  89. </template>
  90. <script>
  91. import {
  92. getDictByKey
  93. } from '@/api/common.js'
  94. import {
  95. getProducts
  96. } from '@/api/product.js'
  97. import {
  98. getUserInfo
  99. } from '@/api/user'
  100. import {
  101. getAdvList
  102. } from '@/api/adv.js'
  103. import {
  104. getIntegralGoodsList
  105. } from '@/api/integral.js'
  106. export default {
  107. data() {
  108. return {
  109. statusBarHeight: 20,
  110. integral: 0,
  111. keyword: "",
  112. dataList: [],
  113. pageNum: 1,
  114. pageSize: 10,
  115. isMore: true,
  116. total: 0,
  117. bannerList: [], // 轮播图图片列表
  118. bannerAdvs: [] // 轮播图完整数据
  119. }
  120. },
  121. created() {
  122. this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
  123. this.initData();
  124. },
  125. methods: {
  126. initData() {
  127. this.getUserInfo();
  128. this.getBannerData();
  129. this.refreshList();
  130. },
  131. getBannerData() {
  132. // 尝试获取轮播图,假设商城首页advType为1或使用通用配置
  133. // 如果没有特定ID,先尝试用1,或者使用模拟数据
  134. let data = {
  135. advType: 1
  136. };
  137. getAdvList(data).then(res => {
  138. if (res.code == 200 && res.data && res.data.length > 0) {
  139. this.bannerAdvs = res.data;
  140. this.bannerList = res.data.map(item => item.imageUrl);
  141. } else {
  142. // 如果接口没有数据,使用默认好看的占位图
  143. this.bannerList = [
  144. 'https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/banner1.jpg',
  145. 'https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/banner2.jpg'
  146. ];
  147. // 这里的图片地址如果是404,我会换成更稳定的图,或者使用项目中已有的图
  148. // 为了稳妥,使用picsum或者mock
  149. // 但考虑到是医疗商城,最好用相关图。先用假数据占位,或者复用项目中看到的图
  150. }
  151. // 如果列表为空(包括接口没数据且上面没设置默认),则设置默认
  152. if (this.bannerList.length === 0) {
  153. this.bannerList = [
  154. 'https://cdn.uviewui.com/uview/swiper/swiper1.png',
  155. 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
  156. 'https://cdn.uviewui.com/uview/swiper/swiper3.png'
  157. ];
  158. }
  159. });
  160. },
  161. getUserInfo() {
  162. getUserInfo().then(res => {
  163. if (res.code == 200 && res.user != null) {
  164. this.integral = res.user.integral;
  165. }
  166. });
  167. },
  168. refreshList() {
  169. this.pageNum = 1;
  170. this.isMore = true;
  171. this.dataList = [];
  172. this.getList();
  173. },
  174. scrolltolower() {
  175. if (this.isMore) {
  176. this.getList();
  177. }
  178. },
  179. getList() {
  180. var data = {
  181. page: this.pageNum,
  182. pageNum: this.pageNum,
  183. limit: this.pageSize,
  184. pageSize: this.pageSize,
  185. keyword: this.keyword,
  186. };
  187. // 保持原逻辑
  188. getProducts(data).then(res => {
  189. // getIntegralGoodsList(data).then(res => {
  190. if (res.code == 200) {
  191. let list = res.data.list && res.data.list.length > 0 ? res.data.list : []
  192. this.dataList = this.dataList.concat(list)
  193. this.total = res.data.total
  194. this.pageNum++
  195. if (this.dataList.length >= this.total) {
  196. this.isMore = false
  197. }
  198. } else {
  199. // this.dataList = [] // Keep existing if error? Or clear. Original cleared.
  200. }
  201. });
  202. },
  203. navTo(url) {
  204. uni.navigateTo({
  205. url: url
  206. })
  207. },
  208. goBack() {
  209. uni.showTabBar()
  210. uni.switchTab({
  211. url: '/pages_im/pages/conversation/conversationList/index'
  212. })
  213. },
  214. switchTab(index) {
  215. this.$emit('switchTab', index);
  216. }
  217. }
  218. }
  219. </script>
  220. <style scoped lang="scss">
  221. .home-container {
  222. display: flex;
  223. flex-direction: column;
  224. height: 100%;
  225. background-color: #F5F7FA;
  226. }
  227. .custom-header {
  228. background: linear-gradient(to bottom, #2583EB, #4FACFE);
  229. padding: 20rpx 30rpx;
  230. color: #fff;
  231. .title-bar {
  232. display: flex;
  233. align-items: center;
  234. justify-content: space-between;
  235. height: 88rpx;
  236. .title {
  237. font-size: 36rpx;
  238. font-weight: bold;
  239. }
  240. .coin-badge {
  241. background: rgba(255, 255, 255, 0.25);
  242. padding: 6rpx 20rpx;
  243. border-radius: 30rpx;
  244. font-size: 24rpx;
  245. backdrop-filter: blur(10px);
  246. }
  247. }
  248. .search-section {
  249. margin-top: 10rpx;
  250. padding-bottom: 20rpx;
  251. }
  252. }
  253. .scroll-content {
  254. flex: 1;
  255. height: 0;
  256. }
  257. .banner-section {
  258. padding: 20rpx 30rpx;
  259. background-color: #fff;
  260. margin-bottom: 20rpx;
  261. .banner-wrapper {
  262. background: linear-gradient(90deg, #FF6B6B, #FF8E53);
  263. border-radius: 16rpx;
  264. padding: 20rpx;
  265. display: flex;
  266. align-items: center;
  267. box-shadow: 0 4rpx 12rpx rgba(255, 107, 107, 0.3);
  268. .banner-icon {
  269. width: 60rpx;
  270. height: 60rpx;
  271. background: rgba(255, 255, 255, 0.2);
  272. border-radius: 50%;
  273. display: flex;
  274. align-items: center;
  275. justify-content: center;
  276. margin-right: 20rpx;
  277. }
  278. .banner-content {
  279. flex: 1;
  280. display: flex;
  281. flex-direction: column;
  282. .banner-title {
  283. font-size: 30rpx;
  284. font-weight: bold;
  285. color: #fff;
  286. margin-bottom: 6rpx;
  287. }
  288. .banner-sub {
  289. font-size: 24rpx;
  290. color: rgba(255, 255, 255, 0.9);
  291. }
  292. }
  293. .banner-action {
  294. display: flex;
  295. align-items: center;
  296. background: rgba(255, 255, 255, 0.2);
  297. padding: 6rpx 16rpx;
  298. border-radius: 24rpx;
  299. text {
  300. font-size: 22rpx;
  301. color: #fff;
  302. margin-right: 4rpx;
  303. }
  304. }
  305. }
  306. }
  307. .scroll-content {
  308. flex: 1;
  309. height: 0; // Important for flex scroll
  310. }
  311. .nav-grid {
  312. display: flex;
  313. justify-content: space-between;
  314. padding: 30rpx;
  315. background: #fff;
  316. margin: 0 30rpx 20rpx;
  317. border-radius: 24rpx;
  318. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  319. .nav-item {
  320. display: flex;
  321. flex-direction: column;
  322. align-items: center;
  323. .icon-box {
  324. width: 100rpx;
  325. height: 100rpx;
  326. border-radius: 36rpx;
  327. display: flex;
  328. align-items: center;
  329. justify-content: center;
  330. margin-bottom: 16rpx;
  331. transition: transform 0.2s;
  332. &:active {
  333. transform: scale(0.95);
  334. }
  335. &.icon-new {
  336. background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  337. }
  338. &.icon-cate {
  339. background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  340. }
  341. &.icon-mall {
  342. background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
  343. }
  344. &.icon-user {
  345. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  346. }
  347. }
  348. text {
  349. font-size: 26rpx;
  350. color: #333;
  351. font-weight: 500;
  352. }
  353. }
  354. }
  355. .goods-section {
  356. padding: 0 30rpx 20rpx;
  357. display: flex;
  358. flex-wrap: wrap;
  359. justify-content: space-between;
  360. .goods-item {
  361. width: 48%;
  362. background: #fff;
  363. border-radius: 20rpx;
  364. margin-bottom: 24rpx;
  365. overflow: hidden;
  366. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);
  367. transition: transform 0.2s;
  368. &:active {
  369. transform: scale(0.98);
  370. }
  371. .goods-img {
  372. width: 100%;
  373. height: 320rpx;
  374. background: #eee;
  375. }
  376. .goods-info {
  377. padding: 20rpx;
  378. .goods-title {
  379. font-size: 28rpx;
  380. color: #333;
  381. margin-bottom: 16rpx;
  382. height: 80rpx;
  383. line-height: 40rpx;
  384. font-weight: 500;
  385. }
  386. .goods-price {
  387. display: flex;
  388. align-items: baseline;
  389. .price {
  390. color: #FF5000;
  391. font-size: 34rpx;
  392. font-weight: bold;
  393. &::before {
  394. content: '¥';
  395. font-size: 24rpx;
  396. margin-right: 4rpx;
  397. }
  398. }
  399. .org-price {
  400. color: #999;
  401. font-size: 22rpx;
  402. text-decoration: line-through;
  403. margin-left: 12rpx;
  404. }
  405. }
  406. }
  407. }
  408. }
  409. </style>