<template>
  <a-form :model="actModel" :label-col="labelCol" :wrapper-col="wrapperCol">
    <a-row :gutter="24">
      <a-col :span="24" :pull="1">
        <a-form-item label="查询结果">
          <BasicTable @register="registerTable" :rowSelection="rowSelection" @selection-change="handlerRowClick">
            <!-- update-begin-author:taoyan date:2022-5-25 for: VUEN-1112一对多 用户选择 未显示选择条数，及清空 -->
            <template #tableTitle></template>
            <!-- update-end-author:taoyan date:2022-5-25 for: VUEN-1112一对多 用户选择 未显示选择条数，及清空 -->
          </BasicTable>
          <!--改为table实现-->
          <!--<a-list size="small" bordered :data-source="resultData" :pagination="pagination" style="height:200px;overflow-x: auto;">
                      <template #renderItem="{ item }">
                          <a-list-item>
                              <a-row :gutter="24" style="width:100%">
                                  <a-col :span="4"><a-button type="link">{{ item.caNo }}</a-button></a-col>
                                  <a-col :span="18"><a-button type="text">{{ item.scenarioName }}</a-button></a-col>
                                  <a-col :span="2">
                                    <a-button type="text">
                                      <a-checkbox v-model:checked="checkBox[item.caNo]" @change="handlerChecked(item)"></a-checkbox>
                                    </a-button>
                                  </a-col>
                              </a-row>
                          </a-list-item>
                      </template>
                  </a-list>-->
        </a-form-item>
      </a-col>
    </a-row>
  </a-form>
</template>
<script setup>
  import { message } from 'ant-design-vue';
  import { reactive, ref } from 'vue';
  import { BasicTable } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { list } from '/@/views/standardlib/risk/StRiskEvent.api';
  const columns = [
    {
      title: '风险事件编号',
      align: 'left',
      dataIndex: 'riskEventNo',
    },
    {
      title: '风险事件名称',
      align: 'left',
      dataIndex: 'riskEventName',
    },
  ];
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '风险场景',
      api: list,
      columns,
      canResize: false,
      useSearchForm: false,
      scroll: { x: false },
      actionColumn: { ifShow: false },
      clickToRowSelect: true,
      immediate: false,
      rowSelection: {
        hideSelectAll: true,
        // onSelect: handlerChecked,
        // onChange: handlerChange,
      },
      //    actionColumn: {
      //        width: 160
      //     },
      showTableSetting: false,
      beforeFetch(params) {
        params = Object.assign(params, { column: 'updatedTime', order: 'desc' });
      },
    },
  });
  const [registerTable, { setProps, reload }, { rowSelection, selectedRowKeys }] = tableContext;

  //const checkBox = ref({})
  //   function handlerChange(selectedRowKeys, selectedRows){
  //     //console.log(selectedRowKeys)
  //     if(selectedRowKeys.length==0){
  //         Object.assign(props.actinfo,{scenarioNo:'',scenarioName:''})
  //     }
  //   }
  //   function handlerChecked(record, selected, selectedRows, nativeEvent){
  //     // console.log(record)
  //     // console.log(selected)
  //     // console.log(selectedRows)
  //     // console.log(nativeEvent)
  //     if(selected){
  //         selectedRowKeys.value = [record.id]
  //         Object.assign(props.actinfo,record)
  //     }else{
  //         Object.assign(props.actinfo,{scenarioNo:'',scenarioName:''})
  //     }
  //   }
  const actModel = ref({
    scenarioName: '',
    lableName: '',
  });
  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 4 },
  });
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 20 },
  });
  // const pagination = reactive({
  //     current: 1,
  //     pageSize: 10,
  //     total: 0,
  //     showTotal: total => `共 ${total} 条数据`
  // })
  function searchQuery(scenarioNo) {
    setProps({ searchInfo: { scenarioNo: scenarioNo } });
    reload();
  }
  function getSelectRiskIds() {
    console.log('--start--');
    console.log(selectedRowKeys.value);
    console.log('--end--');
    if (!selectedRowKeys.value || selectedRowKeys.value.length === 0) {
      message.warn('请选择风险事件！');
      return;
    }
    return selectedRowKeys.value;
  }
  function handlerRowClick({ keys, rows }) {
    if (keys.length > 1) {
      let index = keys.length - 1;
      selectedRowKeys.value = [rows[index].id];
      //Object.assign(props.actinfo,rows[index])
    } else {
      //Object.assign(props.actinfo,rows[0])
    }
  }
  defineExpose({ searchQuery, getSelectRiskIds });
</script>
