yxh
yxh
10 天以前 09dc74e264b6262cbe41c9c8476e24705871d4a6
src/components/RoomBedSelect/src/RoomBedSelect.vue
@@ -1,99 +1,281 @@
<script lang="ts" setup>
import { RoomVO } from '@/api/ecg/room'
import {PropType} from "vue";
import {useUserStore} from "@/store/modules/user";
const emit = defineEmits(['event-haveseat', 'event-leaveseat'])
import { PropType } from "vue";
import { UserVO } from "@/store/modules/user";
import { getCheckTypeName } from "../../../utils/checkTypeFormatter";
// 动态 :src 不会被 Vite 自动处理,需要显式 import
import openImg from '@/assets/room/open.jpg'
import doctorImg from '@/assets/room/desk-doctor.jpg'
const emit = defineEmits(['event-haveseat', 'event-leaveseat', 'event-setcurseat', 'event-takeover'])
defineComponent({
  name: 'RoomBedSelect'
})
//const  props = defineProps({
defineProps({
  title: {
    type: String,
    required: true
  },
  bedList: {
    type: Array as PropType<RoomVO[]>,
const props = defineProps({
  // 一个床位一张卡片
  bed: {
    type: Object as PropType<RoomVO>,
    required: true
  },
  curBed: {
    type: Object as PropType<RoomVO>,
    required: true
  },
  curUser: {
    type: Object as PropType<UserVO>,
    required: true
  }
})
const userStore = useUserStore()
const curUser = userStore.getUser
const onHaveSeatclick = (newItem: RoomVO) => {
  emit('event-haveseat', newItem)
}
const onLeaveSeatclick = (curItem: RoomVO) => {
  emit('event-leaveseat', curItem)
}
/** 初始化 **/
onMounted(() => {
    //console.info(props.bedList)
// 该床位是否已由当前医生入座
// 注:用字符串比较,避免后端返回 number / 前端 userId 为 string 时误判("1" !== 1)
const isMine = computed(
  () => props.bed.docId != null && String(props.bed.docId) === String(props.curUser.id)
)
// 该床位是否**被别人**占用:此时不允许入座(不挤掉正在操作的人)
const occupiedByOther = computed(
  () => props.bed.docId != null && String(props.bed.docId) !== String(props.curUser.id)
)
// 占用情况文案:空闲 / 我的工位 / 已入座:张三(拿不到姓名时显示编号)
const seatStateText = computed(() => {
  if (props.bed.docId == null) return '空闲'
  if (isMine.value) return '我的工位'
  return props.bed.docName ? `已入座:${props.bed.docName}` : `已入座(编号 ${props.bed.docId})`
})
// 该床位是否就是当前会话使用中的工位
const isCurSeat = computed(
  () => props.bed.roomId === props.curBed.roomId && props.bed.bedNo === props.curBed.bedNo
)
const onHaveSeatclick = (bed: RoomVO) => {
  emit('event-haveseat', bed)
}
const onLeaveSeatclick = (bed: RoomVO) => {
  emit('event-leaveseat', bed)
}
const onSetCurSeatclick = (bed: RoomVO) => {
  emit('event-setcurseat', bed)
}
/** 【本需求·接班自助接管】把"别人占用"的工位接管过来(父组件负责二次确认与调接口) */
const onTakeOverclick = (bed: RoomVO) => {
  emit('event-takeover', bed)
}
</script>
<template>
  <el-card style="width: 200px" shadow="hover" >
    <template #header>{{title}}</template>
    <div v-for="(bedItem, index) in bedList" :key="index">
      <div class="deskwarp">
        <img
            v-if="curBed.roomId !== bedItem.roomId || curBed.bedNo !== bedItem.bedNo"
            src="@/assets/room/desk.png"
            style="width: 100%"
            alt="无医生"
        />
        <img
            v-else
            src="@/assets/room/desk-doctor.jpeg"
            style="width: 100%"
            alt="有医生"
        />
        <div>{{bedItem.bedNo}} {{bedItem.docName}}</div>
        <el-button v-if="bedItem.docId === null" @click = onHaveSeatclick(bedItem)>
           入座
        </el-button>
        <el-button v-if="bedItem.docId === curUser.id" @click = onLeaveSeatclick(bedItem)>
           离座
        </el-button>
  <!--
    需求:用户选择的**当前诊室**卡片要加颜色,与其他卡片区分开。
    这里给卡片加 `is-current` 类(主色边框 + 浅色底 + 阴影),
    并在卡片头右侧显示「当前诊室」角标,做到一眼可辨。
  -->
  <el-card
    class="bed-card"
    :class="{ 'is-current': isCurSeat }"
    shadow="hover"
    :body-style="{ padding: '10px' }"
  >
    <template #header>
      <div class="bed-card__header">
        <span class="bed-card__title">{{ bed.roomName }}</span>
        <span v-if="isCurSeat" class="bed-card__badge">当前诊室</span>
      </div>
    </template>
    <img
      class="bed-card__img"
      :src="bed.docId === null ? openImg : doctorImg"
      :alt="bed.docId === null ? '无医生' : '有医生'"
    />
    <div class="bed-card__label">
      {{ bed.bedNo }} {{ bed.docName }} {{ bed.status === 30 ? "-暂停" : "" }}
    </div>
    <!--
      占用情况(本次需求):一眼看出这个工位是"空闲 / 我的 / 别人的"。
      原来卡片只在图片与姓名上体现,别人占了也看不出来,会出现"点了入座却被后端拒绝"的困惑。
    -->
    <div
      class="bed-card__seat"
      :class="occupiedByOther ? 'is-occupied' : isMine ? 'is-mine' : 'is-free'"
    >
      {{ seatStateText }}
    </div>
    <div class="bed-card__meta">
      <span v-for="(checkType, subIndex) in bed.checkTypes" :key="subIndex">
        {{ getCheckTypeName(checkType) }}
      </span>
      <span v-if="bed.opType === 1">领用</span>
      <span v-if="bed.opType === 2">安装</span>
    </div>
    <div class="bed-card__actions">
      <!-- 已被**别人**占用时禁用「入座」(不挤掉正在操作的人),并用 tooltip 说明原因;
           同时提供「接管」——上一班医生下班没点离座时,接班医生可自助接管 -->
      <el-tooltip
        v-if="!isMine"
        :content="
          occupiedByOther
            ? `该工位由「${bed.docName || '其他医生'}」操作中。若是上一班医生忘记离座,可点「接管」`
            : '入座到该工位'
        "
        placement="top"
      >
        <span>
          <el-button :disabled="occupiedByOther" @click="onHaveSeatclick(bed)"> 入座 </el-button>
          <!-- 【本需求·接班自助接管】仅"被他人占用"时出现;接管后对方会被强制离座 -->
          <el-button
            v-if="occupiedByOther"
            type="warning"
            plain
            @click="onTakeOverclick(bed)"
          >
            接管
          </el-button>
        </span>
      </el-tooltip>
      <template v-else>
        <el-button @click="onLeaveSeatclick(bed)"> 离座 </el-button>
        <span v-if="isCurSeat" class="bed-card__current">当前</span>
        <el-button v-else @click="onSetCurSeatclick(bed)"> 设为当前 </el-button>
      </template>
    </div>
  </el-card>
</template>
<style scoped lang="scss">
.card-title {
  font-size: 14px;
  font-weight: 600;
/* ==========================================================================
   需求:用户选择的**当前诊室**卡片加颜色,与其他卡片区分。
   注意类名 `is-current` 与 Element Plus 自带的 `.is-*` 不冲突(卡片上没有其它 is- 类)。
   ========================================================================== */
.bed-card.is-current {
  /* 主色边框加粗 + 浅色底 + 投影,三重区分,远看也明显 */
  border: 2px solid var(--el-color-primary);
  background-color: var(--el-color-primary-light-9);
  box-shadow: 0 0 8px var(--el-color-primary-light-5);
  &::before {
    position: relative;
    top: 8px;
    left: -5px;
    display: inline-block;
    width: 3px;
    height: 14px;
    //background-color: #105cfb;
    background: var(--el-color-primary);
    border-radius: 5px;
    content: '';
    transform: translateY(-50%);
  :deep(.el-card__header) {
    background-color: var(--el-color-primary-light-8);
    border-bottom: 1px solid var(--el-color-primary-light-5);
  }
  .bed-card__title {
    color: var(--el-color-primary);
  }
}
.deskwarp {
/* 卡片头:诊室名 + 当前诊室角标 */
.bed-card__header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.bed-card__badge {
  flex: none;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 400;
  line-height: 16px;
  color: #fff;
  background-color: var(--el-color-primary);
  border-radius: 3px;
  white-space: nowrap;
}
.bed-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  // 卡片头(诊室名)紧凑化
  :deep(.el-card__header) {
    flex: none;
    padding: 6px 10px;
    text-align: center;
  }
  // 卡片体:纵向排列、水平居中
  :deep(.el-card__body) {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    gap: 4px;
  }
  &__title {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
  }
  // 图片固定小尺寸,不再随卡片宽度放大
  &__img {
    flex: none;
    width: 80px;
    height: 64px;
    object-fit: contain;
  }
  &__label {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    // 列宽固定,允许换行避免溢出卡片
    text-align: center;
  }
  &__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0 5px;
    justify-content: center;
    font-size: 14px;
    line-height: 1.3;
    color: var(--el-text-color-secondary);
    text-align: center;
  }
  /* 占用情况:空闲=绿、我的=主色、被别人占=橙(配合禁用入座按钮) */
  &__seat {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    text-align: center;
    &.is-free {
      color: var(--el-color-success);
    }
    &.is-occupied {
      color: var(--el-color-warning);
    }
    &.is-mine {
      color: var(--el-color-primary);
    }
  }
  &__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
    justify-content: center;
    margin-top: 3px;
  }
  &__current {
    font-size: 15px;
    font-weight: 600;
    color: var(--el-color-primary);
  }
}
</style>