let tempList = seatList.value.reduce((acc, seat) => {
const rowIndex = seat.gRow - 1;
if (!acc[rowIndex]) {
acc[rowIndex] = [];
}
acc[rowIndex].push(seat);
return acc;
}, []);
const isSeatList = tempList
.filter(item => Array.isArray(item))
.map(row => row.filter(item => item.seatNo !== ''));
// Set realRow property for each seat
isSeatList?.forEach((itemList, index) => {
for (let i = 0; i < itemList.length; i++) {
if (itemList[i]) {
// Add a check for undefined or null
itemList[i].realRow = index + 1;
// console.log(itemList[i].realRow);
}
// itemList[i].realRow = index + 1;
}
});
selectedSeat.value.forEach(((selectedSeatItem) => {
isSeatList?.forEach((itemLists, index) => {
for (let i = 0; i < itemLists.length; i++) {
if (itemLists[i].seatNo == selectedSeatItem.seatNo) {
selectedSeatItem.realRow = itemLists[i].realRow;
// Add a check for undefined or null
// console.log(itemList[i].realRow);
}
// itemList[i].realRow = index + 1;
}
});
}))
// Group selected seats by row
const seatsByRow = selectedSeat.value.reduce((acc, seat) => {
const row = seat.row;
if (!acc[row]) {
acc[row] = [];
}
acc[row].push(seat);
return acc;
}, {});
// Check conditions based on the number of selected seats in each row
Object.values(seatsByRow).forEach(rowList => {
rowList.sort((a, b) => a.col - b.col);
switch (rowList.length) {
case 1:
let target = rowList[0];
let targetIndex = 0;
let rowNum = 0;
let seat = {}
for (let i = 0; i < isSeatList.length; i++) {
for (let j = 0; j < isSeatList[i].length; j++) {
if (target.seatNo === isSeatList[i][j].seatNo) {
seat = isSeatList[i][j]
targetIndex = j + 1;
rowNum = isSeatList[i].length;
}
}
}
if (targetIndex) {
seatList.value.forEach((item) => {
if ((item.orgIndex == seat.orgIndex + 2 && !item.canClick) || (item.orgIndex == seat.orgIndex - 2 && !item.canClick)) {
Taro.showToast({
title: "座位中间不要留空哦~",
icon: "none",
});
flag = false;
return
}
})
}
if (targetIndex == rowNum - 2) {
seatList.value.forEach((item) => {
if ((item.orgIndex == seat.orgIndex + 2 && !item.canClick)) {
Taro.showToast({
title: "座位中间不要留空哦~",
icon: "none",
});
flag = false;
return
}
})
return;
}
if (targetIndex == 3) {
seatList.value.forEach((item) => {
if (item.orgIndex == seat.orgIndex - 2 && !item.canClick) {
Taro.showToast({
title: "座位中间不要留空哦~",
icon: "none",
});
flag = false;
return
}
})
return;
}
if (targetIndex === 2 || targetIndex === rowNum - 1) {
if (targetIndex === rowNum - 1) {
seatList.value.forEach((item) => {
if (item.orgIndex == seat.orgIndex + 1 && item.canClick) {
Taro.showToast({
title: "座位旁边不要留空哦~",
icon: "none",
});
flag = false;
return
}
})
return;
}
if (targetIndex === 2) {
seatList.value.forEach((item) => {
if (item.orgIndex == seat.orgIndex - 1 && item.canClick) {
Taro.showToast({
title: "座位旁边不要留空哦~",
icon: "none",
});
flag = false;
return
}
})
return;
}
}
break;
case 2:
let firstIndex = 0;
let secondIndex = 0;
let rowNum2 = 0;
let seat0 = {}
let seat1 = {}
for (let i = 0; i < isSeatList.length; i++) {
for (let j = 0; j < isSeatList[i].length; j++) {
if (rowList[0].seatNo === isSeatList[i][j].seatNo) {
firstIndex = j + 1;
rowNum2 = isSeatList[i].length;
seat0 = isSeatList[i][j]
}
if (rowList[1].seatNo === isSeatList[i][j].seatNo) {
secondIndex = j + 1;
seat1 = isSeatList[i][j]
}
}
}
if (isSeatList[firstIndex - 2]?.seatNo === '' || isSeatList[secondIndex]?.seatNo === '') {
Taro.showToast({
title: "座位旁边不要留空哦~",
icon: "none",
});
flag = false;
return;
}
// break;
if (rowList[1].col - rowList[0].col === 2) {
seatList.value.forEach((item) => {
if ((item.orgIndex == rowList[0]?.orgIndex + 1 && item.canClick) || (item.orgIndex == rowList[1]?.orgIndex - 1 && item.canClick)) {
Taro.showToast({
title: "座位中间不要留空哦~",
icon: "none",
});
flag = false;
return
}
})
return;
}
if (firstIndex === 2 && secondIndex === 3) {
seatList.value.forEach((item) => {
if ((item.orgIndex == seat0?.orgIndex - 1 && item.canClick)) {
Taro.showToast({
title: "座位旁边不要留空哦~",
icon: "none",
});
flag = false
return;
}
})
}
if (firstIndex === rowNum2 - 2 && secondIndex === rowNum2 - 1) {
seatList.value.forEach((item) => {
if ((item.orgIndex == seat1?.orgIndex + 1 && item.canClick)) {
Taro.showToast({
title: "座位旁边不要留空哦~",
icon: "none",
});
flag = false
return;
}
})
}
if (firstIndex === 2 && secondIndex === rowNum2 - 1) {
seatList.value.forEach((item) => {
if ((item.orgIndex == seat0?.orgIndex - 1 && item.canClick) || (item.orgIndex == seat1?.orgIndex + 1 && item.canClick)) {
Taro.showToast({
title: "座位旁边不要留空哦~",
icon: "none",
});
flag = false;
return;
}
});
}
seatList.value.forEach((item) => {
if ((item.orgIndex == rowList[1].orgIndex - 3 && item.seatNo && !item.canClick) || (item.orgIndex == rowList[1].orgIndex + 2 && item.seatNo && !item.canClick)) {
Taro.showToast({
title: "座位旁边不要留空哦~",
icon: "none",
});
flag = false;
return;
}
});
break;
default:
if (rowList?.length >= 3) {
seatList.value.forEach((item) => {
// (&& ) ||
if ((item?.orgIndex == rowList[rowList.length - 1]?.orgIndex + 2 && !item?.canClick && item.seatNo)) {
seatList.value.forEach((items) => {
if (items?.orgIndex == rowList[rowList.length - 1]?.orgIndex + 1 && items?.canClick && items.seatNo) {
Taro.showToast({
title: "座位中间不要留空哦~",
icon: "none",
});
flag = false;
return;
}
})
}
if ((item?.orgIndex == rowList[0]?.orgIndex - 2 && !item?.canClick && item.seatNo)) {
seatList.value.forEach((items) => {
if (items?.orgIndex == rowList[0]?.orgIndex - 1 && items?.canClick && items.seatNo) {
Taro.showToast({
title: "座位中间不要留空哦~",
icon: "none",
});
flag = false;
return;
}
})
}
});
}
for (let i = 0; i < rowList.length - 1; i++) {
if (rowList[i + 1].col - rowList[i].col === 2) {
seatList.value.forEach((item) => {
if ((item.orgIndex == rowList[i]?.orgIndex + 1 && item.canClick) || (item.orgIndex == rowList[i + 1]?.orgIndex - 1 && item.canClick)) {
Taro.showToast({
title: "座位中间不要留空哦~",
icon: "none",
});
flag = false;
return
}
})
}
}
let theRowSeatList = isSeatList[rowList[0]?.realRow - 1];
let first = theRowSeatList?.findIndex(item => item?.seatNo === rowList[0]?.seatNo) + 1;
let second = theRowSeatList?.findIndex(item => item?.seatNo === rowList[1]?.seatNo) + 1;
let endFirst = theRowSeatList?.findIndex(item => item.seatNo === rowList[rowList.length - 1].seatNo) + 1;
let endSecond = theRowSeatList?.findIndex(item => item.seatNo === rowList[rowList.length - 2].seatNo) + 1;
if (first === 2 && second === 3) {
seatList.value.forEach((item) => {
if ((item.orgIndex == rowList[0].orgIndex - 1 && item.canClick)) {
console.log(item.orgIndex, rowList[0].orgIndex - 1);
Taro.showToast({
title: "座位旁边不要留空哦~",
icon: "none",
});
flag = false;
return;
}
});
}
if (endFirst === theRowSeatList?.length - 1 && endSecond === theRowSeatList?.length - 2) {
seatList.value.forEach((item) => {
if ((item?.orgIndex == rowList[rowList.length - 1]?.orgIndex + 1 && item?.canClick)) {
Taro.showToast({
title: "座位旁边不要留空哦~",
icon: "none",
});
flag = false;
return;
}
});
}
if (endFirst === theRowSeatList?.length - 1 && endSecond === theRowSeatList?.length - 2) {
seatList.value.forEach((item) => {
if ((item?.orgIndex == rowList[rowList.length - 1]?.orgIndex + 1 && item?.canClick) && (item?.orgIndex == rowList[rowList.length - 1]?.orgIndex + 2 && !item?.canClick)) {
Taro.showToast({
title: "座位中间不要留空哦~",
icon: "none",
});
flag = false;
return;
}
});
}
if (first === 2) {
seatList.value.forEach((item) => {
if ((item.orgIndex == rowList[0].orgIndex - 1 && item.canClick)) {
Taro.showToast({
title: "座位旁边不要留空哦~",
icon: "none",
});
flag = false;
return;
}
});
}
if (endFirst === theRowSeatList?.length - 1) {
seatList.value.forEach((item) => {
if ((item.orgIndex == rowList[rowList.length - 1]?.orgIndex + 1 && item.canClick)) {
Taro.showToast({
title: "座位旁边不要留空哦~",
icon: "none",
});
flag = false;
return;
}
});
}
break;
}
});
if (flag) {
phoneInputVisible.value = true;
}