<script setup>
	// 推流历史
	// 
	import api from '@/api/index.js'
	// 
	import util from '@/common/js/util.js'
	import {
		ref,
		reactive,
		onMounted,
	} from 'vue'

	// 视频菜单
	import videoMenu from '@/components/index/videoMenu.vue';
	// 
	const list = reactive({
		data: [],
		pageNum: 1,
		pageSize: 18,
		total: 0,
	})

	onMounted(() => {
		getList()
	})

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

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

	// 获取推流历史列表
	function getList() {
		api.video.getVideoPushList({
			query: {
				pageNum: list.pageNum,
				pageSize: list.pageSize,
			},
		}).then(rs => {
			if (rs.code == 200) {
				// 第一页
				if (list.pageNum == 1) list.data.length = 0
				// 合并
				list.data.push(...rs.rows.map(node => {
					return {
						pushId: node.id,
						...node.video,
					}
				}))
				console.log('list', list)
				// 总数
				list.total = rs.total
				return
			}
			util.alert({
				content: rs.msg,
				showCancel: false,
			})
		}).finally(() => {
			// 停止下拉刷新
			uni.stopPullDownRefresh()
		})
	}

	// 点击了视频
	function handleVideo() {
		uni.navigateTo({
			url: util.setUrl('/pages/index/dataCenter/pushDetail', {
				// 
			})
		})
	}

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

<template>
	<view class="appbw">
		<view class="listBox">
			<videoMenu :list="list.data" mode="menu" @item="handleVideo" />
		</view>
	</view>
</template>

<style>

</style>