<template>
  <view class="app-container">
    <!-- 背景 -->
    <view class="bg" :style="{ 'background': `url(${data.channelPic})no-repeat 100% / cover` }" />
    <!-- 跳转App -->
    <open-app @open="open" />
    <!-- 详情 -->
    <view class="detail">
      <img :src="data.channelPic" />
      <view class="content">
        <view class="title">{{ data.aliasName }}</view>
        <view class="num">
          <text class="tips">{{ data.channelTypeText }}</text>
          <text>{{ data.count }}个{{ data.channelTypeText }}</text>
        </view>
        <view class="info">
          <text v-if="data.description">{{ data.description }}</text>
          <text v-else>暂无描述</text>
          <uni-icons />
        </view>
      </view>
    </view>
    <!-- 列表 -->
    <view class="list" v-if="list.length > 0">
      <view class="item" v-for="item in list" :key="item.audioId" @click="open">
        <img class="logo" :src="item.audioPic" />
        <view class="title">
          <text>{{ item.audioName }}</text>
          <text>{{ item.audioInfo }}</text>
        </view>
        <img class="play" src="@/static/share/playbtn.png" @click.stop="open" />
      </view>
    </view>
    <view class="no-data" v-else>
      <img src="@/static/share/empty.png" style="width: 240rpx; height:240rpx" />
      <view style="">暂无频道内容哦</view>
    </view>
  </view>
</template>

<script>
import { channelAudioPage, channelDetail } from '@/api/share'
export default {
  data() {
    return {
      form: {
        pageNum: 1,
        pageSize: 10
      },
      list: [],
      total: 0,
      data: {}
    }
  },
  onLoad(e) {
    if (e.userId) {
      this.form.userId = e.userId
      this.form.channelId = e.channelId
      // 频道详情
      channelDetail({
        channelId: e.channelId,
        userId: e.userId
      }).then(res => {
        if (res.data.code === 0) {
          this.data = res.data
        }
      })
      this.getList()
    }
  },
  onReachBottom() {
    if (this.list.length < this.total) {
      this.form.pageSize += 10
      this.getList()
    }
  },
  methods: {
    // 列表
    getList() {
      channelAudioPage(this.form).then(res => {
        if (res.data.code === 0) {
          this.list = res.data.records
          this.total = res.data.total
        }
      })
    },
    // 下一页
    // getNav(item) {
    //   let url = this.data.channelType === 1 || this.data.channelType === 3 ? `/pages/share/controls?channelType=${this.data.channelType}&audioId=${item.audioId}` : `/pages/share/detail?audioId=${item.audioId}`
    //   uni.navigateTo({
    //     url: url
    //   })
    // },
    // 打开app
    open() {
      this.openApp(`?page=/mobile/channelSinglePage&channel=${this.data.channelId}&channelId=${this.data.id}`)
    }
  }
}
</script>

<style lang="scss" scoped>
.bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 450rpx;
  filter: brightness(0.5) blur(16px);
  z-index: -1;
}

.detail {
  display: flex;
  margin-top: 48rpx;

  img {
    width: 240rpx;
    height: 240rpx;
    border-radius: 16rpx;
  }

  .content {
    width: calc(100% - 272rpx);
    margin-left: 32rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    .title {
      font-weight: 600;
      margin-bottom: 10rpx;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .num {
      display: flex;
      flex-direction: column;
      font-size: 24rpx;
      color: rgba(255, 255, 255, 0.7);

      .tips {
        color: rgba(255, 255, 255, 0.7);
        font-size: 22rpx;
        border: 1px solid rgba(255, 255, 255, 0.15);
        border-radius: 20rpx;
        padding: 2rpx 16rpx;
        width: fit-content;
        margin-bottom: 10rpx;
      }
    }

    .info {
      width: 400rpx;
      color: rgba(255, 255, 255, 0.7);
      font-size: 24rpx;
      position: relative;

      text {
        display: block;
        width: 360rpx;
        overflow: hidden;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
      }
    }

    .info::after {
      content: '\e6b5';
      font-family: uniicons;
      position: absolute;
      right: 0rpx;
      top: 5%;
    }
  }
}

.list {
  margin-top: 80rpx;

  .item:last-child {
    margin: 0;
  }

  .item {
    margin: 32rpx 0;
    height: 160rpx;
    position: relative;

    .logo {
      width: 160rpx;
      height: 160rpx;
      position: absolute;
      top: 0;
      left: 0;
      border-radius: 16rpx;
    }

    .title {
      position: absolute;
      top: 50%;
      left: 180rpx;
      transform: translate(0, -50%);
      display: flex;
      flex-direction: column;

      text:first-child {
        font-size: 28rpx;
        width: 360rpx;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      text:last-child {
        font-size: 24rpx;
        color: rgba(255, 255, 255, 0.4);
        width: 360rpx;
        overflow: hidden;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
      }
    }

    .play {
      width: 48rpx;
      height: 48rpx;
      position: absolute;
      top: 50%;
      right: 0;
      transform: translate(0, -50%);
    }
  }
}

.no-data {
  text-align: center;
  margin-top: 200rpx;
  color: rgba(255, 255, 255, 0.7);
  font-size: 24rpx;
}
</style>