掛單
This commit is contained in:
1 parent
9e251fc7d4
commit
98ee587dc0
6 files changed
+1154
-216
No files matched your search
+46
-18
@@ -187,7 +187,7 @@
|
||||
<v-expansion-panel-header class="font-weight-bold">
|
||||
<div class="d-flex align-center">
|
||||
<v-icon color="indigo" class="me-2" size="20">mdi-office-building-marker</v-icon>
|
||||
{{ building.name }} (剩餘: {{ buildingAvailableBedsCount(building) }})
|
||||
{{ building.regionPath?building.regionPath.join("/"):building.name }} (剩餘: {{ buildingAvailableBedsCount(building) }})
|
||||
</div>
|
||||
</v-expansion-panel-header>
|
||||
|
||||
@@ -223,7 +223,7 @@
|
||||
<span>
|
||||
{{ bed.name }}
|
||||
<template v-if="bed.limits && bed.limits.length > 0">
|
||||
<br>【具備條件】:{{ getSpecialNeedsText(Array.isArray(bed.limits) ? bed.limits.join(',') : String(bed.limits)) }}
|
||||
<br>【具備條件】:{{ getSpecialNeedsText(Array.isArray(bed.limits)&&bed.limits!=undefined ? bed.limits.join(',') : String(bed.limits)) }}
|
||||
</template>
|
||||
<template v-else>
|
||||
<br>(無特殊限制床位)
|
||||
@@ -330,7 +330,7 @@
|
||||
menu3: false,
|
||||
e_date: null,
|
||||
states: [
|
||||
'無特殊需求', '需要輪椅', '需要拐杖', '需要陪同人員', '需要特別飲食', '其他需求'
|
||||
//'無特殊需求', '需要輪椅', '需要拐杖', '需要陪同人員', '需要特別飲食', '其他需求'
|
||||
],
|
||||
message_dialog: false,
|
||||
message: "",
|
||||
@@ -416,6 +416,7 @@
|
||||
const guestNeeds = (this.selectedGuestForBed.specialNeeds || '').split(',').filter(c => c);
|
||||
return this.mockBuildings.map(building => {
|
||||
console.log('filteredMockBuildings:', building);
|
||||
|
||||
// 過濾房間並處理床位動態狀態
|
||||
const filteredRooms = building.rooms.map(room => {
|
||||
return {
|
||||
@@ -425,8 +426,9 @@
|
||||
// 檢查條件是否完全滿足
|
||||
const bedConditions = bed.limits || [];
|
||||
const isMatchConditions = guestNeeds.every(need => bedConditions.includes(need));
|
||||
building["regionPath"] = bed.regionPath;
|
||||
room["regionPath"] = bed.regionPath;
|
||||
|
||||
|
||||
return {
|
||||
...bed,
|
||||
isAvailableNow: bed.isAvailable && !isTakenByOthers && isMatchConditions,
|
||||
@@ -661,15 +663,27 @@
|
||||
this.message_dialog = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 關鍵排序:依據「特殊需求數量」降冪排序 (需求多的人先選床位,避免資源被搶)
|
||||
unassignedGuests.sort((a, b) => {
|
||||
const needsA = (a.specialNeeds || '').split(',').filter(c => c && c !== '無特殊需求').length;
|
||||
const needsB = (b.specialNeeds || '').split(',').filter(c => c && c !== '無特殊需求').length;
|
||||
return needsB - needsA; // 數量多的排在前面 (降冪)
|
||||
});
|
||||
|
||||
let successCount = 0;
|
||||
let failCount = 0;
|
||||
|
||||
// 2. 逐一處理未分配床位的人員
|
||||
// 3. 安全轉陣列函數
|
||||
const ensureArray = (val) => {
|
||||
if (!val) return [];
|
||||
if (Array.isArray(val)) return val;
|
||||
if (typeof val === 'string') return val.split(',').filter(c => c && c.trim() !== '');
|
||||
if (typeof val === 'object') return Object.values(val).filter(c => c);
|
||||
return [String(val)];
|
||||
};
|
||||
|
||||
// 4. 逐一處理未分配床位的人員
|
||||
for (const guest of unassignedGuests) {
|
||||
try {
|
||||
// 取得該人員入住時間區間的可分配床位
|
||||
@@ -679,12 +693,12 @@
|
||||
});
|
||||
|
||||
const availableBeds = resp.data?.availableBeds || [];
|
||||
// 過濾出真正的特殊需求 (排除「無特殊需求」與空字串)
|
||||
// 過濾出人員真正的特殊需求 (排除「無特殊需求」與空字串)
|
||||
const rawNeeds = (guest.specialNeeds || '').split(',');
|
||||
const guestNeeds = rawNeeds.filter(need => need && need !== '無特殊需求');
|
||||
|
||||
// 3. 搜尋合適的床位
|
||||
const matchedBed = availableBeds.find(bed => {
|
||||
// 先篩選出符合 basic 條件 (狀態、未被佔用、性別、需求匹配) 的床位列表
|
||||
const validBeds = availableBeds.filter(bed => {
|
||||
// A. 床位狀態需為可用 ('101')
|
||||
if (bed.statusCode !== '101') return false;
|
||||
|
||||
@@ -702,14 +716,35 @@
|
||||
}
|
||||
|
||||
// D. 特殊需求條件檢查 (人員需要的,床位必須具備)
|
||||
const bedConditions = bed.limits || [];
|
||||
const bedConditions = ensureArray(bed.limits);
|
||||
const isMatchConditions = guestNeeds.every(need => bedConditions.includes(need));
|
||||
if (!isMatchConditions) return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// 4. 若找到合適床位,進行分配
|
||||
// =========================================================
|
||||
// 關鍵優化:對符合條件的床位進行排序
|
||||
// 無特殊需求的人員 (guestNeeds.length === 0):優先選 limits 數量少的床位 (普通床位)
|
||||
// 有特殊需求的人員:優先選符合需求且 limits 最精準匹配的床位
|
||||
// =========================================================
|
||||
validBeds.sort((a, b) => {
|
||||
const limitsA = ensureArray(a.limits).length;
|
||||
const limitsB = ensureArray(b.limits).length;
|
||||
|
||||
if (guestNeeds.length === 0) {
|
||||
// 無需求者:limits 少的排前面 (升冪排序,無限制床位優先)
|
||||
return limitsA - limitsB;
|
||||
} else {
|
||||
// 有需求者:優先分配條件數量接近其需求的床位 (避免大材小用)
|
||||
return limitsA - limitsB;
|
||||
}
|
||||
});
|
||||
|
||||
// 取出最合適的床位
|
||||
const matchedBed = validBeds[0];
|
||||
|
||||
// 5. 若找到合適床位,進行分配
|
||||
if (matchedBed) {
|
||||
const buildingName = matchedBed.room?.regionName || '';
|
||||
const roomName = matchedBed.room?.name || '';
|
||||
@@ -729,16 +764,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 分配完成提示
|
||||
// 6. 分配完成提示
|
||||
this.message = `自動分配完成!成功分配 ${successCount} 位,失敗/無合適床位 ${failCount} 位。`;
|
||||
this.message_dialog = true;
|
||||
//if (!this.guadanorder.order_form.uuid) {
|
||||
// this.message_dialog = true;
|
||||
// this.message = '請先儲存掛單資訊';
|
||||
// return;
|
||||
//}
|
||||
//this.automaticBedAllocation.showModal = true;
|
||||
//this.getavailablebedcountbytime(this.guadanorder.order_form.startdate, this.guadanorder.order_form.enddate);
|
||||
},
|
||||
|
||||
getavailablebedcountbytime(startTime, endTime) {
|
||||
|
||||
@@ -897,6 +897,32 @@
|
||||
},
|
||||
changeGuadanGuest(item) {//可以變更人員、床位
|
||||
console.log('變更人員、床位', item);
|
||||
let detail = {
|
||||
uuid: item.uuid,
|
||||
fullName: item.fullName,
|
||||
gender: item.gender,
|
||||
checkInAt: item.checkinat,
|
||||
checkOutAt: item.checkoutat,
|
||||
statuscode: item.statuscode,
|
||||
statusName: item.statusName,
|
||||
note: item.note,
|
||||
handi: item.specialNeeds,
|
||||
bedUuid: item.bedUuid,
|
||||
roomUuid: item.roomUuid,
|
||||
name: item.fullName,
|
||||
guaDanOrderNo: this.guadanorder.order_form.orderNo
|
||||
orderUuid: this.guadanorder.order_form.uuid
|
||||
|
||||
}
|
||||
axios.post(HTTP_HOST + 'api/guadan/changeGuadanGuest', { guest: detail })
|
||||
.then((res => {
|
||||
this.message_dialog = true
|
||||
this.message = '掛單資料更新成功'
|
||||
this.guadanorder.order_form.uuid = res.data.uuid;
|
||||
})).catch((error) => {
|
||||
this.message_dialog = true
|
||||
this.message = '掛單資料更新失敗:' + (error.response?.data?.message || error.message)
|
||||
});
|
||||
},
|
||||
confirmDeleteGuadanOrderGuest(item) {
|
||||
console.log('取消預訂', item);
|
||||
|
||||
@@ -279,7 +279,7 @@
|
||||
formData: {
|
||||
handler(newVal) {
|
||||
//用掛單的uuid去抓掛單資料跟明細檔
|
||||
console.log('掛單uuid', newVal);
|
||||
//console.log('掛單uuid', newVal);
|
||||
if (newVal!="") {
|
||||
this.getGuadanData();
|
||||
}
|
||||
@@ -291,7 +291,7 @@
|
||||
mounted() {
|
||||
this.getActivityList()
|
||||
this.getGuadanLimits()
|
||||
console.log('掛單明細', this.formData);
|
||||
//console.log('掛單明細', this.formData);
|
||||
},
|
||||
computed: {
|
||||
assignedBedUuids() {
|
||||
|
||||
+952
-195
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user