<template>
  <div>

   <BasicTable @register="registerTable" size="small" :rowSelection="rowSelection">
      <template #tableTitle>
          <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined">添加</a-button>
      </template>
    </BasicTable>
  </div>
</template>

<script lang="ts" name="metric-metricMonitorSet" setup>
  import {ref, computed, unref} from 'vue';
  import {BasicTable, useTable} from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage'
  import {columns} from '/@/views/metric/MetricMonitorSet.data';
  import { listAll } from '/@/views/metric/MetricMonitorSet.api';


  const emit = defineEmits(['save']);
  const searchForm: any[] = [
    {
      label: '领域',
      field: 'domainNo',
      component: 'JCascaderDomain',
      colProps: { lg: 10, md: 10 },
      componentProps: {
        dict: 'st_domain,domain_name,domain_code',
        pidField: 'upper_domain_code',
        pidValue: '0',
        hasChildField: 'has_child',
        maxHeight: '185px',
      },
      itemProps: { labelCol: { xs: { span: 24 }, sm: { span: 6 } }, wrapperCol: { xs: { span: 24 }, sm: { span: 18 } } },
    },
    {
      label: '名称',
      field: 'mtrcName',
      component: 'Input',
      colProps: { lg: 5, md: 5 },
    },
    {
      label: '频率',
      field: 'collFreq',
      component: 'JDictSelectTag',
      colProps: { lg: 5, md: 5 },
      componentProps: {
        dictCode: 'colletrate',
      },
    },
  ];


  const { tableContext} = useListPage({
      tableProps:{
           title: '监测方案',
           api:listAll,
           columns,
           canResize:true,
           showActionColumn: false,
           formConfig: {
              schemas: searchForm,
              autoSubmitOnEnter:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
              ],
            },
   
      }
  })

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


  function handleAdd() {
    if(selectedRowKeys.value.length==0) {
      return false 
    }
    emit("save",selectedRowKeys.value)
  }
 
</script>

