<template>
   <BasicTable @register="registerTable" :rowSelection="rowSelection">>
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)"/>
      </template>>
    </BasicTable>
</template>

<script lang="ts" name="wb.manage-wbCompanyThirdApi" setup>
  import {ref, computed, unref} from 'vue';
  import {BasicTable, useTable, TableAction} from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage'
  import {columnsPull, searchFormSchema} from '../WbCompanyThirdApi.data';
  import {queryThirdApi,pullDataFromAPI} from '../WbCompanyThirdApi.api';

  const companyInfo = ref();

  const { prefixCls,tableContext } = useListPage({
      tableProps:{
           title: '',
           api: queryThirdApi,
           columns:columnsPull,
           canResize:true,
           showTableSetting:false,
           formConfig: {
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              //showAdvancedButton:true,
            },
           actionColumn: {
               width: 120,
               fixed:'right'
           },
          defSort :{
             column: 'weight',
             order: 'desc',
          },
          beforeFetch(params) {
              params['cid'] = companyInfo.value.id 
          },
      },
  })

  const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext

  function handleSuccess() {
      (selectedRowKeys.value = []) && reload();
   }

  function getTableAction(record){
       return [
         {
           label: '抓取数据',
           disabled: record.pulled!=undefined,
           onClick: handlePullData.bind(null, record),
         }
       ]
   }

  async function handlePullData(record){
     await pullDataFromAPI({
      cid: companyInfo.value.id,
      apiIds: record.id
    })
  }

  async function setCompanyInfo(obj){
    companyInfo.value = obj
    reload();
  }

  
  defineExpose({
    setCompanyInfo
  });

</script>

<style scoped>

</style>