<!-- 素材分析、复核 -->
<template>
  <div>
    <dialog-edit width="1200px"
                 :visible.sync="dialogVisible"
                 :autoSave="false"
                 :autoClose="true"
                 :editModel="editModel"
                 :form="form"
                 :title="diablogTitle"
                 :footerBtnShow="false"
                 @close="close">
      <div class="titleLine">
        {{$t('reviewMaterialIndex.materialInfo')}}
        <span class="line"></span></div>
      <dym-form :componentList="componentList"
                :formValue.sync="detailForm"
                v-if="loadCount"></dym-form>
      <el-form-item label="附件"
                    label-width="140px"
                    size="medium">
        <btn-batch-download :fileID="FileBatchDown()"
                            :classType="true"
                            downloadButtonMsg="下载附件"
                            type="primary"
                            v-if="downloadVisible"></btn-batch-download>
      </el-form-item>
      <!-- 分析、复核控件 -->
      <repository-listNew ref="repositoryListNew"
                          v-if="listVisible"
                          :sourceData="sourceData"
                          :pageType="editModel"
                          @callbackData="callbackData"
                          @radio='getRadio'></repository-listNew>
      <template slot="footer">
          <auth-button :label="nextArticle"
                       v-if="nextButton && editModel !== 'V'"
                       type="primary"
                       size="medium"
                       @click="submits('0','1')"></auth-button>
          <auth-button label="提 交"
                       v-if="editModel !== 'V'"
                       type="primary"
                       size="medium"
                       @click="submits('0')"></auth-button>
          <auth-button label="暂 存"
                       v-if="editModel !== 'V'"
                       type="primary"
                       size="medium"
                       @click="submits('1')"></auth-button>
          <auth-button label="关 闭"
                       size="medium"
                       @click="close()"></auth-button>
      </template>
    </dialog-edit>
    <!-- <cnki :cnkiData="cnkiData" @cnkiSave="cnkiSave"></cnki> -->
</div>
</template>

<script>
import repositoryListNew from '@/components/element/assetaudit/repositoryListNew'
import BaseEdit from '@/pages/baseEditPage'
import {
  DialogEdit, authButton, dymForm, btnBatchDownload
} from 'newepoch-components'
import ReviewMateriallInput from '@/components/element/assetaudit/ReviewMateriallInput'
import ReviewMateriallInputDic from '@/components/element/assetaudit/ReviewMateriallInput-dic'
import reviewMaterialApi from '@/api/assetaudit/reviewMaterialApi'
import assetauditApi from '@/api/assetaudit/assetauditApi'
import mixin from '@/pages/mixin'
import cnki from '@/components/element/assetaudit/cnki'
export default {
  extends: new BaseEdit(),
  mixins: [mixin],
  name: 'knowledgeBasePop',
  components: {
    repositoryListNew,
    DialogEdit,
    authButton,
    dymForm,
    // RepositoryList,
    ReviewMateriallInput,
    btnBatchDownload,
    cnki
  },
  props: {
    autoSave: {
      type: [Boolean],
      default: false
    },
    options: {
      type: [Array],
      default () {
        return []
      }
    },
    keyId: {
      type: String,
      default () {
        return ''
      }
    },
    diablogTitle: {
      type: String,
      default () {
        return ''
      }
    },
    editModel: {
      type: [String],
      default () {
        return 'E'
      }
    },
    commitStatus: { // 01：分析,02：复核
      type: [String],
      default () {
        return ''
      }
    }
  },
  data () {
    return {
      sourceData: [], // 组件传入数据
      sourceDataK: [], // 组件传入数据（仅知识库）
      tkeyId: 0,
      messages: '分析评审素材',
      nextButton: false, // 下一条按钮是否显示
      appendToBody: false,
      toolMenuFlag: true,
      loadCount: 0,
      menuFlag: false,
      downloadVisible: 'true', // 下载按钮显示
      operateBtnLayout: '',
      loadingFlag: false, // 加载动画控件
      queryParas: {},
      applicableProjectName: '', // 适用产品名
      tableData: [], // 分析内容
      submitData: {}, // 分析提交表单
      detailForm: {}, // 数据信息
      applicableProductsId: '', // 适用产品id
      applicableProductsName: '', // 适用产品名称
      listVisible: false, // 分析、复核插件是否显示
      commitState: 'false', // 是否已经提交
      radio: '1',
      cnkiData: {
        dialogVisible: false,
        fromData: {}, // 表单数据
        showSave: true
      },
      componentList: [
        // 付款确认书编号
        {
          label: this.$i18n.messages[this.$i18n.locale].reviewMaterialIndex.payCode,
          value: 'payCode',
          labelWidth: '140px',
          cols: [8, 8, 8],
          componentName: ReviewMateriallInput
        },
        // 供应商名称
        {
          label: this.$i18n.messages[this.$i18n.locale].reviewMaterialIndex.gysName,
          disabled: true,
          value: 'gysName',
          labelWidth: '140px',
          cols: [8, 8, 8],
          componentName: ReviewMateriallInput
        },
        // 项目公司名称
        {
          label: this.$i18n.messages[this.$i18n.locale].reviewMaterialIndex.xmgsName,
          disabled: true,
          value: 'xmgsName',
          labelWidth: '140px',
          cols: [8, 8, 8],
          componentName: ReviewMateriallInput
        },
        // 产品类型
        {
          label: this.$i18n.messages[this.$i18n.locale].reviewMaterialIndex.productType,
          disabled: true,
          // dictTypeCode: 'BUSINESS_TYPE', //原代码
          dictTypeCode: 'ZD0087', // 临时使用代码
          value: 'businessType',
          labelWidth: '140px',
          cols: [8, 8, 8],
          componentName: ReviewMateriallInputDic
        },
        // 发起负责人
        {
          label: this.$i18n.messages[this.$i18n.locale].reviewMaterialIndex.reviewPromoterName,
          disabled: true,
          value: 'reviewPromoterName',
          labelWidth: '140px',
          cols: [8, 8, 8],
          componentName: ReviewMateriallInput
        },
        // 评审委员会全部人员
        {
          label: this.$i18n.messages[this.$i18n.locale].reviewMaterialIndex.committeeMemberAllNames,
          disabled: true,
          value: 'committeeMemberNamesMerge',
          labelWidth: '140px',
          cols: [8, 8, 8],
          componentName: ReviewMateriallInput
        },
        // 素材来源
        {
          label: this.$i18n.messages[this.$i18n.locale].reviewMaterialIndex.materialOrigin,
          disabled: true,
          dictTypeCode: 'MATERIAL_SOURCE', // （更改过的字典code）
          value: 'materialSourceType',
          labelWidth: '140px',
          cols: [8, 8, 8],
          componentName: ReviewMateriallInputDic
        },
        // 记录者
        {
          label: this.$i18n.messages[this.$i18n.locale].reviewMaterialIndex.registrar,
          disabled: true,
          value: 'registrar',
          labelWidth: '140px',
          cols: [8, 8, 8],
          componentName: ReviewMateriallInput
        },
        // 分析人
        {
          label: this.$i18n.messages[this.$i18n.locale].reviewMaterialIndex.analysisPerson,
          disabled: true,
          // value: 'analysisPerson',
          value: 'analysisPersonName',
          labelWidth: '140px',
          cols: [8, 8, 8],
          componentName: ReviewMateriallInput
        },
        {
          // 问题概要
          label: this.$i18n.messages[this.$i18n.locale].reviewMaterialIndex.problemSummary,
          disabled: true,
          value: 'problemSummary',
          labelWidth: '140px',
          cols: [24, 24, 24],
          componentName: 'el-input',
          // autosize: { minRows: 2, maxRows: 3 },
          rows: 3,
          type: 'textarea'
        },
        {
          // 问题描述
          label: this.$i18n.messages[this.$i18n.locale].reviewMaterialIndex.problemDesc,
          disabled: true,
          value: 'problemDesc',
          labelWidth: '140px',
          cols: [24, 24, 24],
          componentName: 'el-input',
          // autosize: { minRows: 2, maxRows: 3 },
          rows: 3,
          type: 'textarea'
        },
        {
          // 评审结论
          label: this.$i18n.messages[this.$i18n.locale].reviewMaterialIndex.reviewConclusion,
          disabled: true,
          value: 'reviewConclusion',
          labelWidth: '140px',
          cols: [24, 24, 24],
          componentName: 'el-input',
          // autosize: { minRows: 2, maxRows: 3 },
          rows: 3,
          type: 'textarea'
        },
        {
          // 备注
          label: this.$i18n.messages[this.$i18n.locale].reviewMaterialIndex.remark,
          disabled: true,
          value: 'remark',
          labelWidth: '140px',
          cols: [24, 24, 24],
          componentName: 'el-input',
          // autosize: { minRows: 2, maxRows: 3 },
          rows: 3,
          type: 'textarea'
        }
      ],
      nextArticle: this.$t('common.analysisTips') // 提交下一条按钮提示（提交并分析下一条）
    }
  },
  mounted () {
    this.getInfo(this.keyId)
    this.handleFilter()
  },
  computed: {
    api () {
      return reviewMaterialApi.reviewmaterial
    },
    api1 () {
      return assetauditApi.reviewMaterial
    }
  },
  methods: {
    // 下一条
    getNextInfo () {
      let fileList
      this.listVisible = false
      reviewMaterialApi.getNextmsg.setReviewNo({ flag: this.commitStatus }).then(res => {
        this.$LoadingClose()
        fileList = res.data
        if (fileList.showButton === '0') {
          this.nextButton = true
        } else {
          this.nextButton = false
        }
        this.detailForm = res.data
        this.detailForm.fileId = []
        if (fileList && fileList.length > 0) {
          this.downloadVisible = true
          fileList.forEach(res => {
            this.detailForm.fileId.push(res.fileId)
          })
        } else {
          this.downloadVisible = false
        }
        if (fileList.analysisStatus === '1' && fileList.reviewStatus !== '0') { // 已分析、已复核/无需复核取knowledgeMgrDtoList值，并且添加analyseWay
          fileList.knowledgeMgrDtoList.map((res, index) => { // 添加analyseWay值
            fileList.knowledgeMgrDtoList[index].analyseWay = fileList.materialAnalyzeDtoList[index].analyseWay
          })
          this.sourceData = fileList.knowledgeMgrDtoList
        } else {
          this.sourceData = fileList.materialAnalyzeDtoList
        }
        this.listVisible = true
      })
    },
    // 插件返回数据
    callbackData (val) {
      this.parameters = val
    },
    // 提交
    submits (subInx, next) {
      this.$refs.repositoryListNew.callbackDataFun()
      let getData = this.parameters
      if (getData && getData.length === 0) {
        this.warning(this.$t('feedbackMaterialIndex.SelectKnowledgeBase'))
        return
      }
      if (!getData) {
        return
      }
      let putData = Object.assign({}, this.detailForm)
      putData.materialAnalyzeDtoList = getData
      putData.voltooideStatus = subInx // 暂存、保存
      putData.knowledgeMgrDtoList = getData
      putData.dealStatus = this.commitStatus // 分析、复核
      this.$LoadingShow()
      reviewMaterialApi.analyzeInfo.transpond(putData).then(res => {
        if (res.data) {
          if (putData.voltooideStatus === '0') { // 提交（暂存是1，提交是0）
            this.success(this.$t('common.submittedSuccess'))
          } else { // 暂存
            this.success(this.$t('common.temporarynSuccess'))
          }
          this.$LoadingClose()
          this.$emit('getTable')
        } else {
          this.error(this.$t('common.submitFailure'))
          return
        }
        if (next) {
          this.listVisible = false
          this.$emit('handleFilter')
          this.getNextInfo()
        } else {
          this.close()
        }
      })
    },
    // 关闭弹窗
    close () {
      this.dialogVisible = false
    },
    // 获取分析的方式
    getRadio (data) {
      this.radio = data
    },
    // 获取文件类型字符串
    getFileDict (type) {
      if (type === '01') {
        return '单一文件'
      } else {
        return '多个文件'
      }
    },
    // 详情
    getInfo (keyId) {
      reviewMaterialApi.getAnalysisInfo.get(keyId).then(res => {
        if (res.data.analysisStatus === '0') { // 判断修改提交并分析下一条
          this.nextArticle = this.$t('common.analysisTips')
        } else {
          this.nextArticle = this.$t('common.reviewTips')
        }
        if (JSON.stringify(res.data.materialRygxExtDtoList) !== '{}' && res.data.materialRygxExtDtoList.keyId) {
          this.materialAnalyzeDTO_keyId = res.data.materialRygxExtDtoList.keyId
        }
        let fileList = res.data.accessoryExtDtoList // 附件
        this.getInfoData = res.data
        this.sourceData = JSON.parse(JSON.stringify(res.data.materialAnalyzeDtoList)) // 分析/复核数据
        this.sourceDataK = JSON.parse(JSON.stringify(res.data.knowledgeMgrDtoList)) // 分析/复核数据（仅知识库）
        this.sourceData.map((res, index) => {
          if (this.sourceDataK) { // 是否存在知识库数据，存在替换applicableProjectName（适用产品名）为知识库适用产品名
            let knowledge = this.sourceDataK.find(item => item.keyId === res.keyId)
            if (knowledge) {
              this.sourceData[index].applicableProjectName = knowledge.applicableProjectName
            }
          }
          if (res.analyseWay === '01') {
            this.sourceData[index].keyId = res.knowledgeBaseId
          }
        })
        if (res.data.showButton === '0') { // 下一条
          this.nextButton = true
        } else {
          this.nextButton = false
        }
        this.detailForm = res.data
        let per = res.data.committeeMemberNames.split('、') // 判断评审委员会全部人员
        if (per.indexOf(res.data.committeePrincipal) === -1) {
          per.push(res.data.committeePrincipal)
        }
        per = per.join('、')
        this.detailForm.committeeMemberNamesMerge = per
        this.detailForm.fileId = []
        if (fileList && fileList.length > 0) {
          this.downloadVisible = true
          fileList.forEach(res => {
            this.detailForm.fileId.push(res.fileId)
          })
        } else {
          this.downloadVisible = false
        }
        this.listVisible = true
      })
    },
    // 文件下载
    FileBatchDown () {
      return this.detailForm.fileId
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
