<template>
    <el-form>
        <el-form :model="saveForm" label-width="120px" ref="saveForm">
            <el-row>
                <el-col :span="12">
            <el-form-item label="项目/步骤" required>
                <el-input v-model="saveForm.name" type="textarea" :rows="1"></el-input>
            </el-form-item>
            <el-form-item label="检查标准">
                <el-input v-model="saveForm.standard" type="textarea" :rows="2"></el-input>
            </el-form-item>
            <el-form-item label="危害因素">
                <el-input v-model="saveForm.hazard_factors" type="textarea" :rows="2"></el-input>
            </el-form-item>
            <el-form-item label="可能后果">
                <el-select v-model="saveForm.results" multiple>
                    <el-option v-for="item in resultOptions" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="lecd判定" required>
                <el-input-number :min="0" :precision="1" :step="0.1" controls-position="right" v-model="saveForm.riskl" placeholder="L值"/>
                <el-input-number :min="0" :precision="1" :step="0.1" controls-position="right" v-model="saveForm.riske" placeholder="E值" style="margin-left: 2px"/>
                <el-input-number :min="0" :precision="1" :step="0.1" controls-position="right" v-model="saveForm.riskc" placeholder="C值" style="margin-left: 2px"/>
                <span style="margin-left: 6px">D值: <span v-if="saveForm.riskl*saveForm.riske*saveForm.riskc">{{saveForm.riskl*saveForm.riske*saveForm.riskc}}</span></span>
            </el-form-item>
            <el-form-item label="排序" required>
                <el-input-number :min="0" controls-position="right" v-model="saveForm.sort"/>
            </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工程技术措施" required>
                <el-input v-model="saveForm.measure_tech" type="textarea" :rows="2"></el-input>
            </el-form-item>
            <el-form-item label="管理措施" required>
                <el-input v-model="saveForm.measure_manage" type="textarea" :rows="2"></el-input>
            </el-form-item>
            <el-form-item label="培训教育措施" required>
                <el-input v-model="saveForm.measure_edu" type="textarea" :rows="2"></el-input>
            </el-form-item>
            <el-form-item label="个体防护措施" required>
                <el-input v-model="saveForm.measure_protect" type="textarea" :rows="2"></el-input>
            </el-form-item>
            <el-form-item label="应急处置措施" required>
                <el-input v-model="saveForm.measure_emer" type="textarea" :rows="2"></el-input>
            </el-form-item>
        </el-col>
    </el-row>
        </el-form>
        <div style="display: flex; justify-content: flex-end; margin-top: 10px">
				<el-button
					type="primary"
					:loading="formSaving"
					@click="formSubmit()"
					>保 存</el-button
				>
        </div>
    </el-form>
</template>
<script>
const defaultForm = {};
export default {
    props:{
        riskpoint: {type: String, default: ""}
    },
    data() {
        return {
            saveForm: Object.assign({"riskpoint": this.riskpoint}, defaultForm),
            formSaving: false,
            resultOptions:[],
        }
    },
    mounted() {
        this.getResultOptions();
    },
    methods:{
        setData(data){
            this.saveForm = data;
        },
        getResultOptions() {
            this.$API.system.dict.list.req({page: 0, type__code: "accident_result"}).then(res=>{
                this.resultOptions = res;
            })
        },
        formSubmit(){
            this.formSaving = true;
			if (this.saveForm.id) {
				this.$API.dpm.risk.update
					.req(this.saveForm.id, this.saveForm)
					.then((res) => {
                        this.formSaving = false;
						this.$message.success("更新成功");
                        this.$emit("riskConfirm");
					})
					.catch((e) => {
						this.formSaving = false;
					});
			} else {
				this.$API.dpm.risk.create
					.req(this.saveForm)
					.then((res) => {
                        this.formSaving = false;
						this.$message.success("创建成功");
						this.$emit("riskConfirm");
					})
					.catch((err) => {
						this.formSaving = false;
					});
			}
        }
    }
}
</script>