import ColResult from '@/components/col-result'
import request from '@/helpers/request'
import { state } from '@/state'
import VideoItem from '@/student/video-class/video-item'
import { List } from 'vant'
import { defineComponent } from 'vue'
import styles from './video.module.less'

export default defineComponent({
  name: 'VideoList',
  data() {
    const query = this.$route.query
    return {
      list: [],
      dataShow: true, // 判断是否有数据
      loading: false,
      finished: false,
      params: {
        teacherId: query.teacherId,
        page: 1,
        rows: 20
      }
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    async getList() {
      try {
        const params: any = {
          ...this.params
        }
        if (state.version) {
          params.version = state.version || '' // 处理ios审核版本
          params.platform = 'ios-student'
        }
        const res = await request.post('/api-student/videoLesson/selectGroup', {
          data: {
            ...params
          }
        })
        this.loading = false
        const result = res.data || {}
        // 处理重复请求数据
        if (this.list.length > 0 && result.pageNo === 1) {
          return
        }
        this.list = this.list.concat(result.rows || [])
        this.finished = result.pageNo >= result.totalPage
        this.params.page = result.pageNo + 1
        this.dataShow = this.list.length > 0
      } catch {
        this.dataShow = false
        this.finished = true
      }
    },
    onDetail(item: any) {
      this.$router.push({
        path: '/videoDetail',
        query: {
          groupId: item.id
        }
      })
    }
  },
  render() {
    return (
      <>
        {this.dataShow ? (
          <List
            class={styles.videoList}
            v-model:loading={this.loading}
            finished={this.finished}
            immediateCheck={false}
            finishedText="没有更多了"
            onLoad={this.getList}
          >
            {this.list.map(item => (
              <VideoItem item={item} onClick={this.onDetail} />
            ))}
          </List>
        ) : (
          <ColResult btnStatus={false} classImgSize="SMALL" tips="暂无视频课" />
        )}
      </>
    )

    {
      /* <List
v-model:loading={this.loading}
finished={this.finished}
finishedText="没有更多了"
onLoad={this.getList}
>
{this.buyUserList.map(item => (
  <UserList class="mb12" users={item} />
))}
</List> */
    }
  }
})
