<template>
    <BasicTable @register="registerTable">
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'flighttaskid'">
            <a-tag color="#87d068" v-if="record.flighttaskid">已完成</a-tag>
          </template>

          <template v-if="column.key === 'action'">
            <a-button size="small" v-if="!record.tasklist" type="primary" @click="openDraw(record)">生成任务</a-button>
            <span>&nbsp;</span>
            <a-button  size="small"  v-if="record.flighttaskid" type="primary" @click="packageData(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,handlerDbUpload } from '@/api/demo/provincetasks'
import { useRouter } from 'vue-router'
import { geometry } from "@turf/turf";
import {  message } from 'ant-design-vue';
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,
      nember:e.dkbh,
      geometry:e.dkfw,
    }
  })
}

const packageData = (record) => {
  
  let res = handlerDbUpload({taskId:record.id});

  if(res){
      message.success("打包成功！");
  }
}
</script>

<style lang="scss" scoped>

</style>
  