<template>
	<div style="width: 100%">
		<el-breadcrumb separator-class="el-icon-arrow-right">

			<el-breadcrumb-item>首页</el-breadcrumb-item>
			<el-breadcrumb-item>监测任务</el-breadcrumb-item>
			<el-breadcrumb-item>例行监测</el-breadcrumb-item>
			<el-breadcrumb-item :to="{path:'/admin/routineMonitor'}">任务列表</el-breadcrumb-item>
			
		</el-breadcrumb>
		<div class="title">
			退回任务
		</div>

		<el-form :model="form" label-width="100px">
            <el-form-item label="任务名称" prop="form.task_name" required>
				<el-input v-model="form.task_name" :disabled="true"></el-input>
			</el-form-item>

	        <el-form-item label="文件号">
				<el-input v-model="form.filenum"></el-input>
			</el-form-item>

            <el-form-item label="任务时间" required>
				<el-col :span="8">
					<el-date-picker v-model="form.starttime" type="date" value-format="yyyy-MM-dd">
					</el-date-picker>
				</el-col>
				<el-col :span="1">
					<div class="line">--</div>
				</el-col>
				<el-col :span="11">
					<el-date-picker v-model="form.endtime" type="date" value-format="yyyy-MM-dd">
					</el-date-picker>
				</el-col>
			</el-form-item>

			<el-form-item label="任务优先级" required>
				<el-select v-model="form.level" placeholder="请选择">
					<el-option v-for="item in priority" :key="item.value" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-form-item>

			<el-form-item label="年度" required>
				<el-date-picker v-model="form.year" type="year" value-format="yyyy">
				</el-date-picker>
			</el-form-item>

			<el-form-item label="批次" required>
				<el-select v-model="form.batch">
					<el-option v-for="item in batch" :key="item.label" :label="item.label" :value="item.label">
					</el-option>
				</el-select>
			</el-form-item>

		

			<el-form-item label="抽检分离:" prop="is_divide" width="70px" class="labelItem" required>
					<el-select  v-model="form.is_divide" size="" >
						<el-option v-for="item in divideOptions" :key="item.id" :label="item.name" :value="item.id">
						</el-option>
					</el-select>
			</el-form-item>

			<el-form-item label="备注">
				<el-input type="textarea" placeholder="最长300字符" v-model="form.log"></el-input>
			</el-form-item>

             <el-form-item label="附件" required>
				<el-upload class="upload-demo" :file-list="fileList" drag :headers="myHeaders"
					action="http://syjcapi.aielab.net/api/v1/ossUpload" :on-success="uploadSuccess"
					:limit="1">
					<i class="el-icon-upload"></i>
					<div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
				</el-upload>
			</el-form-item>

			<el-form-item>
				<el-button type="success" @click="onSubmit()">保存</el-button>
				<el-button type="success" @click="nextStep()">下一步</el-button>
				<el-button @click="reBack()">返回</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>
<script>
	const rymc = window.sessionStorage.getItem('rymc')
	const token = window.sessionStorage.getItem('token')
	export default {
		data() {
			return {
				myHeaders: {
				Authorization: 'bearer'+ token//上传文件添加token
				},
				// 任务表单
				form: {
					main_unit: [],	
					// batch:'',
					// level:'',
					// filenum:'',
                    // task_name:'',
                    // username:'',
                    // name:'', 
                    // name_other:'', 
                    // groupname: '', 
                    // properties: '', 
                    // contact_name: '', 
                    // contact_phone: '',
                    // create_time:'' ,
                    // update_time:''
				},
				// 优先级选项
				priority: [{
					value: '0',
					label: '一般'
				}, {
					value: '1',
					label: '紧急'
				}, {
					value: '2',
					label: '特急'
				}],
				// 批次选项
				batch: [{
					label: '一季度'
				}, {
					label: '二季度'
				}, {
					label: '三季度'
				}, {
					label: '四季度'
				}],
				// 抽检分离选项
				divideOptions: [{
						id: 0,
						name: '否'
					},
					{
						id: 1,
						name: '是'
					}
				],
				// 上传成功文件列表
				fileList: []
			}
		},
		created() {
            this.task_id = this.$route.params.task_id
            console.log(this.task_id)
			this.getTask()  
		},
		methods: {
            //获取接口
            async getTask() {
				 console.log(this.task_id)
                const result = await this.$http.post("getTask",{task_id:this.task_id});
				this.form=result.data.data
				console.log(result.data)
            }, 
            //保存
			async onSubmit() {
				this.form['token'] = token
				this.form['groupname'] = this.groupname
				// this.form['orgs'] = this.orgs
				this.form['releaser'] = window.sessionStorage.getItem('rymc')
				this.form['task_class'] = 'retask'
				this.form['ispublic'] = 0
				const result = await this.$http.post('putTask', this.form)
				// 判断业务逻辑
				if (result.code == 0) {
						this.$message({
						type: 'success',
						message: result.data.message
					})
				} else {
					this.$message({
						type: 'success',
						message: result.data.message
					})
				}
					
			},
			//返回
			reBack() {
				this.$router.push('reTask')
			},
			//下一步
			nextStep(id){
			console.log(id)
			this.$router.push({
				name:'nextStep',
				params:{
					task_id:id
				}
			})
			},
	}
}
	
</script>
<style lang="less" scoped>
	.title {
		margin-left: 50%;
		margin-bottom: 20px;
	}

	.el-form {
		width: 800px;
		margin: 0 auto;
	}

	.footer {
		margin-top: 5px;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}
</style>
