// 分析、复核共通组件-zhl
<template>
  <div class="repositoryListNew">
    <div style="position: absolute;top:10px;right:10px; z-index:999;" class="addDleBut">
      <!-- 新增 -->
      <auth-button icon="iconfont iconxinzeng"
                  v-if="activeName === '2' && pageType !== 'V'"
                  :size="'medium'"
                  :label="$t('feedbackMaterialIndex.addT')"
                  type="primary"
                  @click="formItemAdd(0)"></auth-button>
      <!-- 删除 -->
      <auth-button icon="iconfont iconshanchu"
                  v-if="activeName === '2' && pageType !== 'V' && deleShow"
                  :size="'medium'"
                  :label="$t('common.delete')"
                  type="danger"
                  @click="formItemDel(0)"></auth-button>
    </div>
    <el-tabs v-model="activeName" type="card">
      <!-- 知识库 -->
      <el-tab-pane label="选择已有知识库" name="1" v-if="tabPaneShow1">
        <div style="display:flex; width:100%;align-items: center;padding:0 10px;margin-top: 2px;"
             v-if="pageType !== 'V'">
          <div style="font-size:14px; color:#666;padding-left:10px;flex-shrink: 0;">
            {{$t('knowledgeBaseIndex.keyWord')}}
          </div>
          <!-- 关键字检索 -->
          <yf-es-search class="yfesSearch-item"
                        style="flex:1; align-items: center"
                        ref="yfEsSearchItem"
                        @callbackFunc="callbackFunc"
                        v-bind="yfEsSearchData"
                        :inputToolTip="inputToolTip"
                        :btnAttrs="btnAttrs"
                        :shouldBefore="true"
                        :beforeLoad="beforeLoad"
                        :paramPostDaata="paramPostDaata"></yf-es-search>
          <!-- 高级检索 -->
          <el-button type="primary"
                     size="medium"
                     @click="isAddShow()">
            <span class="icon iconfont">&#xe6e1;</span>
            {{$t('knowledgeBaseIndex.advancedSearch')}}
          </el-button>
          <!-- 重置 -->
          <el-button size="medium"
                     @click="resetSearch">
            <span class="icon iconfont">&#xe63d;</span>
            {{$t('common.reset')}}</el-button>
        </div>
        <data-table ref="tableData"
                    operateBtnLayout=""
                    :pageSizes="pageSizes"
                    :max-height="300"
                    :queryParas="yfEsSearchData.pageConfig"
                    :sourceData.sync="getTableData"
                    :columns="columns"
                    v-if="pageType !== 'V'"
                    :showSelection="true"
                    :showPage="knowledgeShowPage"
                    @currentChange="currentChange"
                    @sizeChange="sizeChange"
                    @selectRowChange="selectRowChange">
          <!-- 文字折叠 -->
          <template slot="fileName"
                    slot-scope="scope">
            <span-plus :index="scope.data.$index"
                        :text="scope.data.row.fileName"></span-plus>
          </template>
          <template slot="problemType"
                    slot-scope="scope">
            <span-plus :index="scope.data.$index"
                        :text="scope.data.row.problemType"></span-plus>
          </template>
          <template slot="problemPoint"
                    slot-scope="scope">
            <span-plus :index="scope.data.$index"
                        :text="scope.data.row.problemPoint"></span-plus>
          </template>
          <template slot="solution"
                    slot-scope="scope">
            <span-plus :index="scope.data.$index"
                        :text="scope.data.row.solution"></span-plus>
          </template>
          <template slot="applicableProjectName"
                    slot-scope="scope">
            <span-plus :index="scope.data.$index"
                        :text="scope.data.row.applicableProjectName"></span-plus>
          </template>
          <el-table-column :label="$t('common.operate')"
                          align="center"
                          width="100"
                          fixed="right">
            <template slot-scope="scope">
              <auth-button size="small"
                           class="iconCircle marginLeft"
                           icon="iconfont iconlvli"
                           :title="$t('knowledgeBaseIndex.feedback')"
                           @click="showEdit(scope.row.keyId, 'P')"></auth-button>
            </template>
          </el-table-column>
          <template slot="paginationLeft" v-if="advancedShowPage">
            <div style="float: right;">
               <!-- 高级检索页码 -->
              <el-pagination  @size-change="handleSizeChange"
                              @current-change="handleCurrentChange"
                              :current-page="pageConfig.pageIndex"
                              :page-sizes="[5, 10, 20, 30, 40, 50]"
                              :page-size="pageConfig.pageSize"
                              prev-text="上一页"
                              next-text="下一页"
                              layout="total, sizes, prev, pager, next, jumper"
                              :total="pageConfig.totalCount"></el-pagination>
            </div>
          </template>
        </data-table>
        <!-- 已选 -->
        <div data-v-efdee4ac=""
             v-if="pageType !== 'V'"
             class="titleLine">
          {{$t('knowledgeBaseIndex.selectedTitle')}}</div>
        <data-table ref="selectedTableData"
                    operateBtnLayout=""
                    :max-height="300"
                    :showPage="false"
                    :showSelection="false"
                    :sourceData.sync="slectedData"
                    :columns="columns">
          <!-- 文字折叠 -->
           <template slot="fileName"
                    slot-scope="scope">
            <span-plus :index="scope.data.$index"
                        :text="scope.data.row.fileName"></span-plus>
          </template>
          <template slot="problemType"
                    slot-scope="scope">
            <span-plus :index="scope.data.$index"
                        :text="scope.data.row.problemType"></span-plus>
          </template>
          <template slot="problemPoint"
                    slot-scope="scope">
            <span-plus :index="scope.data.$index"
                       :text="scope.data.row.problemPoint"></span-plus>
          </template>
          <template slot="solution"
                    slot-scope="scope">
            <span-plus :index="scope.data.$index"
                        :text="scope.data.row.solution"></span-plus>
          </template>
          <template slot="applicableProjectName"
                    slot-scope="scope">
            <span-plus :index="scope.data.$index"
                        :text="scope.data.row.applicableProjectName"></span-plus>
          </template>
          <!-- 操作 -->
          <el-table-column :label="$t('common.operate')"
                           align="center"
                           v-if="pageType !== 'V'"
                           width="100"
                           fixed="right">
            <template slot-scope="scope">
              <!-- 删除 -->
              <auth-button size="small"
                           type="danger"
                           class="pssc-css iconCircle marginLeft"
                           icon="iconfont iconycjian"
                           :title="$t('common.delete')"
                           @click="del(scope.$index, scope.row)"></auth-button>
            </template>
          </el-table-column>
        </data-table>
      </el-tab-pane>
      <!-- 自定义 -->
      <el-tab-pane label="自定义分析内容" name="2" v-if="tabPaneShow2">
        <el-form ref="submitForm"
                 :model="formDomData"
                 :disabled="pageType === 'V'"
                 size="medium">
          <el-row v-for="(formItem, index) in formDomData.opinionsDTO"
                  :key="index"
                  style="background: rgba(247, 247, 247, 1); padding: 0px 0px 15px; margin-top:5px">
            <el-row style="height:48px; background:rgba(255, 255, 255, 1)"
                    v-if="activeName === '2' && index !== 0">
              <!-- 新增 -->
              <auth-button icon="iconfont iconxinzeng"
                           style="position: absolute;top:0px;right:100px; z-index:999;margin-top:5px"
                           v-if="pageType !== 'V'"
                           :size="'medium'"
                           :label="$t('feedbackMaterialIndex.addT')"
                           type="primary"
                           @click="formItemAdd(index)"></auth-button>
              <!-- 删除 -->
              <auth-button icon="iconfont iconshanchu"
                           style="position: absolute;top:0px;right:0px; z-index:999;margin-top:5px"
                           v-if="pageType !== 'V'"
                           :size="'medium'"
                           :label="$t('common.delete')"
                           type="danger"
                           @click="formItemDel(index)"></auth-button>
            </el-row>
            <el-row style="margin-top:16px; padding:0 10px">
              <el-col :span="8">
                <el-form-item :label="$t('knowledgeBaseIndex.fileType')"
                              :prop="'opinionsDTO.' + index + '.fileType'"
                              label-width="100px"
                              :rules="[
                                {
                                  required: true,
                                  message: $t('common.pleaseSelect') + $t('feedbackMaterialIndex.fileType'),
                                  trigger: ['blue','change']
                                }
                              ]">
                  <!-- 备注：dictTypeCode="FILE_TYPE"要修改成HG_FILE_TYPE -->
                  <SelectDictionaryNew name='fileType'
                                       :disabled="currentDisabled"
                                       v-model="formItem.fileType"
                                       dictTypeCode="HG_FILE_TYPE"
                                       @selectChanged="fileTypeChanged(index, $event)"></SelectDictionaryNew>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item :label="$t('knowledgeBaseIndex.fileName')"
                              :prop="'opinionsDTO.' + index + '.fileId'"
                              label-width="100px"
                              :rules="[
                                {
                                  required: true,
                                  message: $t('common.pleaseSelect') + $t('feedbackMaterialIndex.fileName'),
                                  trigger: ['blue','change']
                                }
                              ]">
                  <el-select v-model="formItem.fileId"
                             style="width:100%"
                             collapse-tags
                             popper-class="optionStyle"
                             multiple
                             filterable
                             clearable
                             :multiple-limit="10"
                             @change="changeFun($event, index )"
                             :placeholder="$t('common.pleaseSelect')">
                    <el-option v-for="(item, key) in options"
                              :key="key"
                              :label="item.fileName"
                              :value="item.keyId"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item :label="$t('knowledgeBaseIndex.problemType')"
                              :prop="'opinionsDTO.' + index + '.problemType'"
                              label-width="100px"
                              :rules="[
                                {
                                  required: true,
                                  message: $t('common.pleaseInput') + $t('feedbackMaterialIndex.problemType'),
                                  trigger: ['blue','change']
                                }
                              ]">
                  <el-autocomplete clearable
                                   :maxlength="12"
                                   :disabled="currentDisabled"
                                   v-model="formItem.problemType"
                                   :fetch-suggestions="problemTypeAsync"
                                   :placeholder="$t('common.pleaseInput')"></el-autocomplete>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item :label="$t('knowledgeBaseIndex.problemPoint')"
                              :prop="'opinionsDTO.' + index + '.problemPoint'"
                              label-width="100px"
                              :rules="[
                                {
                                  required: true,
                                  message: $t('common.pleaseInput') + $t('feedbackMaterialIndex.problemPoint'),
                                  trigger: ['blue','change']
                                }
                              ]">
                  <el-autocomplete clearable
                                   :maxlength="25"
                                   :disabled="currentDisabled"
                                   v-model="formItem.problemPoint"
                                   :fetch-suggestions="problemPointAsync"
                                   :placeholder="$t('common.pleaseInput')"></el-autocomplete>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item :label="$t('knowledgeBaseIndex.solution')"
                              :prop="'opinionsDTO.' + index + '.solution'"
                              label-width="100px"
                              :rules="[
                                {
                                  required: true,
                                  message: $t('common.pleaseInput') + $t('feedbackMaterialIndex.solution'),
                                  trigger: ['blue','change']
                                }
                              ]">
                  <el-input :disabled="currentDisabled"
                            v-model="formItem.solution"
                            :placeholder="$t('common.pleaseInput')"
                            :maxlength="500"
                            type="textarea"
                            style="width:100%"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row style="text-align: center;" v-if="pageType !== 'V'">
              <auth-button label="查 重"
                           type="primary"
                           size="medium"
                           @click="fCnki(formItem, index)"></auth-button>
            </el-row>
          </el-row>
        </el-form>
      </el-tab-pane>
    </el-tabs>
    <!-- 高级检索 -->
    <advanced-search ref="advancedForm"
                     :clickPosition='clickPosition'
                     :visible.sync="dialogFormVisible"
                     :parameter="pageConfig"
                     @advancedUpData="advancedUpData"
                     @advSearchData='advSearchData'></advanced-search>
    <!-- 反馈意见 -->
    <create-feedback v-if="dialogFeedbackVisible"
                    :visible.sync="dialogFeedbackVisible"
                    :feedbackKeyId="feedbackKeyId"></create-feedback>
    <!-- 查重 -->
    <cnki :cnkiData="cnkiData"
          @dleFromData="dleFromData"
          @cnkiSave="cnkiSave"></cnki>
  </div>
</template>

<script>
import knowledgeBaseApi from '@/api/assetaudit/knowledgeBaseApi'
import * as format from '@/filters/index'
import cnki from '@/components/element/assetaudit/cnki'
import SelectFileNameNew from '@/components/element/assetaudit/SelectFileNameNew'
import SelectDictionaryNew from '@/components/element/zhunru/SelectDictionaryNew'
import CreateFeedback from '@/pages/assetaudit/reviewMaterial/createFeedback'
import AdvancedSearch from '@/pages/assetaudit/cKnowledgeBase/advancedSearch'
import BasePage from '@/pages/basePage'
import { DataTable, authButton, searchForm, SpanPlus, yfEsSearch } from 'newepoch-components'
export default {
  extends: new BasePage(),
  components: {
    cnki,
    SelectFileNameNew,
    SelectDictionaryNew,
    SpanPlus,
    CreateFeedback,
    AdvancedSearch,
    DataTable,
    authButton,
    searchForm,
    yfEsSearch
  },
  props: {
    // 页面状态 -- E 编辑 V 查看
    pageType: {
      type: String,
      default () {
        return 'E'
      }
    },
    // 传入值
    sourceData: {
      type: Array,
      default () { // 默认值
        return [
          { // 知识库对象
            // analyseWay: '01',
            // fileType: '文件类型',
            // fileName: '文件名称',
            // problemType: '问题类型',
            // problemPoint: '问题点',
            // solution: '解决方式',
            // applicableProjectName: '适用项目'
          },
          { // 自定义对象
            // analyseWay: '02',
            // fileType: '01',
            // fileName: ['1', '2'],
            // problemType: '测试',
            // problemPoint: '测试',
            // solution: '测试'
          }]
      }
    }
  },
  data () {
    return {
      deleShow: false, // 第一删除按钮是否显示
      inputToolTip: this.$t('common.keywordPrompt'),
      tabPaneShow1: true, // 是否显示切换页面
      tabPaneShow2: true, // 是否显示切换页面
      options: [], // 文件下拉数据
      feildData: [ // 文件名称
        {
          fileId: '',
          fileNameStr: ''
        }
      ],
      pageSizes: [5, 10, 20, 30, 40, 50], // 每页显示
      pageChange: false, // 判断是否页面切换
      slectedDataChange: [],
      checkType: '1',
      advancedShowPage: false, // 高级检索分页
      knowledgeShowPage: false, // 知识库分页
      cnkiData: { // 查重
        dialogVisible: false,
        fromData: {}, // 表单数据
        showSave: true
      },
      formDomData: { // 自定义form数据
        opinionsDTO: [
          {
            fileType: '',
            fileId: [],
            problemType: '',
            problemPoint: '',
            solution: ''
          }
        ]
      },
      dialogFeedbackVisible: false, // 反馈意见显示和隐藏
      pageConfig: { // 高级检出分页
        pageIndex: 1,
        pageSize: 5,
        totalCount: 0
      },
      dialogFormVisible: false, // 高级检索显示和隐藏
      clickPosition: '',
      yfEsSearchData: { // 关键词检索提交数据
        // configUrl: 'http://es.cdyfsz.com',
        // module: 'ckb_knowledge_base',
        filterKeys: [{ name: 'field_advance_group', modle: 'must' }],
        sortKeys: '',
        shouldBefore: true,
        pageConfig: {
          pageIndex: 1,
          pageSize: 5,
          totalCount: 0
        },
        autoSearch: false,
        placeholder: this.$i18n.messages[this.$i18n.locale].retrievalIndex.inputKeyWord,
        recommendKey: { name: 'field_advance_group', modle: 'must' },
        defauleKeys: [
          { name: 'voltooide_status', type: 'term', value: '0' },
          { name: 'data_status', type: 'term', value: '01' },
          { name: 'del_status', type: 'term', value: '0' }
        ],
        nullSeachAll: false
      },
      btnAttrs: { size: 'medium' }, // 关键字检索按钮属性
      columns: [ // 表格列数据
        { // 解决方案编号
          prop: 'solutionCode',
          align: 'center',
          width: '100px',
          label: this.$t('knowledgeBaseIndex.solutionCode')
        },
        { // 文件类型
          prop: 'fileType',
          align: 'center',
          width: '100px',
          label: this.$t('knowledgeBaseIndex.fileType'),
          format: (row) => {
            return format.formatDict(row.fileType, 'HG_FILE_TYPE')
          }
        },
        { // 文件名称
          prop: 'fileName',
          align: 'left',
          width: '100px',
          label: this.$t('knowledgeBaseIndex.fileName'),
          slot: true
        },
        { // 问题类型
          prop: 'problemType',
          align: 'left',
          width: '100px',
          label: this.$t('knowledgeBaseIndex.problemType'),
          slot: true
        },
        { // 问题点
          prop: 'problemPoint',
          align: 'left',
          width: '100px',
          label: this.$t('knowledgeBaseIndex.problemPoint'),
          slot: true
        },
        { // 解决方式
          prop: 'solution',
          align: 'left',
          width: '100px',
          label: this.$t('knowledgeBaseIndex.solution'),
          slot: true
        },
        { // 适用产品
          prop: 'applicableProjectName',
          align: 'left',
          width: '100px',
          label: this.$t('knowledgeBaseIndex.production'),
          slot: true
        }
      ],
      getTableData: [ // table数据
        // {
        //   fileType: '文件类型',
        //   fileName: '文件名称',
        //   problemType: '问题类型',
        //   problemPoint: '问题点',
        //   solution: '解决方式',
        //   applicableProjectName: '适用项目'
        // }
      ],
      slectedData: [ // 选中数据（提交的table数据）
        // {
        //   keyId: '2004091456269330001',
        //   solutionCode: '2020-0005',
        //   fileType: '文件类型',
        //   fileName: '文件名称',
        //   problemType: '问题类型',
        //   problemPoint: '问题点',
        //   solution: '解决方式',
        //   applicableProjectName: '适用项目'
        // }
        // {
        // keyId: '2004091511066820001',
        // solutionCode: '2020-0006',
        // fileType: '文件类型',
        // fileName: '文件名称',
        // problemType: '问题类型',
        // problemPoint: '问题点',
        // solution: '解决方式',
        // applicableProjectName: '适用项目'
        // }
      ],
      activeName: '1' // 默认tabs
    }
  },
  computed: {
    currentDisabled () {
      if (this.pageType === 'V') {
        return true
      } else {
        return false
      }
    }
  },
  mounted () {
    this.envSetFun()
    this.getListData()
    this.decompositionData()
    this.tabPaneShowFun()
  },
  watch: {
    // 监听关键词是否输入字符串空，替换防止查询不了数据
    // '$refs.yfEsSearchItem.$data.esValue': {
    //   handler (val) {
    //     console.log(val, '关键词数据')
    //   },
    //   deep: true
    // },
    // 监听form表单数据是否等于1,不显示删除-----%%%
    'formDomData.opinionsDTO': {
      handler (val) {
        if (val.length === 1) {
          this.deleShow = false
        } else {
          this.deleShow = true
        }
      },
      deep: true
    },
    // 监听当前页是否发生改变（关键字）
    'yfEsSearchData.pageConfig.pageIndex': {
      handler () {
        this.pageChange = true
      },
      deep: true
    },
    // 监听当前页是否发生改变（高级检索）
    'pageConfig.pageIndex': {
      handler () {
        this.pageChange = true
      },
      deep: true
    },
    // 监听是勾选和取消勾选的数据
    slectedDataChange: {
      handler (val, old) {
        if (this.pageChange) { // 判断是否发生了切换table页面，防止切换时导致selectTable 被清空
          val = []
          old = []
        }
        this.pageChange = false
        if (val.length < old.length) {
          let keyId = []
          keyId = val.map(res => {
            return res.keyId
          })
          let dataArr = old.filter(res => keyId.indexOf(res.keyId) === -1)
          dataArr.map(val => {
            this.slectedData.map((res, index) => {
              if (res.keyId === val.keyId) {
                this.slectedData.splice(index, 1)
              }
            })
          })
        }
      },
      deep: true
    },
    // 监听知识库列表
    getTableData: {
      handler (val) {
        if (val.length > 0 && this.slectedData.length > 0) {
          let data = JSON.parse(JSON.stringify(this.slectedData))
          let same = [] // 相同的
          data.map((res, i) => {
            this.getTableData.map((item, j) => {
              if (item.keyId === res.keyId) {
                same.push(item)
              }
            })
          })
          this.$nextTick(() => {
            same.forEach(res => {
              this.getTableData.forEach(item => {
                if (item.keyId === res.keyId) {
                  this.$refs.tableData.$refs.vueTable.toggleRowSelection(item)
                }
              })
            })
          })
        }
      },
      deep: true
    }
  },
  methods: {
    paramPostDaata (data) {
      let inputVal = this.$refs['yfEsSearchItem'].esValue
      if (data.query.match_all !== undefined) {
        data.query.bool = {}
        data.query.bool.filter = [
          { term: { 'voltooide_status': '0' } },
          { term: { 'data_status': '01' } },
          { term: { 'del_status': '0' } }
        ]
        delete data.query.match_all
      }
      if (inputVal !== null && inputVal !== '' && inputVal !== undefined) {
        data.query.bool.must = [
          { match: { 'field_advance_group': inputVal } }
        ]
      } else {
        if (data.query.bool !== undefined) {
          data.query.bool.must = []
        }
      }
      return data
    },
    // 设置关键词环境变量
    envSetFun () {
      this.$set(this.yfEsSearchData, 'configUrl', process.env.VUE_APP_CONFIG_URL)
      this.$set(this.yfEsSearchData, 'module', process.env.VUE_APP_KNOWLEDGE_BASE)
    },
    // 关键词检索loding
    keywordLoading () {
      this.keyloading = this.$loading({
        lock: true,
        text: '加载中',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
    },
    // 关键词检索loding（关闭）
    keywordLoadingClose () {
      this.keyloading.close()
    },
    // 查重返回数据，判断是否存在知识库数据，存在勾选相同数据
    checkDataFCnki () {
      if (this.getTableData.length > 0) {
        this.slectedData.map((res, index) => {
          this.getTableData.find(item => {
            if (res.keyId === item.keyId) {
              this.$nextTick(() => {
                this.$refs.tableData.$refs.vueTable.toggleRowSelection(item, true)
              })
            }
          })
        })
      }
    },
    // 监听数据判断切换
    tabPaneShowFun () {
      if (this.pageType === 'V') {
        if (this.slectedData.length === 0) {
          this.activeName = '2'
          this.tabPaneShow1 = false
        } else if (this.formDomData.opinionsDTO.length === 0) {
          this.activeName = '1'
          this.tabPaneShow2 = false
        }
      } else {
        if (this.slectedData.length === 0 && this.formDomData.opinionsDTO.length === 1 && !this.formDomData.opinionsDTO[0].fileType) { // 没有select数据和form数据
          this.activeName = '1'
        } else if (this.slectedData.length === 0) {
          this.activeName = '2'
        } else if (this.formDomData.opinionsDTO.length === 0) {
          this.activeName = '1'
        }
      }
    },
    // 获取列表
    getListData () {
      let data = {}
      knowledgeBaseApi.knowledgeBaseList.getFileName(data).then(res => {
        this.options = res.data
      })
    },
    // 下拉触发
    changeFun (val, i) {
      let arr = []
      val.map(res => {
        this.options.map(item => {
          if (item.keyId === res) {
            arr.push(item.fileName)
          }
        })
      })
      this.feildData[i] = {
        fileId: val.toString(),
        fileName: arr.toString()
      }
    },
    // 高级检索提交值
    advancedUpData (data) {
      this.$refs['yfEsSearchItem'].esValue = null // 点击高级检索保存，清空输入框（设置为null，防止关键词检索失效）
      this.advancedUpDataEmit = data
    },
    // 每页条数（高级）
    handleSizeChange (val) {
      let updata = this.advancedUpDataEmit
      updata.pageSize = val
      knowledgeBaseApi.knowledgeBaseList.advancedSearch(updata).then(res => {
        this.getTableData = res.data.datas
        this.pageConfig.pageIndex = res.data.pageIndex
        this.pageConfig.pageSize = res.data.pageSize
        this.pageConfig.totalRow = res.data.totalRow
      })
    },
    // 当前页（高级）
    handleCurrentChange (val) {
      let updata = this.advancedUpDataEmit
      updata.pageIndex = val
      knowledgeBaseApi.knowledgeBaseList.advancedSearch(updata).then(res => {
        this.getTableData = res.data.datas
        this.pageConfig.pageIndex = res.data.pageIndex
        this.pageConfig.pageSize = res.data.pageSize
        this.pageConfig.totalRow = res.data.totalRow
      })
    },
    // 查重成功，删除指定的from元素值
    dleFromData (dleIndex) {
      if (this.formDomData.opinionsDTO.length > 1) {
        this.formDomData.opinionsDTO.splice(dleIndex, 1)
      } else {
        this.$set(this.formDomData.opinionsDTO[dleIndex], 'fileType', '')
        this.$set(this.formDomData.opinionsDTO[dleIndex], 'fileId', [])
        this.$set(this.formDomData.opinionsDTO[dleIndex], 'problemType', '')
        this.$set(this.formDomData.opinionsDTO[dleIndex], 'problemPoint', '')
        this.$set(this.formDomData.opinionsDTO[dleIndex], 'solution', '')
      }
      this.$nextTick(() => {
        this.$refs.submitForm.clearValidate() // 清除表单验证
      })
    },
    // 表格表单值返出值
    callbackDataFun () {
      let tableArr = this.slectedData
      tableArr.forEach((res, index) => { // 列表部分
        tableArr[index].analyseWay = '01'
        tableArr[index].knowledgeBaseId = tableArr[index].keyId // 添加知识库管理id
      })
      let formArr = JSON.parse(JSON.stringify(this.formDomData.opinionsDTO)) // 表单部分
      let Exist = false // 是否只有一条自定义值数据
      if (formArr[0].fileType || formArr[0].fileId.length > 0 || formArr[0].problemType || formArr[0].problemPoint || formArr[0].solution) {
        Exist = true
        if (formArr.length > 0) {
          let data = formArr.find(res => { // 检测未填写值
            if (!res.fileType || res.fileId.length === 0 || !res.problemType || !res.problemPoint || !res.solution) {
              return res
            }
          })
          if (data) { // 判断是否有未填自定义数据
            this.warning(this.$t('reviewMaterialIndex.formFillOut'))
            return
          }
        }
        let Duplicate = formArr.find(res => { // 判断是否有重复数据
          let arr = formArr.filter(item => res.fileType === item.fileType && res.fileId.toString() === item.fileId.toString() && res.problemType === item.problemType && res.problemPoint === item.problemPoint && res.solution === item.solution)
          if (arr.length > 1) {
            return res
          }
        })
        if (Duplicate) { // 存在重复
          this.warning(this.$t('common.Duplicate'))
          return
        }
        for (let i = 0; i < formArr.length; i++) {
          if (formArr[i].fileType === '01' && formArr[i].fileId.length > 1) { // 判断单选多选文件
            this.warning(this.$t('knowledgeBaseIndex.oneSelect'))
            return
          } else if (formArr[i].fileType === '02' && formArr[i].fileId.length === 1) {
            this.warning(this.$t('knowledgeBaseIndex.moreSelect'))
            return
          }
          formArr[i].analyseWay = '02'
          formArr[i].fileDic = format.formatDict(formArr[i].fileType, 'HG_FILE_TYPE') // 添加fileDic
          formArr[i].fileTypeStr = formArr[i].fileDic // 添加fileTypeStr
          if (this.feildData[i] && this.feildData[i].fileId) {
            formArr[i].fileId = JSON.parse(JSON.stringify(this.feildData[i].fileId)).toString() // fileId转字符
            formArr[i].fileName = JSON.parse(JSON.stringify(this.feildData[i].fileName)).toString() // fileId转字符
          } else {
            formArr[i].fileId = formArr[i].fileId.toString()
          }
        }
      }
      if (Exist) {
        let repeatData = tableArr.find(res => { // 判断知识库和自定义是否重复
          return formArr.find(item => item.fileType === res.fileType && item.fileName === res.fileName && item.problemType === res.problemType && item.problemPoint === res.problemPoint && item.solution === res.solution)
        })
        if (repeatData) {
          this.warning(this.$t('reviewMaterialIndex.repeatData'))
          return
        }
        let concatArr = tableArr.concat(formArr)
        this.$emit('callbackData', concatArr) // 返回的数据
      } else {
        this.$emit('callbackData', tableArr)
      }
    },
    // 分解传入数据
    decompositionData () {
      let repository = []
      let custom = []
      this.sourceData.forEach(res => {
        if (res.analyseWay === '01') {
          repository.push(res)
        } else if (res.analyseWay === '02') {
          custom.push(res)
          custom.forEach((item, index) => {
            if (typeof (item.fileId) === 'string') {
              custom[index].fileId = item.fileId.split(',') // 文件id
            } else {
              custom[index].fileId = item.fileId
            }
            custom[index].fileName = item.fileName // 文件名
          })
        }
      })
      this.slectedData = JSON.parse(JSON.stringify(repository))
      if (custom.length > 0) {
        this.formDomData.opinionsDTO = JSON.parse(JSON.stringify(custom))
      } else if (this.pageType === 'V' && custom.length === 0) {
        this.formDomData.opinionsDTO = []
      }
    },
    // 文件格式改变
    fileTypeChanged (index, data) {
      if (data[2] && JSON.stringify(data[2]) !== '{}') {
        this.formDomData.opinionsDTO[index].fileTypeStr = format.formatDict(data[2].dictId, 'HG_FILE_TYPE')
      } else {
        this.formDomData.opinionsDTO[index].fileTypeStr = ''
      }
    },
    // 文件名下拉修改
    fileNameChanged (index, data) {
      if (data && data.length > 0) {
        let fileId = []
        let fileName = []
        data.map(res => {
          fileId.push(res.keyId)
          fileName.push(res.fileName)
        })
        if (!this.feildData[index]) {
          this.feildData[index] = {
            fileId: '',
            fileName: ''
          }
        }
        this.feildData[index].fileId = fileId.toString()
        this.feildData[index].fileName = fileName.toString()
      }
    },
    // 查重返回数据
    cnkiSave (data) {
      let temp = {
        solutionCode: data.solutionCode,
        analyseWay: '01',
        fileType: data.fileType,
        // fileName: data.fileId.split(','),
        fileName: data.fileName,
        problemType: data.problemType,
        problemPoint: data.problemPoint,
        solution: data.solution,
        keyId: data.keyId,
        applicableProjectName: data.applicableProjectName
      }
      this.$nextTick(() => {
        this.activeName = '1'
        if (this.slectedData.find(res => res.keyId === temp.keyId)) { // 判断选中项是否已存在
          this.warning(this.$t('reviewMaterialIndex.recheckAlready'))
        } else {
          this.slectedData.push(temp)
        }
        this.checkDataFCnki()
      })
    },
    // 查重
    fCnki (data, index) {
      if (data.fileType === '01' && data.fileId.length > 1) {
        this.warning(this.$t('knowledgeBaseIndex.oneSelect'))
        return
      } else if (data.fileType === '02' && data.fileId.length === 1) {
        this.warning(this.$t('knowledgeBaseIndex.moreSelect'))
        return
      }
      this.$nextTick(() => {
        this.$refs.submitForm.validate((valid) => {
          if (valid) {
            this.cnkiData.fromData = {
              ...data,
              analysisDataIdex: index
            }
            this.cnkiData.fromData.fileName = JSON.parse(JSON.stringify(this.cnkiData.fromData.fileId)) // fileId赋值为fileName
            delete this.cnkiData.fromData.fileId
            this.cnkiData.dialogVisible = true
            if (this.feildData[index] && this.feildData[index].fileName) { // 没有下拉赋值则使用详情的fileName
              this.cnkiData.fromData.fileNameStr = JSON.parse(JSON.stringify(this.feildData[index].fileName))
            } else {
              this.cnkiData.fromData.fileNameStr = JSON.parse(JSON.stringify(this.formDomData.opinionsDTO[index].fileName))
            }
            let TypeStr = format.formatDict(this.cnkiData.fromData.fileType, 'HG_FILE_TYPE') // 获取文件类型名
            this.cnkiData.fromData.fileTypeStr = JSON.parse(JSON.stringify(TypeStr))
          } else {
            this.warning(this.$t('reviewMaterialIndex.formFillOut'))
          }
        })
      })
    },
    // 删除自定义表单
    formItemDel (index) {
      this.formDomData.opinionsDTO.splice(index, 1)
      this.$nextTick(() => {
        this.$refs.submitForm.clearValidate() // 清除表单验证
      })
    },
    // 新增表单
    formItemAdd (index) {
      let formData = this.formDomData.opinionsDTO
      if (formData.find(res => (!res.fileType || res.fileId.length === 0 || !res.problemType || !res.problemPoint || !res.solution || !res.fileTypeStr))) {
        this.warning(this.$t('common.fillDataHg'))
      } else {
        let arr = {
          fileType: '',
          fileId: [],
          problemType: '',
          problemPoint: '',
          solution: ''
        }
        formData.push(arr)
      }
      // if (index) {
      //   if (formData[index].fileType && formData[index].fileId.length > 0 && formData[index].problemType && formData[index].problemPoint && formData[index].solution && formData[index].fileTypeStr) {
      //     let arr = {
      //       fileType: '',
      //       fileId: [],
      //       problemType: '',
      //       problemPoint: '',
      //       solution: ''
      //     }
      //     formData.push(arr)
      //   } else {
      //     this.warning(this.$t('common.fillDataHg'))
      //   }
      // } else {
      //   if (formData[0].fileType && formData[0].fileId.length > 0 && formData[0].problemType && formData[0].problemPoint && formData[0].solution && formData[0].fileTypeStr) {
      //     let arr = {
      //       fileType: '',
      //       fileId: [],
      //       problemType: '',
      //       problemPoint: '',
      //       solution: ''
      //     }
      //     formData.push(arr)
      //   } else {
      //     this.warning(this.$t('common.fillDataHg'))
      //   }
      // }
    },
    // 请选择问题点
    problemPointAsync (queryString, cb) {
      let data = []
      knowledgeBaseApi.knowledgeBaseList.getSelect({ type: '07' }).then((res) => {
        res.data.forEach(item => {
          data.push({ value: item.name })
        })
        var results = queryString ? data.filter(this.createFilter(queryString)) : data
        cb(results)
      })
    },
    // 请选择问题类型
    problemTypeAsync (queryString, cb) {
      let data = []
      knowledgeBaseApi.knowledgeBaseList.getSelect({ type: '06' }).then((res) => {
        res.data.forEach(item => {
          data.push({ value: item.name })
        })
        var results = queryString ? data.filter(this.createFilter(queryString)) : data
        cb(results)
      })
    },
    // 问题点、问题类型使用的方法
    createFilter (queryString) {
      return (restaurant) => {
        return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0)
      }
    },
    // 当前页面改变时触发
    currentChange (pageIndex, pageSize) {
      this.yfEsSearchData.pageConfig.pageIndex = pageIndex
      this.yfEsSearchData.pageConfig.pageSize = pageSize
      this.keywordCheck()
    },
    // 关键字搜索触发
    keywordCheck () {
      this.$refs.yfEsSearchItem.loadData()
    },
    // 每页显示数
    sizeChange (pageIndex, pageSize) {
      this.yfEsSearchData.pageConfig.pageIndex = pageIndex
      this.yfEsSearchData.pageConfig.pageSize = pageSize
      this.keywordCheck()
    },
    // 反馈意见触发
    showEdit (keyId, editmodel) {
      this.dialogFeedbackVisible = true
      this.feedbackKeyId = keyId
    },

    // 高级检索显示和隐藏
    isAddShow () {
      this.dialogFormVisible = true
      this.clickPosition = 'btn'
    },
    // 清空搜索
    resetSearch () {
      this.$refs.yfEsSearchItem.$data.esValue = null // 设置关键词为null
    },
    // 高级检索返回数据
    advSearchData (data) {
      this.pageChange = true // 添加标识，防止查询时勾选数据丢失
      this.pageConfig.pageSize = data.data.pageSize
      this.pageConfig.pageIndex = data.data.pageIndex
      this.pageConfig.totalCount = data.data.totalRow
      this.checkType = '2' // 关键词检索1 高级检索2
      this.knowledgeShowPage = false // 隐藏知识库分页
      this.advancedShowPage = true // 高级检索分页
      this.$refs.tableData.buildTableData(data.data.datas, data.data.total) // DataTable组件构造函数，使用它自定义赋值'table的表数据'和'总条数'
    },
    // 关键字返回数据
    callbackFunc (data) {
      this.keywordLoadingClose() // 删除loding（关键词检索）
      this.checkType = '1' // 关键词检索1 高级检索2
      this.knowledgeShowPage = true // 隐藏知识库分页
      this.advancedShowPage = false // 高级检索分页
      this.$refs.tableData.buildTableData(data.datas, data.total) // DataTable组件构造函数，使用它自定义赋值table的表数据和总条数
    },
    // 关键字查询前的操作
    beforeLoad (load) {
      this.pageChange = true // 添加标识，防止查询时勾选数据丢失
      this.keywordLoading() // 添加loding（关键词检索）
      if (this.$refs['yfEsSearchItem'].esValue === '') { // 检索前如果为空，修改为null
        this.$refs['yfEsSearchItem'].esValue = null
      }
      this.yfEsSearchData.pageConfig.pageIndex = 1
      if (this.getTableData.length !== 0 && this.getTableData[0].analyseWay === '01') {
        this.radioCheck = this.getTableData[0].knowledgeBaseId
      }
      load()
    },
    // 删除
    del (index, row) {
      this.slectedData.splice(index, 1)
      this.getTableData.map(res => {
        if (res.keyId === row.keyId) {
          this.$refs.tableData.$refs.vueTable.toggleRowSelection(res, false)
        }
      })
    },
    // 行勾选触发（监听选中的值的变化）
    selectRowChange (selection) {
      this.slectedDataChange = selection
      let data = JSON.parse(JSON.stringify(this.slectedData.concat(selection)))
      let obj = {}
      this.slectedData = data.reduce((cur, next) => { // 去重
        // eslint-disable-next-line no-unused-expressions
        obj[next.keyId] ? '' : obj[next.keyId] = true && cur.push(next)
        return cur
      }, [])
    }
  }
}
</script>

<style lang="scss">
  .optionStyle{
    width: 20px;
    /deep/ .el-scrollbar__wrap{ // 下拉高度
      max-height: 195px;
    }
  }
</style>

<style lang="scss" scoped>
.yfesSearch-item{ // 关键字框
  background-color: #ffffff !important;
}
.titleLine {
  color: #606266;
  font-size: 14px;
  word-break: break-all;
  border-bottom: 0px;
  padding-bottom: 0px;
}
.repositoryListNew {
  /deep/ .el-select{ // 解决云测环境自定义不对齐
    margin-left: 0px !important;
  }
  position: relative;
  background-color: #ffffff;
  padding: 10px; // padding 留白
  /deep/ .es-search{
    padding-right: 10px;
  }
  /deep/ .el-tag.el-tag--info{
    max-width: 180px;
  }
  /deep/ .el-table__fixed-right::before{ // 删除操作部分下底
    display: none
  }
  /deep/ .el-tabs__nav-wrap {
    padding-bottom: 5px;
    border-bottom: 2px solid rgba(187, 187, 187, 1);
  }
  /deep/ .el-tabs--card .el-tabs__nav {
    padding-left: 0 !important;
    .el-tabs__item {
      border-radius: 4px !important;
      border-bottom-left-radius: 0px !important;
      border-bottom-right-radius: 0px !important;
      background-color: #D2E1FF !important;
      color: #5c6682 !important;
    }
    .is-active {
      border-radius: 4px !important;
      border-bottom-left-radius: 0px !important;
      border-bottom-right-radius: 0px !important;
      background-color: #1890ff !important;
      color: rgba(255, 255, 255, 1) !important;
    }
    :last-child {
      margin-left: 3px;
    }
  }
  /deep/ .el-tabs--card .el-tabs__item {
    border-radius: 0 !important
  }

  /deep/ .el-tabs__nav-wrap {
    padding-bottom: 0px
  }

  /deep/ .el-tabs__item.is-top{
    border: 0px !important;
  }
  /deep/ .addDleBut{
    .el-button--medium{
      padding: 5px 20px !important;
      // border-bottom-left-radius: 0px !important;
      // border-bottom-right-radius: 0px !important;
    }
  }
}
</style>
