<template>
  <div>
    <!--引用表格-->
   <BasicTable @register="registerTable" :rowSelection="rowSelection">
     <!--插槽:table标题-->
      <template #tableTitle>
          <a-dropdown v-if="selectedRowKeys.length > 0">
              <template #overlay>
                <a-menu>
                  <a-menu-item key="1" @click="batchHandleDelete">
                    <Icon icon="ant-design:delete-outlined"></Icon>
                    删除
                  </a-menu-item>
                </a-menu>
              </template>
              <a-button>批量操作
                <Icon icon="mdi:chevron-down"></Icon>
              </a-button>
        </a-dropdown>
      </template>
       <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)"/>
      </template>
    </BasicTable>
    <a-drawer
        :title="detailDrawerTitle"
        placement="right"
        width="70%"
        :closable="true"
        :visible="showDetailDrawer"
        :get-container="false"
        @close="closeDetailDrawer"
        :body-style="{ padding: '0px',margin:'0px' }"
    >
    <WbSurveyExeForm  ref="refWbSurveyExeForm"></WbSurveyExeForm>
    </a-drawer>
  </div>
</template>

<script lang="ts" name="wb.manage-wbCompanyInfo" setup>
  import {ref} from 'vue';
  import {BasicTable, useTable, TableAction} from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage'
  import WbSurveyExeForm from './components/WbSurveyExeForm.vue'
  import {columns, searchFormSchema} from '../manage/WbCompanyInfo.data';
  import {list} from '../manage/WbCompanyInfo.api';
  import { useDrawer } from '/@/components/Drawer';

  const [registerDrawer, { openDrawer }] = useDrawer();
  const showDetailDrawer = ref(false)
  const refWbSurveyExeForm =ref()
  const detailDrawerTitle = ref("")

  //注册table数据
  const { prefixCls,tableContext } = useListPage({
      tableProps:{
           title: 'wb_company_info',
           api: list,
           columns,
           canResize:false,
           formConfig: {
              schemas: searchFormSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
           actionColumn: {
               width: 150,
               fixed:'right'
            },
            beforeFetch(params) {
              params['level'] = 1
          },
      },
    
  })

  const [registerTable, {reload},{ rowSelection, selectedRowKeys }] = tableContext
 
  function handleSuccess() {
      (selectedRowKeys.value = []) && reload();
   }

  function getTableAction(record){
      return [
        {
           label: '查看',
           onClick: handleShowDetailDrawer.bind(null, record)
        }
      ]
   }
  async function handleShowDetailDrawer(record: Recordable){
    showDetailDrawer.value =true
    detailDrawerTitle.value = "【"+record.name+"】详细信息"
    refWbSurveyExeForm.value.setCompanyInfo(record);

  }

  function closeDetailDrawer(){
    showDetailDrawer.value = false
  }

</script>

<style scoped>

</style>

