RecommendSection.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. },
  120. onLiveSwiperChange(e) {
  121. this.liveCurrent = e.detail.current
  122. },
  123. isLiving(item) {
  124. if (!item) return false
  125. if (item.liveType === 1) return true
  126. if (item.liveType === 2 && item.liveFlag === 1) return true
  127. return false
  128. },
  129. onLiveClick(item) {
  130. //console.log(item)
  131. this.$emit('liveClick', item)
  132. },
  133. goMore(type) {
  134. this.$emit('more', { type })
  135. },
  136. onItemClick(item, type) {
  137. //this.$emit('itemClick', { item, section: { type } })
  138. this.$emit('itemClick', item,type)
  139. },
  140. // 取 sliderImage 逗号拼接的第一张图,没有则用 image
  141. getFirstImage(item) {
  142. if (!item) return ''
  143. const str = item.sliderImage || item.image || ''
  144. if (typeof str !== 'string') return item.image || ''
  145. const first = str.split(',')[0]
  146. return (first && first.trim()) || item.image || ''
  147. }
  148. }
  149. }
  150. </script>
  151. <style lang="scss" scoped>
  152. .recommend-section {
  153. margin: 30rpx 24rpx 40rpx;
  154. }
  155. .score-row {
  156. display: flex;
  157. align-items: center;
  158. margin-bottom: 16rpx;
  159. font-size: 26rpx;
  160. }
  161. .score-label {
  162. color: #666;
  163. margin-right: 12rpx;
  164. }
  165. .score-value {
  166. color: #333;
  167. font-weight: 600;
  168. }
  169. .recommend-layout {
  170. display: flex;
  171. gap: 20rpx;
  172. }
  173. .block-left-wrap {
  174. flex: 1;
  175. // width: 340rpx;
  176. flex-shrink: 0;
  177. // height: 420rpx;
  178. border-radius: 24rpx;
  179. overflow: hidden;
  180. position: relative;
  181. }
  182. .live-swiper {
  183. width: 100%;
  184. height: 100%;
  185. }
  186. .block-left {
  187. width: 100%;
  188. height: 100%;
  189. overflow: hidden;
  190. background: #f5f5f5;
  191. position: relative;
  192. }
  193. .live-index-badge {
  194. position: absolute;
  195. top: 0;
  196. right: 0;
  197. z-index: 2;
  198. background: rgba(0, 0, 0, 0.5);
  199. color: #fff;
  200. font-size: 22rpx;
  201. padding: 8rpx 16rpx;
  202. border-radius: 0 0 0 12rpx;
  203. }
  204. .block-label {
  205. position: absolute;
  206. top: 20rpx;
  207. left: 0;
  208. z-index: 2;
  209. color: #fff;
  210. font-size: 24rpx;
  211. padding: 8rpx 20rpx;
  212. background: linear-gradient(135deg, #FF5267 0%, #FF233C 100%);
  213. border-radius: 0rpx 8rpx 8rpx 0rpx;
  214. image {
  215. margin-right: 4rpx;
  216. }
  217. }
  218. // .block-label.live {
  219. // background: #E5212B;
  220. // }
  221. // .block-label.replay {
  222. // background: #666;
  223. // }
  224. .block-img {
  225. width: 100%;
  226. height: 100%;
  227. display: block;
  228. }
  229. .block-title {
  230. position: absolute;
  231. bottom: 0;
  232. left: 0;
  233. right: 0;
  234. background: rgba(0, 0, 0, 0.45);
  235. color: #fff;
  236. font-size: 26rpx;
  237. padding: 16rpx;
  238. }
  239. .block-tit {
  240. display: flex;
  241. align-items: center;
  242. position: absolute;
  243. bottom: 0;
  244. left: 0;
  245. right: 0;
  246. background: rgba(0, 0, 0, 0.45);
  247. color: #fff;
  248. font-size: 26rpx;
  249. padding: 16rpx 16rpx 50rpx;
  250. .item-avatar {
  251. width: 40rpx;
  252. height: 40rpx;
  253. border-radius: 50%;
  254. margin-right: 10rpx;
  255. }
  256. .item-title {
  257. font-size: 32rpx;
  258. color: #FFFFFF;
  259. line-height: 44rpx;
  260. }
  261. }
  262. .swiper-dots {
  263. display: flex;
  264. position: absolute;
  265. left: 50%;
  266. transform: translateX(-50%);
  267. bottom: 12rpx;
  268. z-index: 3;
  269. gap: 6rpx;
  270. }
  271. .dot {
  272. width: 8rpx;
  273. height: 8rpx;
  274. background: #FFFFFF;
  275. opacity: 0.7;
  276. border-radius: 4rpx;
  277. }
  278. .dot-active {
  279. width: 16rpx;
  280. height: 8rpx;
  281. background: #FFFFFF;
  282. border-radius: 4rpx;
  283. }
  284. .block-right {
  285. flex: 1;
  286. display: flex;
  287. flex-direction: column;
  288. gap: 20rpx;
  289. min-width: 0;
  290. }
  291. .block-small {
  292. flex: 1;
  293. background: linear-gradient(180deg, #FFC7A7 0%, #FFF8F3 36.36%, #FFFFFF 100%);
  294. border-radius: 24rpx;
  295. overflow: hidden;
  296. padding: 16rpx;
  297. &:last-child {
  298. background: linear-gradient(180deg, #FFC5C5 0%, #FFF5F5 36.36%, #FFFFFF 100%);
  299. }
  300. }
  301. .block-small-head {
  302. display: flex;
  303. align-items: center;
  304. justify-content: space-between;
  305. margin-bottom: 18rpx;
  306. }
  307. .block-small-title {
  308. font-size: 28rpx;
  309. font-weight: 600;
  310. }
  311. .green {
  312. color: #FF5B25;
  313. }
  314. .hot {
  315. color: #FF485D;
  316. }
  317. .more {
  318. display: flex;
  319. align-items: center;
  320. font-size: 28rpx;
  321. text {
  322. margin-right: 5rpx;
  323. }
  324. // color: #999;
  325. }
  326. .arrow {
  327. margin-left: 4rpx;
  328. font-size: 28rpx;
  329. }
  330. .block-small-body {
  331. display: flex;
  332. // gap: 16rpx;
  333. }
  334. .small-item {
  335. flex: 1;
  336. display: flex;
  337. flex-direction: column;
  338. align-items: center;
  339. }
  340. .small-thumb {
  341. width: 110rpx;
  342. height: 110rpx;
  343. border-radius: 10rpx;
  344. }
  345. .unit {
  346. font-weight: 600;
  347. font-size: 20rpx;
  348. color: #FF233C;
  349. margin-top: 8rpx;
  350. margin-right: 4rpx;
  351. }
  352. .small-price {
  353. font-size: 32rpx;
  354. font-weight: 600;
  355. color: #FF233C;
  356. margin-top: 8rpx;
  357. }
  358. </style>