<template>
  <div class="pa-3 white content">
    <m-filter :option="filter" @search="handleSearch" />
    <m-table
      class="mt-3"
      :loading="loading"
      :headers="headers"
      :items="items"
      :total="total"
      :page-info="pageInfo"
      :show-select="false"
      :is-tools="false"
      :disable-sort="true"
      @add="handleAdd"
      @edit="handleEdit"
      @delete="handleDelete"
      @pageHandleChange="pageHandleChange"
      @sort="handleSort"
    >
    </m-table>
    <knowledge :handle="handleClick"></knowledge>
    <m-dialog :title="title" :visible.sync="show" @submit="handleSubmit">
      <edit-page v-if="show" ref="edit" :item-data="itemData"></edit-page>
    </m-dialog>
  </div>
</template>

<script>
import MFilter from '@/components/Filter'
import MTable from '@/components/List/table.vue'
import MDialog from '@/components/Dialog'
import EditPage from './components/edit'
import Knowledge from '@/components/Knowledge'
export default {
  name: 'knowledge-base-resume-list',
  components: { MFilter, MTable, MDialog, EditPage, Knowledge },
  data () {
    return {
      loading: false,
      show: false,
      filter: {
        list: [
          { type: 'textField', value: '', label: '名称', key: 'name' }
          // { type: 'autocomplete', value: null, label: '选择', key: 'type', items: [] }
        ]
      },
      queryData: {
        name: null
      },
      headers: [
        { text: '简历名称', align: 'start', value: 'name' },
        { text: '简历类型', align: 'start', value: 'type' },
        { text: '操作', align: 'start', value: 'actions' }
      ],
      itemData: {},
      items: [],
      orders: [],
      pageInfo: {
        size: 10,
        current: 1
      },
      total: 0
    }
  },
  computed: {
    title () {
      return Object.keys(this.itemData).length ? '编辑' : '新增'
    }
  },
  created () {
    this.init()
  },
  methods: {
    async init () {},
    handleClick () {
      window.open('http://192.168.3.233:3000/chat/share?shareId=05zt51wb458l1iiv7g3oi8dy')
    },
    handleSearch (val) {
      Object.assign(this.queryData, val)
      this.pageInfo.current = 1
      this.init()
    },
    handleAdd () {
      this.itemData = {}
      this.show = true
    },
    async handleEdit (item) {
      this.itemData = item
      this.show = true
    },
    handleDelete (ids) {
      if (Array.isArray(ids) && !ids.length) return this.$snackbar.warning('请选择要删除的选项')
      this.$confirm('提示', '是否删除该选项')
        .then(async () => {
          try {
            this.$snackbar.success('删除成功')
            this.init()
          } catch (error) {
            this.$snackbar.error('删除失败')
          }
        })
    },
    handleSubmit () {},
    pageHandleChange (page) {
      this.pageInfo.current = page
      this.init()
    },
    handleSort (val) {
      this.orders = val
      this.init()
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
