RecommendSection.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <template>
  2. <view class="recommend-section" v-if="hasContent">
  3. <!-- 平均分(占位,无数据时显示 —) -->
  4. <view class="score-row" v-if="showScore">
  5. <text class="score-label">平均分</text>
  6. <text class="score-value">{{ averageScore != null ? averageScore : '—' }}</text>
  7. </view>
  8. <view class="recommend-layout">
  9. <!-- 左侧:直播卡片轮播,自动滚动 + 可手动左右滑动,右上角 当前index/总数量 -->
  10. <view class="block-left-wrap" v-if="liveList.length > 0" @click="onLive">
  11. <swiper class="live-swiper" :current="liveCurrent" circular :indicator-dots="false" :autoplay="true"
  12. :interval="3000" :duration="1000" indicator-color="rgba(255, 255, 255, 0.6)"
  13. indicator-active-color="#ffffff" @change="onLiveSwiperChange">
  14. <!-- <swiper-item v-for="(item, idx) in liveList" :key="idx" @click="onLiveClick(item)">
  15. <view class="block-left">
  16. <view class="x-c" :class="['block-label', isLiving(item) ? 'live' : 'replay']">
  17. <image class="w24 h24"
  18. :src="isLiving(item) ? '/static/images/live.gif' : '/static/images/replay.png'"
  19. mode="aspectFill"></image>
  20. {{ isLiving(item) ? '直播中' : '回放' }}
  21. </view>
  22. <image class="block-img" :src="item.liveImgUrl" mode="aspectFill"></image>
  23. <view class="block-tit">
  24. <image class="item-avatar" src="/static/logo.jpg" mode="aspectFill"></image>
  25. <view class="item-title one-t">{{ item.liveName }}</view>
  26. </view>
  27. </view>
  28. </swiper-item> -->
  29. <swiper-item>
  30. <view class="block-left">
  31. <image class="block-img" src="https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/app/image/yuanxiangxing.png" mode="aspectFill"></image>
  32. <view class="block-title one-t">央广会客厅</view>
  33. </view>
  34. </swiper-item>
  35. </swiper>
  36. <!-- <view class="swiper-dots" v-if="liveList.length > 1">
  37. <text v-for="(dot, index) in liveList.length" :key="'live-dot-' + index"
  38. :class="liveCurrent === index ? 'dot-active' : 'dot'"></text>
  39. </view> -->
  40. </view>
  41. <!-- 右侧:上 绿色有机,下 上新推荐 -->
  42. <view class="block-right">
  43. <view class="block-small">
  44. <view class="block-small-head">
  45. <image class="w140" src="@/static/images/new.png" mode="widthFix"></image>
  46. <view class="more" @click.stop="goMore('hot')">
  47. <text class="green">更多</text>
  48. <u-icon name="play-right-fill" color="#FF5B25" size="24rpx"></u-icon>
  49. </view>
  50. </view>
  51. <view class="block-small-body">
  52. <view class="small-item" v-for="(item, i) in hot.slice(0, 2)" :key="i"
  53. @click.stop="onItemClick(item, 'hot')">
  54. <image class="small-thumb" :src="getFirstImage(item)" mode="aspectFill"></image>
  55. <view>
  56. <text class="unit">¥</text>
  57. <text class="small-price" v-if="item.price != null">{{ Number(item.price).toFixed(2)
  58. }}</text>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. <view class="block-small">
  64. <view class="block-small-head">
  65. <image class="w140" src="@/static/images/hot.png" mode="widthFix"></image>
  66. <view class="more" @click.stop="goMore('green')">
  67. <text class="hot">更多</text>
  68. <u-icon name="play-right-fill" color="#FF485D" size="24rpx"></u-icon>
  69. </view>
  70. </view>
  71. <view class="block-small-body">
  72. <view class="small-item" v-for="(item, e) in green.slice(0, 2)" :key="e"
  73. @click.stop="onItemClick(item, 'green')">
  74. <image class="small-thumb" :src="getFirstImage(item)" mode="aspectFill"></image>
  75. <view>
  76. <text class="unit">¥</text>
  77. <text class="small-price" v-if="item.price != null">{{ Number(item.price).toFixed(2)
  78. }}</text>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </template>
  87. <script>
  88. export default {
  89. name: 'RecommendSection',
  90. props: {
  91. live: { type: Array, default: () => [] },
  92. green: { type: Array, default: () => [] },
  93. hot: { type: Array, default: () => [] },
  94. averageScore: { type: [String, Number], default: null },
  95. showScore: { type: Boolean, default: false }
  96. },
  97. computed: {
  98. hasContent() {
  99. return (this.live && this.live.length > 0) || (this.green && this.green.length > 0) || (this.hot && this.hot.length > 0)
  100. },
  101. liveList() {
  102. return this.live && this.live.length > 0 ? this.live : []
  103. },
  104. liveCurrentDisplay() {
  105. return this.liveList.length > 0 ? this.liveCurrent + 1 : 0
  106. }
  107. },
  108. data() {
  109. return {
  110. liveCurrent: 0
  111. }
  112. },
  113. methods: {
  114. onLive(){
  115. // uni.showToast({
  116. // title: '暂无课程',
  117. // icon: 'none'
  118. // })
  119. uni.navigateTo({ url: '/pages_live/livingList' })
  120. },
  121. onLiveSwiperChange(e) {
  122. this.liveCurrent = e.detail.current
  123. },
  124. isLiving(item) {
  125. if (!item) return false
  126. if (item.liveType === 1) return true
  127. if (item.liveType === 2 && item.liveFlag === 1) return true
  128. return false
  129. },
  130. onLiveClick(item) {
  131. //console.log(item)
  132. this.$emit('liveClick', item)
  133. },
  134. goMore(type) {
  135. this.$emit('more', { type })
  136. },
  137. onItemClick(item, type) {
  138. //this.$emit('itemClick', { item, section: { type } })
  139. this.$emit('itemClick', item,type)
  140. },
  141. // 取 sliderImage 逗号拼接的第一张图,没有则用 image
  142. getFirstImage(item) {
  143. if (!item) return ''
  144. const str = item.sliderImage || item.image || ''
  145. if (typeof str !== 'string') return item.image || ''
  146. const first = str.split(',')[0]
  147. return (first && first.trim()) || item.image || ''
  148. }
  149. }
  150. }
  151. </script>
  152. <style lang="scss" scoped>
  153. .recommend-section {
  154. margin: 30rpx 24rpx 40rpx;
  155. }
  156. .score-row {
  157. display: flex;
  158. align-items: center;
  159. margin-bottom: 16rpx;
  160. font-size: 26rpx;
  161. }
  162. .score-label {
  163. color: #666;
  164. margin-right: 12rpx;
  165. }
  166. .score-value {
  167. color: #333;
  168. font-weight: 600;
  169. }
  170. .recommend-layout {
  171. display: flex;
  172. gap: 20rpx;
  173. }
  174. .block-left-wrap {
  175. flex: 1;
  176. // width: 340rpx;
  177. flex-shrink: 0;
  178. // height: 420rpx;
  179. border-radius: 24rpx;
  180. overflow: hidden;
  181. position: relative;
  182. }
  183. .live-swiper {
  184. width: 100%;
  185. height: 100%;
  186. }
  187. .block-left {
  188. width: 100%;
  189. height: 100%;
  190. overflow: hidden;
  191. background: #f5f5f5;
  192. position: relative;
  193. }
  194. .live-index-badge {
  195. position: absolute;
  196. top: 0;
  197. right: 0;
  198. z-index: 2;
  199. background: rgba(0, 0, 0, 0.5);
  200. color: #fff;
  201. font-size: 22rpx;
  202. padding: 8rpx 16rpx;
  203. border-radius: 0 0 0 12rpx;
  204. }
  205. .block-label {
  206. position: absolute;
  207. top: 20rpx;
  208. left: 0;
  209. z-index: 2;
  210. color: #fff;
  211. font-size: 24rpx;
  212. padding: 8rpx 20rpx;
  213. background: linear-gradient(135deg, #FF5267 0%, #FF233C 100%);
  214. border-radius: 0rpx 8rpx 8rpx 0rpx;
  215. image {
  216. margin-right: 4rpx;
  217. }
  218. }
  219. // .block-label.live {
  220. // background: #E5212B;
  221. // }
  222. // .block-label.replay {
  223. // background: #666;
  224. // }
  225. .block-img {
  226. width: 100%;
  227. height: 100%;
  228. display: block;
  229. }
  230. .block-title {
  231. position: absolute;
  232. bottom: 0;
  233. left: 0;
  234. right: 0;
  235. background: rgba(0, 0, 0, 0.45);
  236. color: #fff;
  237. font-size: 26rpx;
  238. padding: 16rpx;
  239. }
  240. .block-tit {
  241. display: flex;
  242. align-items: center;
  243. position: absolute;
  244. bottom: 0;
  245. left: 0;
  246. right: 0;
  247. background: rgba(0, 0, 0, 0.45);
  248. color: #fff;
  249. font-size: 26rpx;
  250. padding: 16rpx 16rpx 50rpx;
  251. .item-avatar {
  252. width: 40rpx;
  253. height: 40rpx;
  254. border-radius: 50%;
  255. margin-right: 10rpx;
  256. }
  257. .item-title {
  258. font-size: 32rpx;
  259. color: #FFFFFF;
  260. line-height: 44rpx;
  261. }
  262. }
  263. .swiper-dots {
  264. display: flex;
  265. position: absolute;
  266. left: 50%;
  267. transform: translateX(-50%);
  268. bottom: 12rpx;
  269. z-index: 3;
  270. gap: 6rpx;
  271. }
  272. .dot {
  273. width: 8rpx;
  274. height: 8rpx;
  275. background: #FFFFFF;
  276. opacity: 0.7;
  277. border-radius: 4rpx;
  278. }
  279. .dot-active {
  280. width: 16rpx;
  281. height: 8rpx;
  282. background: #FFFFFF;
  283. border-radius: 4rpx;
  284. }
  285. .block-right {
  286. flex: 1;
  287. display: flex;
  288. flex-direction: column;
  289. gap: 20rpx;
  290. min-width: 0;
  291. }
  292. .block-small {
  293. flex: 1;
  294. background: linear-gradient(180deg, #FFC7A7 0%, #FFF8F3 36.36%, #FFFFFF 100%);
  295. border-radius: 24rpx;
  296. overflow: hidden;
  297. padding: 16rpx;
  298. &:last-child {
  299. background: linear-gradient(180deg, #FFC5C5 0%, #FFF5F5 36.36%, #FFFFFF 100%);
  300. }
  301. }
  302. .block-small-head {
  303. display: flex;
  304. align-items: center;
  305. justify-content: space-between;
  306. margin-bottom: 18rpx;
  307. }
  308. .block-small-title {
  309. font-size: 28rpx;
  310. font-weight: 600;
  311. }
  312. .green {
  313. color: #FF5B25;
  314. }
  315. .hot {
  316. color: #FF485D;
  317. }
  318. .more {
  319. display: flex;
  320. align-items: center;
  321. font-size: 28rpx;
  322. text {
  323. margin-right: 5rpx;
  324. }
  325. // color: #999;
  326. }
  327. .arrow {
  328. margin-left: 4rpx;
  329. font-size: 28rpx;
  330. }
  331. .block-small-body {
  332. display: flex;
  333. // gap: 16rpx;
  334. }
  335. .small-item {
  336. flex: 1;
  337. display: flex;
  338. flex-direction: column;
  339. align-items: center;
  340. }
  341. .small-thumb {
  342. width: 110rpx;
  343. height: 110rpx;
  344. border-radius: 10rpx;
  345. }
  346. .unit {
  347. font-weight: 600;
  348. font-size: 20rpx;
  349. color: #FF233C;
  350. margin-top: 8rpx;
  351. margin-right: 4rpx;
  352. }
  353. .small-price {
  354. font-size: 32rpx;
  355. font-weight: 600;
  356. color: #FF233C;
  357. margin-top: 8rpx;
  358. }
  359. </style>