<!--
 * @Author: ysh
 * @Date: 2025-01-21 10:01:39
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2025-02-19 15:55:13
-->
<template>
	<view>
		<view class="tag-view text-center margin-top-xs margin-bottom-xs" style="padding: 10rpx;">
			<uni-tag :text="'您还有' + total + '个任务待审'" />
		</view>
		<u-list v-if="todoList.length > 0">
			<u-list-item v-for="(item, index) in todoList" :key="index">
				<view @click="goToDetail(item)">
					<view class="box">
						<view style="text-align: right;">
							<span style="font-size: 26rpx;color: #999999;">{{ item.createTime }}</span>
						</view>
						<uni-title type="h3" :title="item.title ? item.title : '暂无标题'"></uni-title>
						<view>流程名称：{{ item.procDefName }}</view>
						<view>当前节点：{{ item.taskName }}</view>
						<view>流程发起人：{{ item.startUserName }}</view>
					</view>
				</view>
			</u-list-item>
		</u-list>
		<u-empty v-else></u-empty>
	</view>
</template>

<script>
import {
	todoList
} from "@/api/flowable/todo";
export default {
	data() {
		return {
			todoList: [],
			total: 0,
		};
	},
	created() {
		this.getTodoList();
	},
	onLoad: function (options) {
		uni.startPullDownRefresh();
	},
	onPullDownRefresh() {
		this.getTodoList();
	},
	methods: {
		getTodoList() {
			todoList({
				pageNum: 1,
				pageSize: 999,
				name: null
			}).then(response => {
				this.total = response.data.total;
				this.todoList = response.data.records;
				uni.stopPullDownRefresh();
			});
		},
		goToDetail(item) {
			// 跳转到详情页，并传递项目ID
			const query = {
				procInsId: item.procInsId,
				executionId: item.executionId,
				deployId: item.deployId,
				taskId: item.taskId,
				taskName: item.taskName,
				startUserName: item.startUserName,
				procDefName: item.procDefName
			}
			const encodedParams = encodeURIComponent(JSON.stringify(query));
			uni.navigateTo({
				url: `/pages/message/apply/detail?params=${encodedParams}`
			})
		}
	}
}
</script>

<style lang="scss">
.box {
	background-color: #fff;
	border-radius: 4px;
	padding: 10px 20px;
	margin: 0 10px 10px;
}
</style>