<template>
 <div class="position-re">
   <el-breadcrumb separator="/" class="my-breadcrumb">
     <el-breadcrumb-item>数据质检</el-breadcrumb-item>
     <el-breadcrumb-item>质检报告</el-breadcrumb-item>
   </el-breadcrumb>
   <div class="back" @click="$emit('changeOperation','',{})"><span class="fa fa-reply cur-po " >返回</span></div>

   <div class="my-detail-main">
     <div class="block">
       <div class="my-b-title">基本信息</div>
       <diy-el-form :span="9" v-model:model-form="forms" :forms="qualityCheckReportDetailBaseForm">
         <template #zjbg>
           <el-link type="primary"  @click="reportPreview('preview')" >在线预览</el-link>
         </template>
       </diy-el-form>
     </div>
     <div class="block">
       <div class="my-b-title">反馈信息</div>
       <diy-el-form :span="9" v-model:model-form="forms" :forms="qualityCheckReportDetailBackForm"/>
     </div>
     <div class="detail-operation-btn" v-if="operationType === 'edit' || operationType === 'hf'">
       <el-button :icon="Check" @click="saveS(1)">提交</el-button>
       <el-button @click="$emit('changeOperation','')"><span class="icon-back iconfont"></span><span>返回</span></el-button>
     </div>
     <div class="detail-operation-btn" v-if="operationType === 'check'">
       <el-button :icon="Check" @click="saveS(2)">审核</el-button>
       <el-button @click="$emit('changeOperation','')"><span class="icon-back iconfont"></span><span>返回</span></el-button>
     </div>
   </div>
 </div>
</template>

<script>
import {onBeforeMount, ref} from "vue";
import DiyElForm from "@/components/common/DiyElForm.vue";
import {qualityCheckReportDetailBackForm, qualityCheckReportDetailBaseForm} from "@/data/all-forms";
import {Check} from "@element-plus/icons-vue";
import {getQualityReportDetailData, saveQualityDetailS} from "@/service/data-quelity-check/qiality-check-report";
import {formatDateFun, getDateToString} from "@/unit/time";
import {useRootStore} from "@/stores/useStore";
import {elAlert, handleMes} from "@/unit/element-ui/tip";

export default {
  name: "QualityCheckReportDetailHome",
  computed: {
    Check() {
      return Check
    }
  },
  components: {DiyElForm},
  props:{
    operationType:{

    },
    currentOpObj:{

    }
  },
  setup(props,{emit}){
    function reportPreview(){
      emit('changeReportDetailOperation','preview',{UUID:props.currentOpObj.UUID})
    }
    function saveS(state) {
      let params = {
        UUID:props.currentOpObj.UUID,
        INSPECTION_COUNT:forms.value.INSPECTION_COUNT,
        INSPECTION_PASSED:forms.value.INSPECTION_PASSED,
        INSPECTION_NOTPASSED:forms.value.INSPECTION_NOTPASSED,
        FEEDBACK_PERSON:forms.value.FEEDBACK_PERSON,
        FEEDBACK_INFO:forms.value.FEEDBACK_INFO,
        PHONE:forms.value.PHONE,
        E_MAIL:forms.value.E_MAIL,
        REPLY_MESSAGE:forms.value.REPLY_MESSAGE,
        // FEEDBACK_STATE:forms.value.FEEDBACK_STATE,
        REPLY_TIME:forms.value.REPLY_TIME?getDateToString(new Date()):'',
        "STATE":state
      }
      if (+forms.value.FEEDBACK_STATE === 1){
        if(!forms.value.REPLY_MESSAGE){
          elAlert('请输入回复信息')

        }else {
          params.FEEDBACK_STATE = '2'
          params.STATE = '2'
        }
      }
      saveQualityDetailS(params).then(res => {
        handleMes(res,() => {
          emit('changeOperation','')
        })
      })
    }
    onBeforeMount(() => {
      getQualityReportDetailData(props.currentOpObj.UUID).then(res => {
        try {
          forms.value ={
            ...forms.value,
            ...res.msg[0].Rows[0],
            INSERTTIME:res.msg[0].Rows[0].INSERTTIME?formatDateFun(+new Date(res.msg[0].Rows[0].INSERTTIME),'yyyy年MM月dd日'):'',
            FEEDBACK_DATE:res.msg[0].Rows[0].FEEDBACK_DATE?formatDateFun(+new Date(res.msg[0].Rows[0].FEEDBACK_DATE),'yyyy年MM月dd日'):'',
            UNIT_CODE:res.msg[0].Rows[0].UNIT_CODE?useRootStore().allSelectUnit.find(i => i.value === res.msg[0].Rows[0].UNIT_CODE)?.label:''
          }
        }catch {}
      })
    })
    const forms = ref({

    })
    return {
      forms,
      qualityCheckReportDetailBaseForm,
      qualityCheckReportDetailBackForm,
      saveS,
      reportPreview
    }
  }
}
</script>

<style scoped lang="scss">
.my-detail-main{
  padding-bottom: 0;
}
</style>
