 <!-- 知识管理-->
<template>
  <app-container>
    <el-row type="flex">
      <el-col :span="5">
        <type-tree @change="changeType"/>
      </el-col>
      <el-col :span="19">
        <search-area :need-clear="false" :need-search-more="false" :size="size" type="default" search-more-type="default" @search="search">
          <!--一般查询条件-->
          <search-item>
            <el-input v-model.trim="listQuery.keywords" :size="size" placeholder="标题/内容" clearable/>
          </search-item>
          <search-item>
            <el-select v-model="listQuery.checkStatus" placeholder="审核状态" size="small" clearable>
              <el-option v-for="item in checkStateList" :key="'checkState_'+item.value" :label="item.name" :value="item.value"/>
            </el-select>
          </search-item>
          <search-item>
            <el-select v-model="listQuery.groundingStatus" placeholder="上架状态" size="small" clearable>
              <el-option v-for="item in groundStateList" :key="'ground_'+item.value" :label="item.name" :value="item.value"/>
            </el-select>
          </search-item>
          <search-item>
            <el-select v-model="listQuery.valid" placeholder="可用状态" size="small" clearable>
              <el-option v-for="item in validStateList" :key="'valid_'+item.value" :label="item.name" :value="item.value"/>
            </el-select>
          </search-item>
        </search-area>
        <div style="margin-bottom:10px;">
          <el-row>
            <el-button class="filter-item" style="" size="small" type="primary" icon="el-icon-edit" @click="add">新增</el-button>
          </el-row>
        </div>
        <case-list-table :list-query="listQuery" :list="list" :total="total" :columns="columns" :list-loading="listLoading" common-columns="" @changePage="changePage">
          <template slot="operations">
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button type="text" size="small" @click.stop="detail(scope.row)">详情</el-button>
                <el-button type="text" size="small" @click.stop="edit(scope.row)">编辑</el-button>
              </template>
            </el-table-column>
          </template>
        </case-list-table>
      </el-col>
    </el-row>
    <edit-knowledge ref="editdialog" @watchChild="fetchData"/>
    <knowledge-detail ref="kdetail"/>
  </app-container>
</template>

<script>
import AppContainer from '@/components/layout/AppContainer'
import SearchArea from '@/components/SearchArea/SearchArea'
import SearchItem from '@/components/SearchArea/SearchItem'
import CaseListTable from '@/views/caseManage/caseCommon/caseListTable'
import { knowledgeList } from '@/api/knowledge'
import { getcheckStatus, getGroundStatus, getValidStatus } from '@/api/allDict'
import TypeTree from './components/TypeTree'
import EditKnowledge from './editKnowledge'
import KnowledgeDetail from '../caseManage/components/knowledgeDetail'

export default {
  name: 'KnowledgeManage',
  components: { KnowledgeDetail, EditKnowledge, TypeTree, AppContainer, SearchArea, SearchItem, CaseListTable },
  data() {
    return {
      list: [],
      total: 0,
      timeRange: [], // 申请时间范围
      listLoading: true, // 列表加载动画
      listQuery: {
        keywords: '', // 关键字
        type: '', // 类别
        checkStatus: '', // 审核状态
        groundingStatus: '', // 上架状态
        valid: '', // 可用状态
        offset: 1,
        limit: 20,
        sort: '',
        order: ''
      }, // 筛选条件
      columns: [
        {
          text: '标题',
          value: 'kName',
          align: 'center'
        },
        {
          text: '类别',
          value: 'kTypeName',
          align: 'center'
        },
        {
          text: '发布人',
          value: 'publisherName',
          align: 'center'
        },
        {
          text: '发布时间',
          value: 'publishTime',
          width: 90,
          align: 'center'
        },
        {
          text: '审核状态',
          value: 'checkStatusName',
          align: 'center'
        },
        {
          text: '上架状态',
          value: 'groundingStatusName',
          align: 'center'
        },
        {
          text: '可用状态',
          value: 'validStatus',
          align: 'center'
        },
        {
          text: '有效时限',
          value: 'validPeroid',
          align: 'center'
        }
      ], // 显示列
      checkStateList: [], // 审核状态
      groundStateList: [], // 上架状态
      validStateList: [], // 可用状态
      size: 'small'
    }
  },
  created() {
    this.fetchCheckStateList()
    this.fetchGroundStateList()
    this.fetchValidList()
    this.fetchData()
  },
  methods: {
    search() {
      this.fetchData(false)
    },
    // 获取数据
    fetchData(isNowPage = true) {
      this.listLoading = true
      if (!isNowPage) { // 是否显示当前页，否则跳转第一页
        this.listQuery.offset = 1
      }
      this.listLoading = true
      knowledgeList(this.listQuery).then(response => {
        if (response.code === 200) {
          // response.data.rows = [
          //   {
          //     'id': '1',
          //     'kName': '特种设备作业人员操作证怎样办理？',
          //     'kTypeName': '大类',
          //     'publisherName': '张三',
          //     'publishTime': '2020-04-12',
          //     'checkStatusName': '未审核',
          //     'groundingStatusName': '未上架',
          //     'validStatusName': '不可用',
          //     'validPeroid': '永久'
          //   }
          // ]
          this.list = response.data.rows
          this.total = response.data.total
          this.listLoading = false
        }
      })
    },
    detail(row) {
      this.$refs.kdetail.initDialog(row)
    },
    // 添加知识库
    add(row) {
      this.$refs.editdialog.initDialog('create', true)
    },
    // 编辑
    edit(row) {
      this.$refs.editdialog.initDialog('update', true, row)
    },
    // 取审核状态列表
    fetchCheckStateList() {
      getcheckStatus().then(repsonse => {
        this.checkStateList = repsonse.data
      })
    },
    // 取上架状态列表
    fetchGroundStateList() {
      getGroundStatus().then(repsonse => {
        this.groundStateList = repsonse.data
      })
    },
    // 取可用状态列表
    fetchValidList() {
      getValidStatus().then(repsonse => {
        this.validStateList = repsonse.data
      })
    },
    // 更换页码等
    changePage(listQuery) {
      this.listQuery = listQuery
      this.fetchData()
    },
    // 更换类别
    changeType(typeid) {
      this.listQuery.type = typeid
      this.search()
    }
  }
}
</script>
