<script lang="ts" setup>
import { computed, 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([])
const expanded = ref(true)

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 : ''
}

const iconName = computed(() => {
  return expanded.value ? 'expand' : 'collapse'
})

function changeExpand() {
  expanded.value = !expanded.value
}

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">
              <div class="card-header">
                <div class="status">
                  审批结果：{{ getLabel(props.data.states) }}
                </div>
                <div class="arrow" @click="changeExpand()">
                  <SvgIcon style="margin-right: 4px" :name="iconName" size="14" />
                  收起
                </div>
              </div>
              <div v-if="expanded" class="card-content">
                <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="item-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.statshis === 2 ? '--' : item.taskcomment }}
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </template>
        </n-timeline-item>
      </n-timeline>
    </div>
  </div>
</template>

<style lang="less" scoped>
  ::v-deep(.n-timeline-item-timeline__line) {
    width: 1px!important;
  }

  .card{
    background: #f9fafc;
    padding-left: 16px;
    border-radius: 3px;

    .card-header{
      padding-right: 16px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 50px;
      border-bottom: 1px solid #eeeeee;
    }

    .arrow{
      font-size: 13px;
      font-family: PingFang SC, PingFang SC-Regular;
      font-weight: 400;
      color: #666666;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .card-content{
      padding: 16px 0 16px 0;
    }
  }

  .info-header {
    display: flex;
    padding: 6px 0 15px 0;
    align-items: center;
    justify-content: space-between;
    .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: 500;
        color: #333333;

        &:before {
          content: "";
          width: 4px;
          height: 12px;
          background: #507afd;
          border-radius: 3px;
          display: inline-block;
          margin-right: 10px;
        }
      }
    }
    .right_box {
      display: flex;
      align-items: center;
      cursor: pointer;
      font-size: 14px;
      font-family: PingFang SC, PingFang SC-Regular;
      color: #666666;

      .icon{
        margin-left: 7px
      }
    }
  }

  .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;
  }

  .status{
    font-size: 14px;
    font-family: PingFang SC, PingFang SC-Medium;
    font-weight: 500;
    text-align: center;
    color: #333333;
  }

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

  .item-title{
    font-size: 14px;
    font-family: PingFang SC, PingFang SC-Medium;
    font-weight: 500;
    color: #333333;
  }

  .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: 400;
      text-align: center;
      color: #666666;
    }

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