<template>
  <a-card
    :bordered="false"
    :loading="loading"
  >
    <a-table
      ref="table"
      :pageSize="5"
      :columns="columns"
      :showPagination="false"
      :data-source="dataList"
      :rowKey="record => record.id">
      <span slot="action" slot-scope="text, record, index">
        <a v-if="index % 3 == 1" @click="$refs.userForm.edit(record)">添加课程</a>
        <a v-if="index % 3 == 2" @click="$refs.userForm.edit(record)">继续学习</a>
        <a v-if="index % 3 == 0">已完成学习</a>
      </span>
    </a-table>
    <CentralizedTrainingDetail ref="centralizedTrainingDetail"></CentralizedTrainingDetail>
  </a-card>
</template>

<script>
import { userPage, userDel, passwordReset } from '@/api/security/user'
import { getCourseList, deleteCourse } from '@/api/course/course'
import { dictionaryDropDown } from '@/api/sys/dictionaryItem'
import { dictToTree } from '@/utils/util'
import CentralizedTrainingDetail from './CentralizedTrainingDetail.vue'
export default {
  components: {
    CentralizedTrainingDetail
  },
	data () {
		return {
      dataList: [],
      activeTab: '1',
      loading: true,
      columns: [
        {
          title: '培训名称',
          dataIndex: 'courseName',
          scopedSlots: { customRender: 'courseName' }
        },
        {
          title: '培训时间',
          dataIndex: 'courseTypeName'
        },
        {
          title: '培训地点',
          dataIndex: 'date'
        },
        {
          title: '培训状态',
          dataIndex: 'status'
        },
        {
          title: '操作',
          width: '150px',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return getCourseList(Object.assign(parameter, this.queryParam)).then(res => {
          return res
        })
      },
      selectedRows: [], // 选中行的数据
      options: {}
		}
	},
	created () {
    this.dictionaryDropDown()
  },
	methods: {
    tabChange (key) {
      console.log('key', key)
    },
		// 点击详情
    handlerDetail () {
      this.$refs.aycourseDetail.visible = true
    },
    // 获取数据词典
    dictionaryDropDown () {
      dictionaryDropDown({ dictionaryCode: '0006' }).then((res) => {
				this.loading = false
        this.queryOptions[1].options = dictToTree(res.data, [], 0)
      })
    },
    classificationChange (value) {
      this.queryParam.classification = value
    },
    // 获取列表
    handleRefresh () {

    },
    sysUserDelete (param) {
      userDel(param)
        .then(res => {
          if (res.code === 200) {
            this.$message.success('删除成功')
            this.$refs.table.refresh()
          } else {
            this.$message.error('删除失败：' + res.msg)
          }
        })
        .catch(err => {
          this.$message.error('删除错误：' + err.msg)
        })
    },
    handleOk () {
      this.$refs.table.refresh()
    }
	}
}
</script>

<style lang="less" scoped>
.table-operator {
  margin-bottom: 18px;
}
button {
  margin-right: 8px;
}
</style>
