<template>
 <div class="position-re h100 detail">
   <el-breadcrumb separator="/" class="my-breadcrumb">
     <el-breadcrumb-item>知识库</el-breadcrumb-item>
     <el-breadcrumb-item>报告模板</el-breadcrumb-item>
   </el-breadcrumb>
   <div class="back">
     <span v-if="operationType !== 'detail'" class="fa fa-save cur-po" @click="editOrAddReport">保存</span>
     <span class="fa fa-reply cur-po " @click="$emit('changeOperation','',{})">返回</span>
   </div>
   <div class="back" ></div>

   <div class="my-detail-main ">
     <quality-testing-report ref="reportRef" :report-mb-type="reportMbType" report-data-type="moban" :operation-type="operationType" :uuid="uuid"/>
   </div>
 </div>
</template>

<script>
import QualityTestingReport from "@/view/other/c-views/data-handle/zsk/qualityTestingReport/QualityTestingReport.vue";
import {ref} from "vue";
import {editOrAddReportMb} from "@/service/zsk/report-mb";
import {handleMes} from "@/unit/element-ui/tip";

export default {
  name: "ReportMbDetail",
  components: {QualityTestingReport},
  props:{
    uuid:{

    },
    operationType:{

    },
    reportMbType:{

    }
  },
  setup(props,{emit}) {
    function editOrAddReport(){

      for(let i=0;i<reportRef.value.items.length;i++){
        if(reportRef.value.items[i].CHART_CONTENT_TEXT){
          if(typeof reportRef.value.items[i].CHART_CONTENT_TEXT ==="object"){
            reportRef.value.items[i].CHART_CONTENT_TEXT = JSON.stringify(reportRef.value.items[i].CHART_CONTENT_TEXT)
          }
        }
        if(reportRef.value.items[i].CONTENT_TEXT){
          if(typeof reportRef.value.items[i].CONTENT_TEXT ==="object"){
            reportRef.value.items[i].CONTENT_TEXT = JSON.stringify(reportRef.value.items[i].CONTENT_TEXT)
          }
        }
      }
      let params = {
        NAME:reportRef.value.items[0].CONTENT_TEXT,
        TYPE:reportRef.value.reportType,
        content:reportRef.value.items.map(i => {
          let obj = {}
          Object.keys(i).forEach(key => {
            if (i[key]){
              obj[key] = i[key]
            }
          })
          return obj
        })
      }
      if (props.operationType !== 'add'){
        params.UUID = props.uuid

      }
      editOrAddReportMb(params).then(res => {
        handleMes(res,() => {
          emit('changeOperation','')
        })
      })
      // reportRef.value.items
      // reportRef.value.validDateRequired()
    }
    const reportRef = ref(null)
    return {
      reportRef,
      editOrAddReport
    }
  }
}
</script>

<style scoped lang="scss">
.fa-save{
  margin-right: 20px;
}
.detail{
  display: flex;
  flex-direction: column;
}
.my-detail-main{
  background: #D4E6FF;
  flex: 1;
  overflow: hidden;
  padding-left: 0px;
  padding-right: 0px;
  padding-bottom: 0px;
}
</style>
