<template>
  <el-dialog
    v-model="dialogFormVisible"
    title="导入记录"
    width="850px"
    @close="close"
  >
    <el-table
      ref="table"
      v-loading="listLoading"
      border
      :data="list"
      @selection-change="setSelectRows"
      @sort-change="onSortChange"
    >
      <el-table-column
        align="center"
        fixed="left"
        label="序号"
        type="index"
        width="55"
      />
      <el-table-column
        align="center"
        label="任务名称"
        min-width="200"
        prop="name"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="操作时间"
        min-width="200"
        prop="created_at"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="失败原因"
        min-width="100"
        prop="message"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="执行结果"
        min-width="200"
        prop="result"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="操作人员"
        min-width="100"
        prop="result"
        show-overflow-tooltip
      >
        <template #default="{ row }">
          {{ row.admin?.name }}
        </template>
      </el-table-column>
      <template #empty>
        <el-empty class="vab-data-empty" description="暂无数据" />
      </template>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.page"
      :layout="layout"
      :page-size="queryForm.per_page"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <template #footer>
      <el-button type="primary" @click="close">取 消</el-button>
    </template>
  </el-dialog>
</template>

<script>
  import { useUserStore } from '@/store/modules/user'
  import { getApi } from '@/api/api'
  export default defineComponent({
    name: 'RoleManagementEdit',
    emits: ['fetch-data'],
    setup(props, { emit }) {
      const state = reactive({
        formRef: null,
        title: '',
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        queryForm: {
          page: 1,
          per_page: 10,
          type: 'App\\\\Repositories\\\\Models\\\\Base\\\\Admin',
        },
        dialogFormVisible: false,
      })

      const showEdit = (type) => {
        state.queryForm.type = type
        getList()
        state.listLoading = false
        state.dialogFormVisible = true
      }
      const close = () => {
        state.dialogFormVisible = false
      }
      const userStore = useUserStore()
      const getList = async () => {
        state.queryForm.admin_id = userStore.id
        const {
          data: { data, meta },
        } = await getApi('/base/tasks', state.queryForm)
        state.list = data
        state.total = meta.pagination.total
        console.log('上传任务', data)
      }

      //切换当前页数据条数
      const handleSizeChange = (val) => {
        state.queryForm.per_page = val
        getList()
      }
      //切换页码
      const handleCurrentChange = (val) => {
        state.queryForm.page = val
        getList()
      }
      onMounted(() => {})
      return {
        ...toRefs(state),
        showEdit,
        getList,
        close,
        handleCurrentChange,
        handleSizeChange,
      }
    },
  })
</script>

<style lang="scss" scoped>
  .body {
    margin-bottom: 30px;
  }
  .title {
    font-size: 16px;
    font-weight: 550;
    color: #333333;
    margin-bottom: 10px;
  }
  .item {
    display: flex;
    padding: 7px 0;
  }
  .item-left {
    min-width: 100px;
  }
</style>
