<template>
	<view class="wrap">
		<u-form :model="form" >
			<u-form-item label="考核参考"  :label-position="labelPosition">
				 考核指标：{{data.name}}
			</u-form-item>
			<u-form-item label="全奖值"  :label-position="labelPosition">
				{{data.allprize}}
			</u-form-item>
			<u-form-item label="零奖值"  :label-position="labelPosition">
				{{data.zeroprize}}
			</u-form-item>
			<u-form-item label="封顶值"  :label-position="labelPosition">
				{{data.capping}}%
			</u-form-item>
			<u-form-item label="考核说明"  :label-position="labelPosition">
				{{data.content}}
			</u-form-item>
			<u-form-item label="指标权重分"  :label-position="labelPosition">
				{{data.weight}}
			</u-form-item>
			<!-- <u-form-item label="达成率"  :label-position="labelPosition">
				{{data.reach}}
			</u-form-item> -->
			<!-- <u-form-item label="考核参考">
				{{rowJiaData.score}}
			</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 @input='inputActual' v-model.number="form.score" type="digit" :border="true" />
			</u-form-item>
			
			<u-form-item label="指标得分" :label-position="labelPosition" v-if="data.scoringmethod==1">
				{{form.scoringscore}}
			</u-form-item>
			<u-form-item label="指标得分" :label-position="labelPosition" v-if="data.scoringmethod==2">
				<u-input v-model="form.scoringscore" 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="附件上传" :label-position="labelPosition">
				<u-upload :action="action" :file-list="fileList" ></u-upload>
			</u-form-item> -->
		</u-form>
		<u-button @click="submit">提交</u-button>
		<u-picker mode="time" :defaultTime="defaultTime" v-model="pickerShow" :params="params" end-year="2030" @confirm="confirm"></u-picker>
		<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
			:mode="mode"
			:defaultTime="defaultTime"
			v-model="pickerShow"
			:params="params"
			end-year="2030"
			@confirm="confirm"
		></u-picker> -->
		<!-- <u-picker v-model="pickerShow" mode="time"></u-picker> -->
	</view>
	
</template>

<script>
export default {
	data() {
		return {
			dataId:{},
			isdisabled:false,
			datetime: '',
			data:{},
			input:'',
			pickerShow:false,
			show: true,
			params: {
			    year: true,
				month: true,
				day: false,
				hour: false,
				minute: false,
				second: false,
				timestamp: false
			},
			defaultTime: '',
			mode: 'selector',
			labelPosition:'top',
			action:'/api/upordown',
			fileList:[],
			buzhou:0,
			form: {
				name: '',
				intro: '',
				sex: ''
			},
			processData:[],
			radio: '',
			switchVal: false
		};
		
	},
	onLoad(option) {
				// this.getCurrentMonth()
				console.log("option")
				console.log(option)
				// alert(JSON.stringify(option))
				this.dataId=option
				const processFrom = {
							id:option.id.toString(),
				
						  }
				this.getData()
				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:{
		getData(){
			const from = {
				id:this.dataId.shemeid.toString()
			}
			this.$u.api.Duty.get_ration_target_cont(from).then(res => {
				if(res.code==0){
					this.data=res.data
					
				}
					
			})
		},
		toTrue(){
			
			this.isdisabled=true
			console.log(this.isdisabled)
		},
		bindDateChange: function(e) {
			            this.datetime = e.target.value
						console.log(this.datetime)
			        },
		getCurrentMonth () {
			const date = new Date()
			let year = date.getFullYear()
			let month = date.getMonth() + 1
			month = month > 9 ? month : '0' + month
			this.datetime=`${year}-${month}`
			console.log(`${year}-${month}`)
			return `${year}-${month}`
		},
		// 公式换算
		// (实际值—零奖值)/（全奖值-零奖值）*100+‘%’
		inputActual(val){
			
			var a = val-this.data.zeroprize
			var b = this.data.allprize-this.data.zeroprize
			
			if (a/b*100!=Infinity&&a/b*100!=NaN) {
				var e =a/b*100
				var d
				if (e>this.data.cappingcal) {
					d=this.data.targetweight*this.data.cappingcal/100
				} else{
					d =parseFloat(this.data.targetweight*(a/b)).toFixed(2)
				}
				var c =parseFloat(a/b*100).toFixed(2)
				 
				
				this.data.reach=c+'%'
				this.form.scoringscore=d
				if (c<0) {
				  this.data.reach=0+'%'
				}
				if (d<0) {
				  this.form.scoringscore=0
				}
			  }
			  if (a/b*100==Infinity) {
				this.data.reach="数据错误/或未设置零奖值全奖值"
				this.form.scoringscore="数据错误/或未设置零奖值全奖值"
			  }
			
			
		},
		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;
		},
		// 提交数据
		submit(){
			
			const dataFrom = {
				id: this.data.id, //考核项ID
				submittime: this.form.time, //提报时间
				scoringmethod: 1, //计分方式（1：自动；2：手动）
				score: this.form.score, //实际数值*100保存
				scoringscore: 0, //手动分*100保存
				reason: this.form.reason, //这样操作的原因
				personliable: this.dataId.key, //责任人
			}
			// alert(JSON.stringify(dataFrom))
			const that = this
			this.$u.api.Duty.submit_ration_post_cont(dataFrom).then(res => {
				if(res.code==0){
					that.$refs.uToast.show({
						title: '操作成功',
						type: 'success',
						isTab:true,
						url: '/pages/post/index',
					})
				}
				if(res.code!=0){
					// alert(JSON.stringify(res))
					that.$refs.uToast.show({
						title: res.msg,
						type: 'error',
						isTab:true,
						
					})
				}
					
				})
		},
	},
};
</script>
<style scoped lang="scss">
// .timeInput{
// 	    padding: 0px 10px;
// 	    border-color: rgb(220, 223, 230) !important;
// 	    text-align: left;
// }
.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>