Commit 2ca25ccd12fe81b857c4dbc40520d725b04c5b59

Authored by wuxw
1 parent 0a06b2d1

优化完成投诉建议功能

src/api/room/roomApi.js
1 import request from '@/utils/request' 1 import request from '@/utils/request'
  2 +import { getCommunityId } from '@/api/community/communityApi'
2 3
3 // 查询房屋列表 4 // 查询房屋列表
4 export function queryRooms(params) { 5 export function queryRooms(params) {
@@ -87,4 +88,24 @@ export function queryRoomsWithOutSell(params) { @@ -87,4 +88,24 @@ export function queryRoomsWithOutSell(params) {
87 reject(error) 88 reject(error)
88 }) 89 })
89 }) 90 })
  91 +}
  92 +
  93 +// 查询房间树形数据
  94 +export function queryRoomsTree(params) {
  95 + return new Promise((resolve, reject) => {
  96 + const communityId = getCommunityId()
  97 + request({
  98 + url: '/room.queryRoomsTree',
  99 + method: 'get',
  100 + params: {
  101 + ...params,
  102 + communityId
  103 + }
  104 + }).then(response => {
  105 + const res = response.data
  106 + resolve(res)
  107 + }).catch(error => {
  108 + reject(error)
  109 + })
  110 + })
90 } 111 }
91 \ No newline at end of file 112 \ No newline at end of file
src/components/room/roomTree.vue 0 → 100644
  1 +<template>
  2 + <div class="room-tree-container">
  3 + <el-dialog :visible.sync="dialogVisible" :title="$t('roomList.selectRoom')" width="280px"
  4 + custom-class="right-dialog" :modal="false">
  5 + <el-tree ref="roomTree" :data="treeData" :props="defaultProps" node-key="id" highlight-current
  6 + :expand-on-click-node="false" @node-click="handleNodeClick">
  7 + <span slot-scope="{ node, data }" class="custom-tree-node">
  8 + <img :src="data.icon" class="tree-icon" v-if="data.icon">
  9 + <span>{{ node.label }}</span>
  10 + </span>
  11 + </el-tree>
  12 + </el-dialog>
  13 + </div>
  14 +</template>
  15 +
  16 +<script>
  17 +import { getUnits, queryRoomsTree } from '@/api/room/roomApi'
  18 +import { getCommunityId } from '@/api/community/communityApi'
  19 +
  20 +export default {
  21 + name: 'RoomTreeList',
  22 + data() {
  23 + return {
  24 + dialogVisible: false,
  25 + callName: '',
  26 + treeData: [],
  27 + defaultProps: {
  28 + children: 'children',
  29 + label: 'text'
  30 + }
  31 + }
  32 + },
  33 + methods: {
  34 + open(callName) {
  35 + this.callName = callName
  36 + this.dialogVisible = true
  37 + this.loadRoomTreeFloorAndUnits()
  38 + },
  39 + async loadRoomTreeFloorAndUnits() {
  40 + try {
  41 + const communityId = getCommunityId()
  42 + const data = await getUnits({ communityId })
  43 + this.treeData = this.formatTreeData(data)
  44 + } catch (error) {
  45 + this.$message.error(this.$t('roomTree.loadError'))
  46 + }
  47 + },
  48 + formatTreeData(units) {
  49 + const floorMap = {}
  50 +
  51 + units.forEach(unit => {
  52 + if (!floorMap[unit.floorId]) {
  53 + floorMap[unit.floorId] = {
  54 + id: `f_${unit.floorId}`,
  55 + floorId: unit.floorId,
  56 + floorNum: unit.floorNum,
  57 + icon: "/img/floor.png",
  58 + text: `${unit.floorNum}${this.$t('room.floorUnitTree.building')}`,
  59 + children: []
  60 + }
  61 + }
  62 +
  63 + const unitNode = {
  64 + id: `u_${unit.unitId}`,
  65 + unitId: unit.unitId,
  66 + text: `${unit.unitNum}${this.$t('room.floorUnitTree.unit')}`,
  67 + icon: "/img/unit.png",
  68 + children: []
  69 + }
  70 +
  71 + floorMap[unit.floorId].children.push(unitNode)
  72 + })
  73 +
  74 + return Object.values(floorMap)
  75 + },
  76 + async handleNodeClick(data, node) {
  77 + if (data.id.startsWith('u_')) {
  78 + if (!node.expanded) {
  79 + await this.loadRooms(data.unitId, node)
  80 + }
  81 + } else if (data.id.startsWith('r_')) {
  82 + this.dialogVisible = false
  83 + this.$emit('selectRoom', {
  84 + roomName: data.roomName,
  85 + roomId: data.roomId
  86 + })
  87 + }
  88 + },
  89 + async loadRooms(unitId, node) {
  90 + try {
  91 + const communityId = getCommunityId()
  92 + const { rooms } = await queryRoomsTree({
  93 + unitId,
  94 + communityId,
  95 + page: 1,
  96 + row: 1000
  97 + })
  98 + console.log(rooms);
  99 +
  100 + if (rooms && rooms.length > 0) {
  101 + const roomDatas = rooms.map(room => ({
  102 + id: `r_${room.roomId}`,
  103 + roomId: room.roomId,
  104 + roomName: `${room.floorNum}-${room.unitNum}-${room.roomNum}`,
  105 + text: room.ownerName ? `${room.roomNum}(${room.ownerName})` : room.roomNum,
  106 + icon: "/img/room.png"
  107 + }))
  108 +
  109 + this.$set(node.data, 'children', roomDatas)
  110 + }
  111 + } catch (error) {
  112 + console.error(this.$t('roomTree.loadRoomError'), error)
  113 + this.$message.error(this.$t('roomTree.loadRoomError'))
  114 + }
  115 + }
  116 + }
  117 +}
  118 +</script>
  119 +<style lang="scss" scoped>
  120 +/* 删除 scoped 改为全局样式 */
  121 +.room-tree-container ::v-deep .right-dialog {
  122 + position: fixed !important;
  123 + right: 0 !important;
  124 + top: 0 !important;
  125 + margin: 0 !important;
  126 + height: 100vh !important;
  127 +
  128 + .el-dialog {
  129 + margin: 0 !important;
  130 + height: 100% !important;
  131 + border-radius: 0 !important;
  132 + }
  133 +
  134 + .el-dialog__header {
  135 + padding: 20px !important;
  136 + border-bottom: 1px solid #eee;
  137 + }
  138 +
  139 + .el-dialog__body {
  140 + padding: 10px 20px !important;
  141 + height: calc(100% - 61px) !important; /* 减去header高度 */
  142 + overflow-y: auto;
  143 + }
  144 +}
  145 +</style>
0 \ No newline at end of file 146 \ No newline at end of file
src/views/oa/addComplaintList.vue
@@ -19,8 +19,8 @@ @@ -19,8 +19,8 @@
19 19
20 <el-row :gutter="20"> 20 <el-row :gutter="20">
21 <el-col :span="24"> 21 <el-col :span="24">
22 - <el-form-item :label="$t('addComplaint.room')" prop="roomName">  
23 - <el-input v-model="addComplaintInfo.roomName" :placeholder="$t('addComplaint.roomPlaceholder')" disabled /> 22 + <el-form-item :label="$t('addComplaint.room')" class="text-left" prop="roomName">
  23 + <el-input v-model="addComplaintInfo.roomName" style="width: 80%;" :placeholder="$t('addComplaint.roomPlaceholder')" disabled />
24 <el-button type="primary" @click="selectComplaintRoom" style="margin-left:10px"> 24 <el-button type="primary" @click="selectComplaintRoom" style="margin-left:10px">
25 {{ $t('addComplaint.register') }} 25 {{ $t('addComplaint.register') }}
26 </el-button> 26 </el-button>
@@ -58,12 +58,15 @@ @@ -58,12 +58,15 @@
58 </el-row> 58 </el-row>
59 </el-form> 59 </el-form>
60 </el-card> 60 </el-card>
  61 + <room-tree ref="roomTree" @selectRoom="selectRoom" />
  62 +
61 </div> 63 </div>
62 </template> 64 </template>
63 65
64 <script> 66 <script>
65 import { listComplaintTypes, saveComplaint } from '@/api/oa/addComplaintApi' 67 import { listComplaintTypes, saveComplaint } from '@/api/oa/addComplaintApi'
66 import { getCommunityId } from '@/api/community/communityApi' 68 import { getCommunityId } from '@/api/community/communityApi'
  69 +import roomTree from '@/components/room/roomTree'
67 70
68 export default { 71 export default {
69 name: 'AddComplaintList', 72 name: 'AddComplaintList',
@@ -98,6 +101,7 @@ export default { @@ -98,6 +101,7 @@ export default {
98 } 101 }
99 } 102 }
100 }, 103 },
  104 + components: { roomTree },
101 created() { 105 created() {
102 this.communityId = getCommunityId() 106 this.communityId = getCommunityId()
103 this.listComplaintTypes() 107 this.listComplaintTypes()
@@ -117,7 +121,11 @@ export default { @@ -117,7 +121,11 @@ export default {
117 } 121 }
118 }, 122 },
119 selectComplaintRoom() { 123 selectComplaintRoom() {
120 - this.$emit('selectRoom') 124 + this.$refs.roomTree.open()
  125 + },
  126 + selectRoom(room) {
  127 + this.addComplaintInfo.roomId = room.roomId
  128 + this.addComplaintInfo.roomName = room.roomName
121 }, 129 },
122 async saveComplaint() { 130 async saveComplaint() {
123 await this.$refs.form.validate() 131 await this.$refs.form.validate()
src/views/oa/complaintList.vue
@@ -121,7 +121,7 @@ export default { @@ -121,7 +121,7 @@ export default {
121 ViewImage, 121 ViewImage,
122 EditComplaint, 122 EditComplaint,
123 DeleteComplaint, 123 DeleteComplaint,
124 - ComplaintDetail 124 + ComplaintDetail,
125 }, 125 },
126 data() { 126 data() {
127 return { 127 return {
src/views/room/roomLang.js
@@ -4,6 +4,7 @@ export const messages = { @@ -4,6 +4,7 @@ export const messages = {
4 addBuilding: 'Add Building', 4 addBuilding: 'Add Building',
5 editBuilding: 'Edit Building', 5 editBuilding: 'Edit Building',
6 deleteBuilding: 'Delete Building', 6 deleteBuilding: 'Delete Building',
  7 + selectRoom: 'Select Room',
7 addUnit: 'Add Unit', 8 addUnit: 'Add Unit',
8 editUnit: 'Edit Unit', 9 editUnit: 'Edit Unit',
9 deleteUnit: 'Delete Unit', 10 deleteUnit: 'Delete Unit',
@@ -384,6 +385,7 @@ export const messages = { @@ -384,6 +385,7 @@ export const messages = {
384 addBuilding: '添加楼栋', 385 addBuilding: '添加楼栋',
385 editBuilding: '修改楼栋', 386 editBuilding: '修改楼栋',
386 deleteBuilding: '删除楼栋', 387 deleteBuilding: '删除楼栋',
  388 + selectRoom: '选择房屋',
387 addUnit: '添加单元', 389 addUnit: '添加单元',
388 editUnit: '修改单元', 390 editUnit: '修改单元',
389 deleteUnit: '删除单元', 391 deleteUnit: '删除单元',