<template>
  <div class="fourStep">
    <div class="header">
      <span class="left">校准闪点</span>
      <span class="right">{{ nowDate }}</span>
    </div>
    <div class="echarts" >
      <div class="top">
        <div class="title">{{flash_point_value?flash_point_value:'-'}}℃</div>
        <div class="subTitle">{{material_name}}</div>
      </div>
      <div id="main" style="width: 100%; height: 400px"></div>
      <div class="info">
        <div v-for="(item,index) in items" :key="index" class="item">
          <div class="label">{{ item.label }}</div>
          <div class="value">{{ item.value }}</div>
        </div>
      </div>
    </div>
    <div class="bottom">
      <div class="button goBack" @click="handBack">返回</div>
      <div class="button delete" @click="handDelete">删除</div>
      <div class="button export" @click="handExport">导出</div>
      <div class="button instrument" v-if="isShow" @click="handClean">清洁仪器</div>
    </div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import router from '../../router';
import { exportReportList } from "@/api/report";
import { deleteData,resultData } from "@/api/step";
export default {
  props:{
    isShow:{
      type:Boolean,
      default:true
    }
  },
  data() {
    return {
      flash_point_value:'',
      material_name:'',
      nowDate: "",
      items:[
        {
          label:'执行标准',
          value:'ASTM D6450'
        },
        {
          label:'初始温度',
          value:'60.6℃'
        },
        {
          label:'最终温度',
          value:'ASTM D6450'
        },
        {
          label:'精密度适用范围',
          value:'60.6℃'
        },
        {
          label:'点火前气压',
          value:'60.6℃'
        },
        {
          label:'环境大气压',
          value:'ASTM D6450'
        },
        {
          label:'瞬间增压',
          value:'60.6℃'
        },
      ],
      xData:[],
      yData:[],
    };
  },
  mounted() {
    this.currentTime();
    this.getInitData();
  },
  methods: {
    async getInitData (){
      console.log(JSON.parse(localStorage.getItem('experiment_info')),'获取初始数据',this.$route.query)
      let data={
        experiment_id:this.$route.query.experiment_id
      }
      var that=this;
      await resultData(data).then(response=>{
         console.log(response,'结果',response.data.data)
         that.xData=response.data.data.chart_data_temp,
          that.yData=response.data.data.chart_data_pressure
          that.items[0].value=response.data.data.determination_standard;
          that.items[2].value=response.data.data.final_temperature_set;
          that.items[1].value=response.data.data.initial_temperature_set;
          that.items[6].value=response.data.data.instant_adding_pressure;
          that.items[4].value=response.data.data.preparation_fire_air_pressure;
          that.items[5].value=response.data.data.ambient_pressure;//环境大气压
          that.items[3].value=response.data.data.application_scope;//紧密度适用范围
          that.flash_point_value=response.data.data.flash_point_value;
          that.material_name=response.data.data.material_name;
          // that.$message.success('导出成功')
          that.init()
      })
    },
    handSet() {},
    handCancel() {
      this.isShow = false;
    },
    currentTime() {
      setInterval(this.getDate, 500);
    },
    getDate() {
      var _this = this;
      let yy = new Date().getFullYear();
      let mm =
        new Date().getMonth() + 1 < 10
          ? "0" + (new Date().getMonth() + 1)
          : new Date().getMonth() + 1;
      let dd =
        new Date().getDate() < 10
          ? "0" + new Date().getDate()
          : new Date().getDate();
      let week = new Date().getDay();
      let hh = new Date().getHours();
      let ms =
        new Date().getSeconds() < 10
          ? "0" + new Date().getSeconds()
          : new Date().getSeconds();
      let mf =
        new Date().getMinutes() < 10
          ? "0" + new Date().getMinutes()
          : new Date().getMinutes();
      _this.nowDate = yy + "/" + mm + "/" + dd + " " + " " + hh + ":" + mf;
    },
    init() {
      console.log('初始化')
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById("main"));
      // 指定图表的配置项和数据
      var option = {
        xAxis: {
          name:'温度/℃',
          type: 'category',
          data: this.xData,
          axisTick:{
            show:false
          },
          axisLine:{
            show:false
          }
        },
        yAxis: {
          name:'瞬间增压/Kpa',
          type: 'value'
        },
        series: [
          {
            data: this.yData,
            type: 'line',
            showSymbol:false,
          }
        ],
        color:'#51A8FF'
      };
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
    },
    handBack(){
      this.$router.push({path:'/home'})
    },
    handDelete(){
      let data={
        experiment_id:this.$route.query.experiment_id
      }
      deleteData(data).then(response=>{
         console.log(response,'删除成功')
         if(response.status==200){
          this.$message.success('删除成功')
          this.$router.push({path:"/ReportList"})
         }else{
          this.$message.warning('删除失败')
         }
         
        //  this.$message.error(response.desc)
      })
    },
    handExport(){
      // let data={
      //   experiment_id:JSON.parse(localStorage.getItem('experiment_info')).experiment_id
      // }
      var formData = new FormData()
      let arr=[]
      let experiment_id=this.$route.query.experiment_id
      arr.push(experiment_id);
      formData.append('experiment_id_list',JSON.stringify(arr));
      exportReportList(formData).then(response=>{
        if(response.data.status==0){
          this.$message.success('导出成功')
        }else{
          this.$message.error(response.data.message)
        }
      })
    },
    handClean(){
      this.$router.push('/clean');
    }
  },
};
</script>

<style lang="less" >
.fourStep {
  .header {
    margin: 40px 40px 0;
    width: 944px;
    height: 44px;
    background: linear-gradient(96deg, #e4e4e4 0%, #f3f3f3 100%);
    border-radius: 0px 0px 0px 0px;
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
    font-size: 20px;
    color: #666666;
    line-height: 44px;
  }
  .echarts {
    margin: 0 40px;
    overflow: auto;
    height:400px;
    .top{
     
      .title{
        text-align: center;
        margin:20px auto 0;
        font-size: 56px;
        color: #666666;
      }
      .subTitle{
        text-align: center;
        font-size: 24px;
        color: #666666;
      }
    }
    .info{
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      padding-bottom:120px;
      .item{
        width:180px;
        padding:24px 30px;
        font-size: 24px;
        color:#808080;
        .value{
          margin-top:10px;
        }
      }
      .item:nth-child(1),.item:nth-child(4),.item:nth-child(5){
        width:260px;
        overflow: hidden;
      }
    }
  }
  .bottom {
    width: 1024px;
    height: 120px;
    background: #ffffff;
    box-shadow: 0px -3px 6px 1px rgba(0, 0, 0, 0.16);
    border-radius: 0px 0px 0px 0px;
    opacity: 1;
    position: fixed;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 40px;
    .button {
      margin-top: 12px;
      width: 208px;
      height: 84px;
      box-shadow: 0px 3px 6px 1px rgba(0, 0, 0, 0.16);
      border-radius: 8px 8px 8px 8px;
      line-height: 84px;
      font-size: 36px;
      text-align: center;
      color: #fff;
    }
    .goBack {
      background: linear-gradient(180deg, #ffffff 0%, #ececec 100%);
      color: #3a3a3a;
    }
    .delete {
      background: linear-gradient(180deg, #ff7b83 0%, #850006 100%);
    }
    .export {
      background: linear-gradient(180deg, #59cc74 0%, #0a8828 100%);
    }
    .instrument {
      background: linear-gradient(180deg, #51a8ff 0%, #1564b1 100%);
    }
  }
}
</style>