<template>
  <div>
    <BasicTable @register="registerTable">
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)"  :dropDownActions="getDropDownAction(record)"/>
      </template>
      <template #htmlSlot="{ text }">
        <div v-html="text"></div>
      </template>
    </BasicTable>
    <RecordDrawer ref="refRecordDrawer"  @showFile="showFileContent"/>
    <RecordDrawer2 ref="refRecordDrawer2"  @showFile="showFileContent"/>
    <FileViewerDrawer 
      ref="refFileContentView" 
      :useStaticPrefixForDocx="true"
      :fixedFiles="fixedFiles"
    />
  </div>
</template>

<script lang="ts" setup>
 
  import { ref, computed, unref } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns, searchFormSchema } from '../task/BaosongTask.data';
  import RecordDrawer from './components/RecordDrawer.vue';
  import RecordDrawer2 from './components/RecordDrawer2.vue';
  import FileViewerDrawer from '/@/components/onlinePreview/FileViewerDrawer.vue';
  import { useRouter } from 'vue-router';
  
  const router = useRouter()

  import { listForFillData } from '../task/BaosongTask.api';
  import { updateFillStaBatch } from '../alloc/BaosongTaskAlloc.api';

  const refRecordDrawer = ref()
  const refRecordDrawer2 = ref()
  const refFileContentView = ref()

  const fixedFiles = ref({
    1:{fileTp:"pdf",filePath:"/baosong/银行业保险业信息科技非现场监管报表（2024版）.pdf",fileName:"银行业保险业信息科技非现场监管报表（2024版）"},
    2:{fileTp:"pdf",filePath:"/baosong/银行业保险业信息科技非现场监管报表填报指南（2024版）.pdf",fileName:"银行业保险业信息科技非现场监管报表填报指南（2024版）.pdf"}
  })

  const { prefixCls, tableContext, } = useListPage({
    tableProps: {
      title: '任务表',
      api: listForFillData,
      columns,
      canResize: false,
      formConfig: {
        labelWidth: 120,
        schemas: searchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: true,
        fieldMapToNumber: [],
        fieldMapToTime: [],
      },
      beforeFetch(params) {
          params['sta'] = 1
      },
      actionColumn: {
        width: 100,
        fixed: 'right',
      },
    },
  });

  const [registerTable, { reload }] = tableContext;

  function getTableAction(record) {
    return [
      {
        label: '填报',
        onClick: handleAddRecord3.bind(null, record),
      },
      {
        label: '提交',
        onClick:updateFillStaBatch.bind(null, {taskid:record.id}),
      },
    ];
  }

  function getDropDownAction(record){
    return [
      {
        label: '表单方式',
        onClick: handleAddRecord.bind(null, record),
      },
      {
        label: '表格方式',
        onClick: handleAddRecord2.bind(null, record),
      }
    ]
  }

  function handleAddRecord(record) {
    refRecordDrawer.value.setIniData(record)
  }

  function showFileContent(tp) {
    refFileContentView.value.setDocFile(tp)
  }

  function handleAddRecord2(record) {
    refRecordDrawer2.value.setIniData(record)
  }

  function handleAddRecord3(record) {
    router.push({path:'/baosong/report/index',
      query: {
        taskId: record.id,
        taskName: record.name
      }
    })
  }

</script>

<style scoped></style>
