马宇豪
2025-05-09 cbb23429b8beed72b58cbb57f9b3c56a0fb2b5d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<template>
    <tr class="m-color b-font" style="text-align: center">实验场所</tr>
    <tr>
        <td class="w-14 m-color required">场所名称</td>
        <td class="w-14 m-color">所在楼栋</td>
        <td class="w-14 m-color">房间</td>
        <td class="w-14 m-color">有无消防设施</td>
        <td class="w-14 m-color">有无隔断</td>
        <td class="w-14 m-color">场所性质</td>
        <td class="w-14 m-color">操作</td>
    </tr>
    <tr v-for="(item,index) in selectRoomState.roomList" :key="index">
        <td class="w-14">
            <el-select :disabled="selectRoomState.disabled" filterable v-model="item.siteId" @change="giveOtherRoomValue($event, index)" @focus="checkAllRoom($event, index)">
                <el-option
                    v-for="item in selectRoomState.allRoomList"
                    :key="item.id"
                    :value="item.id"
                    :label="item.siteName"
                >
                </el-option>
            </el-select>
        </td>
        <td class="w-14">
            <el-input disabled v-model="item.floor" />
        </td>
        <td class="w-14">
            <el-input disabled v-model="item.room" />
        </td>
        <td class="w-14">
<!--            <el-input :disabled="selectRoomState.disabled" v-model="item.stuffStorage" />-->
            <div>{{item.fireFacilities== 1 ? '有' : item.fireFacilities== 2 ? '无' : ''}}</div>
        </td>
        <td class="w-14">
<!--            <el-input :disabled="selectRoomState.disabled" v-model="item.stuffUnit" />-->
            <div>{{item.partitionStatus == 1 ? '有' : item.partitionStatus == 2 ? '无' : ''}}</div>
        </td>
        <td class="w-14">
<!--            <el-input type="number" :disabled="selectRoomState.disabled" v-model="item.stuffUseCount" />-->
            <div>{{item.siteType}}</div>
        </td>
        <td class="w-14">
            <el-button type="danger" :disabled="selectRoomState.disabled" @click="deleteRoomItem(index)">删除</el-button>
        </td>
    </tr>
    <tr style="text-align: center" v-if="!selectRoomState.disabled">
        <el-button type="primary" shape="round" @click="addMaterialItem()">
            添加现有实验场所
        </el-button>
        <el-button shape="round" @click="addNewRoom('新增', {})">
            新增实验场所配置
        </el-button>
    </tr>
    <room-dialog ref="roomDialogRef" :memberList="selectRoomState.memberList" :typeList="selectRoomState.typeList"></room-dialog>
</template>
 
<script setup lang="ts">
import {defineAsyncComponent, onMounted, reactive, ref, watchEffect} from "vue";
import { materialApi } from "/@/api/basic/material";
import {ElMessage} from "element-plus";
import {roomApi} from "/@/api/basic/room";
import {personApi} from "/@/api/basic/person";
let props = defineProps({
    disabled: Boolean,
    data: Array<roomListType>
});
const roomDialog = defineAsyncComponent(() => import('/@/views/basic/room/components/roomDialog.vue'));
const selectRoomState = reactive<SelectRoomType>({
    disabled: false,
    roomList: [],
    allRoomList: [],
    memberList: [],
    typeList: [],
    specialDeviceList: [
      {id: 1, name: '是'},
      {id:2, name: '否'}
    ],
    stuffStorageList: [
      {id:1, name: '智能试剂柜'},
      {id:2, name: '普通储存柜'},
    ],
    stuffUnitList: [
      {id:1, name: 'g'},
      {id:2, name: 'kg'},
      {id:3, name: 'ml'},
      {id:4, name: 'l'},
    ]
})
const roomDialogRef = ref();
 
const getAllMember = async ()=>{
  const res = await personApi().getAllPerson();
  if(res.data.code === 100){
    selectRoomState.memberList = res.data.data
  }
}
 
const getAllType = async ()=>{
  const res = await roomApi().getAllType();
  if(res.data.code === 100){
    selectRoomState.typeList = res.data.data
  }
}
 
const addMaterialItem = () => {
    selectRoomState.roomList.push({siteId: null, siteName: '', floor: '',room:'',fireFacilities: null, partitionStatus: null, siteType: ''});
};
 
watchEffect(() => {
    selectRoomState.roomList = props.data as Array<roomListType>
    selectRoomState.disabled = props.disabled
});
 
const deleteRoomItem = (index: number) => {
    selectRoomState.roomList.splice(index,1);
};
 
const addNewRoom = (title: string, value: RoomType) => {
  roomDialogRef.value.showroomDialog(title, value, selectRoomState.specialDeviceList);
}
 
const checkAllRoom = () => {
  getAllRoom()
}
 
const getAllRoom = async () => {
    let res = await roomApi().getAllRoom();
    if(res.data.code === 100){
        selectRoomState.allRoomList = JSON.parse(JSON.stringify(res.data.data));
    }else{
        ElMessage({
            type: 'warning',
            message: res.data.msg
        })
    }
};
 
const giveOtherRoomValue = (value: number, index:number) => {
    const data = selectRoomState.allRoomList.find(item => item.id === value) as allRoomListType
    selectRoomState.roomList[index] = {
        siteId: data.id,
        siteName: data.siteName,
        floor: data.floor,
        room: data.room,
        fireFacilities: data.fireFacilities,
        partitionStatus: data.partitionStatus,
        siteType: data.siteType
    };
};
 
const formatList = (formatList: Array<roomListType>) => {
    selectRoomState.roomList = formatList
};
 
defineExpose({
    dataList: selectRoomState.roomList,
    formatList
});
 
 
onMounted(() => {
    getAllMember()
    getAllType()
    getAllRoom()
});
</script>
 
<style scoped lang="scss">
.site-layout-background {
    background: #fff;
}
 
.report-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #337ecc;
    margin: 20px 0;
 
    th {
        padding: 10px 0;
        border: 1px solid #337ecc;
        border-left: none;
    }
 
    tr {
        width: 100%;
        height: 44px;
        line-height: 42px;
        border-bottom: 1px solid #ccc;
 
        &:last-of-type {
            border-bottom: none;
        }
 
        td {
            border-right: 1px solid #ccc;
            display: inline-block;
            height: 44px;
            vertical-align: middle;
            text-align: center;
            line-height: 42px;
 
            &:last-of-type {
                border-right: none;
            }
 
            &.required {
              &::before {
                content: "*";
                display: inline-block;
                color: red;
              }
            }
 
            &.w-14 {
                width: calc((100/7)/100 * 100%);
            }
 
            &.w-16 {
                width: calc((100/6)/100 * 100%);
            }
 
            &.w-18 {
                width: 16.59%;
            }
 
            &.w-20 {
                width: 20%;
            }
 
            &.w-25 {
                width: 25%;
            }
 
            &.w-50 {
                width: 50%;
            }
 
            &.w-75 {
                width: 75%;
            }
 
            .ant-input {
                height: 100%;
                border: none;
                background: #f5f7fa;
            }
 
            .ant-picker {
                width: 100%;
                height: 100%;
            }
            :deep(.el-input__wrapper ){
              box-shadow: none;
            }
        }
    }
 
    .b-font {
        font-size: 16px;
        font-weight: bolder;
    }
}
 
.m-color {
    color: #0c4995;
}
</style>