<template>
	<div class="tab-page-content">
		<!-- 搜索区域 -->
		<el-form :model="queryParams" ref="queryRef" v-show="showSearch" :inline="true" label-width="80px">
			<el-form-item label="赛事编号" prop="matchNumStr">
				<el-input v-model="queryParams.matchNumStr" placeholder="请输入赛事编号" clearable style="width: 240px"
					@keyup.enter="handleQuery" />
			</el-form-item>
			<el-form-item label="联赛类型" prop="leagueAbbName">
					<el-select v-model="queryParams.leagueAbbName" @change="handleQuery" style="width: 240px" clearable placeholder="请选择联赛类型">
                  <el-option
                     v-for="item in dataScopeOptions"
                     :key="item.value"
                     :label="item.label"
                     :value="item.value"
                  ></el-option>
               </el-select>
			</el-form-item>

			<el-form-item label="时间">
				<el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
					start-placeholder="开始日期" end-placeholder="结束日期" style="width: 240px"></el-date-picker>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="Search" @click="handleQuery" :loading="loading">查询</el-button>
				<el-button icon="Refresh" @click="resetQuery" :loading="loading">重置</el-button>
			</el-form-item>
		</el-form>
		<!--loading-->
		<div
			v-if="loading"
			v-loading="loading"
			class="loading-page"
			element-loading-text="正在加载..."
			style="width: 100%; height: calc(100vh - 250px)"
		></div>
		<div v-else-if="roleList.length && !loading">
			<!-- 表格数据 -->
			<el-table v-loading="loading" :data="roleList">
				<el-table-column label="赛事编号" prop="matchNumStr" />
				<el-table-column label="联赛" prop="leagueAllName" :show-overflow-tooltip="true"/>
				<el-table-column label="主队" prop="homeTeamAllName" :show-overflow-tooltip="true"  />
				<el-table-column label="客队" prop="awayTeamAbbName"  />
				<el-table-column label="固定奖金" prop="matchId">
					<template #default="scope">
						<el-button link type="primary" @click="handleJumpLink(scope.row)">查看</el-button>
					</template>
				</el-table-column>
				<el-table-column label="比赛开始时间" align="center" prop="matchDateTime">
					<template #default="scope">
						<span>{{ parseTime(scope.row.matchDateTime) }}</span>
					</template>
				</el-table-column>
				<el-table-column label="报告状态" prop="reportSatus">
					<template #default="scope">
						<el-tag v-if="scope.row.reportSatus === 1" type="success">已生成</el-tag>
						<el-tag v-else>未生成</el-tag>	
					</template>
				</el-table-column>
				<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
					<template #default="scope">
						<span :class="['flex-row cursor-pointer tc-view-time  mr-8', scope.row.reportSatus != 1 && 'tc-view-time-disabled']"  @click="handleView(scope.row, 'video')">
							脚本结果<br/>
							{{ scope.row.reportSatus === 1? timerToStr(scope.row.reportTime, 'HH:mm') : '待' }}更新
						</span>
						<span :class="['flex-row cursor-pointer tc-view-time', scope.row.reportSatus != 1 && 'tc-view-time-disabled']"  @click="handleView(scope.row, 'market')">
							营销文案<br/>
							{{ scope.row.reportSatus === 1? timerToStr(scope.row.reportTime, 'HH:mm') : '待' }}更新
						</span>

						<!-- <el-tooltip content="查看" placement="top" v-if="scope.row.roleId !== 1">
							<el-button link type="primary" icon="view" @click="handleView(scope.row)"></el-button>
						</el-tooltip> -->
					</template>
				</el-table-column>
			</el-table>

			<!-- 分页区域 -->
			<pagination 
			:show="total > 0"
			:total="total" 
			v-model:page="queryParams.pageNum"
			v-model:limit="queryParams.pageSize" 
			@pagination="getList" />
		</div>
		<lz-page-empty v-else-if="!loading" :type="'2'">
			<lz-svg-icon icon-class="empty2" style="font-size: 312px;"/>
		</lz-page-empty>
	</div>
</template>

<script setup name="Role">
import { Info, infoSelectDistinctLeagueAbbNames } from "@/api/tc/eventAnalysisReport"
import { jumpLink } from "@/utils/tc"
import { timerToStr } from "@/utils/timer"
import { onMounted } from "vue"

const router = useRouter()
const { proxy } = getCurrentInstance()
const roleList = ref([])
const loading = ref(false)
const showSearch = ref(true)
const total = ref(0)
const dateRange = ref([])

/** 数据范围选项*/
const dataScopeOptions = ref([])

const data = reactive({
	form: {},
	queryParams: {
		pageNum: 1,
		pageSize: 10,
		matchNumStr: undefined,
		leagueAbbName: undefined,
	},
	rules: {},
})

const { queryParams } = toRefs(data)

/** 获取联赛类型 */
function getLeagueAbbNames() {
	infoSelectDistinctLeagueAbbNames().then(response => {
		dataScopeOptions.value = response.rows ? response.rows.map(item => ({ value: item, label: item })) : []
	})
}

/** 跳转链接 */
function handleJumpLink(row) {
	jumpLink(row.matchId, 1)
}

/** 查看详情 */
function handleView(row, type) {
	if (row.reportSatus != 1) {
		return
	}
	// window.open(`/#/tc/videoScript/detail?id=${row.matchId}`)
	router.push({
		path: '/tc/videoScript/detail',
		query: {
			id: row.matchId,
			type
		}
	})
}
/** 查询角色列表 */
function getList() {
	loading.value = true
	const data = { ...queryParams.value }
	if (dateRange.value && dateRange.value[0] && dateRange.value[1]) {
		data.beginTime = dateRange.value[0]
		data.endTime = dateRange.value[1]
	} else {
		data.beginTime = undefined
		data.endTime = undefined
	}
	Info(data).then(response => {
		roleList.value = response.rows
		total.value = response.total
	}).finally(() => {
		loading.value = false
	})
}

/** 搜索按钮操作 */
function handleQuery() {
	queryParams.value.pageNum = 1
	getList()
}

/** 重置按钮操作 */
function resetQuery() {
	dateRange.value = []
	proxy.resetForm("queryRef")
	handleQuery()
}

onMounted(() => {
	// 联赛类型
	getLeagueAbbNames()
	// 列表查询
	getList()
})
</script>
