<template>
  <a-card>
    <a-tabs default-active-key="1">
      <a-tab-pane key="1" tab="推荐给我">
        <sd-data-table
          data-url="api/xcoa-mobile/v1/kmknowledge/knowledge_recommend_accountlist"
          :columns="columns1"
          :row-key="'id'"
          :search-fields="['title']"
        >
          <a slot="bt" slot-scope="text, record" :title="text" @click="click(record)"
            >{{ text }}
          </a>
        </sd-data-table>
      </a-tab-pane>
      <a-tab-pane key="2" tab="我的推荐" force-render>
        <sd-data-table
          data-url="api/xcoa-mobile/v1/kmknowledge/knowledge_recommendlist"
          :columns="columns2"
          :row-key="'id'"
          :search-fields="['title']"
        >
          <a slot="bt" slot-scope="text, record" :title="text" @click="click(record)"
            >{{ text }}
          </a>
        </sd-data-table>
      </a-tab-pane>
    </a-tabs>
  </a-card>
</template>

<script>
import TableColumnTypes from '@/common/services/table-column-types'
import components from './_import-components/km-my-recommend-import'
const columns1 = [
  {
    title: '序号',
    width: '100px',
    align: 'center',
    customRender: (text, record, index) => `${index + 1}`,
  },
  {
    title: '标题',
    dataIndex: 'title',
    sdClickable: true,
    width: '260px',
    align: 'center',
    scopedSlots: { customRender: 'bt' },
  },
  {
    title: '版本号',
    dataIndex: 'versionNum',
    width: '100px',
    align: 'center',
  },
  {
    title: '所属分类',
    align: 'center',
    dataIndex: 'category',
  },
  {
    title: '创建时间',
    align: 'center',
    dataIndex: 'creationTime',
    sorter: (a, b) => a.creationTime - b.creationTime,
    sdRender: TableColumnTypes.dateTime, // 特殊处理的数据类型，时间戳会自动调用sdDateFormat处理
  },
  {
    title: '阅读次数',
    align: 'center',
    dataIndex: 'readTimes',
    sorter: (a, b) => a.readTimes - b.readTimes,
    width: '150px',
  },
  {
    title: '推荐次数',
    align: 'center',
    dataIndex: 'recommendTimes',
    sorter: (a, b) => a.recommendTimes - b.recommendTimes,
    width: '150px',
  },
  {
    title: '点评次数',
    align: 'center',
    dataIndex: 'commentTimes',
    sorter: (a, b) => a.commentTimes - b.commentTimes,
    width: '150px',
  },
]
const columns2 = [
  {
    title: '序号',
    align: 'center',
    width: '100px',
    customRender: (text, record, index) => `${index + 1}`,
  },
  {
    title: '标题',
    dataIndex: 'title',
    sdClickable: true,
    width: '260px',
    align: 'center',
    scopedSlots: { customRender: 'bt' },
  },
  {
    title: '版本号',
    dataIndex: 'versionNum',
    width: '100px',
    align: 'center',
  },
  {
    title: '所属分类',
    align: 'center',
    dataIndex: 'category',
  },
  {
    title: '创建时间',
    dataIndex: 'creationTime',
    align: 'center',
    sorter: (a, b) => a.creationTime - b.creationTime,
    sdRender: TableColumnTypes.dateTime, // 特殊处理的数据类型，时间戳会自动调用sdDateFormat处理
  },
  {
    title: '阅读次数',
    dataIndex: 'readTimes',
    align: 'center',
    sorter: (a, b) => a.readTimes - b.readTimes,
    width: '150px',
  },
  {
    title: '推荐次数',
    align: 'center',

    dataIndex: 'recommendTimes',
    sorter: (a, b) => a.recommendTimes - b.recommendTimes,
  },
  {
    title: '点评次数',
    align: 'center',
    dataIndex: 'commentTimes',
    sorter: (a, b) => a.commentTimes - b.commentTimes,
    width: '150px',
  },
]
export default {
  name: 'KmMyRecommend',
  metaInfo: {
    title: '推荐知识',
  },
  components,
  data() {
    return {
      columns1,
      columns2,
    }
  },
  created() {},
  methods: {
    click(record) {
      window.open(`#/km-knowledage-view?id=${record.id}&title=${record.title}`, '_blank')
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
