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
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" @submit.native.prevent>
      <el-form-item label="平台名称" prop="workOrderNo">
        <el-input v-model="queryParams.keyword" placeholder="请输入平台名称" @clear="handleQuery" clearable @keyup.enter.native="handleQuery" size="small" ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
 
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['platform:add']"
        >添加
        </el-button>
      </el-col>
    </el-row>
 
    <div>
      <el-table
        :data="tableData"
        :span-method="spanMethod"
        border
        style="width: 100%; margin-top: 20px">
        <el-table-column
          prop="platformName"
          label="平台名称">
        </el-table-column>
        <el-table-column
          prop="platformIP"
          label="平台IP">
        </el-table-column>
        <el-table-column
          prop="area"
          label="行政区域">
        </el-table-column>
        <el-table-column
          prop="remark"
          label="备注">
        </el-table-column>
<!--        <el-table-column-->
<!--          prop="monthOutLine"-->
<!--          label="本月离线时长">-->
<!--        </el-table-column>-->
        <el-table-column
          label="操作"
          width="100">
          <template slot-scope="scope">
            <el-button @click="handleEdit(scope.row)" type="text" size="small" style="margin-right: 5px">编辑</el-button>
            <el-popconfirm
              @confirm="delPlatForm(scope.row.id)"
              title="确定要删除该平台吗?"
            >
              <el-button slot="reference" type="text" size="small">删除</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
 
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="handleQuery"
      />
    </div>
 
    <el-dialog
      :title="opTitle"
      :visible.sync="addShow"
      width="500px"
      :close-on-click-modal="false"
      :before-close="addClose">
      <div>
          <el-form :model="addForm" label-position="top" :rules="addFormRules" ref="addForm" size="small">
            <el-form-item label="平台名称" prop="platformName">
              <el-input v-model="addForm.platformName"></el-input>
            </el-form-item>
            <el-form-item label="平台IP" prop="platformIP">
              <el-input v-model="addForm.platformIP"></el-input>
            </el-form-item>
            <el-form-item label="行政区域" prop="areaList">
              <el-select v-model="addForm.areaList" multiple clearable placeholder="请选择行政区域">
                <el-option
                  v-for="dict in dict.type.area_code"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="备注信息" prop="mark">
              <el-input v-model="addForm.remark"></el-input>
            </el-form-item>
          </el-form>
        </div>
<!--        <div style="flex: 4; padding-left: 20px;border-left: 1px solid #b2b2b2; min-height: 400px">-->
<!--          <div>-->
<!--            <h3>部署信息:</h3>-->
<!--          </div>-->
<!--          <div v-for="(deploy, index) in addForm.deployList" :key="index" style="margin-bottom: 20px">-->
<!--            <el-form size="small" ref="deployForm" :inline="true">-->
<!--              <el-form-item label="平台名称" prop="platformName">-->
<!--                <el-input v-model="deploy.subPlatformName"></el-input>-->
<!--              </el-form-item>-->
<!--              <el-form-item label="平台IP" prop="platformIP">-->
<!--                <el-input v-model="deploy.platformIP"></el-input>-->
<!--              </el-form-item>-->
<!--              <el-form-item label="行政区域" prop="area">-->
<!--                <el-input v-model="deploy.area"></el-input>-->
<!--              </el-form-item>-->
<!--              <el-form-item label="备注信息" prop="remark">-->
<!--                <el-input v-model="deploy.remark"></el-input>-->
<!--              </el-form-item>-->
<!--            </el-form>-->
<!--          </div>-->
<!--          <el-button style="float: right" size="small" type="primary" @click="next">继续添加</el-button>-->
<!--        </div>-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="addClose">取 消</el-button>
        <el-button type="primary" @click="addPlatform">保存</el-button>
      </span>
    </el-dialog>
 
  </div>
</template>
 
<script>
import { getPlatforms, addPlatform, editPlatform, deletePlatformById} from '@/api/platform/platform'
export default {
  name: 'index',
  dicts: ['area_code'],
  data() {
    return {
      deployRules: {
        platformName: [
          { required: true, message: '平台名称不能为空', trigger: 'blur' }
        ],
        platformIP: [
          { required: true, message: '平台IP不能为空', trigger: 'blur' }
        ],
        area: [
          { required: true, message: '行政区域不能为空', trigger: 'blur' }
        ]
      },
      addFormRules: {
        platformName: [
          { required: true, message: '平台名称不能为空', trigger: 'blur' }
        ],
        platformIP: [
          { required: true, message: '平台IP不能为空', trigger: 'blur' }
        ],
        areaList: [
          { required: true, message: '请选择区域', trigger: 'change' }
        ]
      },
      addForm: {
        id: null,
        platformName: '',
        remark: '',
        platformIp: '',
        areaList: [],
        area: '',
        deployList: [
          {
            subPlatformName: '',
            platformIp: '',
            remark: '',
            area: ''
          }
        ]  // 部署在了哪些地方
      },
      addShow: false,
      timeRange: [],
      queryParams: {
        keyword: ''
      },
      tableData: [],
      total: 0,
      currentRowNum: 0,
      opTitle: '新增平台'
    }
  },
  mounted() {
    this.getList();
  },
  methods: {
    delPlatForm(id) {
      deletePlatformById(id).then(res => {
        this.$message.success("删除成功")
        this.getList()
      })
    },
    handleEdit(row) {
      this.addForm = row;
      this.opTitle = "修改平台"
      this.addShow = true;
    },
    next() {
      this.addForm.deployList.push({
        platformName: '',
        platformIp: '',
        remark: '',
        area: ''
      })
    },
    handleAdd() {
      this.addShow = true
      this.addForm = {
        id: null,
        platformName: '',
        remark: '',
        platformIp: '',
        areaList: [],
      }
    },
    checkDeployList() {
      if (this.addForm.deployList) {
        this.addForm.deployList = this.addForm.deployList.filter(item => {
          return item.platformName || item.platformIp || item.remark || item.area;
        })
      }
    },
    addPlatform() {
      this.$refs['addForm'].validate((valid) => {
        if (valid) {
          // this.checkDeployList()
          // if (this.addForm.deployList) {
          //   console.log(this.addForm.deployList)
          //   if (this.addForm.deployList.some(item => !item.platformName || !item.platformIP || !item.area)) {
          //     this.$message.error("请检查平台部署信息是否填写完整");
          //     return; // 退出 validate 回调
          //   }
          // }
          if (this.addForm.id) {
            editPlatform(this.addForm).then(res => {
              this.$message.success("修改成功")
              this.addShow = false
              this.getList()
            })
          } else {
            addPlatform(this.addForm).then(res => {
              this.$message.success("添加成功")
              this.addShow = false
              this.getList()
            })
          }
        }
      })
    },
    addClose() {
      this.addShow = false
      // this.addForm = {
      //   platformName: '',
      //   remark: '',
      //   platformIp: '',
      //   deployList: []
      // }
    },
    getList() {
      this.loading = true
      this.queryParams['start'] = this.timeRange ? this.timeRange[0] : null
      this.queryParams['end'] = this.timeRange ? this.timeRange[1] : null
      getPlatforms(this.queryParams).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.loading = false
      })
    },
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    spanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (row.parentId === 0) {
          return {
            rowspan: row.childNum + 1,
            colspan: 1  // 只合并第一列
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
      }
 
    }
  }
}
</script>
 
<style scoped>
 
</style>