<template>
	<el-card class="box-card">
		<template #header>
			<div class="card-header">
				<span>
				我的通知
				<el-badge class="mark" v-if="tablePage.total !== 0" :value="tablePage.total" :max="99" style="line-height: 0;margin-top: 8px"/>
				</span>
				<div style="float:right;">
					<el-button type="text" @click="refreshList()">刷新</el-button>
					<el-button type="text" @click="toPendingList()">更多>></el-button>
				</div>
			</div>
		</template>
		<el-table :data="dataList" style="width: 100%" height="480" border="inner" @sort-change="sortChangeHandle">
			<el-table-column label="实例标题" prop="title" min-width="400px">
				<template #default="scope">
					<el-link  type="primary" :underline="false" @click="todo(scope.row)">{{scope.row.title}}</el-link>
				</template>
			</el-table-column>
			<el-table-column
				min-width="90px"
				show-overflow-tooltip
				label="流程名称"
				prop="taskName"
			></el-table-column>
			<el-table-column
				min-width="100px"
				show-overflow-tooltip
				label="发起人"
				prop="createUser"
			></el-table-column>
			<el-table-column
				fixed="right"
				min-width="100px"
				show-overflow-tooltip
				label="创建时间"
				prop="createTime"
			></el-table-column>
		</el-table>
		<vxe-pager
			background
			size="small"
			:current-page="tablePage.currentPage"
			:page-size="tablePage.pageSize"
			:total="tablePage.total"
			:page-sizes="[
				10,
				20,
				100,
				1000,
				{ label: '全量数据', value: 1000000 },
			]"
			:layouts="[
				'PrevPage',
				'JumpNumber',
				'NextPage',
				'FullJump',
				'Sizes',
				'Total',
			]"
			@page-change="currentChangeHandle"
		>
		</vxe-pager>
	</el-card>
	<WareHouseHistoryPopup ref="wareHouseHistoryPopup"></WareHouseHistoryPopup>
</template>

<script>
	import WareHouseHistoryPopup from '@/views/materialManagement/wareHouseSummary/WareHouseHistoryPopup'
// import notifyService from "@/api/notify/notifyService";
import noticeService from '@/api/flowable/NoticeService'
import taskService from "@/api/flowable/taskService";
	import pick from "lodash.pick";
export default {
	title: "我的通知",
	icon: "tongzhi",
	description: "我的通知",
	layout: {
		w: 6,
		h: 15,
	},
	components: {
		WareHouseHistoryPopup,
	},
	data() {
		return {
			dataList: [],
			typeList: [],
			searchForm: {
				title: '',
				taskName: ''
			},
			tablePage: {
				total: 0,
				currentPage: 1,
				pageSize: 10,
				orders: []
			},
			loading: false,
			visible: false,
			currentTask: null,
			processInstanceId: ''
		};
	},
	mounted() {
		this.refreshList();
	},

	activated() {
		this.refreshList();
	},
	methods: {
		todo (row) {
			// console.log('row', row)
			if (row.taskName === '库存提醒') {
				// console.log('测试进来了')
				this.$refs.wareHouseHistoryPopup.init(row.defId)
				this.inputForm = {
					id: row.id
				}
				noticeService.stockUpdate(this.inputForm)
				this.resetSearch()
			} else {
				this.inputForm = {
					taskId: '',
					noticeId: ''
				}
				console.log('进来了+++', row.taskId)
				taskService.getTaskDef({
					procInsId: row.taskId,
					procDefId: row.defId
				}).then((data) => {
					this.inputForm.taskId = row.taskId
					this.inputForm.noticeId = row.noticeName
					noticeService.update(this.inputForm)
					// this.$router.push({
					// 	path: '/flowable/task/TaskForm',
					// 	query: {
					// 		isShow: false,
					// 		formReadOnly: true,
					// 		formTitle: `${row.title}`,
					// 		num: 2,
					// 		title: `审批【${row.taskName || ''}】`,
					// 		...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title', 'businessId')
					// 	}
					// })
					this.$router.push({
					  path: '/flowable/task/TaskFormDetail',
					  query: {
						  ...pick(data, 'formType', 'formUrl', 'procDefKey', 'taskDefKey', 'procInsId', 'procDefId', 'taskId', 'status', 'title'),
						  isShow: 'false',
						  readOnly: true,
						title: `审批【${row.taskName || ''}】`,
						formTitle: `${row.title}`,
						businessId: data.businessId,
						  status: 'reback'
					  }
					})
				})
			}
		},
		// 获取数据列表
		refreshList() {
			this.loading = true
			noticeService.list({
				current: this.tablePage.currentPage,
				size: this.tablePage.pageSize,
				orders: this.tablePage.orders,
				isSelf: true,
				...this.searchForm
			}).then((data) => {
				this.dataList = data.records
				this.tablePage.total = data.total
				this.loading = false
			})
		},
		// 当前页
		currentChangeHandle({ currentPage, pageSize }) {
			this.tablePage.currentPage = currentPage;
			this.tablePage.pageSize = pageSize;
			this.refreshList();
		},
		resetSearch() {
			this.$refs.searchForm.resetFields();
			this.refreshList();
		},
		toPendingList () {
			// this.$router.push('./PendingList')
			this.$router.push('/flowable/task/NoticePageList')
		},
	},
};
</script>
<style scoped>
	.box-card {
		height: 100%;
	}
</style>
