添加四个按钮控制牌位

This commit is contained in:
WindowBird 2025-10-14 15:48:58 +08:00
parent d4f3df8d38
commit 83cf936b9c

View File

@ -1,13 +1,337 @@
<template>
<view class="">
</view>
<view class="page">
<base-background />
<!-- 使用自定义导航栏组件 -->
<custom-navbar ref="customNavbar" title="牌位管理" />
<view class="header">
<!-- 状态展示 -->
<status-display v-if="loading" loading-text="加载中..." type="loading" />
<!-- 状态栏 -->
<StatusBar
v-if="selectedUnitId"
ref="statusBar"
:unit-id="selectedUnitId"
@view-details="handleViewDetails"
/>
<!-- 楼层选择器 -->
<view class="floor-selector-container">
<FloorSelector
ref="floorSelector"
:default-area-id="defaultAreaId"
:default-floor-id="defaultFloorId"
:default-unit-id="defaultUnitId"
@selection-change="handleSelectionChange"
/>
</view>
</view>
<view class="bottom">
<view class="btn-grid">
<view class="grid-btn" @click="handleForceOpen">强制开启</view>
<view class="grid-btn" @click="handleForceClose">强制关闭</view>
<view class="grid-btn" @click="handleResetDuration">时长归零</view>
<view class="grid-btn" @click="handleIncreaseDuration">增加时长</view>
</view>
</view>
</view>
</template>
<script setup>
<script>
import { CommonEnum } from "@/enum/common.js";
import SearchBox from "../../components/search-box/search-box.vue";
import StatusDisplay from "../../components/status-display/status-display.vue";
import EnshrinedList from "./compositons/enshrinedListIndex.vue";
import FloorSelector from "./compositons/floorSelector.vue";
import StatusBar from "./compositons/statusBar.vue";
// import BottomButton from "../../components/bottom-button/bottom-button.vue";
export default {
components: {
// BottomButton,
SearchBox,
StatusDisplay,
EnshrinedList,
FloorSelector,
StatusBar,
},
data() {
return {
CommonEnum,
searchName: "",
loading: false,
memorialId: "16", // 殿ID
//
defaultFloorId: "",
defaultAreaId: "",
defaultUnitId: "",
//
currentSelection: {
floor: null,
area: null,
unit: null,
},
// ID
selectedUnitId: "",
};
},
onLoad(options) {
// 殿ID
if (options.id) {
this.memorialId = options.id;
}
this.initPage();
},
onShow() {
//
if (
this.selectedUnitId &&
this.$refs.statusBar &&
typeof this.$refs.statusBar.loadUnitData === "function"
) {
this.$refs.statusBar.loadUnitData(this.selectedUnitId);
}
},
methods: {
//
async handleForceOpen() {
try {
const res = await this.$request.put(
`/bst/memorial/open/${this.selectedUnitId}`,
);
if (res && (res.code === 200 || res.status === 200)) {
uni.showToast({ title: res.msg || "操作成功", icon: "success" });
} else {
uni.showToast({
title: (res && res.msg) || "操作失败",
icon: "none",
});
}
} catch (error) {
uni.showToast({ title: "请求失败", icon: "none" });
console.error("handleForceOpen error", error);
}
},
//
async handleForceClose() {
try {
const res = await this.$request.put(
`/bst/memorial/close/${this.selectedUnitId}`,
);
if (res && (res.code === 200 || res.status === 200)) {
uni.showToast({ title: res.msg || "操作成功", icon: "success" });
} else {
uni.showToast({
title: (res && res.msg) || "操作失败",
icon: "none",
});
}
} catch (error) {
uni.showToast({ title: "请求失败", icon: "none" });
console.error("handleForceClose error", error);
}
},
//
async handleResetDuration() {
try {
const res = await this.$request.put(
`/bst/memorial/duration/reset/${this.selectedUnitId}`,
);
if (res && (res.code === 200 || res.status === 200)) {
uni.showToast({ title: res.msg || "操作成功", icon: "success" });
} else {
uni.showToast({
title: (res && res.msg) || "操作失败",
icon: "none",
});
}
} catch (error) {
uni.showToast({ title: "请求失败", icon: "none" });
console.error("handleResetDuration error", error);
}
},
//
async handleIncreaseDuration() {
try {
// 1
const res = await this.$request.put(
`/bst/memorial/duration/increase/${this.selectedUnitId}`,
{ value: 1 },
);
if (res && (res.code === 200 || res.status === 200)) {
uni.showToast({ title: res.msg || "操作成功", icon: "success" });
} else {
uni.showToast({
title: (res && res.msg) || "操作失败",
icon: "none",
});
}
} catch (error) {
uni.showToast({ title: "请求失败", icon: "none" });
console.error("handleIncreaseDuration error", error);
}
},
//
async initPage() {
this.loading = true;
try {
//
console.log("往生殿页面初始化ID:", this.memorialId);
} catch (error) {
console.error("页面初始化失败:", error);
uni.showToast({
title: "页面加载失败",
icon: "none",
});
} finally {
this.loading = false;
}
},
//
handleSearch(value) {
console.log("搜索内容:", value);
this.searchName = value;
//
uni.navigateTo({
url: `/pages/memorial/deceasedSearch?keyword=${encodeURIComponent(value)}`,
success: () => {
console.log("跳转到搜索页面成功");
},
fail: (error) => {
console.error("跳转失败:", error);
uni.showToast({
title: "页面跳转失败",
icon: "none",
});
},
});
},
//
handleItemClick(item) {
console.log("点击供奉记录:", item);
//
uni.showToast({
title: `查看 ${item.worshiperName} 的供奉记录`,
icon: "none",
});
},
//
handleSelectionChange(selection) {
console.log("楼层选择变化:", selection);
this.currentSelection = selection;
// selectedUnitId
if (selection.unit) {
console.log(
"选中单元:",
selection.unit.label,
"ID:",
selection.unit.id,
);
this.selectedUnitId = selection.unit.id;
} else {
//
this.selectedUnitId = "";
}
},
// 殿
navigateToMemorialHall(unitId) {
console.log("跳转到往生大殿页面ID:", unitId);
uni.navigateTo({
url: `/pages/memorial/memorialHall?id=${unitId}`,
success: () => {
console.log("跳转成功");
},
fail: (error) => {
console.error("跳转失败:", error);
uni.showToast({
title: "页面跳转失败",
icon: "none",
});
},
});
},
//
handleViewDetails(unitData) {
console.log("查看单元详情:", unitData);
this.navigateToMemorialHall(unitData.id);
},
// - 殿
submitPrayer() {
console.log("提交供奉跳转到往生大殿页面ID:", this.selectedUnitId);
this.navigateToMemorialHall(this.selectedUnitId);
},
},
};
</script>
<style lang="scss" scoped>
.page {
width: 100%;
min-height: 100vh;
}
.header {
width: 100%;
min-height: 100vh;
display: flex;
align-items: center;
flex-direction: column;
padding-bottom: 180rpx;
box-sizing: border-box;
}
.floor-selector-container {
margin-bottom: 30rpx;
display: flex;
justify-content: center;
}
//
:deep(.status-bar) {
width: 100%;
max-width: 750rpx;
}
.bottom {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background: #fffbf5;
height: 180rpx;
}
.btn-grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
gap: 20rpx;
padding: 20rpx 32rpx;
height: 100%;
box-sizing: border-box;
}
.grid-btn {
display: flex;
align-items: center;
justify-content: center;
background: #a24242;
color: #ffffff;
border-radius: 12rpx;
font-size: 28rpx;
}
</style>