增加房间

main
wangqiujuan0808 2024-03-23 23:46:32 +08:00
parent 186de06aad
commit 426393d7d7
2 changed files with 29 additions and 21 deletions

View File

@ -10,7 +10,6 @@
<el-card class="card-div" v-for="(item, index) in projects" :key="index"> <el-card class="card-div" v-for="(item, index) in projects" :key="index">
<p>{{ item.name }}</p> <p>{{ item.name }}</p>
<p>{{ item.description }}</p> <p>{{ item.description }}</p>
<p>{{ item.content }}</p>
<el-button type="primary" @click="router.push({ name: 'room', query: { project_name: item.name }})">管理</el-button> <el-button type="primary" @click="router.push({ name: 'room', query: { project_name: item.name }})">管理</el-button>
<el-button type="success" @click="openUpdateDialog(item)"></el-button> <el-button type="success" @click="openUpdateDialog(item)"></el-button>
<el-button type="danger" @click="openRemove(item)"></el-button> <el-button type="danger" @click="openRemove(item)"></el-button>
@ -98,7 +97,6 @@ const add_project = async () => {
data: add_project_info, data: add_project_info,
} }
const res = await myApi.getProjects(param); const res = await myApi.getProjects(param);
console.log(res);
if (res.code === 0) { if (res.code === 0) {
ElMessage({ ElMessage({
message: "新增成功", message: "新增成功",

View File

@ -3,8 +3,8 @@
<div class="room-div"> <div class="room-div">
<el-card> <el-card>
<div> <div>
<el-button type="primary" @click="router.push('home')"></el-button> <el-button type="primary" @click="goHome"></el-button>
<el-button type="success" @click="saveProject"></el-button> <el-button type="success" @click="save_room"></el-button>
</div> </div>
<div> <div>
<el-button type="primary" class="add-btn" :icon="Plus" @click="add_room"></el-button> <el-button type="primary" class="add-btn" :icon="Plus" @click="add_room"></el-button>
@ -14,7 +14,7 @@
:class="{ 'selectDiv': item.room_name === currentRoom.room_name }"> :class="{ 'selectDiv': item.room_name === currentRoom.room_name }">
<span>{{ item.room_name }}</span> <span>{{ item.room_name }}</span>
<span>{{ item.room_count }}</span> <span>{{ item.room_count }}</span>
<el-button type="danger" :icon="Delete" circle @click="delet_room(item)"/> <el-button :icon="Delete" circle @click="delet_room(item)"/>
</div> </div>
</div> </div>
</el-card> </el-card>
@ -39,7 +39,7 @@
<div v-for="(item, i) in lightArr" :key="item.label"> <div v-for="(item, i) in lightArr" :key="item.label">
<p>{{ item.label }}</p> <p>{{ item.label }}</p>
<p> <p>
<el-input-number v-model="currentRoom.lightInfo" :min="1" :max="100"></el-input-number> <el-input-number v-model="currentRoom['lightNum'+ item.value]" :min="1" :max="100"></el-input-number>
</p> </p>
</div> </div>
</div> </div>
@ -164,7 +164,11 @@ const project = reactive({
const room_info = reactive({ const room_info = reactive({
room_name: '', room_name: '',
room_count: 1, room_count: 1,
lightInfo: 1, // lightNum0: 1, //
lightNum1: 1,//0-10V
lightNum2: 1,//沿
lightNum3: 1,//沿
lightNum4:1, //DALI
type1: 0,// type1: 0,//
type2: 0, type2: 0,
type3: 0, type3: 0,
@ -196,10 +200,6 @@ const get_project = async () => {
} }
const res = await myApi.getProjects(param); const res = await myApi.getProjects(param);
if (res.code === 0) { if (res.code === 0) {
ElMessage({
message: res.message,
type: "success",
});
project.name = res.data.name; project.name = res.data.name;
project.description = res.data.description; project.description = res.data.description;
if (Array.isArray(res.data.content)) { if (Array.isArray(res.data.content)) {
@ -216,7 +216,15 @@ const get_project = async () => {
} }
} }
const delet_room = (item) => { const delet_room = (item) => {
get_project(); if(project.content.length === 1) {
ElMessage.warning('至少保留一个。。')
return;
}
project.content = project.content.filter(ele => {
return ele.room_name !== item.room_name;
})
console.log(123,project);
save_room();
} }
onMounted(() => { onMounted(() => {
get_project(); get_project();
@ -224,24 +232,21 @@ onMounted(() => {
const select_room = (item) => { const select_room = (item) => {
currentRoom.value = item; currentRoom.value = item;
console.log(123, currentRoom);
} }
const add_room = () => { const add_room = () => {
if (!Array.isArray(project.content)) { if (!Array.isArray(project.content)) {
project.content = [] project.content = []
} }
room_info.room_name = "房型" + (project.content.length + 1); let target=JSON.parse(JSON.stringify(room_info));
project.content.push(room_info); target.room_name = "房型" + (project.content.length + 1);
project.content.push(target);
console.log(1, project.content); console.log(1, project.content);
} }
const saveProject = async () => { const save_room = async () => {
const param = { const param = {
action: 102, action: 1021,
data: { data: project
...project,
new_name: project.name
},
} }
const res = await myApi.getProjects(param); const res = await myApi.getProjects(param);
console.log(res); console.log(res);
@ -259,6 +264,11 @@ const saveProject = async () => {
} }
} }
const goHome = () => {
save_room();
router.push('home');
}
const lightArr = reactive([{ const lightArr = reactive([{
label: '开关回路', label: '开关回路',