<template>
  <div>
    <div>
      <div class="app-container capture-area">
        <div class="headReturn">
          <div>
            <img src="../../../assets/images/report02.png" alt="" @click="handlerReturn">
            <span>铸坯报告</span>
          </div>
          <div>
            <el-button @click="downloadAsPDF" :loading="downloadAsPDFLoding"><svg-icon icon-class="exportSvg" />导出PDF</el-button>
            <el-button @click="wordDemo" :loading="downloadAsPDFLoding"><svg-icon icon-class="exportSvg" />导出Word</el-button>
            <el-button type="primary" @click="publish()" v-show="castingReportData.status === '0'" :loading="downloadAsPDFLoding" v-hasPermi="['business:report:edit']">发布</el-button>
          </div>
        </div>
      </div>
      <div ref="pdfDom" id="pdfDom">
        <BilletInformation :castingInformation="castingReportData" style="margin-bottom:20px;" />
        <Produce :castTimesNo="castingReportData.castTimesNo" style="margin-bottom:20px;" />
        <Quality style="margin-bottom:20px;" :qualityListData="qualityListData" />
        <Feeding :chargingInListZjbbwjData="chargingInListZjbbwjData"
          :chargingInListZjbbwjDosage="chargingInListZjbbwjDosage" :chargingInListZjbfgjData="chargingInListZjbfgjData"
          :chargingInListZjbfgjDosage="chargingInListZjbfgjDosage" :chargingInListJjqbwzData="chargingInListJjqbwzData"
          :chargingInListJjqbwzDosage="chargingInListJjqbwzDosage" :chargingInListJjqfrjData="chargingInListJjqfrjData"
          :chargingInListJjqfrjDosage="chargingInListJjqfrjDosage" style="margin-bottom:20px;" />
        <Abnormal style="margin-bottom:20px;" :abnormalListData="abnormalListData" />
        <Incoming :lftappingData="lftappingData" :queryListAPiData="queryListAPiData" style="margin-bottom:20px;" />
        <Technology :technologyData="technologyData" style="margin-bottom:20px;" />
      </div>
    </div>
  </div>
</template>
<script setup>
import BilletInformation from "./components/BilletInformation.vue";
import Produce from "./components/Produce.vue";
import Quality from "./components/Quality.vue";
import Feeding from "./components/Feeding.vue";
import Abnormal from "./components/Abnormal.vue";
import Technology from "./components/Technology.vue";
import Incoming from "./components/Incoming.vue";
import { reportHeader, getBqsSmprlst, getBoeLftapping, update } from '@/api/digitalCasting/report/report';
import { qualityListApi, abnormalListApi, getChargingInList } from "@/api/produce/information";
import { useRouter } from "vue-router";
const route = useRoute();
const { proxy } = getCurrentInstance();
const router = useRouter();

//导出PDF按钮开关
const downloadAsPDFLoding = ref(false)
// 铸坯报告数据
const castingReportData = ref({})
// const queryByPrdNoData = ref({})
//质量信息数据
const qualityListData = ref([])
//异常信息数据
const abnormalListData = ref({})
//中间包保温计
const chargingInListZjbbwjData = ref({})
const chargingInListZjbbwjDosage = ref(0)
//中间包覆盖计
const chargingInListZjbfgjData = ref({})
const chargingInListZjbfgjDosage = ref(0)
//结晶器保护渣
const chargingInListJjqbwzData = ref({})
const chargingInListJjqbwzDosage = ref(0)
//结晶器发热剂
const chargingInListJjqfrjData = ref({})
const chargingInListJjqfrjDosage = ref(0)
// 精炼出钢实绩
let lftappingData = ref({})
//查询检验实绩列表
let queryListAPiData = ref({})
//echa图标 参数
let technologyData = ref({
  startTime: '',
  endTime: '',
  startLocation: '',
  endLocation: '',
  prdNo: ''
})
// 返回上一页
const handlerReturn = () => {
  router.go(-1)
  proxy.$tab.closePage(route).then(({ visitedViews }) => { })
}
//发布
const publish = () => {
  proxy.$modal.confirm(`否确认发布${castingReportData.value.prdNo}铸坯报告,发布后该报告将可被查看。`).then(() => {
    update({ id: castingReportData.value.id }).then(res => {
      proxy.$modal.msgSuccess("发布成功");
      router.go(-1)
      proxy.$tab.closePage(route).then(({ visitedViews }) => { })
    }).catch(err => { console.log(err) })

  }).catch(err => { })
}
//导出PDF按钮
const pdfDom = ref(null)
const downloadAsPDF = () => {
  downloadAsPDFLoding.value = true
  proxy.htmlToPdf.getPdf(`${castingReportData.value.prdNo}铸坯报告`, "#pdfDom", () => {
    downloadAsPDFLoding.value = false
  });
}
const reportHeaderApi = () => {
  const reportId = router.currentRoute.value.query.id
  reportHeader(reportId).then(res => {
    castingReportData.value = res.data

    technologyData.value.startTime = castingReportData.value.prdStartTime
    technologyData.value.endTime = castingReportData.value.prdEndTime
    technologyData.value.startLocation = ''
    technologyData.value.endLocation = ''
    technologyData.value.prdNo = castingReportData.value.prdNo

    boeLftapping()
    queryListAPi()
    qualityList()
    abnormalList()
    chargingInListZjbbwj()
    chargingInListZjbfgj()
    chargingInListJjqbwz()
    chargingInListJjqfrj()
  }).catch(err => {
    console.log(err)
  })
}

// 下载word
const wordDemo = () => {
  proxy.download("/word/exportWord", { prdNo: castingReportData.value.prdNo, id: castingReportData.value.id }, `${castingReportData.value.prdNo}铸坯报告.docx`);
}
//质量信息
const qualityList = () => {
  let data = {
    prdNo: castingReportData.value.prdNo,
  }
  qualityListApi(data).then(res => {
    qualityListData.value = res.rows
  }).catch(err => {
    console.log(err)
  })
}
//异常事件
const abnormalList = () => {
  let data = {
    pageNum: 1,
    pageSize: 100,
    prdNo: castingReportData.value.prdNo,
  }
  abnormalListApi(data).then(res => {
    abnormalListData.value = res.rows
  }).catch(err => {
    console.log(err)
  })
}
// 加料记录-中间包保温计
const chargingInListZjbbwj = () => {
  let listArr = []
  let data = {
    pageNum: 1,
    pageSize: 100,
    castTimesNo: castingReportData.value.castTimesNo,
    chargingTypes: ['TIA']
  }
  getChargingInList(data).then(res => {
    res.rows.forEach(item => {
      item.chargingAmount = item.chargingAmount * 1 / 2
      //需要分AB 要push两次 勿动!!!!!!!!
      listArr.push(item)
      listArr.push(item)
    })
    chargingInListZjbbwjData.value = listArr
    chargingInListZjbbwjData.value.forEach(item => {
      chargingInListZjbbwjDosage.value += item.chargingAmount * 1
    })
  })
}
// 加料记录-中间包覆盖计
const chargingInListZjbfgj = () => {
  let data = {
    pageNum: 1,
    pageSize: 100,
    castTimesNo: castingReportData.value.castTimesNo,
    chargingTypes: ['TCA']
  }
  getChargingInList(data).then(res => {
    chargingInListZjbfgjData.value = res.rows
    res.rows.forEach(item => {
      chargingInListZjbfgjDosage.value += item.chargingAmount * 1
    })
  })
}
// 加料记录-结晶器保护渣
const chargingInListJjqbwz = () => {
  let data = {
    pageNum: 1,
    pageSize: 100,
    castTimesNo: castingReportData.value.castTimesNo,
    chargingTypes: ['MPF']
  }
  getChargingInList(data).then(res => {
    chargingInListJjqbwzData.value = res.rows
    res.rows.forEach(item => {
      chargingInListJjqbwzDosage.value += item.chargingAmount * 1
    })
  })
}
// 加料记录-结晶器发热剂
const chargingInListJjqfrj = () => {
  let data = {
    pageNum: 1,
    pageSize: 100,
    castTimesNo: castingReportData.value.castTimesNo,
    chargingTypes: ['MHA']
  }
  getChargingInList(data).then(res => {
    chargingInListJjqfrjData.value = res.rows
    res.rows.forEach(item => {
      chargingInListJjqfrjDosage.value += item.chargingAmount * 1
    })
  })
}
// 精炼出钢实绩
const boeLftapping = () => {
  getBoeLftapping({ castTimesNo: castingReportData.value.castTimesNo }).then(res => {
    lftappingData.value = res.data
  })
}
// 查询检验实绩列表
const queryListAPi = () => {
  getBqsSmprlst({ castTimesNo: castingReportData.value.castTimesNo }).then(res => {
    queryListAPiData.value = res.data
  })
}
reportHeaderApi()

</script>
<style lang="scss" scoped>
.headReturn {
  width: 100%;
  display: flex;
  justify-content: space-between;
  text-align: center;
  align-items: center;

  img {
    vertical-align: middle;
    margin-right: 20px;
    cursor: pointer;
  }

  span {
    display: inline-block;
    vertical-align: middle;
    font-size: 18px;
    font-weight: 600;
  }
}
</style>
