<template>
  	<div>  
		<!-- 下转 通用列表 -->

		<el-dialog v-model="props.dialogVisible" :title="props.title"  width="70%" :before-close="closeModal">
			<span>
				
				<JyTable
					ref="table"
					:loading="loading"
					v-bind="props.config"
					:rowKey="''"
					:listCount="listCount"
					:listData="dataList"
					:contentTableHeader="false"
					v-model:page="pageInfo"
					@update:page="getListData"
				> 
					<template #workordercode="scope">
						<a style="color: blue" @click="openCmodal(scope.row)">{{ scope.row['workordercode'] }}</a>
					</template> 
				</JyTable>
				 
			</span>
			<!-- <template #footer>
				<span class="dialog-footer">
					
				</span>
			</template> -->
		</el-dialog>

		
    </div> 
</template>

<script setup >
import { ref, defineEmits, defineProps, } from 'vue' 

import JyTable from '@/base-ui/table' 

import { useRouter } from 'vue-router'
const router = useRouter(); 

import {
  getPageListData,
  deletePageData,
  createPageData,
  editPageData
} from '@/api/main/system/system'


const props = defineProps({
	dialogVisible : { 
		type: Boolean,
		default: false
	},
	title : {
		type : String,
		default : '表格弹出框'
	},
	url : {
		type : String,
		default : ''
	},
	params : {
		type : Object,
		default : {}
	},
	config : {
		type : Object,
		default : {},
	}
})

const emit = defineEmits(['update:dialogVisible'])

// 表格的ref
const table = ref(''); 
// 表格数据
const dataList = ref([])
// 表格loading
const loading = ref(false)

// 分页数据
const pageInfo = ref({ currentPage: 1, pageSize: 10 })
const listCount = ref(0)
 
// 获取列表
const getListData = (() => {
  return (function fn(page) {
    dataList.value = []
    loading.value = true

    let params = {
		...props.params,
		pageNum: page?.currentPage || pageInfo.value.currentPage,
		pageSize: page?.pageSize || pageInfo.value.pageSize, 
    }
    getPageListData( props.url , params).then(({ data, total }) => {
      dataList.value = data
      listCount.value = total
      loading.value = false
    })
    return fn
  })()
})()


function closeModal (){  
	emit('update:dialogVisible' , false);
}

// 处理弹出框
function openCmodal(rowData) { 
	let query = {
		workordercode : rowData.workordercode,
		type : 'zhcx'
	}

	sessionStorage.setItem('workQuery', JSON.stringify(query))

	router.push({ path : '/workHandle' })
}

</script>

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