eight
2024-10-24 1b145b5655fa023032c8713bb2375bccdf0fc314
src/views/ecg/room/RoomLoginSelect.vue
@@ -2,25 +2,26 @@
  <div style="display: flex; flex-direction: column; align-items: center;">
    <div style="display: flex; flex-wrap: wrap; justify-content: center; margin-bottom: 20px">
      <div class=roomwrap v-for="(value, key) in bedMap" :key="key">
        <RoomBedSelect :title="key" :bedList="value" v-model="curSel"/>
        <RoomBedSelect :title="key" :bedList="value" :curBed="curSel" @event-haveseat="haveSeat" @event-leaveseat="leaveSeat"/>
      </div>
      <el-empty v-if="isEmptyOpeningBed" description="工位没有开放"/>
    </div>
    <el-button type="primary" @click="roomConfirm">确认</el-button>
    <el-button type="primary" @click="test">TEST</el-button>
    <div>
      <el-button @click="confirmCurSel">确认</el-button>
      <el-button @click="resetPage">重置</el-button>
    </div>
  </div>
</template>
<script setup lang="ts">
import {RoomBedSelect} from "@/components/RoomBedSelect"
import { RoomApi, RoomVO } from '@/api/ecg/room'
import { queueApi, queueVO } from '@/api/ecg/queue'
import {useUserStore} from "@/store/modules/user";
import {CACHE_KEY, useCache} from "@/hooks/web/useCache";
import {ElMessage} from "element-plus";
import {isStringEmpty}  from "@/utils/stringUtil"
import {ElMessage, ElMessageBox} from "element-plus";
import {isStringEmpty} from "@/utils/stringUtil";
import {cloneDeep} from "lodash-es";
import {DoctorApi} from "@/api/ecg/doctor";
const {  push } = useRouter()
const { wsCache } = useCache()
defineOptions({ name: 'RoomLoginSelect' })
@@ -29,49 +30,57 @@
const userStore = useUserStore()
const curUser = userStore.getUser
const bedMap = ref<Map<string, RoomVO[]>>() // 列表的数据
const originalSel = ref<RoomVO>({
    id: 0,
    roomId: 0,
    roomName: "",
    bedNo: "",
    status: 0,
    docId: 0,
    docName: ""
});
const isEmptyOpeningBed = ref<boolean>(true);
const bedMap = ref() // 列表的数据
const curSel = ref<RoomVO>({
    id: 0,
    roomId: 0,
    roomName: "",
    bedNo: "",
    status: 0,
    docId: 0,
    docName: ""
});
  id: null,
  roomId: null,
  roomName: null,
  bedNo: null,
  status: null,
  docId: null,
  docName: null
})
/** 初始化 **/
onMounted(() => {
  console.info( curUser.id + " onMounted")
    getList()
})
onActivated(() => {
  console.info( curUser.id + " onActivated")
    getList()
})
const resetPage = () => {
    getList()
}
/** 查询列表 */
const getList = async () => {
  const data = await RoomApi.getOnstageBedMap()
  bedMap.value = data;
  resetCurSel()
    for (const key in data) {
        const roomVOArray = data[key] as RoomVO[];
        roomVOArray.forEach((roomVO) => {
            if (roomVO.docId === curUser.id) {
                originalSel.value = roomVO
                curSel.value = roomVO
                return
            }
        } )
    }
  console.info( "getList before"  )
  const data = await RoomApi.getOpeningBedMap()
  bedMap.value = data;
  console.info( "getList after " + data )
  isEmptyOpeningBed.value = true
  for (const key in data) {
      isEmptyOpeningBed.value = false
      const roomVOArray = data[key] as RoomVO[];
      roomVOArray.forEach((roomVO) => {
        if (roomVO.docId === curUser.id) {
          curSel.value = roomVO
          userStore.setRoomInfoAction(curSel.value)
        }
      })
  }
}
const roomConfirm = async () => {
  console.info(curSel.value)
  if (curSel.value.roomId === 0) {
const confirmCurSel = () => {
  if (curSel.value.docId === null ) {
    ElMessage({
      message: '请先选择工作的位置!',
      type: 'info',
@@ -80,8 +89,70 @@
    return
  }
  if (curSel.value !== originalSel.value) {
      const data = await queueApi.bedDoctorOn(curSel.value)
  if (isStringEmpty(route.redirectedFrom?.fullPath))
    push({ path: "/ecg/doctor"})
  else if(route.redirectedFrom?.fullPath === "/roomselect" )
    push({ path: "/ecg/doctor"})
  else if(route.redirectedFrom?.fullPath === "/ecg/roomselect" )
    push({ path: "/ecg/doctor"})
  else
    push({ path: route.redirectedFrom?.fullPath})
}
const haveSeatConfirm = async (newRoomVO: RoomVO) => {
  if (newRoomVO !== curSel.value) {
    let data;
    if (curSel.value.docId !== null) {
      data = await DoctorApi.bedDoctorOff(curSel.value)
      if (data !== 0) {
        ElMessage({
          message: '内部错误!' + data,
          type: 'info',
          duration: 3000 // 自动关闭时间,默认为3000ms
        });
        return
      }
    }
    resetCurSel()
    userStore.clearRoomInfoAction()
    const tempRoomVO = cloneDeep(newRoomVO)
    tempRoomVO.docId = curUser.id
    tempRoomVO.docName = curUser.nickname
    data = await DoctorApi.bedDoctorOn(tempRoomVO)
    if (data !== 0) {
      ElMessage({
        message: '内部错误!' + data,
        type: 'info',
        duration: 3000 // 自动关闭时间,默认为3000ms
      });
      return
    }
    userStore.setRoomInfoAction(tempRoomVO)
    newRoomVO.docId = curUser.id
    newRoomVO.docName = curUser.nickname
    curSel.value = newRoomVO;
  }
  if (isStringEmpty(route.redirectedFrom?.fullPath)) {
    push({path: "/ecg/doctor"})
  }
  else if(route.redirectedFrom?.fullPath === "/roomselect" ) {
    push({path: "/ecg/doctor"})
  }
  else if(route.redirectedFrom?.fullPath === "/ecg/roomselect" ) {
    push({path: "/ecg/doctor"})
  }
  else {
    push({path: route.redirectedFrom?.fullPath})
  }
}
const leaveSeatConfirm = async () => {
  if (curSel.value.docId !== null) {
      let data = await DoctorApi.bedDoctorOff(curSel.value)
      if (data !== 0) {
          ElMessage({
              message: '内部错误!' + data,
@@ -92,27 +163,50 @@
      }
  }
  userStore.setRoomInfoAction(curSel.value)
  if (isStringEmpty(route.redirectedFrom?.fullPath))
    push({ path: "/"})
  else if(route.redirectedFrom?.fullPath === "/login-room-select" )
      push({ path: "/"})
  else
    push({ path: route.redirectedFrom?.fullPath})
}
const test = () => {
  userStore.getRoom;
  console.info(userStore.getRoom);
  const userInfo = wsCache.get(CACHE_KEY.USER)
  console.info(userInfo);
}
/** 初始化 **/
onMounted(() => {
  resetCurSel()
  userStore.clearRoomInfoAction()
  getList()
})
}
const haveSeat = async (newRoomVO: RoomVO) => {
  ElMessageBox.confirm(
      '入座, 是否继续?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
  ).then(async () => {
    haveSeatConfirm(newRoomVO)
  }).catch(() => {
  });
}
const leaveSeat = (roomVO: RoomVO) => {
  ElMessageBox.confirm(
      '离座, 是否继续?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }
  ).then(() => {
    leaveSeatConfirm()
  }).catch(() => {
  });
}
const resetCurSel = () => {
    curSel.value.id = null
    curSel.value.roomId = null
    curSel.value.roomName = null
    curSel.value.bedNo = null
    curSel.value.status = null
    curSel.value.docId = null
    curSel.value.docName = null
}
</script>