<template>
  <BasicTable @register="registerTable" >
    <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'innerControlStrategy'">
            <JEllipsisFormat :isLink="true"  :value="record.innerControlStrategy" :length="60" @click="goToPage(record)"/>
          </template>
          <template v-else-if="column.key === 'fileUploadPath'">
            <a-button type="link" v-for="(item,index) in parsePathsValue(record.fileUploadPath)" :key="index" :href="item.url" target="_blank">
              {{item.name}}
            </a-button>
          </template>
      </template>
  </BasicTable>
</template>
<script lang="ts" setup>
import { defineExpose } from 'vue';
import { useRouter } from 'vue-router';
import { BasicColumn, BasicTable, useTable } from '/@/components/Table';
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
import JEllipsisFormat from '/@/views/standardlib/components/JEllipsisFormat.vue';
import { list } from '/@/views/standardlib/inner/StInnerControlOrder.api';
const router = useRouter()
const props = defineProps({
  actInfo: Map,
});
const columns: BasicColumn[] = [
{
  title: '策略编号',
  align:"left",
  dataIndex: 'strategyNo'
 },
 {
  title: '内控策略',
  align:"left",
  dataIndex: 'innerControlStrategy'
 },
 {
  title: '内控要求',
  align:"left",
  dataIndex: 'innerControlClaim',
 },
 {
  title: '适用对象',
  align:"left",
  dataIndex: 'applicableName'
 },
 {
  title: '管理制度',
  align:"left",
  dataIndex: 'manageOrder'
 },
 {
  title: '职责分工',
  align:"left",
  dataIndex: 'divisionDutyName'
 },
 {
  title: '执行规则',
  align:"left",
  dataIndex: 'execRule'
 },
  ];
const [registerTable,{setProps,reload}] = useTable({
        title: '',
        api: list,
        columns: columns,
        bordered: true,
        showIndexColumn: false,
        immediate: false,
        beforeFetch(params) {
            params = Object.assign(params,{ column: 'updatedTime', order: 'desc' })
         },
      });
//       watch(
//     ()=>props.actInfo,
//     (newVal,oldVla)=>{
//       console.log("metric")
//       console.log(newVal)
//       let parm = {caNo:newVal.caNo}
//       setProps({searchInfo:parm});
//       reload()
//       console.log(oldVla)
//       console.log("metric")
//     }
// )
function goToPage(record) {
  router.push({path: '/standardlib/inner/stInnerControlOrderList',query:{bizNo: record.id}})
}
function getFileName(path) {
    if (path.lastIndexOf('\\') >= 0) {
      let reg = new RegExp('\\\\', 'g');
      path = path.replace(reg, '/');
    }
    return path.substring(path.lastIndexOf('/') + 1);
  }
  
  function uidGenerator() {
    return '-' + parseInt(Math.random() * 10000 + 1, 10);
  }
// 解析数据库存储的逗号分割
function parsePathsValue(paths) {
  console.log(paths)
    if (!paths || paths.length == 0) {
      return [];
    }
    let list: any[] = [];
    for (const item of paths.split(',')) {
      let url = getFileAccessHttpUrl(item);
      list.push({
        uid: uidGenerator(),
        name: getFileName(item),
        status: 'done',
        url: url,
        response: { status: 'history', message: item },
      });
    }
    return list;
  }
  defineExpose({setProps,reload})
</script>