<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="999999"
						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)">
						<span v-if="scope.row.repetitionCount > 0">
							<span style="color: red; font-weight: bold;">【{{ scope.row.repetitionCount }}】</span>{{
								scope.row.title }}
						</span>
						<span v-else>
							{{ scope.row.title }}
						</span>
					</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>
	<PsiWareHouseHistoryPopup ref="wareHouseHistoryPopup2"></PsiWareHouseHistoryPopup>
	<PurchasePageFormCurrent ref="purchasePageFormCurrent"></PurchasePageFormCurrent>
	<RegisterPopup ref="registerPopup"></RegisterPopup>
	<KeyCardPopup ref="keyCardPopup"></KeyCardPopup>
	<DepartPopup ref="departPopup"></DepartPopup>
	<DepartProvePopup ref="departProvePopup"></DepartProvePopup>
	<ProjectRecordsForm ref="projectRecordsForm"></ProjectRecordsForm>
	<CwInvoiceForm ref="cwInvoiceForm"></CwInvoiceForm>
	<InvoiceForm ref="invoiceForm"></InvoiceForm>
	<DishOrderInfoDialog ref="dishOrderInfoDialog"></DishOrderInfoDialog>

</template>

<script>
import WareHouseHistoryPopup from '@/views/materialManagement/wareHouseSummary/WareHouseHistoryPopup'
import PsiWareHouseHistoryPopup from '@/views/psiManagement/loss/PurchasePageFormPopup.vue'
import PurchasePageFormCurrent from '@/views/psiManagement/loss/PurchasePageFormCurrent.vue'
// 优惠结账通知弹框
import DishOrderInfoDialog from '@/views/psiManagement/dishManage/order/DishOrderInfoDialog'
import RegisterPopup from '@/views/human/practice/register/RegisterPopup'
import KeyCardPopup from '@/views/human/enrollment/registration/KeyCardPopup'
import DepartPopup from '@/views/human/depart/handover/DepartPopup'
import DepartProvePopup from '@/views/human/depart/handover/DepartProvePopup'
import ProjectRecordsForm from "@/views/cw/projectRecords/ProjectRecordsForm";
import CwInvoiceForm from '@/views/cw/invoice/InvoiceForm'
import InvoiceForm from '@/views/finance/invoice/InvoiceForm'
// 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,
		PsiWareHouseHistoryPopup,
		PurchasePageFormCurrent,
		RegisterPopup,
		KeyCardPopup,
		DepartPopup,
		DepartProvePopup,
		ProjectRecordsForm,
		CwInvoiceForm,
		InvoiceForm,
		DishOrderInfoDialog
	},
	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.invoiceForm.init(false, row.defId)
				this.inputForm = {
					id: row.id
				}
				noticeService.stockUpdate(this.inputForm)
				this.resetSearch()
			} else if (row.taskName === '超期收款发票') {
				// console.log('测试进来了')
				this.$refs.cwInvoiceForm.init(false, row.defId)
				this.inputForm = {
					id: row.id
				}
				noticeService.stockUpdate(this.inputForm)
				this.resetSearch()
			} else if (row.taskName === '库存提醒') {
				// console.log('测试进来了')
				this.$refs.wareHouseHistoryPopup.init(row.defId)
				this.inputForm = {
					id: row.id
				}
				noticeService.stockUpdate(this.inputForm)
				this.resetSearch()
			} else if (row.taskName === '物资库存提醒') {
				// console.log('测试进来了')
				this.$refs.purchasePageFormCurrent.init(row.defId)
				this.inputForm = {
					id: row.id
				}
				noticeService.stockUpdate(this.inputForm)
				this.resetSearch()
			} else if (row.taskName === '物资临期提醒') {
				this.$refs.wareHouseHistoryPopup2.init(row.defId)
				this.inputForm = {
					id: row.id
				}
				noticeService.stockUpdate(this.inputForm)
				this.resetSearch()
			} else if (row.taskName === '景聚庭-优惠结账') {
				// console.log('测试进来了')
				this.$refs.dishOrderInfoDialog.init(row.defId)
				this.inputForm = {
					id: row.id
				}
				noticeService.stockUpdate(this.inputForm)
				this.resetSearch()
			} else if (row.taskName === '实习日志超时提醒') {
				this.$refs.registerPopup.init(row.defId)
				this.inputForm = {
					id: row.id
				}
				noticeService.stockUpdate(this.inputForm)
				this.resetSearch()
			} else if (row.taskName === '门卡领取提醒') {
				this.$refs.keyCardPopup.init()
				this.inputForm = {
					id: row.id
				}
				noticeService.stockUpdate(this.inputForm)
				this.resetSearch()
			} else if (row.taskName.includes('离职提醒')) {
				this.$refs.departPopup.init(row.taskName)
				this.inputForm = {
					id: row.id
				}
				noticeService.stockUpdate(this.inputForm)
				this.resetSearch()
			} else if (row.taskName.includes('请点击下载离职证明')) {
				this.$refs.departProvePopup.init(row.taskName, row.defId)
				this.inputForm = {
					id: row.id
				}
				noticeService.stockUpdate(this.inputForm)
				this.resetSearch()
			} else if (row.taskName === '预开票项目未关联') {
				this.$refs.projectRecordsForm.init('view', row.defId)
				this.inputForm = {
					id: row.id
				}
				noticeService.stockUpdate(this.inputForm)
				this.resetSearch()
			} else {
				this.inputForm = {
					taskId: '',
					noticeId: '',
					taskName: ''
				}
				console.log('进来了+++', row.taskId)
				taskService.getTaskDef({
					procInsId: row.taskId,
					procDefId: row.defId
				}).then((data) => {
					this.inputForm.taskId = row.taskId
					this.inputForm.noticeId = row.noticeName
					this.inputForm.taskName = row.taskName
					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>
