<template>
	<view class="wrap">
		<!-- 定分From -->
		<u-form :model="form" v-if="urlData.state==1">
			<u-form-item label="考核参考"  :label-position="labelPosition">
				{{urlData.score}}{{urlData.company}}
			</u-form-item>
			<u-form-item label="次数" :label-position="labelPosition">
				<u-input v-model="form.count" type="digit" :border="true"  />
			</u-form-item>
			
			<u-form-item label="发生时间" :label-position="labelPosition">
				<u-input 
				:border="true" 
				type="select" 
				:select-open="pickerShow" 
				v-model="form.time" 
				placeholder="请选择时间"
				 @click="pickerShow = true"></u-input>
			</u-form-item>
			<u-form-item label="原因" :label-position="labelPosition">
				<u-input v-model="form.reason" type="textarea" :border="true" height="100" :auto-height="true" />
			</u-form-item>
			<u-form-item :label-position="labelPosition" label="是否整改" prop="payType" label-width="150">
				 <u-input :border="true" type="select" :select-open="selectShow" v-model="form.rectificationName" placeholder="请选择" @click="selectShow = true"></u-input>
			</u-form-item>
			<u-form-item label="整改期限" :label-position="labelPosition" v-if="form.rectification==1">
				<u-input 
				:border="true" 
				type="select" 
				:select-open="pickertimeShow" 
				v-model="form.correctiontime" 
				placeholder="请选择时间"
				 @click="pickertimeShow = true"></u-input>
			</u-form-item>
			<u-form-item label="附件上传" :label-position="labelPosition">
				<u-upload :action="action" :file-list="fileList" @on-success="uploadjiaSuccess" @on-remove="(file, fileList, index) => {handlejiaRemove(file, fileList, index)}"></u-upload>
			</u-form-item>
		</u-form>
		<!-- 区间分 -->
		<u-form :model="form" v-if="urlData.state==2">
			<u-form-item label="考核参考"  :label-position="labelPosition">
				{{urlData.score}}{{urlData.company}}
			</u-form-item>
			<u-form-item label="分数" :label-position="labelPosition">
				<u-input v-model="form.score" type="digit" :border="true"  />
			</u-form-item>
			<u-form-item label="原因" :label-position="labelPosition">
				<u-input v-model="form.reason" type="textarea" :border="true" height="100" :auto-height="true" />
			</u-form-item>
			<u-form-item label="发生时间" :label-position="labelPosition">
				<u-input 
				:border="true" 
				type="select" 
				:select-open="pickerShow" 
				v-model="form.time" 
				placeholder="请选择时间"
				 @click="pickerShow = true"></u-input>
			</u-form-item>
			<u-form-item :label-position="labelPosition" label="是否整改" prop="payType" label-width="150">
				
			  <u-input :border="true" type="select" :select-open="selectShow" v-model="form.rectificationName" placeholder="请选择" @click="selectShow = true"></u-input>
				
				<!-- <u-input
				:border="true" 
				type="select" 
				:select-open="pickerShow" 
				v-model="form.rectification" 
				placeholder="请选择"
				 @click="pickerShow1 = true"></u-input> -->
			</u-form-item>
			
			<u-form-item label="整改期限" :label-position="labelPosition" v-if="form.rectification==1">
				<u-input 
				:border="true" 
				type="select" 
				:select-open="pickertimeShow" 
				v-model="form.correctiontime" 
				placeholder="请选择时间"
				 @click="pickertimeShow = true"></u-input>
			</u-form-item>
			<u-form-item label="附件上传" :label-position="labelPosition">
				<u-upload :action="action" :file-list="fileList" @on-success="uploadjiaSuccess" @on-remove="(file, fileList, index) => {handlejiaRemove(file, fileList, index)}"></u-upload>
			</u-form-item>
		</u-form>
		<!-- 不定性分值 -->
		<u-form :model="form" v-if="urlData.state==3">
			<u-form-item label="分数" :label-position="labelPosition">
				<u-input v-model="form.score" type="digit" :border="true"  />
			</u-form-item>
			<u-form-item label="原因" :label-position="labelPosition">
				<u-input v-model="form.reason" type="textarea" :border="true" height="100" :auto-height="true" />
			</u-form-item>
			<u-form-item label="发生时间" :label-position="labelPosition">
				<u-input 
				:border="true" 
				type="select" 
				:select-open="pickerShow" 
				v-model="form.time" 
				placeholder="请选择时间"
				 @click="pickerShow = true"></u-input>
			</u-form-item>
			<u-form-item :label-position="labelPosition" label="是否整改" prop="payType" label-width="150">
				 <u-input :border="true" type="select" :select-open="selectShow" v-model="form.rectificationName" placeholder="请选择" @click="selectShow = true"></u-input>
				<!-- <u-input
				:border="true" 
				type="select" 
				:select-open="pickerShow" 
				v-model="form.rectification" 
				placeholder="请选择"
				 @click="pickerShow1 = true"></u-input> -->
			</u-form-item>
			
			<u-form-item label="整改期限" :label-position="labelPosition" v-if="form.rectification==1">
				<u-input 
				:border="true" 
				type="select" 
				:select-open="pickertimeShow" 
				v-model="form.correctiontime" 
				placeholder="请选择时间"
				 @click="pickertimeShow = true"></u-input>
			</u-form-item>
			<u-form-item label="附件上传" :label-position="labelPosition">
				<u-upload :action="action" :file-list="fileList" @on-success="uploadjiaSuccess" @on-remove="(file, fileList, index) => {handlejiaRemove(file, fileList, index)}"></u-upload>
			</u-form-item>
		</u-form>
		<u-button @click="submit">提交</u-button>
		<!-- <u-action-sheet :list="range" v-model="pickerShow1" @click="actionSheetCallback" ></u-action-sheet> -->
		<u-picker mode="time" :defaultTime="defaultTime" v-model="pickerShow" :params="params" end-year="2030" @confirm="confirm"></u-picker>
		<u-picker mode="time" :defaultTime="defaultTime" v-model="pickertimeShow" :params="params" end-year="2030" @confirm="confirm1"></u-picker>
		<u-select v-model="pickerShow1" :list="range"></u-select>
		<u-select mode="single-column" :list="range" v-model="selectShow" @confirm="selectConfirm"></u-select>
		<u-toast ref="uToast" />
		<el-card class="box-card">
		                <el-steps direction="vertical" :active="buzhou">
		                    <el-step v-for="(item,index) in processData" :key="index" :title="item.nodename" icon="el-icon-circle-check" > 
		                        <template slot="description">
		                            <div style="color: rgb(153,153,153);" v-for="(a,userlistIndex) in item.userlist" :key="userlistIndex">
		                                        <el-row>
		                                            <el-col :span="4" v-if="a.log!=null">
		                                                <el-badge is-dot type="primary ">
		                                                    <el-avatar style="margin-right: 5px;" shape="square" size="small" :src="a.icon"></el-avatar>
		                                                </el-badge>
		                                            </el-col>
		                                            <el-col :span="4" v-else>
		                                                <el-avatar style="margin-right: 5px;" shape="square" size="small" :src="a.icon"></el-avatar>
		                                            </el-col>
		                                            <el-col :span="20" style="margin-top: -5px;">
		                                                {{a.workshopname}}-{{a.postname}}-{{a.name}}
		                                                <el-row>
		                                                    <div v-for="(i,logIndex) in a.log" :key="logIndex">
		                                                        <div class="left" v-if="i.state==2">已同意&nbsp·&nbsp</div>
		                                                        <div class="left" v-if="i.state==1" type="info">未操作&nbsp·&nbsp</div>
		                                                        <div class="left" v-if="i.state==3" type="danger">驳回&nbsp·&nbsp</div> 
		                                                        <div class="left">{{i.time}}</div>
		                                                    </div>
		                                                </el-row>
		                                            </el-col>
		                                        </el-row>
		                            </div>
		                        </template>
		                    </el-step>
		                </el-steps>
		               
		            </el-card>
		<!-- <u-picker :list="range" mode="selector" v-model="pickerShow1" :params="params" @confirm="confirm"></u-picker> -->
	</view>
	
</template>

<script>
export default {
	data() {
		return {
			selectShow:false,
			range: [
				{
					value: 1,
					label: '是'
				},
				{
					value: 2,
					label: '否'
				},
			],
			buzhou:0,
			processData:[],
			pickerShow1:false,
			urlData:{},
			input:'',
			pickerShow:false,
			pickertimeShow:false,
			show: true,
			params: {
			    year: true,
				month: true,
				day: true,
				hour: true,
				minute: true,
				second: true,
				timestamp: true
			},
			defaultTime: '',
			mode: 'selector',
			labelPosition:'top',
			action:'http://new.hxgk.group/api/upordown',
			fileList:[],
			form: {
				enclosure:[],
			},
			radio: '',
			switchVal: false
		};
		
	},
	
	onLoad(option) {
		console.log("option")
		console.log(option)
		this.urlData=option
		const processFrom = {
					id:option.id.toString(),
					plusreduction:2
				  }
		
		this.$u.api.Duty.examineflow(processFrom).then(res => {
			if(res.code==0){
					this.buzhou=0
				this.processData=res.data
				this.processData.forEach(element => {
							if (element.state==2) {
								this.buzhou=this.buzhou+1
							}
						});
			}
				
			})
		var date = new Date(),
		year = date.getFullYear(),
		month = date.getMonth() + 1,
		day = date.getDate(),
		hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
		minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
		second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
		month >= 1 && month <= 9 ? (month = "0" + month) : "";
		day >= 0 && day <= 9 ? (day = "0" + day) : "";
		var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
		this.defaultTime = timer
		},
	methods:{
		handlejiaRemove(file, fileList,index){
		      this.form.enclosure=[]
		
		      fileList.forEach((a) => {
		        const data = {
		          filename: a.response.data.name, //文件名称
		          filepath: a.response.data.url, //文件地址
		          type: a.response.data.type //文件类型（1：图片；2：视频；3：office相关文档；4：压缩包；5：其他文件）
		        }
		        this.form.enclosure.push(data)
		        });
		      
		
		    },
		 // 上传成功
		    uploadjiaSuccess(data, index, lists, name){
				console.log("uploadjiaSuccess")
				console.log(data)
		      if (data.code==0) {
		         const wenData = {
		          filename: data.data.name, //文件名称
		          filepath: data.data.url, //文件地址
		          type: data.data.type //文件类型（1：图片；2：视频；3：office相关文档；4：压缩包；5：其他文件）
		        }
		        this.form.enclosure.push(wenData)
		      }
		    },
		// 选择商品类型回调
		selectConfirm(e) {
			this.form.rectificationName = '';
			e.map((val, index) => {
				this.form.rectificationName += this.form.rectificationName == '' ? val.label : '-' + val.label;
			})
			// e.map((val, index) => {
			// 	this.form.rectification += this.form.rectification == '' ? val.value : '-' + val.value;
			// })
			this.form.rectification=e[0].value
			if (this.form.rectification==1) {
			        this.buzhou=0
			      const processFrom ={
			        id:this.urlData.id,
			        iscorrection:1,
					plusreduction:2
			      }
			      this.$u.api.Duty.examineflow(processFrom).then(res => {
			      	if(res.code==0){
			      			this.buzhou=0
			      		this.processData=res.data
			      		this.processData.forEach(element => {
			      					if (element.state==2) {
			      						this.buzhou=this.buzhou+1
			      					}
			      				});
			      	}
			      		
			      	})
			      
			      }
			      if (this.form.rectification==2) {
			        this.buzhou=0
			      const processFrom ={
			        id:this.urlData.id,
			        iscorrection:2,
					plusreduction:2
			      }
			      this.$u.api.Duty.examineflow(processFrom).then(res => {
			      	if(res.code==0){
			      			this.buzhou=0
			      		this.processData=res.data
			      		this.processData.forEach(element => {
			      					if (element.state==2) {
			      						this.buzhou=this.buzhou+1
			      					}
			      				});
			      	}
			      		
			      	});
			      }
			console.log(e[0].value)
		},
		// 下拉回调
		confirm(e) {
			this.result = '';
			e.map((val, index) => {
				this.result += this.result == '' ? val.label : '-' + val.label;
			})
		},
		// 提交数据
		submit(){
			console.log(this.urlData)
			console.log("this.form")
			console.log(this.form)
			this.form.planid=this.urlData.id
			this.form.type=2
			this.form.planversionnumber=this.urlData.planversionnumber
			this.form.state=parseInt(this.urlData.state)
			this.form.count=parseInt(this.form.count)
			const that = this
			// alert(JSON.stringify(this.form))
			this.$u.api.Duty.plusorminuspoints(this.form).then(res => {
				if(res.code==0){
					that.$refs.uToast.show({
						title: '操作成功',
						type: 'success',
						isTab:true,
						url: '/pages/task/index',
					})
				}else{
					that.$refs.uToast.show({
						title: res.msg,
						type: 'error',
					})
				}
					
				})
		},
		confirm(e) {
			// console.log(e);
			this.form.time = '';
			if (this.params.year) this.form.time += e.year;
			if (this.params.month) this.form.time += '-' + e.month;
			if (this.params.day) this.form.time += '-' + e.day;
			if (this.params.hour) this.form.time += ' ' + e.hour;
			if (this.params.minute) this.form.time += ':' + e.minute;
			if (this.params.second) this.form.time += ':' + e.second;
		},
		confirm1(e) {
			// console.log(e);
			this.form.correctiontime = '';
			if (this.params.year) this.form.correctiontime += e.year;
			if (this.params.month) this.form.correctiontime += '-' + e.month;
			if (this.params.day) this.form.correctiontime += '-' + e.day;
			if (this.params.hour) this.form.correctiontime += ' ' + e.hour;
			if (this.params.minute) this.form.correctiontime += ':' + e.minute;
			if (this.params.second) this.form.correctiontime += ':' + e.second;
		},
	},
};
</script>
<style scoped lang="scss">
.wrap {
	padding: 30rpx;
	font-size: 16px !important;
}

.agreement {
	display: flex;
	align-items: center;
	margin: 40rpx 0;

	.agreement-text {
		padding-left: 8rpx;
		color: $u-tips-color;
	}
}
</style>