<template>
  <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body destroy-on-close :close-on-click-modal="false">

    <component
      :is="currentComponent"
      :inspectInfo="inspectInfo"
    />

    <!-- 巡检图片 -->
    <el-image ref="viewImage" :src="imageUrl" v-show="false" :preview-src-list="[imageUrl]" :z-index="9999"></el-image>

  </el-dialog>
</template>

<script>
  import { getInspect } from "@/api/devicemanage/inspect";
  import RegulatorBoxTable from "./RegulatorBoxTable";
  import ValveWellTable from "./ValveWellTable";
  export default {
    name: "inspect-detail-info",
    props:{
      type:{
        type:Number
      },
      title:{
        type:String
      }
    },
    components:{
      RegulatorBoxTable,
      ValveWellTable
    },
    data(){
      return{
        inspectInfo:{},
        open: false,
        currentComponent: null,
        imageUrl: null
      }
    },
    methods:{
      openDetail(row){
        if(!row.content) return this.$message.error("未查到巡检信息信息！");
        this.initComponent();
        this.getInspectInfo(row.id);
      },
      //组件初始化
      initComponent(){
        switch (this.type){
          case 1:
            this.currentComponent = RegulatorBoxTable;
            break;
          case 2:
            this.currentComponent = ValveWellTable;
            break;
          default:
            return null;
        }
      },
      //时间格式化
      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) + " 分";
      },
      //巡检信息
      getInspectInfo(inspectId){
        getInspect(inspectId).then(res =>{
          if(res.code == 200){
              this.inspectInfo = { ...res.data };
              this.inspectInfo.content = JSON.parse(this.inspectInfo.content);
              this.open = true;
          }
        })
      },
      //查看图片
      viewPicture(url){
        this.imageUrl = url;
        this.$refs.viewImage.showViewer = true;
      }
    }
  }
</script>

<style scoped>

</style>
