<template>
  <div class="position-re  h100 detail">
    <div class="back" @click="$emit('changeReportDetailOperation','',{})"><span class="fa fa-reply cur-po " >返回</span></div>

    <div class="back">
      <span class="fa fa-save cur-po" @click="editOrAddReport">保存</span>
      <span class="fa fa-reply cur-po " @click="$emit('changeReportDetailOperation','',{})">返回</span>
    </div>
    <div>
      <el-breadcrumb separator="/" class="my-breadcrumb">
        <el-breadcrumb-item>数据质检</el-breadcrumb-item>
        <el-breadcrumb-item>质检报告</el-breadcrumb-item>
        <el-breadcrumb-item>在线预览</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="my-detail-main ">
    <quality-testing-report ref="reportRef" operation-type="edit" report-data-type="result" :uuid="currentOpObj.UUID" />
    </div>
  </div>

</template>

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

export default {
  name: "QualityCheckReportDetailReport",
  components: {QualityTestingReport},
  props:{
    currentOpObj:{

    }
  },
  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)
          }
        }
      }

      getReportResultDetail(props.currentOpObj.UUID).then(res=>{
        if(res.msg[0]["scuuess"] == "false"){
          ElMessageBox.alert(res.msg[0]["error"], '提示', {
            confirmButtonText: '确定'
          });
          return
        }

        let originData = JSON.parse(JSON.stringify(res.msg[0].Rows[0]));
        originData.content = reportRef.value.items.map(i => {
          let obj = {}
          Object.keys(i).forEach(key => {
            if (i[key]){
              obj[key] = i[key]
            }
          })
          return obj
        })

        editOrAddReportData(originData).then(res => {
          handleMes(res,() => {
            emit('changeOperation','')
          })
        })
      })
    }
    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{
  flex: 1;
  overflow: hidden;
  background: #D4E6FF;
  padding-left: 0px;
  padding-right: 0px;
  padding-bottom: 0px;
}
</style>
