<script setup>
	/**
	 * 我的作品组件
	 */
	import {
		ref,
		reactive,
		onMounted
	} from 'vue'
	// 工具库
	import util from '@/common/js/util';
	// api
	import api from '@/api/index.js'
	// 视频菜单
	import videoMenu from '@/components/index/videoMenu.vue';

	// 列表数据
	const list = reactive({
		data: [],
		pageSize: 10,
		pageNum: 1,
		total: 0,
	})

	onMounted(() => {
		getList()

		// 删除视频
		uni.$on('deleteVideo', (videoId) => {
			const findIndex = list.data.findIndex(node => node.videoId == videoId)
			if (findIndex > 0) list.data.splice(findIndex, 1)
		})
	})

	// 刷新列表
	function refreshList() {
		list.pageNum = 1
		list.total = 0
		getList()
	}

	// 获取更多列表
	function getMoreList() {
		if (list.data.length >= list.total) return
		list.pageNum++
		getList()
	}

	// 获取列表
	function getList() {
		// 
		api.video.myVideoList({
			query: {
				pageSize: list.pageSize,
				pageNum: list.pageNum,
			}
		}).then(rs => {
			if (rs.code == 200) {
				if (list.pageNum == 1) list.data.length = []
				list.data.push(...rs.rows.map(item => {
					item.format_videoUrl = util.format_url(item.videoUrl, 'video')
					item.format_imageUrl = util.format_url(item.imageUrl, 'img')
					return item
				}))
				list.total = rs.total
				return
			}
			util.alert({
				content: rs.msg,
				showCancel: false,
			})
		})
	}

	/**
	 * 点击我的作品
	 * @param {Object} item
	 */
	function handleItem(item) {
		console.log(item)
	}

	// 
	defineExpose({
		getList,
		getMoreList,
		refreshList,
	})
</script>

<template>
	<view class="">
		<videoMenu :list="list.data" isMine="1" />
	</view>
</template>

<style lang="scss" scoped>
	// 
</style>