<script lang="ts" setup>
import { onBeforeMount, onMounted, ref, watch } from 'vue'
import { formatToDateHMS } from '@/utils/dateUtil'
import { useDictionary } from '@/store/modules/dictonary'

const props = defineProps({
  data: {
    type: Object as PropType<any>,
    required: true,
  },
  taskTableData: {
    type: Array,
    default: () => [[]],
  },
})
const dicStore = useDictionary()
const izstatusList = ref([])

onBeforeMount(() => {
  dicStore.fetchizstatusListt()
})

watch(
  () => dicStore.izstatusList,
  (newval) => {
    izstatusList.value = newval
  },
)

function getItemLabel(states) {
  const list = [
    {
      value: 1,
      label: '待审批',
    },
    {
      value: 2,
      label: '通过',
    },
    {
      value: 3,
      label: '不通过',
    },
  ]
  const item: any = list.find(
    (item: any) => item.value == states,
  )
  return item ? item.label : ''
}

function getLabel(states) {
  const item: any = izstatusList.value.find(
    (item: any) => item.value == states,
  )
  return item ? item.label : ''
}

onMounted(() => {

})
</script>

<template>
  <div class="wrap">
    <div class="info-header">
      <div class="left_box">
        <div class="title">
          审查记录信息
        </div>
      </div>
    </div>
    <div class="content">
      <n-timeline>
        <n-timeline-item color="#507AFD" size="medium">
          <template #icon>
            <div class="point-line" />
          </template>
          <template #default>
            <div class="time-wrap">
              <div class="triangle" />
              <div class="time">
                完成时间：{{ props.data.finishtime ? formatToDateHMS(props.data.finishtime) : '' }}
              </div>
            </div>
          </template>
        </n-timeline-item>
        <n-timeline-item color="#507AFD">
          <template #icon>
            <div class="point-empty" />
          </template>
          <template #default>
            <div class="card">
              <n-collapse arrow-placement="right" :default-expanded-names="['1']">
                <template #header-extra>
                  审批结果：{{ getLabel(props.data.states) }}
                </template>

                <n-collapse-item title="收起" name="1">
                  <div v-for="items in props.data.userapproveList" :key="items.nodeName" class="item">
                    <div class="header">
                      <SvgIcon class="icon" name="approve" size="16" />
                      <div class="title">
                        {{ items.nodeName }}
                      </div>
                    </div>
                    <div class="col-content">
                      <div v-for="item in items.userapproveList" :key="item.id" class="col-item">
                        <div class="label label1">
                          <div class="point" />审批时间：{{ formatToDateHMS(item.createdate) }}
                        </div>
                        <div class="label label2">
                          审批人：{{ item.username }}
                        </div>
                        <div class="label label3">
                          审批结果：{{ getItemLabel(item.statshis) }}
                        </div>
                        <div class="label">
                          备注：{{ item.taskcomment }}
                        </div>
                      </div>
                    </div>
                  </div>
                </n-collapse-item>
              </n-collapse>
            </div>
          </template>
        </n-timeline-item>
      </n-timeline>
    </div>
  </div>
</template>

<style lang="less" scoped>
  .info-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    .left_box {
      display: flex;
      align-items: center;
      .title {
        display: flex;
        align-items: center;
        font-size: 16px;
        font-family: PingFang SC, PingFang SC-Medium;
        font-weight: Medium;
        text-align: left;
        color: #333333;
        line-height: 22px;

        &:before {
          content: "";
          width: 4px;
          height: 18px;
          background: #507afd;
          border-radius: 3px;
          display: inline-block;
          margin-right: 10px;
        }
      }
    }
  }

  .point-line{
    width: 10px;
    height: 10px;
    background: #507afd;
    border-radius: 50%;
  }

  .point-empty{
    width: 10px;
    height: 10px;
    background: #dde5fe;
    border: 2px solid #7395ff;
    border-radius: 50%;
  }

  .time-wrap{
    display: flex;
    align-items: center;
  }

  .time{
    font-size: 14px;
    font-family: PingFang SC, PingFang SC-Medium;
    font-weight: 500;
    color: #507afd;
    line-height: 24px;
    position: relative;
    height: 24px;
    background: rgba(80,122,253,0.10);
    display: inline-block;
    padding-right: 6px;
  }

  .triangle{
    width: 0;
    height: 0;
    border-top: 12px solid transparent;
    border-right: 15px solid rgba(80,122,253,0.10);
    border-left: 15px solid transparent;
    border-bottom: 12px solid transparent;
    margin-left: -15px;
  }

  .card{
    background: #f9fafc;
    padding: 16px;
  }

  .point{
    width: 4px;
    height: 4px;
    background: #999999;
    border-radius: 50%;
    margin-right: 6px;
  }

  .header{
    display: flex;
    align-items: center;
    margin-bottom: 12px;

    .icon{
      margin-right: 10px;
    }
  }

  .item{
    margin-bottom: 16px;
  }

  .col-item{
    display: flex;
    align-items: center;
    padding-left: 26px;
    margin-bottom: 8px;

    .label{
      display: flex;
      align-items: center;
      font-size: 14px;
      font-family: PingFang SC, PingFang SC-Regular;
      font-weight: Regular;
      text-align: center;
      color: #666666;
    }

    .label1{
      width: 305px;
    }
    .label2{
      width: 194px;
    }
    .label3{
      width: 208px;
    }
  }
</style>
