<template>
  <div class="fitstStep">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-position="top"
    >
      <el-row :gutter="40">
        <el-col :span="12">
          <el-form-item label="测定标准" prop="determination_standard">
            <el-select
              v-model="ruleForm.determination_standard"
              placeholder="请选择测定标准"
              style="width: 100%"
            >
              <el-option v-for='item in standards' :key='item.value' :label='item.label' :value='item.value'/>
              <!-- <el-option label="区域一" value="shanghai"></el-option>
              <el-option label="区域二" value="beijing"></el-option> -->
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="预期闪点" prop="expected_flash_point">
            <el-input v-model="ruleForm.expected_flash_point" @input="handInput" class="flash rightBorder">
              <template slot="append">℃</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6" >
          <div class="set"  @click="handSet">设为未知</div>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="温度选择" prop="temperature_selection">
            <el-select
              v-model="ruleForm.temperature_selection"
              @change="handChange"
              :disabled="isDisabled"
              placeholder="请选择温度"
              style="width: 100%"
            >
              <el-option v-for='item in temps' :key='item.value' :label='item.label' :value='item.value'/>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="初始温度" prop="initial_temperature_set">
            <el-input
              class="rightBorder"
              v-model="ruleForm.initial_temperature_set"
              :disabled="isDisabled"
              placeholder="≤预期闪点-18℃"
            >

              <template slot="append">℃</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="样品名称" prop="material_name">
            <el-input v-model="ruleForm.material_name" placeholder="请输入样品名称">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="最终温度" prop="final_temperature_set">
            <el-input
              class="rightBorder"
              v-model="ruleForm.final_temperature_set"
              :disabled="isDisabled"
              placeholder="≥预期闪点+10℃"
            >
              <template slot="append">℃</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="样品编号" prop="material_code">
            <el-input v-model="ruleForm.material_code" placeholder="请输入样品编号">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="goBack" @click="handBack">返回</div>
        </el-col>
        <el-col :span="6">
          <div class="sampling" @click="handTake('ruleForm')">装样</div>
        </el-col>
      </el-row>
    </el-form>
    
    <div class="model" v-show="isShow">
        <span class="icon">!</span>
        <div class="dec">请确定您已连接好制冷装置</div>
        <div class="tip">请确定连接好制冷装置，再继续</div>
        <div class="bottom">
            <div class="cancel button" @click="handCancel">取消</div>
            <div class="continue button" @click="handContinue">继续</div>
        </div>
    </div>
  </div>
</template>

<script>
import { addExperiment } from "@/api/step";
import { getInitParams } from "@/api/setSystem";
export default {
  data() {
    return {
      isDisabled:false,
      initialMinNum:100,
      initialMaxNum:420,
      isShow:false,
      standards:[
        // {
        //   value:'ASTM D6450(1ml)',
        //   label:'ASTM D6450(1ml)'
        // },
        // {
        //   value:'ASTM D7094(2ml)',
        //   label:'ASTM D7094(2ml)'
        // },
        // {
        //   value:'SH/T 0768(1ml)',
        //   label:'SH/T 0768(1ml)'
        // },
      ],
      temps:[
        {
          value:'高温测定(100~420℃)',
          label:'高温测定(100~420℃)'
        },
        {
          value:'低温测试(-25~100℃)',
          label:'低温测试(-25~100℃)'
        },
      ],
      ruleForm: {
        determination_standard: "",
        temperature_selection:'高温测定(100~420℃)',
        expected_flash_point:'',
        initial_temperature_set:'',
        material_name:'',
        final_temperature_set:'',
        material_code:'',
        user_id:JSON.parse(sessionStorage.LoginUser).user_id
      },
      rules: {
        determination_standard:[
          { required: true, message: '该项不能为空', trigger: 'blur' },
        ],
        temperature_selection:[
          { required: true, message: '该项不能为空', trigger: 'blur' },
        ],
        material_name:[
          { required: true, message: '该项不能为空', trigger: 'blur' },
        ],
        material_code:[
          { required: true, message: '该项不能为空', trigger: 'blur' },
        ],
        expected_flash_point:[
          { required: true, message: '该项不能为空', trigger: 'blur' },
        ],
        initial_temperature_set:[
          { required: true, message: '该项不能为空', trigger: 'blur' },
        ],
        final_temperature_set:[
          { required: true, message: '该项不能为空', trigger: 'blur' },
        ],
      },
    };
  },
  // watch:{
  //   ruleForm:{
  //       handler(newVal) {
  //         if (newVal) {
  //           console.log(this.ruleForm,'温度改变2')
  //           if(this.ruleForm.temperature_selection=='低温测试(-25~100℃)'){
  //               this.isShow=true;
  //           }else{
  //             this.isShow=false;
  //           }
  //         }
  //       },
  //       deep:true,
  //       immediate: true,

  //   },

  // },
  mounted(){
    this.getInit()
  },
  methods: {
    handChange(val){
      if(val=='低温测试(-25~100℃)'){
        this.isShow=true
      }else{
        this.isShow=false
      }
    },
    handInput(val){
     console.log(val,'闪电值')
     if(val!='未知'){
      this.isDisabled=false;
     }
    },
    getInit(){
      getInitParams().then(res=>{
        if(res.data.data.length>0){
          res.data.data.map(item=>{
            this.standards.push({
              value:item.determination_standard,
              label:item.determination_standard,
            })
          })
        }else{
          this.$message.warning('请初始化测定标准参数')
        }
      })
    },
    handSet() {
      this.ruleForm.expected_flash_point='未知';
      this.ruleForm.temperature_selection='低温测试(-25~100℃)';
      this.ruleForm.initial_temperature_set='10';
      this.ruleForm.final_temperature_set='100';
      this.isDisabled=true
    },
    handCancel(){
      this.ruleForm.temperature_selection='高温测定(100~420℃)'
      this.isShow=false
    },
    handContinue(){
      this.isShow=false
      this.ruleForm.temperature_selection='低温测试(-25~100℃)'
    },
    handBack(){
      this.$router.push({path:'/home'})
    },
    handTake(formName){
      var that=this
      this.$refs[formName].validate((valid) => {
          if (valid) {
            if(that.ruleForm.expected_flash_point!='未知'&&isNaN(that.ruleForm.expected_flash_point)){
              return that.$message.warning('预期闪点只能设置为数值或未知!')
            }
             if(!isNaN(that.ruleForm.expected_flash_point)){
              console.log(Number(that.ruleForm.expected_flash_point)-Number(that.ruleForm.initial_temperature_set),'测试')
              if(Number(that.ruleForm.expected_flash_point)-Number(that.ruleForm.initial_temperature_set)<18){
                return that.$message.warning('初始温度<=预期闪点18℃')
              }
              if(Number(that.ruleForm.final_temperature_set)-Number(that.ruleForm.expected_flash_point)<10){
                return that.$message.warning('最终温度>=预期闪点10℃')
              }
            }
            if(Number(that.ruleForm.final_temperature_set)<Number(that.ruleForm.initial_temperature_set)){
              return  that.$message.warning('最终温度不能小于初始温度')
            }
            if(that.ruleForm.temperature_selection=='高温测定(100~420℃)'){
              if(that.ruleForm.initial_temperature_set<100||that.ruleForm.initial_temperature_set>420){
                return  that.$message.warning('高温模式下初始温度范围为100-420℃')
              }
              if(that.ruleForm.final_temperature_set<100||that.ruleForm.final_temperature_set>420){
                return  that.$message.warning('高温模式下最终温度范围为100-420℃')
              }
              
            }else if(that.ruleForm.temperature_selection=='低温测试(-25~100℃)'){
              if(that.ruleForm.initial_temperature_set<-25||that.ruleForm.initial_temperature_set>100){
               return that.$message.warning('低温模式下初始温度范围为-25~100℃')
              }
              if(that.ruleForm.final_temperature_set<-25||that.ruleForm.final_temperature_set>100){
                return  that.$message.warning('低温模式下最终温度范围为-25~100℃')
              }
            }
            addExperiment(this.ruleForm).then(res=>{
              if(res.data.status==0){
                localStorage.setItem('experiment_info',JSON.stringify(res.data.data))
                this.$emit('next')
              }else{
                this.$message.error(res.data.message)
              }
            })
          }
      })  
    }
  },
};
</script>

<style lang="less" >
.el-select-dropdown__item{
        height: 68px;
        background: #F6F6F6;
        border-radius: 0px 0px 0px 0px;
        opacity: 1;
        font-size: 28px;
        border:2px solid #E4E4E4;
        line-height: 68px;
    }
.fitstStep {
  .el-form {
    margin-top: 28px;
    padding: 0 40px;

    //label标题
    .el-form-item__label {
      padding: 0;
      font-size: 24px;
      color: #666666;
      margin-bottom: 12px;
    }
    // 表格
    .el-form-item__content {
      // width: 440px;
     
      .el-input__inner {
        height: 68px;
        background: #ffffff;
        border-radius: 4px 0 0 4px;
        opacity: 1;
        border: 1px solid #dcdcdc;
        font-size: 28px;
        color: #3a3a3a;
      }
      .rightBorder .el-input__inner {
        border-right: 0;
      }
      .flash {
        width: 220px;
      }
      .el-input-group__append,
      .el-input-group__prepend {
        background: #ffffff;
        border: 1px solid #dcdcdc;
        border-left: 0;
        color: #c3c3c3;
        font-size: 28px;
      }
    }
    .set {
      width: 220px;
      height: 68px;
      background: linear-gradient(180deg, #ffffff 0%, #ececec 100%);
      box-shadow: 0px 3px 6px 1px rgba(0, 0, 0, 0.16);
      border-radius: 8px 8px 8px 8px;
      margin-top: 44px;
      font-size: 28px;
      color: #51a8ff;
      text-align: center;
      line-height: 68px;
    }
    .goBack {
      width: 208px;
      height: 84px;
      background: linear-gradient(180deg, #ffffff 0%, #ececec 100%);
      box-shadow: 0px 3px 6px 1px rgba(0, 0, 0, 0.16);
      border-radius: 8px 8px 8px 8px;
      font-size: 36px;
      line-height: 84px;
      color: #3a3a3a;
      text-align: center;
      margin-top: 36px;
    }
    .sampling {
      width: 208px;
      height: 84px;
      background: linear-gradient(180deg, #ff7b83 0%, #850006 100%);
      box-shadow: 0px 3px 6px 1px rgba(0, 0, 0, 0.4);
      border-radius: 8px 8px 8px 8px;
      font-size: 36px;
      line-height: 84px;
      color: #fff;
      text-align: center;
      margin-top: 36px;
    }
  }
  .footer{
    width: 1024px;
    height: 40px;
    background: #3A3A3A;
    border-radius: 0px 0px 0px 0px;
    opacity: 0.18;
    text-align: center;
    
    span{
        z-index:99;
        font-size: 24px;
        color: red;
        line-height: 40px;
    }
  }
  .model{
    position: fixed;
    top:116px;
    left:286px;
    width:440px;
    height:534px;
    box-shadow: 0px 3px 6px 1px rgba(0,0,0,0.16);
    border-radius: 8px 8px 8px 8px;
    background:#fff;
    .icon{
        display:block ;
        border-radius: 50%;
        margin:80px auto 0;
        width: 94px;
        height: 94px;
        background: linear-gradient(180deg, #FFB300 0%, #FF7D00 100%);
        font-size: 80px;
        color:#fff;
        text-align: center;
    }
    .dec{
        margin:70px auto 0;
        font-size: 28px;
        font-weight: bold;
        color: #3A3A3A;
        text-align: center;
    }
    .tip{
        margin:32px auto 0;
        font-size: 24px;
        font-weight: 400;
        color: #C3C3C3;
        text-align: center;
    }
    .bottom{
        margin-top:64px;
        display: flex;
        justify-content: center;
        text-align: center;
        width:100%;
        height:70px;
        .button{
            width: 136px;
            height: 68px;
            box-shadow: 0px 3px 6px 1px rgba(0,0,0,0.16);
            border-radius: 8px 8px 8px 8px;
            font-size: 28px;
        }
        .cancel{
            background: linear-gradient(180deg, #FFFFFF 0%, #ECECEC 100%); 
            color: #3A3A3A;
            margin-right:12px;
            line-height:68px;
        }
        .continue{
            background: linear-gradient(180deg, #FF7B83 0%, #850006 100%);
            color: #fff;
            line-height:68px;
        }
    }
  }
}
</style>