<template>
  <sd-data-table
    ref="dataTable"
    data-url="api/framework/v1/related-doc-manager/reverse-related-doc-list"
    :columns="columns"
    :filter-expressions="filterExpressions"
    :pagination="{ pageSize: totalSize }"
    @rowClick="rowClick"
  >
  </sd-data-table>
</template>

<script>
import components from './_import-components/sd-be-related-doc-import'

export default {
  name: 'SdBeRelatedDoc',
  metaInfo: {
    title: '被关联文件',
  },
  components,
  inject: {
    webflow: { default: () => {} },
  },
  data() {
    return {
      totalSize: 5,
      columns: [
        {
          title: '标题',
          dataIndex: 'srcTitle',
          sdClickable: true,
        },
        {
          title: 'srcInstId',
          dataIndex: 'srcInstId',
          sdHidden: true,
        },
        {
          title: 'srcFlowId',
          dataIndex: 'srcFlowId',
          sdHidden: true,
        },
      ],
      filterExpressions: [
        {
          dataType: 'str',
          name: 'targetInstId',
          op: 'eq',
          // 子流程时，取顶层文档的instId，主流程时直接取当前文档的instId
          stringValue: this.webflow.FlowData.attrs?.isSubflow
            ? this.webflow.rootParentInfo?.id
            : this.webflow.FlowData?.instId,
        },
      ],
    }
  },
  methods: {
    rowClick(record) {
      const { href } = this.$router.resolve(
        `/sd-webflow/done-pages/${record.srcInstId}?openAuthType=reverseRelatedDoc&openAuthParameter=${record.targetInstId},${record.uuid},${this.webflow.FlowData?.instId}`
      )
      window.open(href)
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
</style>
