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

<script lang="ts" name="baosong-baosongTask" setup>
  import { ref, computed, unref } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useModal } from '/@/components/Modal';
  import { useDrawer } from '/@/components/Drawer';
  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 FileContentView from '../components/FileContentView.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 { 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'] = 2
      },
      actionColumn: {
        width: 200,
        fixed: 'right',
      },
    },
  });

  const [registerTable, { reload }] = tableContext;

  function getTableAction(record) {
    return [
      {
        label: '表单方式',
        onClick: handleAddRecord.bind(null, record),
      },
      {
        label: '表格方式',
        onClick: handleAddRecord2.bind(null, record),
      },
      {
        label: 'WORD方式',
        onClick: handleAddRecord3.bind(null, record),
      },
      {
        label: '提交',
        onClick:updateFillStaBatch.bind(null, {taskid:record.id}),
      },
    ];
  }


  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>
