<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable" >
      <!--操作栏-->
      <template #action="{ record }" >
        <TableAction :actions="getTableAction(record)"/>
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <WjxWjxxTmlbDjjgModal ref="WjxWjxxTmlbDjjgModalPage" @success="handleSuccess"></WjxWjxxTmlbDjjgModal>
  </div>
</template>

<script lang="ts" name="wjxWjxx-wjxWjxx" setup>
import {ref, reactive, defineExpose, unref} from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { defHttp } from '/@/utils/http/axios';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns } from './WjxWjxxTmlbDjjgs.data';
  import { list } from './WjxWjxxTmlbDjjgs.api';
  import WjxWjxxTmlbDjjgModal from '/@/views/kc/wjxWjxx/components/WjxWjxxTmlbDjjgModal.vue'

  const queryParam = ref<any>({});
  const isFinished = ref<string>('');
  const toggleSearchStatus = ref<boolean>(false);
  const WjxWjxxTmlbDjjgModalPage = ref();
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '',
      api: list,
      columns,
      canResize:false,
      useSearchForm: false,
      actionColumn: {
        width: 120,
        fixed: 'right',
      },
      beforeFetch: (params) => {
        params.column = '',params.order = '';//新生成的默认不带排序
        return Object.assign(params, queryParam.value);
      },
    }
  });
  const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
  const labelCol = reactive({
    xs: { span: 24 },
    sm: { span: 7 },
  });
  const wrapperCol = reactive({
    xs: { span: 24 },
    sm: { span: 16 },
  });

  /**
   * 答卷详情
   */
  function handlePeizhiDjjg(record: Recordable) {
    WjxWjxxTmlbDjjgModalPage.value.disableSubmit = true;
    WjxWjxxTmlbDjjgModalPage.value.edit(record.id,false);
  }

  /**
   * 操作栏
   */
  function getTableAction(record) {
    console.log(`🚀 ~ getTableAction ~ record:`, record.totalScore)
    if(record.totalScore>0){
      return [
        {
          label: '答卷结果',
          onClick: handlePeizhiDjjg.bind(null, record),
        }
      ]
    }else{
      return [];
    }
    
  }

  function init(record,flag){
    queryParam.value.id = record.id;
    queryParam.value.rwbh = record.rwbh;
    queryParam.value.isFinished = flag;
    isFinished.value = flag;
    reload();
  }

  defineExpose({
    init
  });


</script>

<style lang="less" scoped>
  .jeecg-basic-table-form-container {
    .table-page-search-submitButtons {
      display: block;
      margin-bottom: 24px;
      white-space: nowrap;
    }
    .query-group-cust{
      width: calc(50% - 15px);
      min-width: 100px !important;
    }
    .query-group-split-cust{
      width: 30px;
      display: inline-block;
      text-align: center
    }
  }
</style>
