<template>
	<div>
		<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item>
				<el-input v-model="state.queryForm.reportCode" placeholder="报表编码" clearable></el-input>
			</el-form-item>
			<el-form-item>
				<el-input v-model="state.queryForm.reportName" placeholder="报表名称" clearable></el-input>
			</el-form-item>
			<el-form-item>
				<el-button @click="getDataList()">查询</el-button>
			</el-form-item>
			<el-form-item>
				<el-button v-auth="'ebo:fast:report:save'" type="primary" @click="addOrUpdateHandle()">新增</el-button>
			</el-form-item>
      <el-form-item>
        <el-button v-auth="'ebo:fast:report:exp'" type="primary" @click="expConfig()">导出配置</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-auth="'ebo:fast:report:import'" type="primary" @click="importConfig()">导入配置</el-button>
      </el-form-item>
			<el-form-item>
				<el-button v-auth="'ebo:fast:report:delete'" type="danger" @click="deleteBatchHandle()">删除</el-button>
			</el-form-item>
		</el-form>
		<el-table
			class="flex-content-1"
			v-loading="state.dataListLoading"
			show-overflow-tooltip
			:data="state.dataList"
			border
			style="width: 100%"
			height="100%"
			@selection-change="selectionChangeHandle"
		>
			<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
			<el-table-column label="报表ID" align="left" prop="id" show-overflow-tooltip width="290" />
			<el-table-column label="报表编码" align="left" prop="reportCode" show-overflow-tooltip width="120">
				<template #default="scope">
					<div style="color: #409eff; cursor: pointer" @click="reviewReport(scope.row)">
						{{ scope.row.reportCode }}
					</div>
				</template>
			</el-table-column>
			<el-table-column label="报表名称" align="left" prop="reportName" show-overflow-tooltip width="200" />
			<el-table-column label="报表SQL" align="left" prop="reportSql" show-overflow-tooltip width="180" />
			<el-table-column label="动态数据源" align="left" prop="reportDbSource" show-overflow-tooltip width="120" />
			<el-table-column label="系统产品" align="left" prop="systemProduct" show-overflow-tooltip width="120" />
			<el-table-column label="报表描述" align="left" prop="reportContent" show-overflow-tooltip width="220" />
			<el-table-column label="创建人" align="left" prop="creator" show-overflow-tooltip />
			<el-table-column label="创建时间" align="left" prop="createTime" show-overflow-tooltip width="180" />
			<el-table-column label="更新人" align="left" prop="updater" show-overflow-tooltip />
			<el-table-column label="更新时间" align="left" prop="updateTime" show-overflow-tooltip width="180" />
			<el-table-column label="操作" width="80" fixed="right">
				<template #default="scope">
					<el-button v-auth="'ebo:fast:report:update'" type="text" @click="addOrUpdateHandle(scope.row.id)"> 修改 </el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
			:current-page="state.page"
			:page-sizes="state.pageSizes"
			:page-size="state.limit"
			:total="state.total"
			layout="total, sizes, prev, pager, next, jumper"
			@size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"
		>
		</el-pagination>

		<!-- 弹窗, 新增 / 修改 -->
		<add-or-update ref="addOrUpdateRef" @refresh-data-list="getDataList"></add-or-update>
	</div>
</template>

<script setup lang="ts" name="ReportIndex">
import { useCrud } from '@/hooks'
import { reactive, ref } from 'vue'
import AddOrUpdate from './add-or-update.vue'
import { IHooksOptions } from '@/hooks/interface'
import { useRouter } from 'vue-router'

const router = useRouter()
const state: IHooksOptions = reactive({
	dataListUrl: '/fast/report/page',
	deleteUrl: '/fast/report',
	queryForm: {
		reportCode: '',
		reportName: ''
	}
})

const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: number) => {
	addOrUpdateRef.value.init(id)
}

const expConfig = () =>{

}

const importConfig = () =>{

}

const reviewReport = (row: any) => {
	router.push({ path: '/ebo/fast/report/reportDevReview/' + row.id })
}

const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, deleteBatchHandle } = useCrud(state)
</script>
