<template>
	<div ref='search' class='bg-white pt-4 pl-5 pr-5 border app-container'>
		<!--条件组-->
		<div class='searchAlign'>
			<el-form :inline='true' :model='searchForm'>
				<GdInput :label='$t("applyInfo")' prop='i_sch_field' placeholder="" style='width: 250px' :maxlength="50" />
			</el-form>
			<el-button icon="Search" @click='getData'>{{ $t("search_btn") }}</el-button>
		</div>

		<!--功能按钮-->
		<SearchBtnBar class="pb-4" style="display: inline-block" :permission='permission' @OnClickDelete=''
			@OnClickExport='onClickExport' @OnClickImport='' @onClickAdd=''></SearchBtnBar>
	</div>

	<!-- <div class='mt-2 flex-grow'> -->
	<div class='mt-2 flex-grow app-container'>
		<el-table :data='tableData' :height='tableHeight' border>
			<el-table-column label='No' prop='no' width="60" align='center' />
			<el-table-column :label='$t("applyID")' prop='i_apply_id' width='180' align='center'>
				<template #default='scope'>
					<el-link type='primary' @click='handleLink(scope.row)'>
						{{ scope.row.i_apply_id }}
					</el-link>
				</template>
			</el-table-column>
			<el-table-column :label='$t("applyName")' prop='i_apply_name' align='center' />
			<el-table-column :label='$t("submitTime")' prop='i_apply_date' align='center' />
			<el-table-column :label='$t("deleteTime")' prop='i_delete_date' align='center' />
		</el-table>
	</div>
	<!--分页-->
	<!-- <div ref='pagination' class='mt-2 flex flex-row-reverse'> -->
	<div ref='pagination' class='mt-2 flex flex-row-reverse app-container pagination-container'>
		<el-pagination v-model:current-page="searchForm.i_pageindex" v-model:page-size="searchForm.i_perpage"
			:page-sizes="pageSizeList" layout="total, sizes, prev, pager, next, jumper" :total="dataCount"
			@size-change="getData" @current-change="getData" />
	</div>
</template>

<script>
import { getWorkFlowInvalidListInit, getWorkFlowInvalidList, exportWorkFlowInvalidList } from '@/api/workflowManagement'
import SearchBtnBar from '@/components/GdElement/BtnBar.vue';
import { createDownloadFile } from '@/utils/exportExcel';
import { ref, computed } from 'vue'
import { useGlobalPinia } from '@/pinia/global'
import { useWindowSize, useElementBounding } from '@vueuse/core'
import router from '@/router';

export default {
	// name: 'WFApplyListInvalid',
	name: 'WfApplyListInvalid',
	components: { SearchBtnBar },
	data() {
		return {
			startDate: null,
			endDate: null,
			searchForm: {
				i_sch_field: null,
				i_sch_apply_status: null,
				i_perpage: 10,
				i_pageindex: 1
			},
			permission: '',
			tableData: [],
			dataCount: 1,
			pageSizeList: []
		}
	},
	mounted() {
		getWorkFlowInvalidListInit().then(res => {
			if (res.resultCode == '0') {
				const { perpageList, i_perpage, ...permission } = res.data
				this.permission = permission
				this.pageSizeList = perpageList.map(page => { return page.value })
				this.searchForm.i_perpage = Number(i_perpage) || 10
				this.getData()
			}
		})

	},
	activated() {
		this.getData()
	},
	setup() {
		const windowSize = useWindowSize();
		const search = ref();
		const searchSize = useElementBounding(search);
		const pagination = ref();
		const paginationSize = useElementBounding(pagination);
		const global = useGlobalPinia();
		// const tableHeight = computed(() => windowSize.height.value - searchSize.height.value - global.header - global.mainPadding - 16 - paginationSize.height.value + 'px');
		const tableHeight = computed(() => windowSize.height.value - searchSize.height.value - global.header - global.mainPadding - 241 - paginationSize.height.value + 'px');
		return { tableHeight, search, pagination, windowSize, global }
	},
	methods: {
		activated() {
			this.getData()
		},
		//获取列表数据
		getData() {
			getWorkFlowInvalidList(this.searchForm).then(res => {
				if (res.resultCode === '0') {
					this.tableData = res.dataList
					this.dataCount = Number(res.i_total) || 0
				}
			})
		},
		getPeriod(row) {
			return (row.i_use_s_ymd || "") + '~' + (row.i_use_e_ymd || "")
		},
		handleLink({ i_form_id, i_apply_id }) {
			// this.$router.push({ name: 'WFApplyDetail', query: { formId: i_form_id, dataId: i_apply_id } })
			router.push({path:'wfApplyDetail', query: { formId: i_form_id, dataId: i_apply_id }})
		},
		async onClickExport() {
			const table_info = [
				{ label: 'no', value: 'No', index: 1 },
				{ label: 'i_apply_id', value: this.$t("applyID"), index: 2 },
				{ label: 'i_apply_name', value: this.$t("applyName"), index: 3 },
				{ label: 'i_apply_date', value: this.$t("submitTime"), index: 4 },
				{ label: 'i_delete_date', value: this.$t("deleteTime"), index: 5 },
			];
			const res = await exportWorkFlowInvalidList({
				...this.searchForm,
				table_info: table_info,
			});

			createDownloadFile(res);
		}
	},
}
</script>

<style scoped>
.searchBar {
	display: flex;
	align-items: center;
	align-content: center;
}

.datePicker {
	width: 250px;
}

.searchAlign {
	display: flex;
	align-content: flex-start;
}

.el-card {
	--el-card-padding: 10px !important;
}
</style>
