张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<template>
  <div class="main floor_main">
    <div class="main_header">
      <div class="header_item">
        <span style="color: #fff">楼号:</span>
        <el-select v-model="buildId" :size="size" clearable placeholder="请选择楼号" @change="changeBuildData">
          <el-option
            v-for="item in buildingData"
            :key="item.buildId"
            :label="item.buildNum"
            :value="item.buildId">
          </el-option>
        </el-select>
      </div>
      <div class="header_item">
        <span style="color: #fff">楼层:</span>
        <el-select v-model="floorId" :size="size" clearable placeholder="请选择楼层">
          <el-option
            v-for="item in floorData"
            :key="item.floorNum"
            :label="item.floorNum"
            :value="item.floorNum">
          </el-option>
        </el-select>
      </div>
      <div class="header_item">
        <el-button v-if="showButton('search')" icon="el-icon-search" @click="searchFloorList(true)">查询</el-button>
        <el-button class="search_btn" v-if="showButton('insert')" icon="el-icon-plus" @click="propInsert()">新增</el-button>
      </div>
    </div>
    <div class="card_main">
      <div class="card_item" v-for="item in floolList" :key="item.id">
        <div class="card_item_header">
          <div>
            楼号:<span class="item_header_value">{{item.buildNum}}</span>
          </div>
          <div>
            楼层:<span class="item_header_value">{{item.floorNum}}</span>
          </div>
        </div>
        <div class="card_item_content">
          <div>房间号:</div>
          <div class="card_item_content--list">
            <div class="list_item" v-for="item in item.dormNums.split(',')" :key="item.id">
              {{item}}
            </div>
          </div>
        </div>
        <div class="card_item_footer">
          <el-button type="text" size="mini" icon="el-icon-edit-outline" v-if="showButton('update')" @click="propUpdate(item)">修改</el-button>
          <el-button type="text" class="delete" icon="el-icon-delete" v-if="showButton('delete')" @click="deleteInfo(item)">删除</el-button>
        </div>
      </div>
    </div>
    <!-- 增加楼层房间号 修改楼层房间号 -->
    <el-dialog
      class="prop_dialog"
      :title="asyncTitle ? '新增楼层房间号' : '修改楼层房间号信息'"
      :visible.sync="asyncFloor"
      width="35%">
      <el-form ref="form" :model="formFloor" :rules="rulesFloor" label-width="auto" class="rule_form">
        <el-form-item label="楼号:" prop="buildId">
          <el-select v-model="formFloor.buildId" :size="size" clearable placeholder="请选择楼号" @change="changeBuildData">
            <el-option
              v-for="item in buildingData"
              :key="item.buildId"
              :label="item.buildNum"
              :value="item.buildId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="楼层:" prop="floorNum">
          <el-input-number 
            v-model="formFloor.floorNum" 
            :size="size"
            :min="1"
            :controls="false"
            placeholder="请输入楼层"
            @change="changeFloorData">
          </el-input-number>
        </el-form-item>
        <div class="room_table">
          <div class="room_table_header">
            <div>房间号</div>
            <el-button class="search_btn" v-if="showButton('insert')" icon="el-icon-plus" @click="addRoomInfo()">新增</el-button>
          </div>
          <div class="room_table_content">
            <el-table
              :data="roomDataList"
              height="100%">
              <el-table-column label="序号" width="100" align="center">
                <template #default="scope">
                  <span>{{scope.$index + 1}}</span>
                </template>
              </el-table-column>
              <el-table-column label="房间号" align="center">
                <template #default="{ row }">
                  <el-input 
                    v-model="row.dormNum" 
                    :size="size"
                    placeholder="请输入房间号">
                  </el-input>
                </template> 
              </el-table-column>
              <el-table-column label="操作" align="center" width="200">
                <template #default="scope">
                  <el-button class="delete_btn" size="mini" v-if="showButton('delete')" @click="deleteRoomInfo(scope.$index)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </el-form>
      <div slot="footer">
        <el-button @click="asyncFloor = false">取 消</el-button>
        <el-button class="submit_btn" @click="asyncTitle ? submitInsertForm() : submitUpdateForm()">提 交</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import { buttonPinia } from "../../../../pinia/index";
import { changeSize, throttle } from "../../../../plugins/public";
  export default {
    name: 'FloornoIndex',
    data() {
      return {
        buildId: '',
        buildingData: [],
        floorId: '',
        floorData: [],
        size: changeSize(),
        floolList: [], // 列表信息
        asyncTitle: true, // true 添加楼层房间号信息  false 修改楼层房间号信息
        asyncFloor: false, // 弹窗
        formFloor: {}, // 表单信息
        rulesFloor: {
          buildId: [{
            required: true,
            message: '请选择楼号',
            trigger: ['blur', 'change']
          }],
          floorNum: [{
            required: true,
            message: '请输入楼层号',
            trigger: 'blur'
          }]
        }, // 表单校验规则
        roomDataList: [], //
        roomList: [], // 新增的房间号信息
        deleteList: [], // 删除的房间号信息
      }
    },
    mounted() {
      const that = this;
      // 根据窗口大小动态修改组件尺寸
      window.onresize = () => {
        that.size = changeSize();
      }
      that.getAllBuildData();
      that.searchFloorList();
    },
    methods: {
      // 获取全部楼号信息
      async getAllBuildData() {
        const { data } = await this.$api.Basics.GETALLBUILDDATA();
        this.buildingData = data;
      },
      // 查询楼层信息
      searchFloorList() {
        this.floolList = [];
        this.$api.Basics.SEARCHFLOORLIST({
          buildId: this.buildId,
          floorNum: this.floorId
        }).then((res) => {
          if(res.success) {
            this.floolList = res.data.list;
          }
        })
      },
      // 打开添加信息
      propInsert() {
        this.asyncTitle = true;
        this.asyncFloor = true;
      },
      // 打开修改信息
      propUpdate(row) {
        this.asyncTitle = false;
        this.asyncFloor = true;
        this.$set(this.formFloor, 'buildId', row.buildId);
        this.$set(this.formFloor, 'floorNum', row.floorNum);
        this.searchFloorRoomList();
      },
      // 删除楼层房间号信息
      deleteInfo(row) {
        this.$confirm("该操作将删除该楼层与房间号信息,是否继续删除?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
       })
       .then(() => {
         this.$api.Basics.DELETELOORANDROOMINFO({
          buildId: row.buildId,
          floorNum: row.floorNum
        }).then(res => {
          if(res.success) {
            this.searchFloorList(true);
            this.getAllBuildData();
            this.$message.success("删除成功!");
          } else {
            this.$message.warning(res.statusMsg);
          }
        })
       })
       .catch(() => {
         this.$message.warning("您已取消");
       })
      },
      // 提交添加信息
      submitInsertForm: throttle(function() {
        this.$refs.form.validate((valid) => {
          if(valid) {
            const params = Object.assign({}, this.formFloor);
            params.roomList = this.roomDataList.map(item => {
              return {
                roomId: item.roomId,
                dormNum: item.dormNum
              }
            });
            params.deleteList = this.deleteList;
            this.$api.Basics.INSERTFLOORANDROOMINFO(params).then((res) => {
              if(res.success) {
                this.asyncFloor = false;
                this.$message.success('添加成功!');
                this.searchFloorList();
              } else {
                this.$message.warning(res.statusMsg);
              }
            })
          }
        })
      }, 3000),
      // 提交修改信息
      submitUpdateForm: throttle(function() {
        this.$refs.form.validate((valid) => {
          if(valid) {
            const params = Object.assign({}, this.formFloor);
            params.roomList = this.roomDataList.map(item => {
              return {
                roomId: item.roomId,
                dormNum: item.dormNum
              }
            });
            params.deleteList = this.deleteList;
            this.$api.Basics.UPDATEFLOORANDROOMINFO(params).then((res) => {
              if(res.success) {
                this.asyncFloor = false;
                this.$message.success('修改成功!');
                this.searchFloorList();
              } else {
                this.$message.warning(res.statusMsg);
              }
            })
          }
        })
      }, 3000),
      // 删除房间号信息
      deleteRoomInfo(index) {
        this.$nextTick(() => {
          this.roomDataList.splice(index, 1)
          this.$message.success('删除成功!');
        })
        if(this.roomDataList[index].roomId) {
          this.deleteList.push({
            roomId: this.roomDataList[index].roomId,
            dormNum: this.roomDataList[index].dormNum
          })
        }
      },
      // 选择楼号
      changeBuildData(value) {
        this.floorData = [];
        if(value) {
          const data = this.buildingData.find(item => item.buildId === value);
          this.floorData = data.floors;
        }
        if(value && this.formFloor.floorNum) {
          this.searchFloorRoomList();
        }
      },
      // 输入楼层失焦 查询楼层房间号信息
      changeFloorData(value) {
        if(value && this.formFloor.buildId) {
          this.searchFloorRoomList();
        }
      },
      // 查询房间号信息
      async searchFloorRoomList() {
        this.roomDataList = [];
        this.deleteList = [];
        await this.$api.Basics.SEARCHROOMINFOLIST({
          buildId: this.formFloor.buildId,
          floorNum: this.formFloor.floorNum
        }).then((res) => {
          if(res.success && res.data.list.length > 0) {
            this.roomDataList = res.data.list;
          }
        })
      },
      // 新增房间号信息
      addRoomInfo() {
        this.$refs.form.validate((valid) => {
          if(valid) {
            const data = {
              roomId: '',
              dormNum: ''
            };
            this.roomDataList.push(data);
            this.$message.success('增加成功,请输入房间号!');
          }
        })
      },
      // 判断按钮权限信息
      showButton(str) {
        const pinia = buttonPinia();
        return pinia.$state.buttonInfo.includes(str);
      }
    },
    watch: {
      asyncFloor(bol) {
        if(!bol) {
          this.formFloor = {};
          this.deleteList = [];
          this.roomList = [];
          this.roomDataList = [];
          this.$refs.form.resetFields();
          this.getAllBuildData();
        }
      }
    }
  }
</script>
 
<style lang="scss" scoped>
@import '../../../../style/layout-main.scss';
 
.floor_main {
  padding: 0 10px 10px;
  margin: 0 !important;
  width: 100% !important;
  height: 100% !important;
}
 
::v-deep .main_header {
  margin: 10px !important;
}
 
.card_main {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  background: transparent;
  overflow: auto;
  flex: 1;
 
  .card_item {
    display: flex;
    flex-direction: column;
    margin: 10px 10px 10px 0;
    width: calc(100% / 4);
    height: 240px;
    max-width: 390px;
    color: #0F9CAF;
    background: #031A46;
    border-radius: 4px;
 
    .card_item_header {
      padding: 10px 20px 20px;
      display: flex;
      justify-content: space-between;
 
      .item_header_value {
        color: #18F5F7;
      }
    }
 
    .card_item_content {
      position: relative;
      height: 60%;
      padding: 0 20px;
 
      .card_item_content--list {
        display: flex;
        flex-wrap: wrap;
        margin-top: 10px;
        height: 70%;
        overflow-y: auto;
 
        &::-webkit-scrollbar {
          width: 4px;
        }
 
        &::-webkit-scrollbar-thumb {
            border-radius: 10px;
            box-shadow: inset 0 0 5px transparent;
            background: rgba(8, 81, 114, .8);
        }
 
        &::-webkit-scrollbar-track {
            box-shadow: inset 0 0 5px transparent;
            border-radius: 10px;
            background: rgba(8, 81, 114, .4) 5%,;
        }
 
        .list_item {
          display: flex;
          align-items: center;
          justify-content: center;
          padding: 5px 0;
          margin: 4px;
          width: calc((100% / 7) - 8px);
          color: #18F5F7;
          background: #073C62;
          border-radius: 4px;
        }
      }
    }
 
    .card_item_footer {
      position: relative;
      padding: 10px 20px;
      display: flex;
      align-items: center;
      justify-content: space-around;
      height: 51px;
      font-size: 18px;
      border-top: 1px solid #0F9CAF;
 
      &::before {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translateX(-50%) translateY(-50%);
        width: 1px;
        height: 60%;
        background: #0F9CAF;
      }
    }
  }
}
 
.room_table {
 
  .room_table_header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 10px;
    color: #fff;
    font-size: 18px;
 
    &::before {
      content: "";
      position: absolute;
      top: 50%;
      left: 0;
      transform: translateY(-50%);
      width: 3px;
      height: 60%;
      background: #18F5F7;
    }
  }
 
  .room_table_content {
    padding: 15px 0;
    height: 300px;
  }
}
 
.delete {
  color: #F94550;
  &:hover {
    color: rgba($color: #F94550, $alpha: .7);
  }
}
</style>