<template>
	<view>
		<view class="dtop">
			<view class="title">{{ item.title || '' }}</view>
		</view>
		<view class="mbos">
			<view class="ms mt0">
				<view class="mtitle">兼职金额</view>
				<view class="desc mb15">{{ item.salary || '' }}元</view>
				<view class="mtitle">兼职时间</view>
				<view class="desc mb15">{{ item.startDate || '' }}至{{ item.endDate || '' }}，共计：{{ item.days }}天</view>
				<view class="mtitle">兼职地点</view>
				<view class="desc mb15">{{ item.address || '工作地点不限' }}</view>
				<view class="mtitle">结算方式</view>
				<view class="desc mb15">在规定时间内完工结算（平台打款）</view>
				<view class="mtitle">兼职描述</view>
				<u-parse :content="item.contents" class="item"></u-parse>
			</view>
		</view>
		<view class="mfooter">
			<view class="cn">
				<view class="f">
					<button class="btn" style="background-color: #607d8b" @click="go('/pages/user/resume/application/task_list?taskId=' + obj.id + '&role=' + obj.role)">
						<text class="icon">&#xe656;</text>
						<text>任务日志</text>
					</button>
				</view>
				<view class="f" style="flex: 1.4">
					<button class="btn" @click="send()" :disabled="obj.isComplete == 1 || obj.isComplete == 2" v-if="obj.role == 1">
						<text class="icon">&#xe612;</text>
						<text v-if="obj.isComplete == 0">确认完成</text>
						<text v-if="obj.isComplete == 1">等待甲方确认</text>
						<text v-if="obj.isComplete == 2">任务完成</text>
						<text v-if="obj.isComplete == 3">申请驳回,重新提交</text>
					</button>
					<button class="btn" @click="show()" :disabled="obj.isComplete != 1" v-else>
						<text class="icon">&#xe612;</text>
						<text v-if="obj.isComplete == 0">任务进行中...</text>
						<text v-if="obj.isComplete == 1">确认完成</text>
						<text v-if="obj.isComplete == 2">任务完成</text>
						<text v-if="obj.isComplete == 3">申请完成驳回</text>
					</button>
				</view>
			</view>
		</view>
		<complete ref="complete" @confirm="confirm"></complete>
	</view>
</template>

<script>
export default {
	data() {
		return {
			item: {},
			obj: {}
		};
	},
	onLoad(e) {
		this.obj = JSON.parse(e.item);
		this.http.request({
			url: '/app/position/detail/' + this.obj.positionId,
			success: (res) => {
				this.item = res.data.data.position;
				this.item.days = this.util.days(this.item.startDate, this.item.endDate);
			}
		});
	},
	methods: {
		go(url) {
			uni.navigateTo({ url: url });
		},
		send() {
			uni.showModal({
				title: '提示',
				content: '确定提交完成申请?',
				success: (res) => {
					if (res.confirm) {
						this.http.request({
							url: '/app/deliver/yTaskComplete',
							data: { id: this.obj.id },
							method: 'POST',
							success: (res) => {
								uni.showModal({
									title: '提示',
									content: '提交完成申请成功，等待甲方确认',
									showCancel: false,
									success: (res) => {
										uni.$emit('task_to_do');
										uni.navigateBack();
									}
								});
							}
						});
					}
				}
			});
		},
		confirm() {
			uni.$emit('task_to_do');
			uni.navigateBack();
		},
		show() {
			this.$refs.complete.init(this.obj.id);
		}
	}
};
</script>

<style lang="scss">
.mfooter {
	background-color: white;
	bottom: 0px;
	border-top: 1px solid $line;
	.cn {
		padding: 0px 10px 15px 10px;
		overflow: hidden;
		display: flex;
		.f {
			flex: 1;
			padding: 0px 10px 0px 10px;
			.btn {
				width: 100%;
			}
		}
	}
}
</style>
