<script lang="ts" setup>
import { format } from 'date-fns'
import { computed } from 'vue'

defineOptions({ name: 'ListItem' })

const props = defineProps({
  selected: {
    type: Boolean,
    default: false,
  },
  listItem: {
    type: Object as PropType<any>,
    required: true,
  },
  showFieldList: {
    type: Array as any,
    default: () => [],
  },
})
const svgName = computed(() => {
  return props.selected ? 'task-select' : 'task'
})
</script>

<template>
  <div class="list-item" :class="{ 'list-item-selected': selected }">
    <div v-for="(item, index) in showFieldList" :key="index">
      <div v-if="item.id === 'fromtaskname'" class="list-item-header">
        <div class="id-wrap">
          <SvgIcon :name="svgName" size="28" />
          <span
            class="list-item-header-name"
            :class="{ 'list-item-header-selected': selected }"
          >
            <n-ellipsis style="max-width: 226px">
              任务ID:{{ listItem.fromtaskname }}
            </n-ellipsis>
          </span>
        </div>
        <!-- <SvgIcon v-show="selected" size="14" name="more-ver" /> -->
      </div>
      <ul v-else class="list-item-detail">
        <li v-if="item.id === 'statshisText'">
          审批状态：<span
            class="list-item-status"
            :class="
              listItem.statshisText === '通过'
                ? 'list-item-success'
                : listItem.statshisText === '不通过'
                  ? 'list-item-error'
                  : 'list-item-watting'
            "
          >{{ listItem.statshisText }}</span>
        </li>
        <li v-else-if="item.id === '提报时间'">
          提交时间：{{ format(listItem.createdate, "yyyy-MM-dd HH:mm:ss") }}
        </li>
        <li v-else class="ellipsis">
          <n-ellipsis style="max-width: 226px">
            <span class="label">{{ item.name }}：</span>{{ listItem[item.id] }}
          </n-ellipsis>
        </li>
      </ul>
    </div>

    <!-- <div class="list-item-header">
      <div style="display: flex">
        <SvgIcon :name="svgName" size="28" />
        <span
          class="list-item-header-name"
          :class="{ 'list-item-header-selected': selected }"
        >
          任务ID:{{ listItem.fromtaskname }}
        </span>
      </div>
      <SvgIcon v-show="selected" size="14" name="more-ver" />
    </div> -->
    <!-- <ul class="list-item-detail">
      <li>
        审批状态：<span
          class="list-item-status"
          :class="
            listItem.statshisText == '通过'
              ? 'list-item-success'
              : listItem.statshisText == '不通过'
              ? 'list-item-error'
              : 'list-item-watting'
          "
          >{{ listItem.statshisText }}</span
        >
      </li>
      <li>审批节点：{{ listItem.tasknamehis }}</li>
      <li>
        提交时间：{{ format(listItem.createdate, "yyyy-MM-dd HH:mm:ss") }}
      </li>
      <li>提报人：{{ listItem.fromUserName }}</li>
    </ul> -->
    <div class="list-item-divider" />
  </div>
</template>

<style lang="less" scoped>
.list-item {
  padding: 12px 0px 12px 16px;
  position: relative;

  &-header {
    display: flex;
    align-items: center;

    .id-wrap{
      display: flex;
      align-items: center;
      margin-bottom: 6px
    }

    .list-item-header-name{
      width: 226px;
      font-size: 14px;
      font-family: PingFang SC, PingFang SC-Medium;
      font-weight: 500;
      color: #333333;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-bottom: 0;
    }

    &-name {
      font-size: 16px;
      font-weight: bold;
      color: #333333;
      line-height: 22px;
      margin: 0px 0px 8px 8px;
    }

    &-selected {
      color: #507afd!important;
    }
  }

  .label{
    font-size: 13px;
    font-family: PingFang SC, PingFang SC-Regular;
    font-weight: 400;
    text-align: left;
    color: #666666;
    line-height: 18px;
  }

  &-selected {
    background: rgba(68,113,232,0.07);
  }

  &-status {
    display: inline-block;
    display: flex;
    align-items: center;
  }
  &-error {
    &:before {
      content: "";
      width: 6px;
      height: 6px;
      background: #e45656;
      border-radius: 50%;
      display: inline-block;
      margin-left: 8px;
      margin-right: 4px;
    }
  }
  &-success {
    &:before {
      content: "";
      width: 6px;
      height: 6px;
      background: #53c21d;
      border-radius: 50%;
      display: inline-block;
      margin-left: 8px;
      margin-right: 4px;
    }
  }
  &-watting {
    &:before {
      content: "";
      width: 6px;
      height: 6px;
      background: #398ade;
      border-radius: 50%;
      display: inline-block;
      margin-left: 8px;
      margin-right: 4px;
    }
  }

  &-detail {
    margin-left: 36px;

    li {
      font-size: 13px;
      color: #666666;
      line-height: 18px;
      margin-bottom: 8px;
      display: flex;
    }
  }

  &-divider {
    width: 100%;
    height: 1px;
    background-color: #e8e8e8;
    position: absolute;
    bottom: 0px;
  }
}
</style>
../types
