<template>
  <el-card shadow="hover" class="margin">
    <div class="full-width flex flex-center flex-justify-start">
      <el-button-group>
        <el-button type="primary" icon="el-icon-edit">全部任务</el-button>
        <el-button type="primary" plain icon="el-icon-share"
          >我创建的
        </el-button>
        <el-button type="primary" plain icon="el-icon-delete"
          >我执行的
        </el-button>
      </el-button-group>
    </div>
    <div class="flex flex-center flex-justify-start flex-col full-width">
      <div class="full-width flex flex-justify-start">
        <span>按时间排序</span>
      </div>
      <div class="full-width">
        <task-table
          :option="option"
          :data="data"
          @rowClick="rowClick"
        ></task-table>
      </div>
      <task ref="task" :task="task"></task>
    </div>
  </el-card>
</template>

<route>
{
path: '/task',
name: '任务列表'
}
</route>

<script>
import TaskTable from '@/views/task/component/task-table.vue'
import Task from '@/views/task/component/task.vue'

export default {
  components: { Task, TaskTable },
  data() {
    return {
      data: [],
      task: [],
      taskId: '',
      option: {
        showCheckBox: false,
        folderChecked: true,
        column: [
          {
            label: '共20个任务',
            prop: 'title',
            display: false,
            width: 600
          },
          {
            label: '标签',
            prop: 'createUserName'
          },
          {
            label: '时间',
            prop: 'createUserName'
          },
          {
            label: '执行人',
            prop: 'createTime'
          }
        ]
      }
    }
  },
  created() {
    this.getTaskList()
  },
  methods: {
    getTaskList() {
      this.$api.task.taskList({}).then(res => {
        if (res.code === 200) {
          this.data = res.data.records
        }
      })
    },
    rowClick(res) {
      this.taskId = res.id
      this.getTaskInfo()
    },
    getTaskInfo() {
      this.$api.task.taskInfo({ id: this.taskId }).then(res => {
        if (res.code === 200) {
          this.task = res.data
        } else {
          this.$message.error(res.msg)
        }
      })
    }
  }
}
</script>

<style scoped></style>
