<!-- 新增任务 -->
<template>
	<div class='addTask'>
		<div class="addHeader">
			<ul>
				<li style="font-weight: bold;">发布者：{{announcer}}</li>
				<li class="addRightBtn">
					<!--<div >-->
						<el-button type="primary" @click="submitForm('taskForm','unpublished')"><span><img class="addImgs" src="../../assets/images/saveIcon.png"/></span>保存</el-button>
						<el-button style="margin-left: 50px;" type="primary" @click="submitForm('taskForm', 'ongoing')"><span><img class="addImgs" src="../../assets/images/pushIcon.png"/></span>发布</el-button>
					<!--</div>-->
				</li>
			</ul>
		</div>
		<!--<div class="addRightBtn">-->
			<!--<el-button type="primary" @click="submitForm('taskForm','unpublished')"><span><img class="addImgs" src="../../assets/images/saveIcon.png"/></span>保存</el-button>-->
			<!--<el-button style="margin-left: 50px;" type="primary" @click="submitForm('taskForm', 'ongoing')"><span><img class="addImgs" src="../../assets/images/pushIcon.png"/></span>发布</el-button>-->
		<!--</div>-->
		<div>
			<el-form :model="taskForm" :rules="rules" ref="taskForm" label-width="130px" class="demo-ruleForm">
				<div class="addTips">
					<img src="../../assets/images/tipMust.png"/>为必填项
				</div>
				<div class="showMainTaskDetail" v-show="saveStoreTaskDetailValue !== '' && saveStoreTaskDetailValue !== undefined">
					<el-form-item label="主任务名称">
						<!--<div style="cursor: pointer;">-->
							<el-tooltip placement="bottom" effect="light">
								<div slot="content">
									<ul class="mainTaskTip">
										<li><span class="tipSpan">主任务名称：</span>{{saveStoreTaskDetailValue.title}}</li>
										<li><span class="tipSpan">任务开始时间：</span>{{saveStoreTaskDetailValue.stateTime}}</li>
										<li><span class="tipSpan">预计完成时间：</span>{{saveStoreTaskDetailValue.completeTime}}</li>
										<li><span class="tipSpan">总任务量：</span>{{saveStoreTaskDetailValue.workloadCount}}</li>
									</ul>
								</div>
								<span style="cursor:pointer;border-bottom: 1px solid #5059d5">{{saveStoreTaskDetailValue.title}}</span>
							</el-tooltip>
						<!--</div>-->
					</el-form-item>

					<!--<el-popover-->
									<!--placement="bottom"-->
									<!--width="400"-->
									<!--trigger="click">-->
						<!--<div>-->
							<!--<ul>-->
								<!--<li>主任务名称：{{saveStoreTaskDetailValue.title}}</li>-->
								<!--<li>任务开始时间：{{saveStoreTaskDetailValue.stateTime}}</li>-->
								<!--<li>预计完成时间：{{saveStoreTaskDetailValue.completeTime}}</li>-->
								<!--<li>总任务量：{{saveStoreTaskDetailValue.workloadCount}}</li>-->
							<!--</ul>-->
						<!--</div>-->
						<!--<el-button>主任务名称：</el-button>-->
					<!--</el-popover>-->
				</div>
				<el-row :gutter="30">
					<el-col :span="8">
						<el-form-item label="任务名称" prop="title">
							<div>
								<el-input v-model="taskForm.title"></el-input>
							</div>
						</el-form-item>
						<!--<el-form-item label="小组名称" prop="taskGroupName">-->
							<!--<el-input v-model="taskForm.taskGroupName"></el-input>-->
						<!--</el-form-item>-->
						<el-form-item label="组长" prop="executor">
							<el-select style="width: 100%;" v-model="taskForm.executor" placeholder="请选择组长">
								<el-option
												v-for="item in leaderOptions"
												:key="item.id"
												:label="item.username + '(' + $common.personStatusName(item.status) + ')'"
												:value="item.id">
									<span style="display: inline-block;width: 70px;">{{item.username}}</span>
									<span :style="{color: $common.colorNum(item.status)}">({{$common.personStatusName(item.status)}})</span>
								</el-option>
							</el-select>
						</el-form-item>
						<!--<el-form-item label="发布者">-->
							<!--<span>{{announcer}}</span>-->
						<!--</el-form-item>-->
					</el-col>
					<el-col :span="8">
						<el-form-item label="任务开始时间" prop="stateTime">
							<el-date-picker :clearable="false" :editable="false" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期" v-model="taskForm.stateTime" style="width: 100%;"></el-date-picker>
						</el-form-item>
						<el-form-item label="任务量(天)" prop="workload">
							<el-input onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" v-model="taskForm.workload"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="预计完成时间" prop="completeTime">
							<el-date-picker :clearable="false" :picker-options="pickerOptionsComplete" :editable="false" default-time="09:00:00" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期" v-model="taskForm.completeTime" style="width: 100%;"></el-date-picker>
						</el-form-item>
						<el-form-item v-if="showAuditName === false" label="审核者" prop="audit">
							<el-select  style="width: 100%;" v-model="taskForm.audit" placeholder="请选择审核者">
								<el-option
												v-for="item in auditOptions"
												:key="item.id"
												:label="item.username"
												:value="item.id">
									<span style="display: inline-block;width: 70px;">{{item.username}}</span>
									<span :style="{color: $common.colorNum(item.status)}">({{$common.personStatusName(item.status)}})</span>
								</el-option>
							</el-select>
							<span v-if="showAuditName === true">{{userLoginData.username}}</span>
						</el-form-item>
						<el-form-item v-if="showAuditName === true" label="审核者" >
							<span>{{userLoginData.username}}</span>
						</el-form-item>
					</el-col>
				</el-row>
				<div>
					<el-form-item class="groupAdd" label="组员">
						<!--prop="crewList"-->
						<el-select 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">
								<span style="display: inline-block;width: 70px;">{{item.username}}</span>
								<span :style="{color: $common.colorNum(item.status)}">({{$common.personStatusName(item.status)}})</span>
							</el-option>
						</el-select>
					</el-form-item>
				</div>
				<div class="upload-container">
					<div class="upload-file" style="margin-left: 0px;">
						<el-upload
										class="upload-demo"
										ref="upload"
										action="https://jsonplaceholder.typicode.com/posts/"
										:http-request="handleChange"
										:on-remove="handleRemove"
										:on-exceed="handleExceed"
										:before-upload="beforeAvatarUpload"
										:file-list="fileList"
										:auto-load="false"
										:limit="5">
							<el-button size="small" @click="submitUpload" style="margin-top: 10px;"><span><img class="annexImg" src="../../assets/images/annex.png"/></span>添加附件</el-button>
							<!--<button>添加附件</button>-->
							<div style="margin-top: 10px;" slot="tip">最多只能上传5个文件，否则请上传压缩包！</div>
						</el-upload>
					</div>
				</div>
				<div>
					<div class="contentTitles" style="padding: 10px 0px;margin-top: 20px;">
						<span style="color: #FC1F1F;">*</span>任务内容
						<span style="color: #FC1F1F;margin-left: 10px;" v-show="contentTip">(请输入任务内容)</span>
					</div>
					<editor-bar v-model="content" :isClear="isClear" @change="change"></editor-bar>
				</div>
			</el-form>
		</div>
		<div style="text-align: center;margin-top: 30px;">
			<!--<el-button type="primary" @click="submitForm('taskForm','unpublished')">保存</el-button>-->
			<!--<el-button style="margin-left: 50px;margin-right: 40px;" type="primary" @click="submitForm('taskForm', 'ongoing')">发布</el-button>-->
			<!--<el-button @click="resetForm('taskForm')">重置</el-button>-->
		</div>
	</div>
</template>

<script>
	//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
	//例如：import 《组件名称》 from '《组件路径》';
	import EditorBar from '../../components/taskEditer'
	export default {
		name: "AddTask",
//import引入的组件需要注入到对象中才能使用
		components: { EditorBar },
		data () {
			let stateTimeVal = (rule, value, callback) => {
				if (!value) {
					return callback(new Error('任务开始时间不能为空'));
				}
				if (this.taskForm.completeTime !== '') {
					if (new Date(value).getTime() > new Date(this.taskForm.completeTime).getTime()) {
						callback(new Error('任务开始时间不能超过预计完成时间'));
					}
				}
				if (this.saveStoreTaskDetailValue !== '') {
					if (new Date(value).getTime() < new Date(this.saveStoreTaskDetailValue.stateTime).getTime()) {
						callback(new Error(`主任务开始时间为${this.saveStoreTaskDetailValue.stateTime}`));
					} else {
						callback();
					}
				} else {
					callback();
				}
			};
			let completeVal = (rule, value, callback) => {
				console.log(rule, value, callback)
				console.log(this.saveStoreTaskDetailValue)
				if (!value) {
					return callback(new Error('预计完成时间为空'));
				}
				if (this.taskForm.stateTime !== '') {
					if (new Date(value).getTime() < new Date(this.taskForm.stateTime).getTime()) {
						callback(new Error('预计完成时间不能小于任务开始时间'));
					}
				}
				if (this.saveStoreTaskDetailValue !== '' && this.taskForm.stateTime !== undefined) {
					if (new Date(value).getTime() > new Date(this.saveStoreTaskDetailValue.completeTime).getTime()) {
						callback(new Error(`主任务完成时间为${this.saveStoreTaskDetailValue.completeTime}`));
					} else {
						callback();
					}
				} else {
					callback();
				}
			};
			let workloadVal = (rule, value, callback) => {
				if (!value) {
					return callback(new Error('任务量不能为空'));
				} else {
					if (this.saveStoreTaskDetailValue !== '' && this.saveStoreTaskDetailValue !== undefined) {
						if (parseInt(value) > parseInt(this.saveStoreTaskDetailValue.workloadCount)) {
							callback(new Error(`剩余工作量为${this.saveStoreTaskDetailValue.workloadCount}`));
						} else if (value.toString().length > 4) {
							callback(new Error('任务量长度最大为4'));
						} else {
							callback();
						}
					} else if (value.toString().length > 4) {
						callback(new Error('任务量长度最大为4'));
					} else {
						callback();
					}
				}
			};
//这里存放数据
			return {
				taskForm: {
					title: '',
					publisher: '',
					stateTime: '',
					completeTime: '',
					workload: '',
					executor: '',
					crewList: [],
					attachment: [],
					pworkload: 1,
					status: '',
					workCoefficient: 0,
					workloadCount: 1,
					audit: '',
				},
				announcer: '',
				rules: {
					title: [
						{ required: true, message: '请输入任务名称', trigger: 'blur' },
						{ max: 30, message: '长度在 30 个字符之内', trigger: 'blur' }
					],
					stateTime: [
						{ required: true, validator: stateTimeVal, trigger: 'blur' },
						// { type: 'string', required: true, message: '请选择任务开始时间', trigger: 'change' }
					],
					completeTime: [
						{ required: true, validator: completeVal, trigger: 'blur' }
						// { type: 'string', required: true, message: '请选择预计完成时间', trigger: 'change' }
					],
					executor: [
						{ required: true, message: '请选择组长', trigger: 'change' }
					],
					crewList: [
						{ type: 'array', required: true, message: '请选择组员', trigger: 'change' },
					],
					workload: [
						{ required: true, validator: workloadVal, trigger: 'blur' },
						// { required: true, message: '请输入任务量', trigger: 'blur' },
						// { max: 4, message: '长度在 4 个字符之内', trigger: 'blur' }
					],
					audit: [
						{ required: true, message: '请选择审核者', trigger: 'change' }
					],
				},
				leaderOptions: [], // 组长
				memberOptions: [], // 组员
				auditOptions:[], // 审核者
				content: '', // 任务内容
				isClear: false,
				fileList: [], // 文件列表
				attachmentsArr: [], // 存储多个附件对象
				userLoginData: '',
				contentTip: false,
				saveStoreTaskDetailValue: '', // 存储任务详情传来的值
				showAuditName: false,
				pickerOptionsComplete: {
					disabledDate: time => {
						return this.findTimes(time)
					}
				},
			};
		},
//监听属性 类似于data概念
		computed: {
		},
//监控data中的数据变化
		watch: {
			'taskForm.completeTime': function(val) {
				console.log(val)
				let count;
				if (val !== '' && val !== null) {
					let a1 = Date.parse(this.taskForm.stateTime);
					let a2 = Date.parse(val);
					console.log(a1, a2)
					console.log(a2-a1);
					count = Math.ceil((a2-a1)/ (1000 * 60 * 60 * 24)) + 1;//核心：时间戳相减，然后除以天数
					console.log(count)
					if (this.taskForm.executor !== '') {
						if (this.taskForm.crewList.length > 0) {
							console.log(this.taskForm.executor,this.taskForm.crewList)
							let crew = [...this.taskForm.crewList];
							let index = crew.indexOf(this.taskForm.executor);
							console.log(index)
							if (index > -1) {
								crew.splice(index, 1);
							}
							console.log(crew.length)
							count = (1 + crew.length) * count;
							console.log(count)
						}
					}
					this.taskForm.workload = count;
				}
			},
			'taskForm.stateTime': function(val) {
				console.log(val)
				let count;
				if (val !== '' && val !== null && this.taskForm.completeTime !== '' && this.taskForm.stateTime !== null) {
					let a1 = Date.parse(val);
					let a2 = Date.parse(this.taskForm.completeTime);
					console.log(a1, a2)
					console.log(a2-a1);
					count = Math.ceil((a2-a1)/ (1000 * 60 * 60 * 24)) + 1;//核心：时间戳相减，然后除以天数
					console.log(count)
					if (this.taskForm.executor !== '') {
						if (this.taskForm.crewList.length > 0) {
							console.log(this.taskForm.executor,this.taskForm.crewList)
							let crew = [...this.taskForm.crewList];
							let index = crew.indexOf(this.taskForm.executor);
							console.log(index)
							if (index > -1) {
								crew.splice(index, 1);
							}
							console.log(crew.length)
							count = (1 + crew.length) * count;
							console.log(count)
						}
					}
					this.taskForm.workload = count;
				}
			},
			'taskForm.crewList': function(val) {
				console.log(val)
				if (this.taskForm.completeTime !== '' && this.taskForm.completeTime !== null) {
					// let count = JSON.parse(JSON.stringify(this.taskForm.workload));
					let a1 = Date.parse(this.taskForm.stateTime);
					let a2 = Date.parse(this.taskForm.completeTime);
					console.log(a1, a2)
					console.log(a2-a1);
					let count = Math.ceil((a2-a1)/ (1000 * 60 * 60 * 24)) + 1;//核心：时间戳相减，然后除以天数
					console.log(count)
					if (this.taskForm.executor !== '') {
						if (val.length > 0) {
							let crew = [...val];
							console.log(crew)
							let index = crew.indexOf(this.taskForm.executor);
							console.log(index)
							if (index > -1) {
								crew.splice(index, 1);
							}
							console.log(crew.length)
							count = (1 + crew.length) * count;
							console.log(count)
						}
					}
					this.taskForm.workload = count;
				}
			},
			content: function (val) {
				if (val === '') {
					this.contentTip = true;
				} else {
					this.contentTip = false;
				}
			}
		},
//方法集合
		methods: {
			findTimes(val) {
				// console.log(val)
				return Date.parse(val) < Date.parse(this.taskForm.stateTime) - 8.64e7;
			},
			getPublisherUsers() {
				this.$axios.getPublisherUser().then((res) => {
					console.log(res)
					if (res.status === 200) {
						this.auditOptions = res.data;
					}
				})
			},
			getUserById(val) { // 判断组长、组员
				this.$axios.getUserById(val).then((res) => {
					console.log(res)
					if (res.request.status === 200) {
						this.showAuditName = false;
						if (JSON.stringify(this.$store.getters.getSuperior.superior) !== '{}' && JSON.stringify(this.$store.getters.getSuperior.superior) !== undefined) {
							console.log(this.$store.getters.getSuperior.superior)
							this.saveStoreTaskDetailValue = this.$store.getters.getSuperior.superior;
							this.taskForm.title = this.$store.getters.getSuperior.superior.title;
							this.showAuditName = true;
						}
						if (res.data.length === 0 && (JSON.stringify(this.$store.getters.getSuperior.superior) !== '{}' && JSON.stringify(this.$store.getters.getSuperior.superior) !== undefined)) {
							let data = this.$store.getters.getSuperior.superior.crewList;
							if (data.findIndex(item => item.id === this.userLoginData.id) > -1) {
								this.leaderOptions = data;
								this.memberOptions = data;
							} else {
								data.push(JSON.parse(JSON.stringify(this.userLoginData)));
								console.log(data)
								// let data2 = Array.from(new Set(data));
								let data2 = []
								let obj = {};
								for (let i = 0; i < data.length; i++) {
									if (!obj[data[i].id]) {
										data2.push(data[i]);
										obj[data[i].id] = true;
									}
								}
								this.leaderOptions = data2;
								this.memberOptions = data2;
							}
						} else if (res.data.length > 0 && (JSON.stringify(this.$store.getters.getSuperior.superior) === '{}' || JSON.stringify(this.$store.getters.getSuperior.superior) === undefined)) {
							let data = res.data;
							if (data.findIndex(item => item.id === this.userLoginData.id) > -1) {
								this.leaderOptions = data;
								this.memberOptions = data;
							} else {
								data.push(JSON.parse(JSON.stringify(this.userLoginData)));
								// let data2 = Array.from(new Set(data));
								let data2 = []
								let obj = {};
								for (let i = 0; i < data.length; i++) {
									if (!obj[data[i].id]) {
										data2.push(data[i]);
										obj[data[i].id] = true;
									}
								}
								this.leaderOptions = data2;
								this.memberOptions = data2;
							}
						} else if (res.data.length > 0 && (JSON.stringify(this.$store.getters.getSuperior.superior) !== '{}' && JSON.stringify(this.$store.getters.getSuperior.superior) !== undefined)) {
							let arr1 = res.data;
							let arr2 = this.$store.getters.getSuperior.superior.crewList;
							arr1.push(...arr2);
							if (arr1.findIndex(item => item.id === this.userLoginData.id) > -1) {
								// let arr3 = Array.from(new Set(arr1));
								// let arr3 = [...new Set(arr1)];
								let arr3 = []
								let obj = {};
								for (let i = 0; i < arr1.length; i++) {
									if (!obj[arr1[i].id]) {
										arr3.push(arr1[i]);
										obj[arr1[i].id] = true;
									}
								}
								this.leaderOptions = arr3;
								this.memberOptions = arr3;
							} else {
								arr1.push(JSON.parse(JSON.stringify(this.userLoginData)));
								// let arr3 = Array.from(new Set(arr1));
								// let arr3 =  [...new Set(arr1)]
								let arr3 = []
								let obj = {};
								for (let i = 0; i < arr1.length; i++) {
									if (!obj[arr1[i].id]) {
										arr3.push(arr1[i]);
										obj[arr1[i].id] = true;
									}
								}
								this.leaderOptions = arr3;
								this.memberOptions = arr3;
							}
						}
					}
				})
			},
			change(val) {
				// console.log(val)
			},
			submitForm(formName, sta) { // 提交发布
				// alert(this.content);
				this.$refs[formName].validate((valid) => {
					if (valid) {
						// console.log(JSON.stringify(this.$store.getters.getSuperior.superior));
						if (JSON.stringify(this.$store.getters.getSuperior.superior) !== '{}' && JSON.stringify(this.$store.getters.getSuperior.superior) !== undefined) {
							if (new Date(this.taskForm.stateTime).getTime() < new Date(this.$store.getters.getSuperior.superior.stateTime).getTime()) {
								this.$message({
									message: `当前任务开始时间不能早于${this.$store.getters.getSuperior.superior.stateTime}`,
									type: 'warning'
								});
								return false;
							}
							if (new Date(this.taskForm.completeTime).getTime() > new Date(this.$store.getters.getSuperior.superior.completeTime).getTime()) {
								this.$message({
									message: `当前预计完成时间不能超过${this.$store.getters.getSuperior.superior.completeTime}`,
									type: 'warning'
								});
								return false;
							}
							this.$axios.putFindWorkload(this.$store.getters.getSuperior.superior.id).then((res) => {
								console.log(res)
								if (res.status === 200) {
									if (parseInt(this.taskForm.workload) > parseInt(res.data)) {
										this.$alert(`当前总任务量为${res.data}，请重新评估任务量`, '任务量提示', {
											confirmButtonText: '确定'});
										return false;
									} else {
										this.postTaskData(formName, sta);
									}
								}
							})
						} else {
							this.postTaskData(formName, sta);
						}
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			postTaskData(formName, sta) { // 表单验证通过后
				console.log(this.taskForm);
				let data = JSON.parse(JSON.stringify(this.taskForm));
				let arr = [];
				this.attachmentsArr.forEach((v, i) => {
					arr.push(v.id);
				})
				console.log(arr)
				if (new Date(data.stateTime).getTime() > new Date(data.completeTime).getTime()) {
					this.$message({
						message: '任务开始时间不能大于预计完成时间',
						type: 'warning'
					});
					return false;
				}
				if (this.content === '') {
					this.contentTip = true;
					return false;
				} else {
					this.contentTip = false;
				}
				data.workCoefficient = 0;
				data.content = this.content;
				data.pworkload = 1;
				data.attachment = arr;
				data.status = sta;
				data.endTime = '';
				data.workload = Number(data.workload);
				data.workloadCount = 1;
				if (this.showAuditName === true) {
					data.audit = this.userLoginData.id;
				} else {
					data.audit = this.taskForm.audit;
				}
				if (JSON.stringify(this.$store.getters.getSuperior.superior) !== '{}' && JSON.stringify(this.$store.getters.getSuperior.superior) !== undefined) {
					data.superiorId = this.$store.getters.getSuperior.superior.id;
				}
				let obj = {
					"remarks": "",
					"userId": this.userLoginData.id,
					'work': data
				}
				this.$axios.postAddTask(obj).then((res) => {
					console.log(res)
					if (res.request.status === 200) {
						if (res.data.id !== undefined) {
							this.$store.commit('changeSuperior', {
								superior: {}
							})
							let obj = {};
							if (JSON.stringify(this.$store.getters.getSuperior.superior) !== '{}' && JSON.stringify(this.$store.getters.getSuperior.superior) !== undefined) {
								obj = {
									active: 'three',
									page: 1,
									url: 'addTask'
								}
							} else {
								obj = {
									active: 'four',
									page: 1,
									url: 'addTask'
								}
							}
							this.$store.commit('changeSaveView', {
								saveView: obj
							})
							let tip;
							if(sta === 'ongoing') {
								tip = '发布任务';
							} else {
								tip = '保存任务';
							}
							this.$message({
								message: tip + '成功!',
								type: 'success'
							});
							this.$refs[formName].resetFields();
							this.content = '';
							this.$router.push({name: 'viewTask'});
						}
					}
				})
			},
			resetForm(formName) {
				this.$refs[formName].resetFields();
			},
			submitUpload() {
				// this.$refs.uploaad.submit();
			},
			handleExceed (files, fileList) { //  最多上传5个附件，多出时提示
				this.$message.warning(`最多只能上传 5 个文件`);
			},
			handleRemove (file, fileList) { // 删除附件
				let arr = JSON.parse(JSON.stringify(this.attachmentsArr));
				arr.splice(arr.findIndex(item => item.name === file.name), 1);
				this.attachmentsArr = arr;
				console.log(this.attachmentsArr);
				// for (let i = 0; i < arr; i++) {
					// if (file.name === this.attachmentsArr[a].name) {
					// 	console.log(22222)
					// 	this.attachmentsArr.splice(a, 1);
					// }
				// }
			},
			beforeAvatarUpload(file) { // 文件上传大小限制
				let isLt2M = file.size / 1024 / 1024 < 300;
				if (!isLt2M) {
					this.$message({
						message: '文件上传大小不能超过300M',
						type: 'warning'
					})
				}
				return isLt2M
			},
			handleChange (files) { // 文件上传
				let Obj = {
					"fileId": "",
					"name": "",
					"suffix": "",
					"time": "",
					"type": "",
					"uploader": ""
				}
				console.log(files)
				let form = new FormData();
				form.append('file', files.file);
				this.$axios.postUpload(form).then(res => {
					console.log(res)
					if (res.status === 200) {
						Obj.fileId = res.data.id;
						this.$message({
							message: '附件上传成功!',
							type: 'success'
						});
						Obj.uploader = this.userLoginData.id;
						Obj.name = files.file.name;
						Obj.type = 'init';

						let index = files.file.name.indexOf('.');
						let s = files.file.name.substring(index + 1);
						Obj.suffix = s;

						let time = new Date();
						let y = time.getFullYear();
						let m = time.getMonth() + 1;
						m = m < 10?'0' + m:m;
						let d = time.getDate();
						d = d < 10?'0' + d:d;
						let h = time.getHours();
						h = h < 10?'0' + h:h;
						let mm = time.getMinutes();
						mm = mm < 10?'0' + mm:mm;
						let ss = time.getSeconds();
						ss = ss < 10?'0' + ss:ss;
						Obj.time = `${y}-${m}-${d} ${h}:${mm}:${ss}`;
						// let newObj = {
						// 	attachment: Obj
						// }
						console.log(Obj)
						this.$axios.postAttachmentOneByOne(Obj).then((res) => {
							console.log(res)
							if (res.status === 200) {
								let data = {
									id: res.data.id,
									name: Obj.name
								}
								this.attachmentsArr.push(data)
							}
						})
						// this.attachmentsArr.push(Obj); // 把多个附件添加到一个数组中，留到把附件添加到所属工作中时使用
						console.log(this.attachmentsArr);

					}
				})
			},
		},
//生命周期 - 创建完成（可以访问当前this实例）
		created () {

		},
//生命周期 - 挂载完成（可以访问DOM元素）
		mounted () {
			this.taskForm.stateTime = this.$common.timeYMDFilter(new Date()) + ' ' + '09:00:00';
			console.log(this.$store.getters.getLoginData.loginData)
			if (this.$store.getters.getLoginData.loginData !== undefined) {
				this.userLoginData = this.$store.getters.getLoginData.loginData;
			} else {
				this.userLoginData = JSON.parse(this.$Base64.decode(localStorage.getItem('login')));
			}
			this.announcer = this.userLoginData.username;
			this.taskForm.publisher = this.userLoginData.id;
			let that = this;
			setTimeout(function () {
				that.getUserById(that.userLoginData.id);
				that.getPublisherUsers();
			}, 200)
		},
		beforeCreate () {
		}, //生命周期 - 创建之前
		beforeMount () {
		}, //生命周期 - 挂载之前
		beforeUpdate () {
		}, //生命周期 - 更新之前
		updated () {
		}, //生命周期 - 更新之后
		beforeDestroy () {
		}, //生命周期 - 销毁之前
		destroyed () {
			this.$store.commit('changeSuperior', {
				superior: {}
			})
		}, //生命周期 - 销毁完成
		activated () {
		}, //如果页面有keep-alive缓存功能，这个函数会触发
	}
</script>
<style scoped>
	.addTask{
		/*height: 655px;*/
		padding: 20px 24px;
		/*overflow-y: auto;*/
		/*border: 1px solid #000;*/
		position: relative;
	}

	.addRightBtn{
		/*width: 76%;*/
		position: fixed;
		/*bottom: 25px;*/
		right: 80px;
		z-index: 1000;
		/*margin: 0 auto;*/
		/*text-align: center;*/
	}

	.addHeader{
		line-height: 40px;
		border-bottom: 1px solid #5059D5;
		margin-bottom: 20px;
	}

	.addHeader ul {
		display: flex;
		justify-content: space-between;
		font-size: 18px;
		color: #19152c;
	}

	/deep/ .w-e-text-container {
		border: 1px solid #fff !important;
		border-top: none !important;
		/*height: 300px;*/
		font-family: Alibaba;
		z-index: 10000 !important;
		width: 100% !important;
		height: 800px !important;
		background: #EFF2FA !important;
		color: #19152c !important;
		/*padding: 0.119792rem 0 0 0.234375rem;*/
		/*margin: 0.208333rem auto;*/
	}

	/deep/ .el-form-item__label {
		text-align: center;
		vertical-align: middle;
		float: none;
		font-size: 18px;
		color: #606266;
		line-height: 40px;
		padding: 0 12px 0 0;
		-webkit-box-sizing: border-box;
		box-sizing: border-box;
	}

	/deep/ .el-form-item__content {
		line-height: 40px;
		position: relative;
		font-size: 18px;
		/*font-weight: bold;*/
		margin-left: 0 !important;
	}

	.addImgs{
		width: 15px;
		margin-right: 5px;
		vertical-align: top;
	}

	.contentTitles{
		font-size: 18px;
	}

	/deep/ .w-e-text {
		padding: 0 10px;
		overflow-y: scroll;
		font-size: 20px;
	}

	/deep/ .el-input__inner{
		border-color: #a8acea;/*no*/
		font-size: 18px;
	}

	/deep/ .el-input__inner:hover {
		border-color: #5059d5;
	}

	/deep/ .el-input.is-active .el-input__inner, .el-input__inner:focus {
		border-color: #5059d5;
		outline: 0;
	}

	/deep/ .el-textarea__inner{
		border-color: #a8acea;
	}

	/deep/ .el-textarea__inner:hover {
		border-color: #5059d5;
	}

	/deep/ .el-textarea__inner:focus {
		outline: 0;
		border-color: #5059d5;
	}

	/deep/ .w-e-text-container:hover {
		border-color: #fff !important;
	}

	/deep/ .w-e-toolbar {
		display: -webkit-box;
		display: -ms-flexbox;
		display: flex;
		padding: 0 5px;/*no*/
		background-color: #f1f1f1 !important;
		border: 1px solid #fff !important; /*no*/
	}

	/deep/ .el-select .el-input.is-focus .el-input__inner {
		border-color: #5059d5;
	}

	/deep/ .el-date-table td.today span {
		color: #5059d5  !important;
		font-weight: 700;
	}
	/deep/ .el-date-table td.current:not(.disabled) span {
		color: #FFF  !important;
		background-color: #5059d5  !important;
	}

	/deep/ .el-date-table td.available:hover {
		color: #5059d5 !important;
	}

	.groupAdd /deep/ .el-input__inner {
		-webkit-appearance: none;
		background-color: #EFF2FA;
		background-image: none;
		border-radius: 4px;
		border: 0px solid #DCDFE6;
		-webkit-box-sizing: border-box;
		box-sizing: border-box;
		color: #19152c;
		display: inline-block;
		font-size: 18px;
		height: 60px !important;
		line-height: 60px !important;
		outline: 0;
		padding: 0 15px;
		-webkit-transition: border-color .2s cubic-bezier(.645,.045,.355,1);
		transition: border-color .2s cubic-bezier(.645,.045,.355,1);
		width: 100%;
	}

	.groupAdd /deep/ .el-tag {
		background-color: #FFF;
		border-color: #FFF;
		display: inline-block;
		height: 35px;
		padding: 0 15px;
		line-height: 35px;
		margin-right: 10px;
		font-size: 16px;
		color: #19152c;
		border-width: 1px;
		border-style: solid;
		border-radius: 4px;
		-webkit-box-sizing: border-box;
		box-sizing: border-box;
		white-space: nowrap;
	}

	.groupAdd /deep/ .el-select .el-input .el-select__caret {
		color: #19152c;
	}
	.annexImg{
		width: 16px;
		vertical-align: middle;
		margin-right: 5px;
	}

	.mainTaskTip li{
		line-height: 40px;
		font-size: 18px;
		color: #19152c;
	}

	.mainTaskTip .tipSpan{
		display: inline-block;
		width: 130px;
	}

	.addTips{
		margin-bottom: 20px;
		color: #F6302E;
		font-size: 18px;
	}
</style>
