<template>
  <a-card class="custom-card" title="历史填报记录" :bodyStyle="{padding:'0px',height:'90%'}" style="height:100%">
    <template #extra>
      <a-button v-for="(item,ind) in taskList" :key="ind" type="link" :loading="loading" :disabled="loading" @click="handleShowHistory(item)">
        {{ item.name }}
      </a-button>
    </template>
    <vxe-table
        :show-header="true"
        ref="refActTable"
        size="small"
        show-overflow
        height="auto"
        :data="dataList"
        :show-radio="true"
        :row-config="{ isCurrent: true, isHover: true }"
        @cell-click="rowChangeEvent"
        :columnConfig="{ resizable: true }"
        :scroll-y="{ enabled: true, gt: 50 }"
        :radio-config="{ labelField: 'name', highlight: true }"
      >
        <vxe-column type="seq" width="10%" />
        <vxe-column field="title" sortable type="html" title="名称" width="40%"/>
        <vxe-column field="content" sortable  type="html" title="填报值"/>
        <vxe-column field="code" sortable  type="html" title="编码" width="15%"/>
        <vxe-column field="rind" sortable  type="html" title="行号" width="15%"/>
   
    </vxe-table>
  </a-card>  
</template>

<script setup lang="ts">
  import { ref, reactive } from 'vue';
  import { defHttp } from '/@/utils/http/axios';

  const showTableData  = ref(false)
  const loading = ref(false)
  

  const emit = defineEmits(['callback']);
  const histroyUrl =  '/baosong/baosongTaskRecord/findTaskRecords';

  const reportUrlList =  '/baosong/baosongTask/list';

  const dataList = ref([]);
  const taskList = ref([])
  const curTplid = ref()
  const curTask = ref()
  const curItemPid = ref()

  const iniData = async (task,tplid,itempid) => { 
    curTplid.value = tplid
    curTask.value = task
    curItemPid.value =itempid
    dataList.value = []
    await setReportList();
    let histTask0 = taskList.value[0];
    await handleShowHistory(histTask0);
  }

  const rowChangeEvent = async({row}) =>{
    emit("callback",row)
  }

  const handleShowHistory = async(row)=> {
    showTableData.value = true
    let params = {taskid:row?.id,tplid:curTplid.value,itempid:curItemPid.value}
    dataList.value = await defHttp.get({url: histroyUrl,params})
  }

  const setReportList = async()=> {
    let tp = curTask.value .tp
    let retData  = await defHttp.get({url: reportUrlList, params:{tp:tp,column:'enterDate',order:'desc'}})
    taskList.value = retData.records
  }

  defineExpose({
    iniData,
  });
</script>

<style scope>
  blockquote {
    padding: 0px 5px;
    color: black;
    cursor: pointer;
  }
</style>

