<script lang="ts" setup>
import { format } from 'date-fns';
import { computed, onMounted, ref } from "vue";
import type { PackageListItem } from "/#/workorder";

defineOptions({ name: "ListItem" });
const emit = defineEmits(['dismisClick'])

const props = defineProps({
  selected: {
    type: Boolean,
    default: false,
  },
  listItem: {
    type: Object as PropType<PackageListItem>,
    required: true,
  },
  showFieldList: {
    type: Array as any,
    default: () => [],
  },
  dicts: {
    type: Array,
    default: () => [],
  },
  mouseOverTask: {
    type: Array,
    default: () => [],
  },
});
const svgName = computed(() => {
  return props.selected ? "taskpack-select" : "taskpack";
});

const popconfirmTarget: any = ref(null)
const popconfirmRef: any = ref(null)

function handleDismissTask() {
  emit('dismisClick',  props.mouseOverTask.id)
  popconfirmRef.value[0]?.setShow(false); // 关闭 popconfirm
}

onMounted(async () => {
})
</script>

<template>
  <div class="list-item" :class="{ 'list-item-selected': selected }" ref="popconfirmTarget">
    <div v-for="(item, index) in showFieldList" :key="index">
      <div v-if="item.id === 'name'" 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: 180px">
              {{ listItem.name }}
            </n-ellipsis>
            <span class="list-item-header-selected">({{ listItem.pictureCount }})</span>
            <n-popconfirm id="taskPopconfirmRef" ref="popconfirmRef" :show-icon="false" :show-arrow="false"
              placement="bottom" trigger="click">
              <template #trigger>
                <span class="dismiss-task-pack" v-show="mouseOverTask?.id" style="cursor: pointer;">...</span>
              </template>
              <template #action>
                <span @click="handleDismissTask" style="cursor: pointer;">解散任务包</span>
              </template>
            </n-popconfirm>
          </span>
        </div>
      </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 === 'createdate'">
          提交时间：{{ format(listItem.createdate, "yyyy-MM-dd HH:mm:ss") }}
        </li>
        <li v-else-if="item.id === 'createTime'">
          生成时间：{{ listItem.createTime && format(listItem.createTime, "yyyy-MM-dd HH:mm:ss") }}
        </li>
        <li v-else class="ellipsis" v-if="listItem[item.id]">
          <span class="label">{{ item.name }}：</span>{{ listItem[item.id] }}
        </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 }">
          {{ listItem.packagename }}
        </span>
        <span class="list-item-header-selected">({{ listItem.pictureno }})</span>
      </div>
      <SvgIcon v-show="selected" size="14" name="more-ver" />
    </div> -->
    <!-- <ul class="list-item-detail">
      <li>筛选时间：{{ listItem.createTime }}</li>
      <li>执行人：{{ listItem.createBy }}</li>
    </ul> -->
  </div>
</template>

<style lang="less" scoped>
.list-item {
  padding: 10px 0px 10px 8px;
  position: relative;
  border-bottom: 1px solid #e8e8e8;

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

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

    .dismiss-task-pack {
      position: absolute;
      right: 15px;
    }

    .list-item-header-name {
      width: 250px;
      font-size: 16px;
      font-family: PingFang SC, PingFang SC-Medium;
      font-weight: 700;
      color: #333333;
      margin-bottom: 0 0 8px 8px;
      display: flex;
      justify-content: flex-start;
      align-items: center;

      .list-item-title {
        width: 200px;
        display: inline-block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }

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

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

  &-selected {
    background-color: #f2f5fe;
  }

  &-detail {
    margin-left: 36px;

    li {
      color: #666666;
      line-height: 18px;
      margin-bottom: 8px;
      font-size: 13px;
      font-family: PingFang SC, PingFang SC-Regular;
      font-weight: Regular;
      text-align: left;
      color: #666666;
      line-height: 18px;
    }
  }

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