<template>
  <el-dialog title="详情" :visible.sync="open" width="900px" append-to-body destroy-on-close :close-on-click-modal="false">
    <component :is="currentComponent" ref="currentComponents"/>
  </el-dialog>
</template>

<script>
  import FireUpTable from "./FireUpTable";
  import BreakGround from "./BreakGround";
  import BreakRode from "./BreakRode";
  import High from "./High";
  import Electric from "./Electric";
  import BlindPlate from "./BlindPlate";
  import LimitSpace from "./LimitSpace";
  import Hoisting from "./Hoisting";
  import { signInfoList }from "@/api/specialworkpermit/sign";
  export default {
    name: "detail-info",
    components:{
      FireUpTable,
      BreakGround,
      BreakRode,
      High,
      Electric,
      BlindPlate,
      LimitSpace,
      Hoisting
    },
    data(){
      return{
        open: false,
        type: 1,
        currentComponent: null,
        dataInfo: null,
        signInfo: []
      }
    },
    watch:{
      open(newVal,oldVal){
        if(newVal){
          this.initComponent();
          this.initData();
        }
      }
    },
    methods:{
      //时间格式化
      dateFormatter(dateTime){
        if(!dateTime) return "";
        let splitTime = dateTime.split(" ");
        return splitTime[0].substr(0,4) + " 年 " + splitTime[0].substr(5,2) + " 月 " + splitTime[0].substr(8,2) + " 日 " + splitTime[1].substr(0,2) + " 时 " + splitTime[1].substr(3,2) + " 分";
      },
      //初始化组件
      initComponent(){
        switch (this.type){
          case 1:
            //动火
            this.currentComponent = FireUpTable;
            break;
          case 2:
            //动土
            this.currentComponent = BreakGround;
            break;
          case 3:
            //断路
            this.currentComponent = BreakRode;
            break;
          case 4:
            //高空作业
            this.currentComponent = High;
            break;
          case 5:
            //临时用电
            this.currentComponent = Electric;
            break;
          case 6:
            //盲板
            this.currentComponent = BlindPlate;
            break;
          case 7:
            //受限空间
            this.currentComponent = LimitSpace;
            break;
          default:
            //吊装
            this.currentComponent = Hoisting;
        }
      },
      //初始化数据
      initData(){
        this.$nextTick(() => {
          let dataInfo = {...this.dataInfo};
          this.$refs.currentComponents.baseInfo = JSON.parse(dataInfo.baseJson);
          this.$refs.currentComponents.dataInfo = dataInfo;
          if(dataInfo.analysisJson){
            this.$refs.currentComponents.analysisInfo = JSON.parse(dataInfo.analysisJson);
          }
          this.getSignInfoList(dataInfo.id);
        })
      },
      //获取签名信息
      getSignInfoList(specialId){
        signInfoList({specialId:specialId}).then(res =>{
          if(res.code == 200 && res.data){
            this.signInfo = res.data;
          }
        })
      },
      //获取签名信息
      getSignInfo(sort){
        let signInfo = this.signInfo.find(item => item.sort == sort);
        return signInfo ? signInfo : {};
      }
    }
  }
</script>

<style scoped>

</style>
