<!-- components/TaskItem.vue -->
<template>
  <view class="u-tab-item" :class="{ 'u-tab-item-active': active }" @tap.stop="handleClick">
    <u-row class="full-width">
      <u-col span="2" class="text-center" style="position: relative">
        <slot name="tag" v-if="$slots.tag" :task="task"></slot>
        <template v-else>
          <u-icon :color="taskStyle(task)" name="tags-fill" size="50"></u-icon>
          <text class="seq">{{ seq }}</text>
        </template>
      </u-col>
      <u-col span="10">
        <view class="fs20">{{ task.taskNo }}</view>
        <view class="mt8 mb8">{{ task.taskName }}{{ task.assayOper }}</view>
        <view class="x-f">
          <u-icon name="clock"></u-icon>
          <text class="ml5">{{ taskAssignTime }}</text>
        </view>
      </u-col>
    </u-row>
  </view>
</template>

<script setup>
import nx from '@/nx'

const props = defineProps({
  task: {
    type: Object,
    required: true
  },
  active: {
    type: Boolean,
    default: false
  },
  seq: {
    type: Number,
    required: true
  }
})

const taskAssignTime = nx.$dayjs(props.task.taskAssignTime).format('YYYY-MM-DD HH:mm:ss')
const emit = defineEmits(['click'])

const handleClick = () => {
  emit('click')
}

// 与原逻辑一致的 taskStyle 方法
const taskStyle = task => {
  if ((task.weightTaskStatus === 0 || task.weightTaskStatus === 1) && task.reviewCount > 0) return 'red'
  if (task.weightTaskStatus === 2 && task.reviewCount > 0) return 'green'
  return ''
}
</script>

<style lang="scss" scoped>
.u-tab-item {
  padding: 3px;
  background: #f6f6f6;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #444;
  border-bottom: 2px dotted;
}

.u-tab-item-active {
  position: relative;
  color: #0055a2;
  font-weight: 600;
  background: #fff;
}
.seq {
  position: absolute;
  top: 20px;
  left: 20px;
  color: #fff;
  font-size: 11px;
}
</style>
