多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

449 lines
12 KiB

2 years ago
2 years ago
  1. <template>
  2. <view class="live-box">
  3. <view class="live-ongoing" v-if="liveData.liveStatus === 101" @click="toLive">
  4. <image class="cover-img" :src="liveData.feedsImg" />
  5. <view class="status">
  6. <view class="status-state">
  7. <image class="img" src="https://ceres.zkthink.com/static/img/live/icon-live-num.png" />直播中
  8. </view>
  9. <!-- <view class="status-num">1000</view> -->
  10. </view>
  11. <view class="user">
  12. <view class="user-pic">
  13. <image class="img" :src="liveData.anchorHeadImg" />
  14. </view>
  15. <view class="user-name">{{ liveData.anchorNickName }}</view>
  16. </view>
  17. <view class="products">
  18. <view class="uni-padding-wrap">
  19. <view class="page-section swiper">
  20. <view class="page-section-spacing">
  21. <swiper class="swiper"
  22. :indicator-dots="indicatorDots"
  23. :autoplay="autoplay"
  24. :interval="interval"
  25. :duration="duration"
  26. :vertical="true"
  27. >
  28. <swiper-item
  29. v-for="item in liveData.goods"
  30. :key="item.goods_id"
  31. >
  32. <view class="swiper-item">{{ item.name }}</view>
  33. </swiper-item>
  34. </swiper>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <view class="live-other" v-else @click="toLive">
  41. <image class="cover-img" :src="liveData.feedsImg" />
  42. <div class="filter-box-warp">
  43. <div class="filter-box">
  44. <image class="cover-img" :src="liveData.feedsImg" />
  45. </div>
  46. </div>
  47. <view class="user">
  48. <view class="user-pic"><image class="img" :src="liveData.anchorHeadImg" /></view>
  49. <view class="user-name">{{ liveData.anchorNickName }}</view>
  50. </view>
  51. <view class="count-down" v-if="liveStatus === 102">
  52. <image v-if="isLate" class="img" src="../../../static/images/live/live-late.png"/>
  53. <view class="text">{{ liveTimeTitle }}</view>
  54. <view v-if="!isLate" class="time">
  55. <view class="time-item">{{times[0]}}</view>
  56. <view class="dot">:</view>
  57. <view class="time-item">{{times[1]}}</view>
  58. <view class="dot">:</view>
  59. <view class="time-item">{{times[2]}}</view>
  60. </view>
  61. </view>
  62. <!-- #ifdef MP-WEIXIN -->
  63. <view
  64. v-if="liveStatus === 102 && !isLate"
  65. class="btn-subscribe"
  66. :class="{subscribed : subscribeLive === '已预约'}"
  67. @click.stop="onSubscribe"
  68. >{{ subscribeLive }}</view>
  69. <!-- #endif -->
  70. <view class="endContainer" v-if="liveStatus === 103">
  71. <view class="endBox">
  72. <view></view>
  73. <view></view>
  74. <view></view>
  75. <view></view>
  76. </view>
  77. <view>直播已结束</view>
  78. </view>
  79. </view>
  80. </view>
  81. </template>
  82. <script>
  83. const NET = require('@/utils/request')
  84. const API = require('@/config/api')
  85. import { startLiveTemplate } from '@/config/subscribe.js'
  86. import { liveAppid } from '@/config/live.js'
  87. // #ifdef MP-WEIXIN
  88. // const livePlayer = requirePlugin('live-player-plugin')
  89. // #endif
  90. export default {
  91. props: {
  92. liveData: {
  93. type: Object,
  94. default: () => ({
  95. roomId: 0,
  96. anchorNickName: '',
  97. feedsImg: '' // 官方收录封面
  98. })
  99. }
  100. },
  101. data () {
  102. return {
  103. background: ['color1', 'color2', 'color3'],
  104. indicatorDots: false,
  105. autoplay: true,
  106. interval: 2000, // 自动播放间隔时长
  107. duration: 500, // 幻灯片切换时长(ms)
  108. d: 0,
  109. m: 0,
  110. s: 0,
  111. times: ['00', '00', '00'],
  112. liveStatus: 100,
  113. liveTimeTitle: '开播倒计时',
  114. subscribeLive: '立即预约',
  115. timer: null,
  116. isLate: false,
  117. }
  118. },
  119. created() {
  120. this.liveStatus = this.liveData.liveStatus
  121. this.subscribeLive = this.liveData.subscribeStatus === 0 ? '立即预约' : '已预约'
  122. this.getStatus()
  123. this.countTime()
  124. // this.getSubscribeStatus()
  125. },
  126. destroyed() {
  127. clearTimeout(this.timer)
  128. },
  129. methods: {
  130. getStatus() {
  131. if (!this.liveData.roomId) { return }
  132. let _this = this
  133. // #ifdef MP-WEIXIN
  134. livePlayer.getLiveStatus({ room_id: this.liveData.roomId })
  135. .then(res => {
  136. // 101: 直播中, 102: 未开始, 103: 已结束, 104: 禁播, 105: 暂停中, 106: 异常,107:已过期
  137. // _this.liveData.liveStatus = res.liveStatus
  138. _this.liveStatus = res.liveStatus
  139. })
  140. .catch(err => {
  141. })
  142. this.timer = setInterval(() => {
  143. livePlayer.getLiveStatus({ room_id: this.liveData.roomId })
  144. .then(res => {
  145. // 101: 直播中, 102: 未开始, 103: 已结束, 104: 禁播, 105: 暂停中, 106: 异常,107:已过期
  146. _this.liveStatus = res.liveStatus
  147. this.countTime()
  148. })
  149. .catch(err => {
  150. })
  151. }, 60000)
  152. // #endif
  153. },
  154. changeIndicatorDots(e) {
  155. this.indicatorDots = !this.indicatorDots
  156. },
  157. changeAutoplay(e) {
  158. this.autoplay = !this.autoplay
  159. },
  160. intervalChange(e) {
  161. this.interval = e.target.value
  162. },
  163. durationChange(e) {
  164. this.duration = e.target.value
  165. },
  166. countTime(){
  167. const nowtime = new Date().getTime() //获取当前时间
  168. const starttime = new Date(this.liveData.startTime).getTime()
  169. if(this.liveStatus === 102){
  170. if(starttime > nowtime){
  171. var lefttime = starttime - nowtime //距离结束时间的毫秒数
  172. var leftd = Math.floor(lefttime/(1000*60*60)), //计算小时数
  173. leftm = Math.floor(lefttime/(1000*60)%60), //计算分钟数
  174. lefts = Math.floor(lefttime/1000%60); //计算秒数
  175. this.times = [leftd < 10?'0'+ leftd:leftd,leftm < 10?'0'+ leftm:leftm,lefts < 10?'0'+ lefts:lefts]
  176. this.liveTimeTitle = '开播倒计时'
  177. setTimeout(() => {
  178. this.countTime()
  179. },1000)
  180. } else {
  181. this.times = ['00', '00', '00']
  182. this.isLate = true
  183. this.liveTimeTitle = '正在赶来的路上...'
  184. }
  185. }
  186. },
  187. toLive() {
  188. if (!liveAppid || !this.liveData) { return }
  189. // 跳转直播间携带路由参数
  190. // let customParams = encodeURIComponent(JSON.stringify({ path: 'livePage/index', pid: 1 }))
  191. // #ifdef MP-WEIXIN
  192. wx.navigateTo({
  193. url: `plugin-private://${liveAppid}/pages/live-player-plugin?room_id=${this.liveData.roomId}`
  194. // url: `plugin-private://${liveAppid}/pages/live-player-plugin?room_id=${this.liveData.roomId}&custom_params=${customParams}`
  195. })
  196. // #endif
  197. },
  198. onSubscribe() {
  199. if (this.subscribeLive === '立即预约') {
  200. const _this = this
  201. // #ifdef MP-WEIXIN
  202. uni.requestSubscribeMessage({
  203. tmplIds: [startLiveTemplate],
  204. success (res) {
  205. if (res[startLiveTemplate] === "accept") {
  206. NET.request(API.SubScribeLive, {id: _this.liveData.id }, 'post')
  207. .then(res => {
  208. if (res.data) {
  209. _this.subscribeLive = '已预约'
  210. } else {
  211. uni.showToast({
  212. title: res.message || '订阅失败,请稍后再试!',
  213. icon: "none"
  214. })
  215. }
  216. })
  217. .catch(err => {
  218. uni.showToast({
  219. title: res.message || '订阅失败,请稍后再试!',
  220. icon: "none"
  221. })
  222. })
  223. }
  224. }
  225. })
  226. // #endif
  227. }
  228. }
  229. }
  230. }
  231. </script>
  232. <style lang="scss" scoped>
  233. .live-box{
  234. position: relative;
  235. color: #fff;
  236. width: 100%;
  237. height: 100%;
  238. .cover-img{
  239. width: 100%;
  240. height: 100%;
  241. position: absolute;
  242. z-index: 0;
  243. }
  244. .user{
  245. display: flex;
  246. line-height: 60rpx;
  247. height: 64rpx;
  248. &-pic{
  249. .img{
  250. width: 60rpx;
  251. height: 60rpx;
  252. border: 2px solid rgba(255, 255, 255, 0.5019607843137255);
  253. border-radius: 50%;
  254. overflow: hidden;
  255. }
  256. }
  257. &-name{
  258. font-size: 28rpx;
  259. margin-left: 16rpx;
  260. overflow: hidden;
  261. text-overflow: ellipsis;
  262. white-space: nowrap;
  263. width: 245rpx;
  264. }
  265. }
  266. .live-ongoing{
  267. width: 100%;
  268. height: 100%;
  269. position: relative;
  270. .status{
  271. position: absolute;
  272. top: 22rpx;
  273. left: 22rpx;
  274. //width: 212upx;
  275. height: 48rpx;
  276. // background: rgba(0,0,0,0.3);
  277. // border: 2rpx solid rgba(255,255,255,0.3);
  278. border-radius: 24rpx;
  279. font-size: 20rpx;
  280. line-height: 44rpx;
  281. display: flex;
  282. // padding-right: 8rpx;
  283. &-state{
  284. width: 118rpx;
  285. height: 44rpx;
  286. background: linear-gradient(90deg, #C83732 0%, #E25C44 100%);
  287. opacity: 1;
  288. border-radius: 26rpx;
  289. display: flex;
  290. align-items: center;
  291. justify-content: center;
  292. .img{
  293. width: 20rpx;
  294. height: 20rpx;
  295. margin-right: 6rpx;
  296. }
  297. }
  298. &-num{
  299. min-width: 80rpx;
  300. padding: 0 8rpx;
  301. }
  302. }
  303. .user{
  304. position: absolute;
  305. bottom: 62rpx;
  306. left: 20rpx;
  307. }
  308. .products{
  309. position: absolute;
  310. left: 0rpx;
  311. bottom: 20rpx;
  312. width: 100%;
  313. padding:0 20rpx;
  314. .swiper{
  315. height: 34rpx;
  316. line-height: 34rpx;
  317. font-size: 24rpx;
  318. overflow: hidden;
  319. text-overflow:ellipsis;
  320. white-space: nowrap;
  321. }
  322. }
  323. }
  324. .live-other{
  325. position: relative;
  326. height: 100%;
  327. display: flex;
  328. align-items: center;
  329. justify-content: center;
  330. .filter-box-warp{
  331. background-color: #000000;
  332. position: absolute;
  333. top: 0;
  334. left: 0;
  335. width: 100%;
  336. height: 100%;
  337. .filter-box{
  338. position: absolute;
  339. top: -30rpx;
  340. left: -30rpx;
  341. width: 348rpx;
  342. height: 464rpx;
  343. display: flex;
  344. align-items: center;
  345. justify-content: center;
  346. -webkit-filter: blur(20px);
  347. -moz-filter: blur(21px);
  348. -ms-filter: blur(20px);
  349. -o-filter: blur(20px);
  350. padding: 30rpx;
  351. box-sizing: content-box;
  352. }
  353. }
  354. .user{
  355. position: absolute;
  356. top: 20rpx;
  357. left: 20rpx;
  358. }
  359. .count-down{
  360. position: relative;
  361. .text{
  362. font-size: 26rpx;
  363. line-height: 36rpx;
  364. margin-bottom: 16rpx;
  365. opacity: 0.5;
  366. text-align: center;
  367. }
  368. .img{
  369. display: block;
  370. width: 80rpx;
  371. height: 80rpx;
  372. margin: 16rpx auto;
  373. }
  374. .time{
  375. display: flex;
  376. justify-content: space-around;
  377. align-items: center;
  378. &-item{
  379. min-width: 52rpx;
  380. padding: 0 5rpx;
  381. height: 52rpx;
  382. line-height: 52rpx;
  383. background: #FFFFFF;
  384. opacity: 1;
  385. border-radius: 6rpx;
  386. font-size: 26rpx;
  387. color: #C83732;
  388. text-align: center;
  389. .dot{
  390. line-height: 52rpx;
  391. }
  392. }
  393. }
  394. }
  395. .btn-subscribe{
  396. width: 200rpx;
  397. height: 64rpx;
  398. line-height: 64rpx;
  399. background: linear-gradient(90deg, #C83732 0%, #E25C44 100%);
  400. box-shadow: 0rpx 6rpx 12rpx rgba(233, 0, 0, 0.3);
  401. opacity: 1;
  402. border-radius: 6rpx;
  403. color: #fff;
  404. font-size: 24rpx;
  405. text-align: center;
  406. position: absolute;
  407. bottom: 60rpx;
  408. left: 50%;
  409. margin-left: -100rpx;
  410. &.subscribed{
  411. background: #FFFFFF;
  412. color: #999999;
  413. box-shadow: none;
  414. }
  415. }
  416. .endContainer{
  417. position: relative;
  418. .endBox{
  419. width: 40%;
  420. height: 60rpx;
  421. margin: 20rpx auto;
  422. display: flex;
  423. justify-content: space-between;
  424. align-items: flex-end;
  425. view{
  426. width: 0;
  427. border: 2rpx solid #FFF;
  428. }
  429. view:nth-of-type(1){
  430. height: 20%;
  431. }
  432. view:nth-of-type(2){
  433. height: 50%;
  434. }
  435. view:nth-of-type(3){
  436. height: 30%;
  437. }
  438. view:nth-of-type(4){
  439. height: 70%;
  440. }
  441. }
  442. }
  443. }
  444. }
  445. </style>