<template>
	<view class="todo-page">
		<view class="main">
			<view class="empty-wrap" v-if="!lists.length">
				<u-empty text="暂无任务" icon="/static/empty@2x.png">
				</u-empty>
			</view>
			<view class="content-list" v-else>
				<common-card :dataSource="item" v-for="(item, key) in lists" :key="key" icon @click="taskClisk">
				</common-card>
			</view>
		</view>

	</view>
</template>

<script>
	import CommonCard from '@/components/custom/common-card2.nvue';

	import {
		userToDo
	} from '../../services/app'
	import {
		ApproveCode,
		SourceFormcode
	} from '../../utils/common'

	export default {
		components: {
			CommonCard,
		},
		data() {
			return {
				nameID: '',
				lists: [],
				timingGet: undefined,
				affairType: '1'
			}
		},
		onLoad(options) {
			this.nameID = options.sameData
			this.getUserToDo()
			uni.setNavigationBarTitle({
				title: options.name + '-岗位任务' //将参数作为标题
			})
		},
		onShow() {
			this.getUserToDo()
			this.timingGet = setInterval(() => {
				this.getUserToDo()
			}, 1500000)
		},
		onHide() {
			clearInterval(this.timingGet)
		},
		methods: {
			getUserToDo() {
				const orgId = uni.getStorageSync('orgId')
				const json = {
					Parameter1: this.nameID,
					orgid: orgId
				}
				userToDo(json).then(res => {
					const newRes = (res || []).map(i => {
						const obj = {
							...i,
							title: i.NOTICE_TITLE,
							startTime: i.TASK_STARTDT,
							endTime: i.TASK_ENDDT,
						}
						obj.status = i.OVER_TIME === '正常' ? 0 : 1
						obj.statusText = i.OVER_TIME
						return obj
					})
					this.lists = newRes

				})
			},
			taskClisk(item) {
				let linkToUrl = ''
				if (item.SOURCE_FORMCODE == 'PF119') {
					const orgId = uni.getStorageSync('orgId')
					const json = initFilter(orgId)
					extendRule(json, 'ID', 1, item.SOURCE_DATA_ID);
					extendInclude(json, "Nav_ApproveDetails")
					extendInclude(json, "Nav_ApproveDetails.Nav_ApproveUser")
					FullGet(json).then(res => {
						let okApi = res.CALLBACK_INTERFACE
						// api 请求 获取  APPROVE_CODE ID
						linkToUrl = ApproveCode(res.APPROVE_CODE)
						if (okApi && okApi.indexOf('New') > -1) {
							okApi = res.CALLBACK_INTERFACE
						} else {
							okApi = 'PF/Approve/Submit'
						}
						// //特殊处理
						// if (okApi === 'BS/BSSafeCheck/CheckAuditEnd' || okApi ===
						// 	'BS/BSSafeCheck/CheckPlanAuditEnd' || okApi === 'BS/BSRiskSubmit/Notice' ||
						// 	okApi === 'BS/BSRiskSubmit/DealEnd' || okApi ===
						// 	'BS/BSRiskSubmitDelayApply/DealEnd' || okApi === 'FO/FOJobEventRecord/BackUpdate'|| 
						// 	okApi === 'FO/FOCrucialLicenseJob/BackUpdate'||okApi ==='FO/FOCrucialLicenseJobOutsource/BackUpdate') {
						// 	okApi = res.CALLBACK_INTERFACE + 'New'
						// } else {
						// 	okApi = 'PF/Approve/Submit'
						// }
						if (linkToUrl != '') {
							linkToUrl += "?tableKey=1&ID=" + res.DATA_ID + "&ApproveID=" + item
								.SOURCE_DATA_ID + "&taskID=" +
								item.ID + '&isAudit=true&okApi=' + okApi + '&refuseApi=' + res
								.REJECT_INTERFACE
							this.$store.commit('updateAuditModel', res)
							uni.navigateTo({
								url: linkToUrl
							})
						} else {
							// uni.$showMsg('此任务请到电脑上操作!', 'error')
							this.showToast()
						}
					})
				} else {
					linkToUrl = SourceFormcode(item.SOURCE_FORMCODE)
					if (linkToUrl != '') {
						linkToUrl += "?tableKey=" + this.affairType + "&ID=" + item.SOURCE_DATA_ID + "&taskID=" + item.ID

						if (item.SOURCE_FORMCODE == 'SC034' || item.SOURCE_FORMCODE == 'SC030' ||item.SOURCE_FORMCODE =='SE050_SHOWPRINT') {
							linkToUrl += "&FORMCODE=" + item.SOURCE_FORMCODE //会议 纪要 load时 添加标识
						}

						uni.navigateTo({
							url: linkToUrl
						})
					} else {
						// uni.$showMsg('此任务请到电脑上操作!', 'error')
						this.showToast()
					}
				}
			}
		}
	}
</script>

<style>
	.todo-page {
		/* position: relative; */
	}

	/* .todo-page .status-bar {
		height: 120px;
		background-image: linear-gradient(to right, #CFECFF, #6EB6FF);
		position: absolute;
		top: 0;
		left: 0;
		z-index: -10;
	} */

	.todo-page .main {
		padding: 10px 8px 62px 8px;
		position: relative;
		z-index: 10;
		background-size: 100% 120px;
		background-repeat: no-repeat;
	}

	.todo-page .swiper-wrap {
		margin-bottom: 16px;
	}

	.empty-wrap {
		margin-top: 60px;
	}

	.content-list {
		padding: 10px 0;
		/* position: relative; */
	}
</style>