Blame view

src/components/inspection/ChooseInspectionRoutePoint.vue 5.32 KB
48ea9c43   wuxw   巡检开发完成
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
  <template>
    <el-dialog
      :title="$t('inspectionRoute.choosePointTitle')"
      :visible.sync="visible"
      width="70%"
      @close="handleClose"
    >
      <el-row :gutter="20">
        <el-col :span="24">
          <el-card>
            <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-card>
        </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 { data, total } = await listInspectionPoints(params)
          this.chooseInspectionRoutePointInfo.points = data
          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('inspectionRoute.addSuccess'))
          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>