<template>
  <div class="video">
    <div class="nav">
      <div class="tabs">
        <div :class="tabindex == 4 ? 'on' : ''" @click="tabchange(4)">
          {{lan.$t('quanbushipin')}}
        </div>
        <div :class="tabindex == 0 ? 'on' : ''" @click="tabchange(0)">
          {{lan.$t('shenhezhong')}}
        </div>
        <div :class="tabindex == 2 ? 'on' : ''" @click="tabchange(2)">
          {{lan.$t('weitongguo')}}
        </div>
        <div :class="tabindex == 1 ? 'on' : ''" @click="tabchange(1)">
          {{lan.$t('yifabu')}}
        </div>
      </div>
      <div class="sel">
        <img src="@/static/images/sousuo.png" alt="" class="icon" />
        <input type="text"  :placeholder="lan.$t('shipinsousuo')"  @keyup.enter="sel()" v-model="input"/>
      </div>
    </div>
    <template v-if="!videolist.total">
        <a-empty />
    </template>
    <div class="list" v-if="tabindex == 4">
      <LiveItemad v-if="videolist.total"></LiveItemad>
      <VideoItem
        v-for="(i, j) in videolist.data"
        :key="j"
        :videoid="i.videoid"
        :img="i.img"
        :title="i.title"
        :score="i.score"
        :date="i.created_at"
        :takehour="i.fileduration"
        :livenum="i.statusname"
        :status="i.status"
        :watch="i.watch"
        :share="i.share"
        :transcoding="i.transcoding"
      ></VideoItem>
    </div>

    <div class="list" v-if="tabindex == 0">
      <LiveItemad v-if="videolist.total"></LiveItemad>
      <VideoItem
        v-for="(i, j) in videolist.data"
        :key="j"
        :videoid="i.videoid"
        :img="i.img"
        :title="i.title"
        :score="i.score"
        :date="i.created_at"
        :takehour="i.fileduration"
        :livenum="i.statusname"
        :status="i.status"
        :watch="i.watch"
        :transcoding="i.transcoding"
        :share="i.share"
      ></VideoItem>
    </div>
    <div class="list" v-if="tabindex == 2">
      <LiveItemad v-if="videolist.total"></LiveItemad>
      <VideoItem
        v-for="(i, j) in videolist.data"
        :key="j"
        :img="i.img"
        :videoid="i.videoid"
        :title="i.title"
        :score="i.score"
        :date="i.created_at"
        :takehour="i.fileduration"
        :livenum="i.statusname"
        :status="i.status"
        :watch="i.watch"
        :transcoding="i.transcoding"
        :share="i.share"
      ></VideoItem>
    </div>
    <div class="list" v-if="tabindex == 1">
      <LiveItemad v-if="videolist.total"></LiveItemad>
      <VideoItem
        v-for="(i, j) in videolist.data"
        :key="j"
        :img="i.img"
        :videoid="i.videoid"
        :title="i.title"
        :score="i.score"
        :date="i.created_at"
        :takehour="i.fileduration"
        :livenum="i.statusname"
        :status="i.status"
        :watch="i.watch"
        :transcoding="i.transcoding"
        :share="i.share"
      ></VideoItem>
    </div>
    <div class="pages">
      <a-pagination :defaultPageSize="9" v-if="videolist.total" v-model:current="page" :total="videolist.total" :showLessItems="true" @change="pagechange" />
    </div>
  </div>
</template>
<style lang="scss" scoped>
.video {
  width: 100%;
  // height: 706px;
  background-color: #fff;
  border-radius: 17px;
  padding: 40px;
  position: relative;
  display: flex;
  flex-direction: column;
  padding-bottom: 160px;
  align-items: center;
  .nav {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #eee;
    justify-content: space-between;
    width: 100%;
    .tabs {
      display: flex;
      align-items: center;
      font-size: 13px;
      font-weight: bold;
      color: #111;
      padding: 11px 0;
      > div {
        margin-right: 58px;
        cursor: pointer;
        text-align: center;
        width: 54px;
        &:hover{
          color: #08ae98;
        }
      }
      .on {
        color: #08ae98;
        position: relative;
        &::before {
          content: "";
          display: block;
          position: absolute;
          bottom: -12px;
          width: 57px;
          height: 1px;
          background-color: #08ae98;
        }
      }
    }
    .sel {
      width: 171px;
      height: 26px;
      border: 1px solid #999;
      display: flex;
      align-items: center;
      padding: 8px;
      border-radius: 4px;
      > img {
        width: 11px;
        height: 11px;
      }
      > input {
        width: 119px;
        font-size: 9px;
        line-height: 1;
        margin-left: 6px;
        border: none;
        outline: none;
      }
    }
  }
  .list {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    > div {
      margin-top: 28px;
      margin-left: 23px;
      &:nth-child(1),
      &:nth-child(6) {
        margin-left: 0;
      }
    }
  }
  .pages {
    position: absolute;
    bottom: 114px;
    display: flex;
    justify-content: center;
    ::v-deep(.ant-pagination-next) > .ant-pagination-item-link,
    ::v-deep(.ant-pagination-prev) > .ant-pagination-item-link,
    ::v-deep(.ant-pagination-item),
    ::v-deep(.ant-pagination-jump-next-custom-icon),
    ::v-deep(.ant-pagination-jump-prev-custom-icon) {
      border: 1px solid #08ae98;
    }
    ::v-deep(.ant-pagination-item-active) a {
      color: #fff;
    }
    ::v-deep(.ant-pagination-item-active) {
      background-color: #08ae98;
    }
  }
}
</style>
<script lang="ts">
import { defineComponent, onMounted, reactive, ref, UnwrapRef } from "vue";
import VideoItem from "@/components/VideoItem.vue";
import LiveItemad from "@/components/LiveItemad.vue";
import { getvideolist } from "@/api";
import { useRoute } from 'vue-router';
import { useI18n } from '@/utils/i18n';
export default defineComponent({
  components: {
    VideoItem,
    LiveItemad
  },
  setup() {
    const lan: any = useI18n();
    const page = ref(1);
    const tabindex = ref(4);
    interface VideoList {
      videoid: number;
      memberid: number;
      title: string;
      img: string;
      fileid: string;
      fileurl: string;
      fileduration: string;
      status: number;
      desc: string;
      deleted_at: null;
      created_at: string;
      updated_at: string;
      statusname: string;
    }
    
    const videolist = ref({})
    // const newvideolist = ref<Array<VideoList>>();
     const input = ref("")
    

    onMounted(async () => {

      const res = await getvideolist();
      videolist.value = res;

    });
    async function tabchange(e: number) {
      tabindex.value = e;
      videolist.value = {};
      videolist.value = await getvideolist({title: input.value,page:page.value,status:e == 4 ? '' : e});
      // console.log(videolist)
    }
    async function sel(){
        console.log(input.value);
        page.value = 1;
        videolist.value = await getvideolist({title: input.value,page:page.value,status:tabindex.value});
    }
    async function  pagechange(e: number) {
      page.value=e
      videolist.value = await getvideolist({title: input.value,page:e,status:tabindex.value});
    }
    return {
      page,
      tabindex,
      tabchange,
      videolist,
      sel,
      input,
      pagechange,
      lan
    };
  },
});
</script>