<template>
    <BasicTable @register="registerTable">
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'action'">
            <a-button v-if="!record.tasklist" type="primary" @click="openDraw(record)">生成任务</a-button>
          </template>
        </template>
    </BasicTable>
</template>
  
<script setup lang="ts">
import { ref, defineProps, onMounted, watch, nextTick } from "vue"
import { BasicTable, useTable, TableAction } from '@/components/Table';
import { columns, searchFormSchema } from './utils' 
import { GetDataList } from '@/api/demo/provincetasks'
import { useRouter } from 'vue-router'

const router = useRouter()

const [registerTable, { reload, expandAll, getForm,getDataSource,setTableData }] = useTable({
    title: '任务列表',
    api: GetDataList,
    columns,
    rowKey: 'id',
    formConfig: {
      labelWidth: 100,
      schemas: searchFormSchema,
    },
    striped: false,
    // 序号列
    showIndexColumn: false,
    // 使用搜索表单
    useSearchForm: true,
    // 显示表格设置工具
    showTableSetting: true,
    bordered: false,
    actionColumn: {
      width: 160,
      title: '操作',
      dataIndex: 'action',
    },
    beforeFetch(data) {
      return data
    },
    afterFetch(data) {
      return data.map(item => {
        return {...item, children: item.tasklist}
      })
    },
    handleSearchInfoFn(info) {
      return info;
    },
});
const openDraw = (e) =>{
  router.push({ 
    path: '/workmanagement/workplan',
    query: {
      taskid: e.id
    }
  })
}
</script>

<style lang="scss" scoped>

</style>
  