ChooseInspectionRoutePoint.vue
4.79 KB
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
<template>
<el-dialog :title="$t('inspectionRoute.choosePointTitle')" :visible.sync="visible" width="70%" @close="handleClose">
<el-row :gutter="20">
<el-col :span="24">
<el-row :gutter="20" class="margin-bottom">
<el-col :span="18"></el-col>
<el-col :span="6">
<el-input v-model="chooseInspectionRoutePointInfo.inspectionName"
:placeholder="$t('inspectionRoute.pointNamePlaceholder')" clearable class="search-input">
<el-button slot="append" type="primary" @click="queryPoints">
<i class="el-icon-search"></i>
</el-button>
<el-button slot="append" type="primary" @click="resetPoints">
<i class="el-icon-refresh"></i>
</el-button>
</el-input>
</el-col>
</el-row>
<el-table :data="chooseInspectionRoutePointInfo.points" border style="width: 100%"
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column prop="inspectionId" :label="$t('inspectionRoute.pointId')" align="center" />
<el-table-column prop="inspectionName" :label="$t('inspectionRoute.pointName')" align="center" />
</el-table>
<el-pagination :current-page.sync="page.current" :page-size="page.size" :total="page.total"
layout="total, prev, pager, next" @current-change="handlePageChange" />
<div class="text-right margin-top">
<el-button @click="handleClose">
{{ $t('common.cancel') }}
</el-button>
<el-button type="primary" @click="_chooseInspectionRoutePoint">
{{ $t('common.confirm') }}
</el-button>
</div>
</el-col>
</el-row>
</el-dialog>
</template>
<script>
import { getCommunityId } from '@/api/community/communityApi'
import { listInspectionPoints, saveInspectionRoutePoint } from '@/api/inspection/inspectionRouteApi'
export default {
name: 'ChooseInspectionRoutePoint',
data() {
return {
visible: false,
chooseInspectionRoutePointInfo: {
points: [],
inspectionName: '',
inspectionRouteId: '',
selectPoints: []
},
page: {
current: 1,
size: 10,
total: 0
},
communityId: '',
multipleSelection: []
}
},
created() {
this.communityId = getCommunityId()
},
methods: {
open(params) {
this.visible = true
this.chooseInspectionRoutePointInfo.inspectionRouteId = params.inspectionRouteId
this._loadAllPointsInfo(1, 10)
},
async _loadAllPointsInfo(page, row) {
try {
const params = {
page,
row,
inspectionName: this.chooseInspectionRoutePointInfo.inspectionName,
relationship: '0',
inspectionRouteId: this.chooseInspectionRoutePointInfo.inspectionRouteId,
communityId: this.communityId
}
const { inspectionPoints, total } = await listInspectionPoints(params)
this.chooseInspectionRoutePointInfo.points = inspectionPoints
this.page.total = total
} catch (error) {
console.error('获取巡检点列表失败:', error)
}
},
async _chooseInspectionRoutePoint() {
if (this.multipleSelection.length === 0) {
this.$message.warning(this.$t('inspectionRoute.choosePointWarning'))
return
}
try {
const params = {
communityId: this.communityId,
inspectionRouteId: this.chooseInspectionRoutePointInfo.inspectionRouteId,
points: this.multipleSelection.map(item => ({
inspectionId: item.inspectionId,
inspectionName: item.inspectionName
}))
}
await saveInspectionRoutePoint(params)
this.$message.success(this.$t('common.operationSuccess'))
this.$emit('success')
this.handleClose()
} catch (error) {
console.error('添加巡检点失败:', error)
}
},
queryPoints() {
this._loadAllPointsInfo(1, 10)
},
resetPoints() {
this.chooseInspectionRoutePointInfo.inspectionName = ''
this._loadAllPointsInfo(1, 10)
},
handleSelectionChange(val) {
this.multipleSelection = val
},
handlePageChange(currentPage) {
this._loadAllPointsInfo(currentPage, 10)
},
handleClose() {
this.visible = false
this.chooseInspectionRoutePointInfo = {
points: [],
inspectionName: '',
inspectionRouteId: '',
selectPoints: []
}
this.multipleSelection = []
}
}
}
</script>
<style lang="scss" scoped>
.search-input {
width: 100%;
}
.margin-bottom {
margin-bottom: 20px;
}
.margin-top {
margin-top: 20px;
}
</style>