RecommendSection.vue 9.0 KB

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