<!-- 查看任务详情 -->
<template>
	<div class='taskDetails'>
		<div style="text-align: right;"><el-button type="primary" @click="openHistory">查看任务历史</el-button></div>
		<div style="height: 90%;margin-top: 20px;">
			<el-form :model="taskForm" :rules="rules" ref="taskForm" label-width="100px" class="demo-ruleForm">
				<el-row :gutter="10">
					<el-col :span="6">
						<el-form-item label="工作标题:" prop="title">
							<span>{{taskForm.title}}</span>
						</el-form-item>
						<el-form-item label="发布者:" >
							<span>{{taskForm.publisher.username}}</span>
						</el-form-item>
						<el-form-item v-if="isPublisher === true && taskForm.status === 'audit'" label="工作量(天):" prop="workload">
							<el-input v-if="isPublisher === true && taskForm.status === 'audit'" v-model.number="taskForm.workload"></el-input>
						</el-form-item>
						<el-form-item v-if="taskForm.status !== 'audit'" label="工作量(天):" prop="workload">
							<span v-if="taskForm.status !== 'audit'">{{taskForm.workload}}</span>
						</el-form-item>
						<el-form-item v-if="taskForm.status === 'finished'" label="结束时间:">
							<span v-if="taskForm.status === 'finished'">{{taskForm.endTime}}</span>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="任务开始时间:">
							<span>{{taskForm.stateTime}}</span>
							<!--<el-date-picker v-if="taskForm.status !== 'audit'" type="date" placeholder="选择日期" v-model="taskForm.startTime" style="width: 100%;"></el-date-picker>-->
						</el-form-item>
						<el-form-item label="组长:" >
							<span>{{taskForm.executor.username}}</span>
							<!--<el-select style="width: 100%;" v-model="taskForm.executor.id" placeholder="请选择组长">-->
								<!--<el-option-->
												<!--v-for="item in leaderOptions"-->
												<!--:key="item.id"-->
												<!--:label="item.username"-->
												<!--:value="item.id">-->
								<!--</el-option>-->
							<!--</el-select>-->
						</el-form-item>
						<el-form-item v-if="(taskForm.status === 'audit' && isPublisher === true) || ((isPublisher === true || isExecutor === true) && (taskForm.status === 'review' || taskForm.status === 'finished'))" label="考评分数:" prop="workCoefficient">
							<span v-if="taskForm.status === 'review' || taskForm.status === 'finished'">{{taskForm.workCoefficient}}</span>
							<el-input v-if="isPublisher === true && taskForm.status === 'audit'" v-model.number="taskForm.workCoefficient"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="预计完成时间:" prop="completeTime">
							<span>{{taskForm.completeTime}}</span>
							<!--<el-date-picker type="date" placeholder="选择日期" v-model="taskForm.endTime" style="width: 100%;"></el-date-picker>-->
						</el-form-item>
						<el-form-item label="组员:">
							<span v-if="isPublisher === false">
								<span v-for="(item, index) in taskForm.crewList" :key="index">{{item.username}}<span v-show="index !== (taskForm.crewList.length - 1)">、</span></span>
							</span>
							<el-select v-if="isPublisher === true && taskForm.status === 'ongoing'" style="width: 100%;" v-model="taskForm.crewList" multiple placeholder="请选择">
								<el-option
												v-for="item in memberOptions"
												:key="item.id"
												:label="item.username"
												:value="item.id">
								</el-option>
							</el-select>
						</el-form-item>
						<el-form-item v-if="taskForm.status === 'audit' || taskForm.status === 'review' || taskForm.status === 'finished' || taskForm.status === 'delete'" label="提交时间:">
							<span v-if="taskForm.status === 'audit' || taskForm.status === 'review' || taskForm.status === 'finished' || taskForm.status === 'delete'">{{taskForm.submitTime}}</span>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="任务创建时间:">
							<span>{{taskForm.createTime}}</span>
							<!--<el-date-picker type="date" placeholder="选择日期" v-model="taskForm.endTime" style="width: 100%;"></el-date-picker>-->
						</el-form-item>
						<el-form-item label="任务状态:">
							<span>{{$common.statusName(taskForm.status)}}</span>
						</el-form-item>
						<el-form-item v-if="taskForm.status === 'review' || taskForm.status === 'finished' || taskForm.status === 'delete'" label="审核时间:">
							<span v-if="taskForm.status === 'review' || taskForm.status === 'finished' || taskForm.status === 'delete'">{{taskForm.auditTime}}</span>
						</el-form-item>
					</el-col>
				</el-row>
				<div style="padding: 10px 35px;">
					<div style="padding: 10px 0px;font-size: 14px;">工作内容</div>
					<div style="padding: 20px 20px;height: 600px;border: 1px solid #dedede;overflow-y: auto;" v-html="taskForm.content">{{taskForm.content}}</div>
					<!--<editor-bar v-model="content" :isClear="isClear" @change="change"></editor-bar>-->
				</div>
				<div class="upload-container">
					<div style="margin-left: 35px;margin-top: 20px;" class="upload-file">

							<el-button size="small" @click="openFileTaskDialog()">查看附件</el-button>
							<!--<button>添加附件</button>-->

					</div>
				</div>
			</el-form>
		</div>
		<div style="text-align: center;height: 10%;margin-top: 20px;">
			<el-button v-show="isPublisher === true && (taskForm.status === 'audit' || taskForm.status === 'ongoing')" type="primary" @click="openChangeTaskDialog('taskForm')">修改</el-button>
			<el-button v-show="isExecutor === true && taskForm.status === 'ongoing' && isCanSubmit === true" type="primary" @click="openSubmitTaskDialog()">提交</el-button>
			<el-button v-show="isExecutor === true && isCanBreakDown && taskForm.status === 'ongoing'" type="primary" @click="breakDownTask()">分解</el-button>
			<el-button v-show="isExecutor === true && taskForm.status === 'audit'" type="primary" @click="openWithdrawTaskDialog()">撤回</el-button>
			<el-button v-show="((isPublisher === true && isEditEva === true) || isExecutor === true) && taskForm.status === 'review'" type="primary" @click="openEvaTaskDialog()">考评</el-button>
			<el-button v-show="taskForm.status === 'finished'" type="primary" @click="openViewTaskEvaDialog()">查看考评</el-button>
			<el-button v-show="isPublisher === true && (taskForm.status === 'audit' || taskForm.status === 'finished')" type="primary" @click="openDeleteTaskDialog('taskForm')">删除</el-button>
			<el-button v-show="isPublisher === true && taskForm.status === 'audit'" @click="reviewBtnClick('review', 'taskForm')" type="primary" >审核通过</el-button>
			<el-button v-show="isPublisher === true && taskForm.status === 'audit'" @click="reviewBtnClick('ongoing', 'taskForm')" type="primary" >审核不通过</el-button>
		</div>
		<div>

		</div>
		<history :showHistoryDialog="showHistoryDialog" :historyData="historyDatas" @close="closeHistory()"></history>
		<div>
			<el-dialog title="任务修改" :show-close="false" :append-to-body="true" :close-on-click-modal="false" :close-on-press-escape="false" :lock-scroll="true" :visible.sync="dialogTaskChangeVisible">
				<div slot="title" class="header-title">
					<span class="dialogHeader">任务修改</span>
					<img @click="closeChangeTaskDialog()" class="dialogHeaderClose" src="../assets/images/modal-gb.png" />
				</div>
				<div style="text-align: left;margin-top: 80px;">
					<span >修改说明：</span>
					<el-input
									type="textarea"
									:rows="2"
									style="margin-top: 30px;"
									placeholder="请输入修改说明"
									v-model="changeTaskTextarea">
					</el-input>
				</div>
				<div class="btnStyle">
					<el-button type="primary" @click="changeTaskSubmit()">确定</el-button>
				</div>
			</el-dialog>
		</div>
		<div>
			<el-dialog title="审核不通过" :show-close="false" :append-to-body="true" :close-on-click-modal="false" :close-on-press-escape="false" :lock-scroll="true" :visible.sync="dialogTaskFailVisible">
				<div slot="title" class="header-title">
					<span class="dialogHeader">审核不通过</span>
					<img @click="closeFailTaskDialog()" class="dialogHeaderClose" src="../assets/images/modal-gb.png" />
				</div>
				<div style="text-align: left;margin-top: 80px;">
					<span >审核不通过说明：</span>
					<el-input
									type="textarea"
									:rows="2"
									style="margin-top: 30px;"
									placeholder="请输入审核不通过说明"
									v-model="failTaskTextarea">
					</el-input>
				</div>
				<div class="btnStyle">
					<el-button type="primary" @click="failTaskSubmit('ongoing')">确定</el-button>
				</div>
			</el-dialog>
		</div>
		<div>
			<el-dialog title="任务提交" :show-close="false" :append-to-body="true" :close-on-click-modal="false" :close-on-press-escape="false" :lock-scroll="true" :visible.sync="dialogTaskSubmitVisible">
				<div slot="title" class="header-title">
					<span class="dialogHeader">任务提交</span>
					<img @click="closeSubmitTaskDialog()" class="dialogHeaderClose" src="../assets/images/modal-gb.png" />
				</div>
				<div style="text-align: left;margin-top: 80px;">
					<span >提交说明：</span>
					<el-input
									type="textarea"
									:rows="2"
									style="margin-top: 30px;"
									placeholder="请输入提交说明"
									v-model="submitTaskTextarea">
					</el-input>
				</div>
				<div class="btnStyle">
					<el-button type="primary" @click="statusTaskSubmit('audit', '提交')">确定</el-button>
				</div>
			</el-dialog>
		</div>
		<div>
			<el-dialog title="任务撤回" :show-close="false" :append-to-body="true" :close-on-click-modal="false" :close-on-press-escape="false" :lock-scroll="true" :visible.sync="dialogTaskWithdrawVisible">
				<div slot="title" class="header-title">
					<span class="dialogHeader">任务撤回</span>
					<img @click="closeWithdrawTaskDialog()" class="dialogHeaderClose" src="../assets/images/modal-gb.png" />
				</div>
				<div style="text-align: left;margin-top: 80px;">
					<span >撤回说明：</span>
					<el-input
									type="textarea"
									:rows="2"
									style="margin-top: 30px;"
									placeholder="请输入提交说明"
									v-model="withdrawTaskTextarea">
					</el-input>
				</div>
				<div class="btnStyle">
					<el-button type="primary" @click="statusTaskSubmit('ongoing', '撤回')">确定</el-button>
				</div>
			</el-dialog>
		</div>
		<div>
			<el-dialog title="任务评价" :show-close="false" :append-to-body="true" :close-on-click-modal="false" :close-on-press-escape="false" :lock-scroll="true" :visible.sync="dialogTaskEvaVisible">
				<div slot="title" class="header-title">
					<span class="dialogHeader">任务评价</span>
					<img @click="closeEvaTaskDialog()" class="dialogHeaderClose" src="../assets/images/modal-gb.png" />
				</div>
				<div style="text-align: left;">
					<el-form ref="evaForm" :rules="evaRules" :model="evaForm" label-width="100px">
						<!--<el-form-item v-if="isPublisher === true || (isExecutor === true && isEditEva === true) || (isPublisher === false && isExecutor === false)" label="自我评分" >-->
							<!--&lt;!&ndash;prop="score1"&ndash;&gt;-->
							<!--<el-input :disabled="isPublisher === true || (isExecutor === true && isEditEva === true)" v-model="evaForm.score1"></el-input>-->
						<!--</el-form-item>-->
						<div v-if="isEditEva === false && isExecutor === false">
							<el-form-item label="自我评分" prop="score1">
								<el-input disabled v-model="evaForm.score1"></el-input>
							</el-form-item>
							<el-form-item label="自我评价">
								<el-input disabled type="textarea" v-model="evaForm.comments1"></el-input>
							</el-form-item>
							<el-form-item label="发布者评分" prop="score2">
								<el-input disabled v-model="evaForm.score2"></el-input>
							</el-form-item>
							<el-form-item label="发布者评价">
								<el-input type="textarea" disabled v-model="evaForm.comments2"></el-input>
							</el-form-item>
						</div>
						<div v-if="isEditEva === false && isExecutor === true">
							<el-form-item label="自我评分" prop="score1">
								<el-input v-model="evaForm.score1"></el-input>
							</el-form-item>
							<el-form-item label="自我评价">
								<el-input type="textarea" v-model="evaForm.comments1"></el-input>
							</el-form-item>
							<el-form-item label="发布者评分">
								<el-input disabled v-model="evaForm.score2"></el-input>
							</el-form-item>
							<el-form-item label="发布者评价">
								<el-input type="textarea" disabled v-model="evaForm.comments2"></el-input>
							</el-form-item>
						</div>
						<div v-if="isEditEva === true && isPublisher === false">
							<el-form-item label="自我评分" prop="score1">
								<el-input disabled v-model="evaForm.score1"></el-input>
							</el-form-item>
							<el-form-item label="自我评价">
								<el-input disabled type="textarea" v-model="evaForm.comments1"></el-input>
							</el-form-item>
							<el-form-item label="发布者评分" prop="score2">
								<el-input disabled v-model="evaForm.score2"></el-input>
							</el-form-item>
							<el-form-item label="发布者评价">
								<el-input type="textarea" disabled v-model="evaForm.comments2"></el-input>
							</el-form-item>
						</div>
						<div v-if="isEditEva === true && isPublisher === true">
							<el-form-item label="自我评分" prop="score1">
								<el-input disabled v-model="evaForm.score1"></el-input>
							</el-form-item>
							<el-form-item label="自我评价">
								<el-input disabled type="textarea" v-model="evaForm.comments1"></el-input>
							</el-form-item>
							<el-form-item label="发布者评分" prop="score2">
								<el-input v-model="evaForm.score2"></el-input>
							</el-form-item>
							<el-form-item label="发布者评价">
								<el-input type="textarea" v-model="evaForm.comments2"></el-input>
							</el-form-item>
						</div>
					</el-form>
					<div style="text-align: center;">
						<el-button type="primary" @click="submitEvaDialog('evaForm')">确定</el-button>
						<!--<el-button type="primary" @click="closeEvaTaskDialog()">取消</el-button>-->
					</div>
				</div>
			</el-dialog>
		</div>
		<div>
			<el-dialog title="任务评价" :show-close="false" :append-to-body="true" :close-on-click-modal="false" :close-on-press-escape="false" :lock-scroll="true" :visible.sync="dialogViewTaskEvaVisible">
				<div slot="title" class="header-title">
					<span class="dialogHeader">任务评价</span>
					<img @click="closeViewTaskEvaDialog()" class="dialogHeaderClose" src="../assets/images/modal-gb.png" />
				</div>
				<div style="text-align: left;">
					<ul class="viewEvaLi">
						<li>自我评分：{{evaForm.score1}}</li>
						<li>自我评价：{{evaForm.comments1}}</li>
						<li>发布者评分：{{evaForm.score2}}</li>
						<li>发布者评价：{{evaForm.comments2}}</li>
					</ul>
				</div>
			</el-dialog>
		</div>
		<div>
			<el-dialog title="查看附件" :show-close="false" :append-to-body="true" :close-on-click-modal="false" :close-on-press-escape="false" :lock-scroll="true" :visible.sync="dialogViewTaskFileVisible">
				<div slot="title" class="header-title">
					<span class="dialogHeader">查看附件</span>
					<img @click="closeFileTaskDialog()" class="dialogHeaderClose" src="../assets/images/modal-gb.png" />
				</div>
				<div style="text-align: left;">
					<ul class="viewFileLi">
						<li v-for="(item,index) in taskForm.attachment" :key="index">
							<div style="text-align: center;">
								<img v-show="item.suffix === 'pdf'" src="../assets/images/yd-pdf.png"/>
								<img v-show="item.suffix === 'png'" src="../assets/images/yd-png.png"/>
								<img v-show="item.suffix === 'rar'" src="../assets/images/yd-rar.png"/>
								<img v-show="item.suffix === 'jpg'" src="../assets/images/yd-jpg.png"/>
								<img v-show="item.suffix === 'tp'" src="../assets/images/yd-tp.png"/>
								<img v-show="item.suffix === 'word'" src="../assets/images/yd-word.png"/>
								<img v-show="item.suffix === 'xml'" src="../assets/images/yd-xml.png"/>
								<img v-show="item.suffix === 'zip'" src="../assets/images/yd-zip.png"/>
								<div>{{item.name}}</div>
							</div>
						</li>
					</ul>
				</div>
			</el-dialog>
		</div>
		<div>
			<el-dialog title="任务删除" :show-close="false" :append-to-body="true" :close-on-click-modal="false" :close-on-press-escape="false" :lock-scroll="true" :visible.sync="dialogDeleteTaskVisible">
				<div slot="title" class="header-title">
					<span class="dialogHeader">任务删除</span>
					<img @click="closeDeleteTaskDialog()" class="dialogHeaderClose" src="../assets/images/modal-gb.png" />
				</div>
				<div style="text-align: left;margin: 0 30px;">
					<div style="margin-bottom: 30px;">是否需要纳入统计：</div>
					<el-checkbox label="个人工作量" v-model="deleteCheck">个人工作量</el-checkbox>
					<el-checkbox label="任务工作量" v-model="deleteCheck">任务工作量</el-checkbox>
					<div style="text-align: left;margin-top: 50px;">
						<span >删除说明：</span>
						<el-input
										type="textarea"
										:rows="2"
										style="margin-top: 30px;"
										placeholder="请输入删除说明"
										v-model="deleteTextarea">
						</el-input>
					</div>
					<div style="text-align: center;margin-top: 30px;">
						<el-button type="primary" @click="submitDeleteDialog()">确定</el-button>
					</div>
				</div>
			</el-dialog>
		</div>
	</div>
</template>

<script>
	//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
	//例如：import 《组件名称》 from '《组件路径》';
	import History from '../components/taskHistory';
	export default {
		name: "TaskDetails",
//import引入的组件需要注入到对象中才能使用
		components: { History },
		data () {
			let checkScore = (rule, value, callback) => {
				if (!value) {
					return callback(new Error('评分不能为空'));
				}
				if (value > this.taskForm.workCoefficient) { //  * 100
					callback(new Error(`根据考评分数，评分不能超过${this.taskForm.workCoefficient}`)); //  * 100
				} else if (value < 50) {
					callback(new Error('根据考评分数，评分不能低于50'));
				} else {
					callback();
				}
			};
			let workScore = (rule, value, callback) => {
				if (!value) {
					return callback(new Error('考评系数不能为空'));
				}
				if (value < 50) {
					callback(new Error('考评系数不能低于50'));
				} else {
					callback();
				}
			};
			let workLoadScore = (rule, value, callback) => {
				if (!value) {
					return callback(new Error('工作量不能为空'));
				} else {
					callback();
				}
			};
//这里存放数据
			return {
				showHistoryDialog: false, // 查看历史弹框
				dialogTaskChangeVisible:false, // 修改弹框
				dialogTaskSubmitVisible: false, // 提交弹框
				dialogTaskEvaVisible: false, // 考评弹框
				dialogTaskWithdrawVisible: false, // 撤回弹框
				dialogViewTaskEvaVisible: false,  // 查看考评弹框
				dialogViewTaskFileVisible: false,  // 查看附件弹框
				dialogDeleteTaskVisible: false, // 删除任务弹框
				dialogTaskFailVisible: false, // 审核不通过弹框
				taskForm: {
					attachment: [],
					completeTime: '',
					content: '',
					createTime: '',
					crewList: [],
					endTime: '',
					executor: '',
					id: '',
					publisher: '',
					pworkload: 1,
					stateTime: '',
					status: '',
					superiorId: '',
					title: '',
					updateTime: '',
					workCoefficient: 0,
					workload: 10,
					workloadCount: 1,
				},
				rules: {
					executor: [
						{ required: true, message: '请选择组长', trigger: 'change' }
					],
					crewList: [
						{ type: 'array', required: true, message: '请选择组员', trigger: 'change' },
					],
					workCoefficient: [
						{ validator: workScore, trigger: 'blur' },
						{ type: 'number', message: '考评分数必须为数字值'}
					],
					workload: [
						{ validator: workLoadScore, trigger: 'blur' },
						// { required: true, message: '工作量不能为空'},
						{ type: 'number', message: '工作量必须为数字值'}
					]
				},
				changeTaskTextarea: '',
				submitTaskTextarea: '',
				withdrawTaskTextarea: '',
				failTaskTextarea: '', // 审核不通过
				evaForm:{
					score1: '',
					score2: '',
					comments2: '',
					comments1: '',
					endWorkLoad: '',
					workId: '',
					id: null,
					userId: ''
				},
				evaRules: {
					score1: [
						{ required: true, validator: checkScore, trigger: 'blur' }
						// { required: true, message: '请填写自我评分', trigger: 'blur' }
					],
					score2: [
						{ required: true, validator: checkScore, trigger: 'blur' }
						// { validator: validcodeScore2, trigger: 'blur' }
						// { required: true, message: '请填写发布者评分', trigger: 'blur' }
					],
				},
				leaderOptions: [],
				memberOptions: [],
				isPublisher: false, // 判断是否是发布者
				// isGroupLeader: false, // 是否是组长
				// isCarriedOut: false, // 是否是执行者
				isExecutor: false, // 是否是执行者
				isCanBreakDown: false, // 是否能分解任务
				isEditEva: false, // 是否提交了评价
				hasAuthority: false, // 是否有分解权限
				isCanSubmit: false, // 判断是否可以提交
				userDetail: '', // 当前用户的信息
				taskListData: '',
				historyDatas: [], // 历史数据
				deleteCheck:['个人工作量', '任务工作量'], // 删除多选框
				deleteTextarea: '', // 删除说明
				showScore2Tip: false,
				showScore1Tip: false,
				workScores: 0,
			};
		},
//监听属性 类似于data概念
		computed: {},
//监控data中的数据变化
		watch: {},
//方法集合
		methods: {
			getUserById(val) {
				this.$axios.getUserById(val).then((res) => {
					console.log(res)
					if (res.request.status === 200) {
						this.leaderOptions = res.data;
						this.memberOptions = res.data;
					}
				})
			},
			getDetailsTask(val) {
				this.$axios.getWorkDetails(val).then((res) => {
					console.log(res)
					if (res.request.status === 200) {
						let postData = JSON.parse(JSON.stringify(res.data));
						if ((postData.workCoefficient.toString()).indexOf(".") > -1) {
							postData.workCoefficient = (Math.round(postData.workCoefficient*100)/100) * 100;
						} else {
							if ((postData.workCoefficient.toString()).length < 2) {
								postData.workCoefficient = (Math.round(postData.workCoefficient*100)/100) * 100;
							} else {
								postData.workCoefficient = JSON.parse(JSON.stringify(postData.workCoefficient));
							}
						}
						// postData.workCoefficient = (Math.round(postData.workCoefficient*100)/100) * 100;
						this.workScores = JSON.parse(JSON.stringify(postData.workCoefficient));
						this.taskForm = postData;
						let arr = [];
						if (res.data.publisher.id === this.userDetail.id) {
							this.isPublisher = true;
							if (postData.status === 'ongoing' || postData.status === 'unpublished') {
								if (postData.crewList !== null && postData.crewList.length > 0) {
									postData.crewList.forEach((v,i)=> {
										arr.push(v.id);
									})
									this.taskForm.crewList = arr;
								}
								let dataUser = JSON.parse(JSON.stringify(this.leaderOptions));
								console.log(dataUser)
								if (res.data.crewList !== null && res.data.crewList.length > 0) {
									dataUser.push(...res.data.crewList);
									console.log(dataUser)
								}
								// console.log()
								let dataUser2 = JSON.parse(JSON.stringify(dataUser));
								for(let i = 0; i < dataUser2.length; i++) {
									for(let j = i + 1; j < dataUser2.length ; j++) {
										if(dataUser2[i].id === dataUser2[j].id) {
											dataUser2.splice(j, 1)
											j--;
										}
									}
								}
								// let dataUser2 = Array.from(new Set(dataUser));
								this.leaderOptions = dataUser2;
								this.memberOptions = dataUser2;
							}
						} else {
							this.isPublisher = false;
						}
						if (res.data.executor.id === this.userDetail.id) {
							this.isExecutor = true;
						} else {
							this.isExecutor = false;
						}
						if (this.isExecutor === true) {
							if ((postData.crewList !== null && postData.crewList.length > 0) || (this.userDetail.roles !== null && this.userDetail.roles.length > 0 && this.userDetail.roles[0].authorities.findIndex(item => item.name === '分解任务') > -1)) {
								this.isCanBreakDown = true;
							} else {
								this.isCanBreakDown = false
							}
						} else {
							this.isCanBreakDown = false;
						}
						// if (res.data.crewList.length > 0) {
						// 	let index = res.data.crewList.findIndex(item => item.id === this.userDetail.id);
						// 	if (index > 0) {
						// 		this.isCarriedOut = true;
						// 	} else {
						// 		this.isCarriedOut = false;
						// 	}
						// }
						// if (this.userDetail.roles.length > 0) {
						// 	let index = this.userDetail.roles[0].authorities.findIndex(item => item.name === '分解任务');
						// 	console.log(index)
						// 	if (index > -1) {
						// 		this.hasAuthority = true;
						// 	}
						// } else {
						// 	this.hasAuthority = false;
						// }
					}
					this.$axios.putCanSubmitTask(res.data.id).then((res) => {
						console.log(res)
						if (res.status === 200) {
							console.log(res.data.isNotCommit === '1')
							this.isCanSubmit = res.data.isNotCommit === '1' ? true : false;
						}
					})
					this.$axios.getScore(res.data.id).then((res) => {
						console.log(res);
						if (res.status === 200) {
							if (res.data.score1 !== '') {
								this.isEditEva = true;
							} else {
								this.isEditEva = false;
							}
						}
					})
				})
			},
			openHistory() {
				this.$axios.getTaskHistory(this.taskListData.workId).then((res) => {
					console.log(res)
					if (res.request.status === 200) {
						this.historyDatas = res.data;
					}
				})
				this.showHistoryDialog = true;
			},
			closeHistory() {
				this.showHistoryDialog = false;
			},
			closeChangeTaskDialog() {
				this.dialogTaskChangeVisible = false;
			},
			openChangeTaskDialog(val) {
				this.$refs[val].validate((valid) => {
					if (valid) {
						this.dialogTaskChangeVisible = true;
					} else {
						console.log('error submit');
						return false;
					}
				});
			},
			closeSubmitTaskDialog() {
				this.dialogTaskSubmitVisible = false;
			},
			openSubmitTaskDialog() {
				this.dialogTaskSubmitVisible = true;
			},
			closeEvaTaskDialog() {
				this.dialogTaskEvaVisible = false;
			},
			openEvaTaskDialog() {
				// if (this.isPublisher === true) {
				this.isEditEva = false;
					this.$axios.getScore(this.taskForm.id).then((res) => {
						console.log(res);
						if (res.status === 200) {
							this.evaForm = res.data;
							// if (this.isExecutor === true) {
								if (res.data.score1 !== '') {
									this.isEditEva = true;
								} else {
									this.isEditEva = false;
								}
							// }
						}
					})
				// }
				console.log(this.isEditEva)
				this.dialogTaskEvaVisible = true;
			},
			closeFileTaskDialog() {
				this.dialogViewTaskFileVisible = false;
			},
			openFileTaskDialog() {
				this.dialogViewTaskFileVisible = true;
			},
			submitEvaDialog(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						if (this.isEditEva === false) {
							let obj = JSON.parse(JSON.stringify(this.evaForm));
							obj.workId = this.taskListData.workId;
							obj.userId = this.userDetail.id;
							obj.score2 = null;
							obj.comments2 = null;
							obj.endWorkLoad = 1;
							this.$axios.postScore(obj).then((res) => {
								console.log(res)
								if (res.status === 200) {
									this.$message({
										message: '评价任务成功!',
										type: 'success'
									});
									this.$refs[formName].resetFields();
									this.dialogTaskEvaVisible = false;
									this.getDetailsTask(this.taskListData.workId);
								}
							})
						} else {
							this.$axios.putScore(this.userDetail.id, this.evaForm).then((res) => {
								console.log(res)
								if (res.status === 200) {
									let obj = {
										msg: '',
										userId: this.userDetail.id,
										workId: this.taskForm.id,
										status: 'finished'
									}
									this.$axios.putTaskStatus(obj).then((res) => {
										console.log(res)
										if (res.status === 200) {
											this.$message({
												message: '评价任务成功!',
												type: 'success'
											});
											this.$refs[formName].resetFields();
											this.dialogTaskEvaVisible = false;
											this.getDetailsTask(this.taskListData.workId);
										}
									})
								}
							})
						}
						// if (this.isPublisher === true) {
						// 	if (this.evaForm.score1 === '') {
						// 		this.$message({
						// 			message: '请先让任务执行者评分后在评价',
						// 			type: 'warning'
						// 		});
						// 		return false;
						// 	} else {
								// this.$axios.putScore(this.userDetail.id, this.evaForm).then((res) => {
								// 	console.log(res)
								// 	if (res.status === 200) {
								// 		let obj = {
								// 			msg: '',
								// 			userId: this.userDetail.id,
								// 			workId: this.taskForm.id,
								// 			status: 'finished'
								// 		}
								// 		this.$axios.putTaskStatus(obj).then((res) => {
								// 			console.log(res)
								// 			if (res.status === 200) {
								// 				this.$message({
								// 					message: '评价任务成功!',
								// 					type: 'success'
								// 				});
								// 				this.$refs[formName].resetFields();
								// 				this.dialogTaskEvaVisible = false;
								// 				this.getDetailsTask(this.taskListData.workId);
								// 			}
								// 		})
								// 	}
								// })
						// 	}
						// } else {
							// let obj = JSON.parse(JSON.stringify(this.evaForm));
							// obj.workId = this.taskListData.workId;
							// obj.userId = this.userDetail.id;
							// obj.score2 = null;
							// obj.comments2 = null;
							// obj.endWorkLoad = 1;
							// this.$axios.postScore(obj).then((res) => {
							// 	console.log(res)
							// 	if (res.status === 200) {
							// 		this.$message({
							// 			message: '评价任务成功!',
							// 			type: 'success'
							// 		});
							// 		this.$refs[formName].resetFields();
							// 		this.dialogTaskEvaVisible = false;
							// 		this.getDetailsTask(this.taskListData.workId);
							// 	}
							// })
						// }
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},

			closeWithdrawTaskDialog() {
				this.dialogTaskWithdrawVisible = false;
			},
			openWithdrawTaskDialog() {
				this.dialogTaskWithdrawVisible = true;
			},
			closeViewTaskEvaDialog() {
				this.dialogViewTaskEvaVisible = false;
			},
			openViewTaskEvaDialog() {
				this.$axios.getScore(this.taskForm.id).then((res) => {
					console.log(res);
					if (res.status === 200) {
						this.evaForm = res.data;
					}
				})
				this.dialogViewTaskEvaVisible = true;
			},
			closeDeleteTaskDialog() {
				this.dialogDeleteTaskVisible = false;
			},
			openDeleteTaskDialog() {
				this.dialogDeleteTaskVisible = true;
			},
			changeTaskSubmit() {
				// 修改任务确定
				if (this.taskForm.status === 'ongoing') {
					let obj = {
						"msg": this.changeTaskTextarea,
						"userid": this.userDetail.id,
						"users": this.taskForm.crewList,
						"workId": this.taskListData.workId
					}
					console.log(obj)
					this.$axios.putTaskGroup(obj).then((res) => {
						console.log(res)
						if (res.request.status === 200) {
							// if (res.data.id !== undefined) {
								this.$message({
									message: '修改任务成功!',
									type: 'success'
								});
							// }
							this.changeTaskTextarea = '';
							this.dialogTaskChangeVisible = false;
							this.getDetailsTask(this.taskListData.workId);
						}
					})
				} else if (this.taskForm.status === 'audit') {
					let obj = {
						"msg": this.changeTaskTextarea,
						"userId": this.userDetail.id,
						"workCoefficient": parseFloat(this.taskForm.workCoefficient),
						"workload": this.taskForm.workload,
						"workId": this.taskListData.workId
					}
					this.$axios.putTaskWorkload(obj).then((res) => {
						console.log(res)
						if (res.request.status === 200) {
							if (res.data.id !== undefined) {
								this.$message({
									message: '修改任务成功!',
									type: 'success'
								});
							}
							this.changeTaskTextarea = '';
							this.dialogTaskChangeVisible = false;
							this.getDetailsTask(this.taskListData.workId);
						}
					})
				}
			},
			statusTaskSubmit(val, tip) {
				let msg = '';
				if (tip === '撤回') {
					msg = this.withdrawTaskTextarea;
				} else if (tip === '提交') {
					msg = this.submitTaskTextarea;
				}
				let obj = {
					msg: msg,
					status: val,
					userId: this.userDetail.id,
					workId: this.taskListData.workId
				}
				this.$axios.putTaskStatus(obj).then((res) => {
					console.log(res)
					if (res.request.status === 200) {
						// if (res.data.id !== undefined) {
							this.$message({
								message: tip + '任务成功!',
								type: 'success'
							});
							this.submitTaskTextarea = '';
							this.withdrawTaskTextarea = '';
							this.dialogTaskSubmitVisible = false;
							this.dialogTaskWithdrawVisible = false;
							this.getDetailsTask(this.taskListData.workId);
						// }
					}
				})
			},
			submitDeleteDialog() {
				console.log(this.deleteCheck)
				let pw = this.deleteCheck.includes('个人工作量') ? 1 : 0;
				let wc =this.deleteCheck.includes('任务工作量') ? 1 : 0;
				console.log(pw, wc)
				let obj = {
					msg: this.deleteTextarea,
					personalWorkload: pw,
					userId: this.userDetail.id,
					workId: this.taskListData.workId,
					workloadCount: wc
				}
				console.log(obj)
				this.$axios.deleteTaskByParams(obj).then((res) => {
					console.log(res)
					if (res.request.status === 200) {
						this.$message({
							message: '删除任务完成!',
							type: 'success'
						});
						this.deleteTextarea = '';
						this.deleteCheck = ['个人工作量', '任务工作量'];
						this.$router.push({name: 'viewTask'})
					}
				})
			},
			closeFailTaskDialog() {
				this.dialogTaskFailVisible = false;
			},
			failTaskSubmit(val) {
				let obj = {
					msg: this.failTaskTextarea,
					status: val,
					workId: this.taskListData.workId,
					userId: this.userDetail.id
				}
				this.$axios.putTaskStatus(obj).then((res) => {
					console.log(res)
					this.$message({
						message: '审核不通过!',
						type: 'success'
					});
					this.getDetailsTask(this.taskListData.workId);
					this.failTaskTextarea = '';
				})
			},
			reviewBtnClick(val, formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						if (val === 'ongoing') {
							this.dialogTaskFailVisible = true;
						} else {
							let obj = {
								msg: '',
								status: val,
								workId: this.taskListData.workId,
								userId: this.userDetail.id
							}
							this.$axios.putTaskStatus(obj).then((res) => {
								console.log(res)
								this.$message({
									message: '审核通过!',
									type: 'success'
								});
								this.getDetailsTask(this.taskListData.workId);
							})
						}
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			breakDownTask() {
				console.log(this.taskForm)
				let arr = [];
				if (this.taskForm.crewList !== null && this.taskForm.crewList.length > 0) {
					console.log(this.taskForm.crewList[0].username);
					if (this.taskForm.crewList[0].username !== undefined) {
						let crew = JSON.parse(JSON.stringify(this.taskForm.crewList));
						let le = JSON.parse(JSON.stringify(this.leaderOptions));
						console.log(crew)
						console.log(le)
						let arrPush = [...crew, ...le];
						arr = Array.from(new Set(arrPush));
					} else {
						arr = JSON.parse(JSON.stringify(this.leaderOptions));
					}
				} else {
					arr = JSON.parse(JSON.stringify(this.leaderOptions));
				}
				console.log(arr)
				let obj = {
					name: this.taskForm.title,
					id: this.taskForm.id,
					stateTime: this.taskForm.stateTime,
					completeTime: this.taskForm.completeTime,
					crewList: arr,
				}
				this.$store.commit('changeSuperior', {
					superior: obj
				})
				this.$router.push({name: 'addTask'});
			}
		},
//生命周期 - 创建完成（可以访问当前this实例）
		created () {

		},
//生命周期 - 挂载完成（可以访问DOM元素）
		mounted () {
			this.taskListData = JSON.parse(this.$Base64.decode(localStorage.getItem('taskDetail')));
			console.log(this.taskListData)
			this.userDetail = JSON.parse(this.$Base64.decode(localStorage.getItem('login')));
			this.getUserById(this.userDetail.id);
			let that = this;
			setTimeout(function () {
				if (that.taskListData.workId !== undefined) {
					that.getDetailsTask(that.taskListData.workId);
				} else {
					that.getDetailsTask(that.taskListData.id);
				}

			}, 100)
		},
		beforeCreate () {
		}, //生命周期 - 创建之前
		beforeMount () {
		}, //生命周期 - 挂载之前
		beforeUpdate () {
		}, //生命周期 - 更新之前
		updated () {
		}, //生命周期 - 更新之后
		beforeDestroy () {
		}, //生命周期 - 销毁之前
		destroyed () {
		}, //生命周期 - 销毁完成
		activated () {
		}, //如果页面有keep-alive缓存功能，这个函数会触发
	}
</script>
<style scoped>
	.viewEvaLi {
		margin: 10px 30px;
	}
	.viewEvaLi li{
		margin-top: 20px;
		height: 80px;
		line-height: 80px;
		margin-left: 100px;
	}

	.btnStyle{
		text-align: center;
		margin-top: 30px;
	}

	.viewFileLi{
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: left;
		align-items: center;
	}

	.viewFileLi li{
		margin-right: 40px;
		cursor: pointer;
	}
</style>
