<template>
    <div>
        <el-dialog width="800px" title="添加报告结果" :visible.sync="showDialog" :before-close="resetForm">
            <el-form :model="form" label-width="120px">
                <el-form-item label="报告结果">
                <el-checkbox-group v-model="form.cronIds">
                    <el-checkbox v-for="item in conclusion" :key="item.value" :label="item.value">{{ item.label }}</el-checkbox>
                </el-checkbox-group>
                </el-form-item>
                <el-form-item label="结论论述" >
                <el-input v-model="form.cronDescription" type="textarea" placeholder="请输入结论论述"></el-input>
                </el-form-item>
                <el-form-item label="后续跟进事项">
                <span v-if="form.followUps"><span v-for="item in form.followUps" :key="item.name" style="margin-right:10px">{{ item.name}}</span></span> 
                <span>
                    <el-popover
                        ref="popover"
                        placement="bottom"
                        @hide="hidePopover"
                        trigger="click">
                        <div>
                            <addMatter :type="matterType" ref="addMatter"></addMatter>
                        </div>
                        <el-button slot="reference">添加后续事项</el-button>
                    </el-popover>
                </span>
                
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm()" size="small" style="width:100px" :loading="btnLoading">保存</el-button>
                <el-button  @click="resetForm()" size="small" style="width:100px">取消</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import addMatter from "../matter/addMatters.vue";
export default {
    components:{
        addMatter,
    },
    data() {
        return {
            showDialog:false,
            form:{
                cronIds:[]
            },
            matterSign:false,
            matterType:null,
            btnLoading:false,
            conclusion:[],
            reportAsDicItem:{
                "0":"INVALID_ASSESS",
                "1":"THIRD_ASSESS",
                "2":"STABILITY_ASSESS",
                "3":"FTO_ASSESS",
                "4":"TORT_ASSESS",
                "5":"AVOID_ASSESS",
                "7":"REINVALID_ASSESS",
            },
        }
    },
    computed: {
        dictMessage() {
            return this.$store.state.dictMessage.dictMessage
        },
    },
    mounted() {
    },
    methods: {
        //打开弹窗
        open(row){
            this.matterType = 2
            this.form = {
                cronIds:[],
                ...row
            }
            this.conclusion = this.dictMessage[this.reportAsDicItem[row.reportType]]
            this.showDialog = true
        },
        //隐藏popover
        hidePopover(){
            var a = this.$refs.addMatter.emitData()
            if(a){
                this.$set(this.form,'followUps',a)
            }else{
                return false
            }
        },
        validMatter(){
            return this.$refs.addMatter.emitData()
        },

        //添加核心结论
        submitForm(){
            this.form.type = 2//项目类型（1专利数据库 2报告 3专利挖掘项目）
          // 判断文件是否都上传完毕
          var guids = this.$commonJS.checkUploadFile(this.form.systemFileList)
            if(!guids){
                return false
            }
            this.form.fileGuids = guids
          // this.$commonJS.allUploadFile(this.form)
         
          //判断报告是否是已完成的
        this.$refs.addMatter.submitForm1()
          this.form.status = 3
          // 事件及调查类型处理
          if (this.form.scenarioIds && this.form.scenarioIds.length > 0) {
            var scenarioIds = JSON.parse(JSON.stringify(this.form.scenarioIds))
          }
          if (this.form.eventId) {
            this.form.events = []
            this.form.scenarioIds = []
            this.form.matterIds.forEach(item => {
              this.form.events.push(
                {
                  matterId: item,
                  scenarioId: scenarioIds[0],
                  eventId: this.form.eventId
                }
              )
            })
          }
          let formData = this.form
            this.$api.updateReportProject(formData).then(response=>{
                if(response.code == 200){
                    this.$message.success('报告结果添加成功')
                    this.resetForm()
                    this.$emit('save',true)
                }
            }).catch(error=>{
                this.$message.error('报告结果添加失败')
            })
        },
        //关闭弹窗
        resetForm(){
            this.matterType=null
            this.showDialog = false
        },

    },
}
</script>