<template>
	<view class="">
		<nav-bar title="审核详情" goBack />
		<view class="task-audit">
			<template v-if="TaskInfo">
				<view class="task-title">
					{{TaskInfo.childTaskTitle}}
				</view>
				<view class="task-explain">
					{{TaskInfo.childTaskRemark}}
				</view>
				<share :sharePoster="mainTask.sharePoster" :taskId="mainTask.taskId" />

				<taskContent v-if="mainTask">
					<view class="task-info-item">
						<text class="task-info-title">任务时间：</text>
						<text class="task-info-val">{{mainTask.startTime}} - {{mainTask.endTime}}</text>
					</view>
					<view class="task-info-item">
						<text class="task-info-title">任务领取后完成时间：</text>
						<text class="task-info-val">{{mainTask.completionDays}}天</text>
					</view>
					<view class="task-info-item">
						<text class="task-info-title">任务奖励：</text>
						<text class="task-info-val task-info-integral">{{mainTask.rewardPoints}}积分</text>
					</view>
				</taskContent>
			</template>
			<template v-if="TaskInfo">
				<view class="task-title-2">
					审核信息
				</view>
				<taskContent>
					<view class="task-info-item">
						<text class="task-info-title">提交时间：</text>
						<text class="task-info-val">{{ TaskInfo.submitTime }}</text>
					</view>
					<view class="task-info-item">
						<text class="task-info-title">审核状态：</text>
						<text class="task-info-val">{{$TaskStatusText(TaskInfo.checkStatus)}}</text>
					</view>
					<view class="task-info-item" v-if="TaskInfo.checkStatus === 2">
						<text class="task-info-title">驳回原因：</text>
						<text class="task-info-val">{{ TaskInfo.rejectReason }}</text>
					</view>
				</taskContent>
			</template>
		</view>
		<template v-if="TaskInfo">
			<task-bottom-btn v-if="TaskInfo.checkStatus === 3" btnName="去查看"
				@onClick="onSubmit(mainTask.taskType , true  )" />
			<task-bottom-btn v-if="[0,1,2].includes(TaskInfo.checkStatus)" btnName="去提交"
				@onClick="onSubmit(mainTask.taskType, false )" />
		</template>
	</view>
</template>

<script>
	import share from "./components/share.vue"
	import taskContent from "./components/task-content.vue"
	import taskBottomBtn from "./components/task-bottom-btn.vue"
	import {
		getMyTaskInfo_Api,
		getMyMoreTaskInfo_Api,
		onSubmitCheck_Api
	} from "@/api/task.js"
	import {
		onSubmint_val
	} from "./task_common.js"
	export default {
		components: {
			share,
			taskContent,
			taskBottomBtn
		},
		data() {
			return {
				config: {
					back: true,
					title: '审核详情',
					color: 'black',
					backgroundColor: [1, '#fff'],
					statusBarFontColor: 'black'
				},
				mainTask: null, // 主任务
				TaskInfo: null, // 子任务
				receiveTaskId: null, // 单任务审核详情
				receiveChildTaskId: null,
			}
		},
		onLoad(opt) {
			this.receiveTaskId = opt.receiveTaskId;
			this.receiveChildTaskId = opt.receiveChildTaskId;
			this.init();
		},
		methods: {
			init() {
				if (this.receiveTaskId) {
					this.getMyTaskInfo()
				}
				if (this.receiveChildTaskId) {
					this.getMyMoreTaskInfo()
				}
			},
			// 查询单任务详情
			getMyTaskInfo() {
				getMyTaskInfo_Api(this.receiveTaskId || this.receiveChildTaskId).then(res => {
					const childTask = res.data ? res.data.childTaskVoList[0] : null
					this.mainTask = res.data;
					if (childTask) {
						this.TaskInfo = childTask;
						this.TaskRule = childTask.childTaskRule || null
					};
				})
			},
			// 多任务
			getMyMoreTaskInfo() {
				getMyMoreTaskInfo_Api(this.receiveChildTaskId).then(res => {
					const childTask = res.data || null
					this.TaskInfo = childTask;
					this.mainTask = childTask.myTaskVo;
					this.TaskRule = childTask?.childTaskRule || null
					console.log(this.TaskInfo, '------TaskInfo--------')
				})
			},

			onSubmit(type, checkPage = false, page = 'submitDetails') {
				const taskInfo = this.TaskInfo;
				onSubmint_val(type, taskInfo, checkPage, page)
			},
			// onSubmit(type) {
			// 	onSubmit(type, checkPage = false) {
			// 		const taskInfo = this.taskInfo.childTaskVoList[0];
			// 		onSubmint_val(type, taskInfo, checkPage)
			// 	}
			// 	// onSubmitCheck_Api(this.TaskInfo.receiveChildTaskId).then(res => {
			// 	// 	let path = '/pages/task/submit-task';
			// 	// 	if (type === 0) {
			// 	// 		// 单任务提交
			// 	// 		path = `${path}?receiveTaskId=${this.receiveTaskId}`
			// 	// 	} else {
			// 	// 		// 多任务下子任务提交
			// 	// 		path = `${path}?receiveChildTaskId=${this.TaskInfo.receiveChildTaskId}`
			// 	// 	};

			// 	// 	uni.navigateTo({
			// 	// 		url: path
			// 	// 	})
			// 	// })
			// },
			onExamine() {
				let path = '/pages/task/submit-task';
				if (type === 0) {
					// 单任务提交
					path = `${path}?receiveTaskId=${this.receiveTaskId}`
				} else {
					// 多任务下子任务提交
					path = `${path}?receiveChildTaskId=${this.TaskInfo.receiveChildTaskId}`
				};

				uni.navigateTo({
					url: path
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "./common.scss";

	.task-audit {
		padding: 0 30rpx;
	}
</style>