<!-- 安全学习 -->
<template>
  <view class="videoIndex">
    <!--秒杀-->
    <view class="topBox"
          v-for="item in modelData"
          :key="item.id">
      <view class="tui-block__box ">
        <view class="tui-group-name">
          <view class="tui-seckill__box">
            <text style="font-size: 27rpx;">《 {{item.name}} 》</text>
          </view>
          <view class="tui-more__box"
                @tap="navTo('/pages/template/learn/videoDetails',item)">
            <text>查看章节更多视频</text>
            <tui-icon name="arrowright"
                      :size="36"
                      unit="rpx"
                      color="#999"></tui-icon>
          </view>
        </view>
        <scroll-view scroll-x>
          <view class="tui-goods__list">
            <view class="tui-goods__item"
                  @tap="navTo('/pages/template/learn/videoDetails',item,index)"
                  v-for="(itemChildren, index) in item.video"
                  :key="index">
              <view class="tui-goods__imgbox">
                <image :src="!!itemChildren.video_header_url?itemChildren.video_header_url:'/static/images/sxlq/bg-img.png'"
                       mode="widthFix"
                       class="tui-goods__img"></image>
              </view>
              <view class="tui-original__pri">{{itemChildren.video_title}}</view>
            </view>
          </view>
        </scroll-view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      modelData: null,
      LearnVideoClassify: [],
      LearnVideoList: [],
      searchForm: {
        name: "",
      },
    };
  },
  created() {
    this.onLoding();
  },
  methods: {
    async onLoding() {
      await this.getLearnVideoClassify();
      await this.getLearnVideoList();
      this.modelData = this.parseLearn(
        this.LearnVideoClassify,
        this.LearnVideoList
      );
    },
    async getLearnVideoClassify() {
      let res = await this.$request.get("learn/videoCate/index", {
        params: this.searchForm,
      });
      this.LearnVideoClassify = res.data;
    },
    async getLearnVideoList() {
      let res = await this.$request.get("learn/video/index", {
        params: this.searchForm,
      });
      this.LearnVideoList = res.data;
    },
    //整合函数
    parseLearn(titleData, videoList) {
      return titleData.map((item) => {
        item.video = [];
        videoList.map((itemChildren) => {
          if (item.id == itemChildren.cate_id) {
            item.video.push(itemChildren);
          }
        });
        return item;
      });
    },
    navTo(url, dataModel, index = 0) {
      uni.navigateTo({
        url: `${url}?index=${index}&dataModel=${JSON.stringify(dataModel)}`,
      });
    },
  },
};
</script>

<style lang="less" scoped>
.videoIndex {
  .tui-block__box {
    width: 100%;
    padding: 0 25rpx 25rpx;
    box-sizing: border-box;
    background-color: #ffffff;
    border-radius: 20rpx;
    overflow: hidden;
  }

  .tui-group-name {
    width: 100%;
    font-size: 34rpx;
    line-height: 34rpx;
    font-weight: bold;
    text-align: center;
    padding: 30rpx 0 20rpx 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #333;
  }

  .tui-sub__desc {
    color: #34c7a9;
    font-size: 28rpx;
    font-weight: 400;
    padding-left: 25rpx;
  }

  .tui-seckill__box {
    display: flex;
    align-items: center;
  }

  .tui-seckill__img {
    width: 160rpx;
    height: 34rpx;
  }

  .tui-countdown__box {
    width: 228rpx;
    display: flex;
    align-items: center;

    color: #fff;
    background-color: #fff;
    font-weight: 400;
    border: 1px solid #eb0909;
    height: 40rpx;
    border-radius: 30px;
    overflow: hidden;
    margin-left: 25rpx;
  }

  .tui-countdown__title {
    width: 100rpx;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #eb0909;
    flex-shrink: 0;
    font-size: 24rpx;
    line-height: 24rpx;
  }

  .tui-flex__center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /*秒杀商品*/
  .tui-goods__list {
    display: flex;
    align-items: center;
  }

  .tui-goods__item {
    background-color: #fff;
    width: 150rpx;
    // height: 230rpx;
    padding: 20rpx;
    border-radius: 6rpx;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    flex-shrink: 0;
    margin-right: 18rpx;
  }

  .tui-goods__imgbox {
    width: 150rpx;
    height: 130rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
  }

  .tui-goods__img {
    max-width: 180rpx;
    max-height: 180rpx;
    display: block;
  }

  .tui-pri__box {
    max-width: 150rpx;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .tui-sale-pri {
    display: flex;
    align-items: flex-end;
    padding: 10rpx 0 8rpx;
    box-sizing: border-box;
    font-size: 28rpx;
    line-height: 28rpx;
    color: #eb0909;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .tui-size-sm {
    font-size: 24rpx;
    line-height: 24rpx;
    transform: scale(0.8);
    transform-origin: 0 50%;
  }

  .tui-original__pri {
    font-size: 24rpx;
    line-height: 24rpx;
    color: #999999;
    // transform-origin: center 10%;
    // transform: scale(0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    // text-decoration: line-through;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  /*秒杀商品*/

  .tui-more__box {
    display: flex;
    align-items: center;
    font-weight: 400;
    color: #999;
  }

  .tui-more__box text {
    font-size: 24rpx;
    line-height: 24rpx;
  }
}
</style>