 <!--leixiaoyan 知识库管理 一览-->
<template>
  <div>
    <up-down-layout :handleFlag.sync="handleFlag">
      <search-form :formValue.sync="queryParas"
                   :isShowSearchBtn="isShowSearchBtn"
                   searchPerms="search"
                   @handleFilter="handleFilterSearch"
                   @clearParam="clearParam"
                   slot="query"
                   resetPerms="reset"
                   :componentList="componentList">
          <!-- 查询 -->
          <template slot="beforeBtnArea">
            <auth-button type="primary"
                         :size="'medium'"
                         icon="iconfont iconycchaxun"
                         :label="$t('common.search')"
                         @click="handleFilterSearch()"></auth-button></template>
          <!-- 高级检索 -->
          <template slot="beforeBtnArea">
            <auth-button type="primary"
                         :size="'medium'"
                         icon="iconfont icongaojijiansuo"
                         :label="$t('knowledgeBaseIndex.advancedSearch')"
                         @click="fAdvancedSearch()"></auth-button></template>
      </search-form>
      <template slot="table">
         <data-table :api="apiList"
                     :loadCount.sync="loadCount"
                     v-bind="elHeightObj"
                     :queryParas="queryParas"
                     :sourceData.sync="sourceData"
                     :operateBtnLayout="operateBtnLayout"
                     loadPage="getPage"
                     :pageAll="true"
                     :columns="columns"
                     :menuFlag="menuFlag"
                     ref="dataTable">
            <!-- 文字折叠 -->
            <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="applicableProjects"
                      slot-scope="scope">
              <span-plus :index="scope.data.$index"
                         :text="scope.data.row.applicableProjects ? scope.data.row.applicableProjects : '/'"></span-plus>
            </template>
            <!-- 新增 -->
            <template slot="headButton">
                <div align="right">
                  <auth-button type="primary"
                               size="medium"
                               v-if="check"
                               icon="iconfont iconxinzeng"
                               :label="$t('common.create')"
                               @click="fNewKnowledge()"></auth-button>
                </div>
            </template>
            <!-- 相关素材  -->
            <el-table-column :label="$t('knowledgeBaseIndex.relatedMaterial')"
                             align="center"
                             width="100px"
                             fixed="right">
              <template slot-scope="scope">
                <!-- 查看  -->
                <auth-button class="iconCircle marginLeft"
                             icon="iconfont iconchakan"
                             :title="$t('common.view')"
                             @click="showRelated(scope.row, 'V')"></auth-button>
              </template>
            </el-table-column>
            <!-- 反馈意见  -->
            <el-table-column :label="$t('knowledgeBaseIndex.feedback')"
                              align="center"
                              width="100px"
                              fixed="right">
              <template slot-scope="scope">
                <!-- 待处理 -->
                <auth-button class="iconCircle marginLeft"
                              icon="iconfont icondaichuli"
                              :title="$t('common.pending')"
                              @click="fFeedBack(scope.row, 'hand')"
                              v-if="scope.row.sortcol === '1'"></auth-button>
                <!-- 查看  -->
                <auth-button class="iconCircle marginLeft"
                             icon="iconfont iconchakan"
                             @click="fFeedBack(scope.row, 'see')"
                            :title="$t('common.view')" v-else></auth-button>
              </template>
            </el-table-column>
            <!-- 操作  -->
            <el-table-column :label="$t('common.operate')" align="center" width="260" fixed="right">
              <template slot-scope="scope">
                <!-- 编辑  -->
                <auth-button size="small"
                             class="iconCircle marginLeft"
                             icon="iconfont iconbianji"
                             v-if="check && scope.row.dataStatus==='01'"
                             :title="$t('common.edit')"
                             @click="fEdit(scope.row)"></auth-button>
                <!-- 禁用  -->
                <auth-button size="small"
                             class="iconCircle marginLeft"
                             icon="iconfont iconjinyong1"
                             v-if="check && scope.row.dataStatus==='01'"
                             :title="$t('common.disabled')"
                             @click="enable(scope.row, '0')"></auth-button>
                <!-- 启用 -->
                <auth-button size="small"
                             class="iconCircle marginLeft"
                             icon="iconfont iconqiyong"
                             v-if="check && scope.row.dataStatus==='02'"
                             :title="$t('common.enable')"
                             @click="enable(scope.row, '1')"></auth-button>
                <!-- 修改履历 -->
                <auth-button size="small"
                             class="iconCircle marginLeft"
                             icon="iconfont iconxiugailvli"
                             :title="$t('common.editHistory')"
                             @click="showOperate(scope.row, 'V')"></auth-button>
                <!-- 删除 -->
                <btnDel btnSize="small"
                        class="iconCircle marginLeft"
                        :rowData='scope.row'
                        v-if="check && scope.row.use==='0' && scope.row.dataStatus==='01'"
                        :label="$t('common.del')"
                        :deleteApi="api"
                        @operateBtnClick="operateBtnClick"></btnDel>
                <!-- 查看 -->
                <auth-button size="small"
                             class="iconCircle marginLeft"
                             icon="iconfont iconchakan"
                             :title="$t('common.view')"
                             @click="fEdit(scope.row,true)"></auth-button>
              </template>
            </el-table-column>
          </data-table>
      </template>
    </up-down-layout>
    <!--反馈意见详情 -->
    <feedback-details-pop v-if="dialogFeedbackVisible"
                          :visible.sync="dialogFeedbackVisible"
                          :keyId='keyId'
                          :form="form"
                          :editModel="editModel"
                          :feedBackOperation='feedBackOperation'
                          @operateBtnClick="operateBtnClick"></feedback-details-pop>
    <!-- 知识库新增、编辑 -->
    <knowledge-base-pop v-if="dialogVisible"
                        :visible.sync="dialogVisible"
                        :form="form"
                        :keyId='keyId'
                        :viewMode="viewMode"
                        :editModel="editModelDetail"
                        @operateBtnClick="operateBtnClick"></knowledge-base-pop>
    <!-- 高级检索 -->
    <advanced-search ref="advancedForm"
                     :visible.sync="dialogFormVisible"
                     :flag="flag"
                     @advSearchData="advSearchData"></advanced-search>
    <!-- 相关素材查看 -->
    <related-material-pop v-if="dialogRelatedVisible"
                          :visible.sync="dialogRelatedVisible"
                          :form="form" :keyId='keyId'
                          :editModel="editModel"></related-material-pop>
    <!-- 修改履历 弹窗-->
    <operate-history-pop v-if="dialogHistoryVisible"
                         :visible.sync="dialogHistoryVisible"
                         :form="form"
                         :keyId='keyId'
                         :editModel="editModel"
                         @operateBtnClick="operateBtnClick"></operate-history-pop>
  </div>
</template>

<script>
import * as hgCommon from '@/pages/common/hgCommon'
import issueInputCustom from '@/components/element/assetaudit/issueInput-custom.vue'
import { keyWordInput, searchForm, upDownLayout, SelectDictionary, DataTable, authButton, btnDel, SpanPlus } from 'newepoch-components'
import SelectUpholdPerson from '@/components/element/assetaudit/SelectUpholdPerson'
import KnowledgeBasePop from '@/pages/assetaudit/knowledgeBase/knowledgeBasePop'
import FeedbackDetailsPop from '@/pages/assetaudit/knowledgeBase/feedbackDetailsPop'
import relatedMaterialPop from '@/pages/assetaudit/knowledgeBase/relatedMaterialPop'
import operateHistoryPop from '@/pages/assetaudit/knowledgeBase/operateHistoryPop'
import * as format from '@/filters/index'
import knowledgeBaseApi from '@/api/assetaudit/knowledgeBaseApi'
import reviewPersonApi from '@/api/assetaudit/reviewPersonSetupApi'
import BasePage from '@/pages/basePage'
import mixin from '@/pages/mixin'
import AdvancedSearch from '@/pages/assetaudit/cKnowledgeBase/advancedSearch'
export default {
  extends: new BasePage(),
  mixins: [mixin],
  components: {
    issueInputCustom,
    searchForm,
    upDownLayout,
    SelectUpholdPerson,
    SelectDictionary,
    DataTable,
    authButton,
    btnDel,
    KnowledgeBasePop,
    AdvancedSearch,
    FeedbackDetailsPop,
    relatedMaterialPop,
    operateHistoryPop,
    SpanPlus
  },
  name: 'knowledgeBaseIndex',
  data () {
    return {
      isShowSearchBtn: false,
      flag: '',
      dialogFormVisible: false, // 高级检索弹框
      handleFlag: true,
      form: {},
      sourceData: [],
      operateBtnLayout: '',
      menuFlag: true,
      check: false, // 用户权限
      dialogVisible: false, // 新增编辑弹框
      dialogFeedbackVisible: false, // 修改履历弹框
      dialogRelatedVisible: false, // 相关素材弹框
      editModel: 'V', // 编辑：E,查看:V,新增:C,
      editModelDetail: 'C', // 新增编辑  编辑：E,查看:V,新增:C,
      dialogHistoryVisible: false, // 修改履历
      componentList: [
        {
          // 维护人
          label: this.$t('knowledgeBaseIndex.accendant'),
          disabled: false,
          value: 'upholdPersonId',
          placeholder: this.$t('common.pleaseSelect'),
          labelWidth: '100px',
          clearable: true,
          name: 'upholdPersonName',
          componentName: SelectUpholdPerson
        },
        {
          // 数据状态
          label: this.$t('knowledgeBaseIndex.dataStatus'),
          disabled: false,
          value: 'dataStatus',
          placeholder: this.$t('common.pleaseSelect'),
          labelWidth: '100px',
          clearable: true,
          componentName: 'SelectDictionary',
          dictTypeCode: 'DATA_STATE'
        },
        {
          // 关键词
          label: this.$t('knowledgeBaseIndex.keyWord'),
          disabled: false,
          value: 'keyChar',
          placeholder: this.$t('common.pleaseInput'),
          labelWidth: '100px',
          clearable: true,
          componentName: keyWordInput,
          attrs: {
            toolTip: this.$t('knowledgeBaseIndex.keyWordTop')
          }
        }
      ],
      columns: [
        {
          // 解决方式编号
          prop: 'solutionCode',
          align: 'center',
          width: '130px',
          label: this.$t('knowledgeBaseIndex.solveNo')
        },
        {
          // 文件类型
          prop: 'fileType',
          align: 'center',
          width: '130px',
          label: this.$t('knowledgeBaseIndex.fileType'),
          format: (row) => {
            return format.formatDict(row.fileType, 'HG_FILE_TYPE')
          }
        },
        {
          // 文件名称
          prop: 'fileName',
          align: 'left',
          width: '150px',
          label: this.$t('knowledgeBaseIndex.fileName'),
          slot: true
        },
        {
          // 问题类型
          prop: 'problemType',
          align: 'left',
          width: '150px',
          label: this.$t('knowledgeBaseIndex.problemType'),
          slot: true
        },
        {
          // 问题点
          prop: 'problemPoint',
          align: 'left',
          width: '150px',
          label: this.$t('knowledgeBaseIndex.problemPoint'),
          slot: true
        },
        {
          // 解决方式
          prop: 'solution',
          align: 'left',
          width: '300px',
          label: this.$t('knowledgeBaseIndex.solution'),
          slot: true
        },
        {
          // 适用产品
          prop: 'applicableProjects',
          align: 'left',
          width: '200px',
          label: this.$t('knowledgeBaseIndex.production'),
          slot: true
        },
        {
          // 适用律所
          prop: 'correspondingLawFirmNames',
          align: 'left',
          width: '200px',
          label: this.$t('knowledgeBaseIndex.lawFirm'),
          format: (row) => {
            return hgCommon.formatLs(row) // 转换为空显示‘/’
          }
        },
        {
          // 维护人
          prop: 'upholdPersonName',
          align: 'left',
          width: '100px',
          label: this.$t('knowledgeBaseIndex.accendant')
        },
        {
          // 暂存数据
          prop: 'voltooideStatus',
          align: 'center',
          width: '80px',
          label: this.$t('common.voltooideStatus'),
          format: (row) => {
            return format.formatDict(row.voltooideStatus, 'HG_YES_NO') // 原暂存字典值为01和02，但和返回数据不对应，因此使用HG_YES_NO的字典
          }
        },
        {
          // 数据状态
          prop: 'dataStatus',
          align: 'center',
          width: '100px',
          label: this.$t('knowledgeBaseIndex.dataStatus'),
          format: (row) => {
            return format.formatDict(row.dataStatus, 'DATA_STATE')
          }
        }
      ],
      feedBackOperation: '' // 反馈意见 处理意见操作栏
    }
  },
  created () {
    this.checkAuthority()
  },
  mounted () {
    // 触发loadCount去请求获得表格数据
    this.queryParas.status = '1'
    this.handleFilter()
  },
  methods: {
    // 高级检索 弹窗打开
    fAdvancedSearch () {
      this.dialogFormVisible = true
    },
    // 查询 函数
    handleFilterSearch () {
      this.queryParas.status = '1'
      this.handleFilter()
    },
    // 编辑
    fEdit (data, viewMode) {
      if (viewMode) {
        this.viewMode = true
      } else {
        this.viewMode = false
      }
      this.editModelDetail = 'E'
      this.keyId = data.keyId
      this.dialogVisible = true
    },
    // 反馈
    fFeedBack (data, type) {
      this.feedBackOperation = type
      this.keyId = data.keyId
      this.dialogFeedbackVisible = true
    },
    // 新增权限
    checkAuthority () {
      this.apiReview.check().then(res => {
        this.check = res.data
      })
    },
    // 知识库新增
    fNewKnowledge () {
      this.editModelDetail = 'C'
      this.viewMode = false
      this.dialogVisible = true
    },
    // 表单刷新
    operateBtnClick (data) {
      if (data) { this.$refs.dataTable.loadTableData() }
    },
    onSave (data) {
      if (data) { this.$refs.dataTable.loadTableData() }
    },
    // 高级检索
    advSearchData (searchData) {
      let SearchDTO = {
        'knowledgeMgrAdvancedSearchCdsDTO.applicableProject': searchData.checkAllThree ? null : searchData.applicableProjectIds,
        'knowledgeMgrAdvancedSearchCdsDTO.businessType': searchData.checkAllOne ? null : searchData.businessTypes,
        'knowledgeMgrAdvancedSearchCdsDTO.correspondingLawFirms': searchData.checkAllFour ? null : searchData.correspondingLawFirmsIds,
        'knowledgeMgrAdvancedSearchCdsDTO.fileName': searchData.fileNames.trim(),
        'knowledgeMgrAdvancedSearchCdsDTO.keyWord': searchData.keyWords.trim(),
        'knowledgeMgrAdvancedSearchCdsDTO.problemPoint': searchData.problemPoints.trim(),
        'knowledgeMgrAdvancedSearchCdsDTO.relatedSources': searchData.checkAllTwo ? null : searchData.relatedSources,
        'knowledgeMgrAdvancedSearchCdsDTO.solution': searchData.solutions.trim(),
        status: '2',
        pageSize: 10
      }
      this.queryParas = SearchDTO
      this.handleFilter()
    },
    // 禁用/启用
    enable (data, type) {
      let disableMsg = type === '0'
        ? this.$t('knowledgeBaseIndex.sureProhibit')
        : this.$t('knowledgeBaseIndex.sureEnable')
      this.$confirm(disableMsg, this.$t('common.tip'), {
        type: 'warning'
      }).then(() => {
        this.apiList.enable(data.keyId).then(res => {
          if (res.data) {
            this.$refs.dataTable.loadTableData()
          }
        })
      })
    },
    // 相关素材
    showRelated (data, editModel) {
      this.keyId = data.keyId
      this.editModel = editModel
      this.dialogRelatedVisible = true
    },
    // 修改履历
    showOperate (data, editModel) {
      this.keyId = data.keyId
      this.editModel = editModel
      this.dialogHistoryVisible = true
    }
  },
  computed: {
    // API接口
    api () {
      return knowledgeBaseApi.knowledgeBase
    },
    apiList () {
      return knowledgeBaseApi.knowledgeBaseList
    },
    apiReview () {
      return reviewPersonApi.checkAuthority
    }
  }
}
</script>
