增加房间

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">
<p>{{ item.name }}</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="success" @click="openUpdateDialog(item)"></el-button>
<el-button type="danger" @click="openRemove(item)"></el-button>
@ -98,7 +97,6 @@ const add_project = async () => {
data: add_project_info,
}
const res = await myApi.getProjects(param);
console.log(res);
if (res.code === 0) {
ElMessage({
message: "新增成功",

View File

@ -3,8 +3,8 @@
<div class="room-div">
<el-card>
<div>
<el-button type="primary" @click="router.push('home')"></el-button>
<el-button type="success" @click="saveProject"></el-button>
<el-button type="primary" @click="goHome"></el-button>
<el-button type="success" @click="save_room"></el-button>
</div>
<div>
<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 }">
<span>{{ item.room_name }}</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>
</el-card>
@ -39,7 +39,7 @@
<div v-for="(item, i) in lightArr" :key="item.label">
<p>{{ item.label }}</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>
</div>
</div>
@ -164,7 +164,11 @@ const project = reactive({
const room_info = reactive({
room_name: '',
room_count: 1,
lightInfo: 1, //
lightNum0: 1, //
lightNum1: 1,//0-10V
lightNum2: 1,//沿
lightNum3: 1,//沿
lightNum4:1, //DALI
type1: 0,//
type2: 0,
type3: 0,
@ -196,10 +200,6 @@ const get_project = async () => {
}
const res = await myApi.getProjects(param);
if (res.code === 0) {
ElMessage({
message: res.message,
type: "success",
});
project.name = res.data.name;
project.description = res.data.description;
if (Array.isArray(res.data.content)) {
@ -216,7 +216,15 @@ const get_project = async () => {
}
}
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(() => {
get_project();
@ -224,24 +232,21 @@ onMounted(() => {
const select_room = (item) => {
currentRoom.value = item;
console.log(123, currentRoom);
}
const add_room = () => {
if (!Array.isArray(project.content)) {
project.content = []
}
room_info.room_name = "房型" + (project.content.length + 1);
project.content.push(room_info);
let target=JSON.parse(JSON.stringify(room_info));
target.room_name = "房型" + (project.content.length + 1);
project.content.push(target);
console.log(1, project.content);
}
const saveProject = async () => {
const save_room = async () => {
const param = {
action: 102,
data: {
...project,
new_name: project.name
},
action: 1021,
data: project
}
const res = await myApi.getProjects(param);
console.log(res);
@ -259,6 +264,11 @@ const saveProject = async () => {
}
}
const goHome = () => {
save_room();
router.push('home');
}
const lightArr = reactive([{
label: '开关回路',