<template>
  <div class="flow-box">
    <!-- 流转记录 -->
    <EmptyBox
      v-if="results.length == 0"
      :title="t('当前无相关流转记录')"
      :desc="t('流程需发起后才会有流转记录产生')"
    />
    <div class="relative" v-else>
      <a-tabs v-model:activeKey="activeKey">
        <a-tab-pane v-for="(parent, idx) in results" :key="idx" :tab="t(parent.schemaName)">
          <div class="content">
            <div class="card-box" v-for="(item, index) in parent.records" :key="index">
              <div class="card-item">
                <div class="dot-box"
                  ><div class="line2"></div><div class="dot"></div><div class="line"></div
                ></div>
                <div class="card">
                  <div class="node-title">{{ item.nodeName }}</div>
                  <a-alert
                    message=""
                    type="info"
                    style="border-radius: 4px; padding: 10px; margin-bottom: 10px"
                  >
                    <template #description>
                      <div class="node-box">
                        <div class="node-desc" v-if="item.circulateMessage"
                          >{{ t('传阅信息') }}：{{ item.circulateMessage }}</div
                        >
                        <div class="node-desc">{{ t('审批信息') }}：{{ item.comment }}</div>
                        <div class="time-title">{{ item.startTime }}</div>
                      </div>
                    </template>
                  </a-alert>
                </div>
              </div>
            </div>
          </div>
        </a-tab-pane>
      </a-tabs>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { onMounted, ref } from 'vue';
  import EmptyBox from './EmptyBox.vue';
  import { getSelfRecords } from '/@/api/workflow/process';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { TaskRecordList } from '/@/model/workflow/bpmnConfig';

  const { t } = useI18n();

  const props = defineProps({
    list: { type: Array as PropType<TaskRecordList[]> },
    processId: String,
  });
  const results = ref<TaskRecordList[]>([]);
  const activeKey = ref(0);

  onMounted(() => {
    getRecords(1);
  });

  function getRecords(isSelf) {
    getSelfRecords({ processId: props.processId, onlySelf: isSelf }).then((res) => {
      if (res.taskRecords) {
        results.value.push({
          records: res.taskRecords,
          schemaName: '审批流',
        });
      }

      if (res.otherProcessApproveRecord) {
        results.value = results.value.concat(res.otherProcessApproveRecord);
      }
    });
  }
</script>

<style lang="less" scoped>
  .flow-box {
    height: 80vh;
    padding: 0 20px;
  }

  .dot-box {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    .dot {
      width: 18px;
      height: 18px;
      border: 4px solid #e0eaff;
      border-radius: 50%;
      background-color: #5e95ff;
    }

    .line2 {
      width: 2px;
      height: 2px;
      background-color: #f1f1f1;
    }

    .line {
      width: 2px;
      flex: 1;
      background-color: #f1f1f1;
    }
  }

  .card-item {
    display: flex;
  }

  .card {
    padding: 0 0 0 20px;
    flex: 1;

    .node-title {
      font-size: 14px;
      margin-bottom: 8px;
    }

    .node-box {
      font-size: 12px;

      .node-desc {
        color: @primary-color;
        line-height: 20px;
      }

      .time-title {
        color: #999;
      }
    }
  }
</style>
