<!--
@ 作者: 秦东
@ 时间: 2023-09-22 08:59:47
@ 备注: 任务列表
-->
<script lang='ts' setup>
import { gainTaskListQuery,taskListCont } from '@/api/taskapi/types'
import { gainTaskList } from '@/api/taskapi/management'

const props = defineProps({
	isshow:{
		type:Boolean,
		default:true
	}
})
const taskLoding = ref(false);
const gainTaskListInfo = reactive<gainTaskListQuery>({
	page:1,
	pagesize:9,
	status:1
});
const taskTotal = ref<number>(0)
const taskList = ref<taskListCont[]>();

const emits = defineEmits(["update:isshow","opencustomerform"]);
const isShow =   computed({
	get: () => props.isshow,
	set: (val) => {
		emits("update:isshow", val);
	},
});
//获取记录
const gainTaskContAry = () => {
	taskLoding.value = true
		gainTaskList(gainTaskListInfo)
			.then(({data})=>{
				console.log(data)
				if(data != null){
					taskList.value = data.list;
					taskTotal.value = data.total;
				}
			})
			.finally(()=>{
				taskLoding.value = false
			})
}
//初始化数据
const initData = () => {
	gainTaskListInfo.page = 1;
	gainTaskListInfo.pagesize = 9;
	gainTaskListInfo.status = 1;
}
//关闭弹窗
const taskEntryClose = () => {
	emits("update:isshow", false);
	initData();
}
//监听
watch(() => props.isshow,(val:boolean)=>{
	if(val) {
		gainTaskContAry();
	}
})
//使用版本
const startUsing = (id:string,title:string) => {
	taskEntryClose();
	emits("opencustomerform",id,title)
}
</script>
<template>
	<el-dialog
		v-model="isShow"
		title="选择任务"
		width="845"
		:before-close="taskEntryClose"
	>
		<el-space v-loading="taskLoding" wrap >
			<el-card v-for="item in taskList" :key="item.id"  style="width: 260px">
				<el-space direction="vertical" style="width: 100%;">
					<div>
						<el-space wrap>
							<el-text class="mx-1">{{ item.name }}</el-text>
							<el-text class="mx-1">设计者：{{ item.createrName }}（{{ item.createrNumber }}）</el-text>
							<el-text class="mx-1">发布时间：{{ item.createrTame }}</el-text>
						</el-space>
					</div>
					<div class="taskButton"><el-button type="primary" @click.stop="startUsing(item.id,item.name)">使用</el-button></div>
				</el-space>
			</el-card>
		</el-space>
		<template #footer>
			<pagination
				v-if="taskTotal > 0"
				v-model:total="taskTotal"
				v-model:page="gainTaskListInfo.page"
				v-model:limit="gainTaskListInfo.pagesize"
				align="center"
				@pagination="gainTaskContAry"
			/>
	
			
		</template>
		
	</el-dialog>
</template>
<style  lang='scss' scoped>
.taskButton{
	width: 100%;
	text-align: center;
	
}
</style>
