Browse Source

采集盒

lipengtao 6 years ago
parent
commit
ef33d6005b
2 changed files with 294 additions and 116 deletions
  1. 83 0
      src/api/collectionbox.js
  2. 211 116
      src/views/baseInfoManage/boxesConfig/index.vue

+ 83 - 0
src/api/collectionbox.js

@ -0,0 +1,83 @@
1
import request from '@/utils/request'
2
3
/*  添加采集盒 */
4
export function addDevice(params) {
5
  console.log(params)
6
  return request({
7
    url: '/ajax/device',
8
    method: 'post',
9
    params
10
  })
11
}
12
13
/*  更新采集盒信息 */
14
export function updateDevice(params) {
15
  return request({
16
    url: '/ajax/device/update',
17
    method: 'post',
18
    params
19
  })
20
}
21
22
/*  删除采集盒信息 */
23
export function deleteDevice(params) {
24
  return request({
25
    url: '/ajax/device/delete',
26
    method: 'get',
27
    params
28
  })
29
}
30
31
/*  查询单个采集盒 */
32
export function queryDevice(params) {
33
  return request({
34
    url: '/ajax/device/qo',
35
    method: 'get',
36
    params
37
  })
38
}
39
40
/*  分页查询采集盒 */
41
export function pageQueryDevice(params) {
42
  return request({
43
    url: '/ajax/device/pq',
44
    method: 'get',
45
    params
46
  })
47
}
48
49
/*  采集盒所属服务器编号列表 */
50
export function DeviceOfservice(params) {
51
  return request({
52
    url: '/ajax/server/listByCode',
53
    method: 'get',
54
    params
55
  })
56
}
57
58
/*  校验采集盒编号 */
59
export function checkDeviceCode(params) {
60
  return request({
61
    url: '/ajax/server/checkCode',
62
    method: 'get',
63
    params
64
  })
65
}
66
67
/*  校验采集盒内部编号 */
68
export function checkDeviceInternalCode(params) {
69
  return request({
70
    url: '/ajax/server/checkSeq',
71
    method: 'get',
72
    params
73
  })
74
}
75
76
/*  查询服务器名字 */
77
export function queryServer(params) {
78
  return request({
79
    url: '/ajax/server/qo',
80
    method: 'get',
81
    params
82
  })
83
}

+ 211 - 116
src/views/baseInfoManage/boxesConfig/index.vue

@ -13,22 +13,22 @@
13 13
      style="width: 100%;min-height:550px;">
14 14
      <el-table-column width="150px" align="center" label="采集盒编号">
15 15
        <template slot-scope="scope">
16
          <span>{{scope.row.num}}</span>
16
          <span>{{scope.row.code}}</span>
17 17
        </template>
18 18
      </el-table-column>
19 19
      <el-table-column width="150px" align="center" label="采集盒信道数量">
20 20
        <template slot-scope="scope">
21
          <span>{{scope.row.name}}</span>
21
          <span>{{scope.row.channels}}</span>
22 22
        </template>
23 23
      </el-table-column>
24 24
      <el-table-column min-width="150px" align="center" label="所属服务器编号">
25 25
        <template slot-scope="scope">
26
          <span>{{scope.row.address}}</span>
26
          <span>{{scope.row.serverName}}</span>
27 27
        </template>
28 28
      </el-table-column>
29 29
      <el-table-column min-width="200px" align="center" label="备注信息">
30 30
        <template slot-scope="scope">
31
          <span>{{scope.row.message}}</span>
31
          <span>{{scope.row.remark}}</span>
32 32
        </template>
33 33
      </el-table-column>
34 34
      <el-table-column align="center" label="Actions" width="230" class-name="small-padding fixed-width">
@ -40,22 +40,22 @@
40 40
      </el-table-column>
41 41
    </el-table>
42 42
    <el-dialog title="采集盒配置" ref="ruleForm" :visible.sync="dialogTableVisible" width="680px">
43
      <el-form class="form-main" label-width="120px">
43
      <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" class="form-main" label-width="120px" label-position='right' status-icon>
44 44
        <el-row>
45 45
          <el-col :span="12">
46
            <el-form-item label="采集盒编号">
47
              <el-input placeholder="请输入采集盒编号"></el-input>
46
            <el-form-item label="采集盒编号"  prop="code">
47
              <el-input placeholder="请输入采集盒编号" v-model="ruleForm2.code"></el-input>
48 48
            </el-form-item>
49 49
          </el-col>
50 50
          <el-col :span="12">
51
            <el-form-item label="采集盒信道数量">
52
              <el-input placeholder="请输入采集盒信道数量"></el-input>
51
            <el-form-item label="采集盒信道数量" prop="channels">
52
              <el-input placeholder="请输入采集盒信道数量" v-model="ruleForm2.channels"></el-input>
53 53
            </el-form-item>
54 54
          </el-col>
55 55
           <el-col :span="12">
56
            <el-form-item label="所属服务器编号">
56
            <el-form-item label="所属服务器编号" prop="server">
57 57
              <el-autocomplete
58
                v-model="state4"
58
                v-model="ruleForm2.server"
59 59
                :fetch-suggestions="querySearchAsync"
60 60
                placeholder="请选择服务器编号"
61 61
                @select="handleSelect">
@ -63,20 +63,19 @@
63 63
            </el-form-item>
64 64
          </el-col>
65 65
          <el-col :span="12">
66
            <el-form-item label="内部编号">
67
              <el-input placeholder="请输入内部编号"></el-input>
66
            <el-form-item label="内部编号" prop="seq">
67
              <el-input placeholder="请输入内部编号" v-model="ruleForm2.seq"></el-input>
68 68
            </el-form-item>
69 69
          </el-col>
70 70
           <el-col :span="24" >
71
           备注
72
            <div class="editTe">
73
              <el-input type="textarea"></el-input>
74
            </div>
71
            <el-form-item label="备注" prop="remark">
72
              <el-input type="textarea" maxlength=100 v-model="ruleForm2.remark" rows=4></el-input>
73
             </el-form-item>
75 74
          </el-col>
76 75
          <el-col :span="24" class="el-btn-col">
77 76
            <div class="el-btn-col-box">
78
              <el-button type="primary" @click="submitForm('ruleForm')">确认</el-button>
79
              <el-button type="info">返回</el-button>
77
              <el-button type="primary" @click="submitForm('ruleForm2')">确认</el-button>
78
              <el-button type="info" @click="resetForm('ruleForm2')">返回</el-button>
80 79
            </div>
81 80
          </el-col>
82 81
        </el-row>
@ -90,39 +89,106 @@
90 89
</template>
91 90
92 91
<script>
93
//  import { fetchList, fetchPv, createArticle, updateArticle } from '@/api/article'
92
import { addDevice, updateDevice, deleteDevice, pageQueryDevice, DeviceOfservice, checkDeviceCode, checkDeviceInternalCode, queryServer } from '@/api/collectionbox'
94 93
import waves from '@/directive/waves'
95
//  import { parseTime } from '@/utils'
96
97 94
export default {
98 95
  name: 'complexTable',
99 96
  directives: {
100 97
    waves
101 98
  },
102 99
  data() {
100
    var server = (rule, value, callback) => {
101
      const that = this
102
      setTimeout(function() {
103
        if (value === '' || that.ruleForm2.serverId === '') {
104
          callback(new Error('请选择服务器编号'))
105
        } else {
106
          callback()
107
        }
108
      }, 300)
109
    }
110
    var seq = (rule, value, callback) => {
111
      if (value === '') {
112
        callback(new Error('请输入内部编号'))
113
      } else {
114
        if (this.edit) {
115
          checkDeviceInternalCode({ seq: value, id: this.edit }).then(response => {
116
            if (response.data) {
117
              callback(new Error('采集盒编号已存在,请重新输入'))
118
            } else {
119
              callback()
120
            }
121
          })
122
        } else {
123
          checkDeviceInternalCode({ seq: value }).then(response => {
124
            if (response.data) {
125
              callback(new Error('采集盒编号已存在,请重新输入'))
126
            } else {
127
              callback()
128
            }
129
          })
130
        }
131
      }
132
    }
133
    var code = (rule, value, callback) => {
134
      if (value === '') {
135
        callback(new Error('请输入采集盒编号'))
136
      } else {
137
        if (this.edit) {
138
          checkDeviceCode({ code: value, id: this.edit }).then(response => {
139
            if (response.data) {
140
              callback(new Error('采集盒编号已存在,请重新输入'))
141
            } else {
142
              callback()
143
            }
144
          })
145
        } else {
146
          checkDeviceCode({ code: value }).then(response => {
147
            if (response.data) {
148
              callback(new Error('采集盒编号已存在,请重新输入'))
149
            } else {
150
              callback()
151
            }
152
          })
153
        }
154
      }
155
    }
103 156
    return {
104
      restaurants: [],
105
      state4: '',
157
      edit: '',
158
      ruleForm2: {
159
        code: '',
160
        channels: '',
161
        server: '',
162
        seq: '',
163
        serverId: '',
164
        remark: ''
165
      },
166
      rules2: {
167
        code: [
168
          { required: true, validator: code, trigger: 'blur' }
169
        ],
170
        channels: [
171
          { required: true, message: '请输入采集盒数量', trigger: 'blur' }
172
        ],
173
        server: [
174
          { required: true, validator: server, trigger: 'blur' }
175
        ],
176
        seq: [
177
          { required: true, validator: seq, trigger: 'blur' }
178
        ]
179
      },
106 180
      timeout: null,
107 181
      dialogTableVisible: false,
108 182
      tableKey: 0,
109 183
      list: null,
110
      dataList: { total: 20, data: [{ num: 1111, name: '北京科技大学', address: '北京', org: '机电学院', message: '想落户上海,你还差几分?抢人才看出身,清华北大照单全收' }] },
111 184
      total: null,
112 185
      listLoading: true,
113 186
      listQuery: {
114
        page: 1,
115
        limit: 10,
116
        importance: undefined,
117
        title: undefined,
118
        type: undefined,
119
        sort: '+id'
120
      },
121
      dialogFormVisible: false,
122
      dialogStatus: '',
123
      textMap: {
124
        update: 'Edit',
125
        create: 'Create'
187
        scode: '',
188
        code: '',
189
        active: 1,
190
        pageSize: 10,
191
        pageNo: 1
126 192
      }
127 193
    }
128 194
  },
@ -132,69 +198,72 @@ export default {
132 198
    }
133 199
  },
134 200
  created() {
135
    this.restaurants = this.loadAll()
136 201
    this.getList()
137 202
  },
138 203
  methods: {
139 204
    submitForm(formName) {
205
      const that = this
140 206
      this.$refs[formName].validate((valid) => {
141 207
        if (valid) {
142
        //   let paramsData = {
143
        //     'title': this.ruleFormDem.demandTit,
144
        //     'descp': this.ruleFormDem.demandDesc,
145
        //     'province': this.ruleFormDem.province,
146
        //     'city': this.ruleFormDem.city,
147
        //     'invalidDay': util.dateFormatter(this.ruleFormDem.lastDate, false, true),
148
        //     'cost': this.selectCostRange,
149
        //     'duration': this.selectLongTime,
150
        //     'orgName': this.ruleFormDem.orgName,
151
        //     'contactNum': this.ruleFormDem.linkTel,
152
        //     'creator': this.kxUserId,
153
        //     'source': this.platSource
154
        //   };
155
        //   this.$axios.post(httpUrl.kxQurey.demand.add, paramsData).then((res) => {
156
        //     if (res.success) {
157
        //       this.$alert('我们已收到您的需求,马上为您对接合适的专家和专业机构,您可以登录科袖网与对方做进一步沟通。', '需求发布成功!', {
158
        //         confirmButtonText: '进入科袖网,发现更多服务和资源',
159
        //         type: 'success',
160
        //         center: true,
161
        //         cancelButtonText: '取消',
162
        //         callback: action => {
163
        //           if (action === 'confirm') {
164
        //             window.open(util.ekexiuUrl, '科袖网首页');
165
        //           };
166
        //         }
167
        //       });
168
        //       this.resetForm(formName);
169
        //       this.$emit('dialogChangedLogin', false);
170
        //     } else {
171
        //       this.$message({
172
        //         message: '需求发布失败,请重新发布!',
173
        //         type: 'warning'
174
        //       });
175
        //     };
176
        //     console.log(res);
177
        //   });
178
        // } else {
179
        //   console.log('error submit!!');
180
        //   return false
208
          if (!this.edit) {
209
            addDevice(this.ruleForm2).then(response => {
210
              setTimeout(function() {
211
                that.pop('已成功添加传感器')
212
              }, 1000)
213
              this.resetForm(this.ruleForm2)
214
              this.getList()
215
              this.dialogTableVisible = false
216
            }).catch(error => {
217
              console.log(error)
218
            })
219
          } else {
220
            const par = this.ruleForm2
221
            par.id = this.edit
222
            updateDevice(par).then(response => {
223
              if (response.success) {
224
                setTimeout(function() {
225
                  that.pop('已成功更新传感器')
226
                }, 1000)
227
                this.resetForm('ruleForm2')
228
                this.getList()
229
                this.dialogTableVisible = false
230
                this.edit = ''
231
                this.ruleForm2 = {
232
                  code: '',
233
                  channels: '',
234
                  server: '',
235
                  seq: '',
236
                  serverId: '',
237
                  remark: ''
238
                }
239
              }
240
            })
241
          }
181 242
        }
182 243
      })
183 244
    },
245
    resetForm(formName) {
246
      this.dialogTableVisible = false
247
      this.$refs[formName].resetFields()
248
      this.ruleForm2.mark = ''
249
    },
184 250
    getList() {
185 251
      this.listLoading = true
186
      this.list = this.dataList.data
187
      this.total = this.dataList.total
188
      setTimeout(() => {
189
        this.listLoading = false
190
      }, 1.5 * 1000)
191
      /*  fetchList(this.listQuery).then(response => {
192
        this.list = this.dataList.data
193
        this.total =  this.dataList.total
252
      pageQueryDevice(this.listQuery).then(response => {
253
        const $data = response.data.data
254
        for (let i = 0; i < $data.length; i++) {
255
          $data[i].serverName = ''
256
          queryServer({ id: $data[i].serverId }).then(response => {
257
            this.list[i].serverName = response.data.code
258
            this.$forceUpdate()
259
          })
260
        }
261
        this.list = $data
262
        this.total = response.data.total
194 263
        setTimeout(() => {
195 264
          this.listLoading = false
196 265
        }, 1.5 * 1000)
197
      })  */
266
      })
198 267
    },
199 268
    handleFilter() {
200 269
      this.listQuery.page = 1
@ -209,7 +278,28 @@ export default {
209 278
      //  this.getList()
210 279
    },
211 280
    handleModifyStatus(row, status) {
212
      this.$confirm('已成功删除该传感器', '提示', {
281
      this.$confirm('确实要删除:采集盒' + row.code + '吗?', '提示', {
282
        confirmButtonText: '确定',
283
        cancelButtonText: '取消',
284
        type: 'warning',
285
        center: true
286
      }).then(() => {
287
        deleteDevice({ id: row.id }).then(response => {
288
          if (response.success) {
289
            this.getList()
290
            this.pop('已成功删除该传感器')
291
            /*  this.$message({
292
              type: 'success',
293
              message: '已成功删除该采集盒!'
294
            })  */
295
          }
296
        })
297
      }).catch(() => {
298
299
      })
300
    },
301
    pop($par) {
302
      this.$confirm($par, '提示', {
213 303
        confirmButtonText: '确定',
214 304
        cancelButtonText: '取消',
215 305
        type: 'success',
@ -220,48 +310,53 @@ export default {
220 310
      }).catch(() => {
221 311
222 312
      })
223
      /*  this.$confirm('确实要删除:桥梁12324吗?, 是否继续?', '提示', {
224
      confirmButtonText: '确定',
225
          cancelButtonText: '取消',
226
          type: 'warning',
227
          center: true
228
        }).then(() => {
229
          this.$message({
230
            type: 'success',
231
            message: '删除成功!'
232
          });
233
        }).catch(() => {
234
235
        }); */
236 313
    },
237
    resetTemp() {
238
314
    resetTemp(row) {
315
      this.ruleForm2 = {
316
        code: row.code,
317
        channels: row.channels,
318
        server: row.serverName,
319
        seq: row.seq,
320
        serverId: row.serverId,
321
        remark: row.remark
322
      }
323
      this.edit = row.id
239 324
    },
240 325
    handleCreate() {
241 326
      this.dialogTableVisible = true
242 327
    },
243 328
    handleUpdate(row) {
244
    },
245
    loadAll() {
246
      return [{ 'value': '三全鲜食(北新泾店)', 'address': '长宁区新渔路144号' }]
329
      this.resetTemp(row)
330
      this.dialogTableVisible = true
247 331
    },
248 332
    querySearchAsync(queryString, cb) {
249
      console.log(queryString + 'wewe')
250
      var restaurants = this.restaurants
251
      var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants
252
      console.log(results + 'dddd')
333
      if (queryString === '') {
334
        cb([])
335
        return
336
      }
337
      this.ruleForm2.serverId = ''
253 338
      clearTimeout(this.timeout)
254 339
      this.timeout = setTimeout(() => {
255
        cb(results)
340
        DeviceOfservice({ code: this.ruleForm2.bridge }).then(response => {
341
          const $info = response.data
342
          if ($info.length) {
343
            const $data = $info.map(item => {
344
              return { 'value': item.code, 'id': item.id }
345
            })
346
            cb($data)
347
            if ($info.length === 1 && this.ruleForm2.bridge === $info[0].code) {
348
              this.ruleForm2.serverId = $info[0].id
349
            } else {
350
              this.ruleForm2.serverId = ''
351
            }
352
          } else {
353
            cb([])
354
          }
355
        })
256 356
      }, 3000 * Math.random())
257 357
    },
258
    createStateFilter(queryString) {
259
      return (state) => {
260
        return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0)
261
      }
262
    },
263 358
    handleSelect(item) {
264
      console.log(item + 'ccc')
359
      this.ruleForm2.serverId = item.id
265 360
    }
266 361
  }
267 362
}