deviceAdmin.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. <template>
  2. <div>
  3. <div class="header_title">设备管理</div>
  4. <div class="device-management">
  5. <!-- 设备管理 -->
  6. <div class="box">
  7. <div class="box_item" v-for="item in boxList" :key="item.id">
  8. <p>{{item.name}}</p>
  9. <p>{{item.value}}</p>
  10. </div>
  11. </div>
  12. <!-- 查询条件 -->
  13. <div class="conditions">
  14. <el-form ref="searchForm" inline :model="searchForm" size="mini" label-width="110px">
  15. <el-form-item label="注册时间:" prop="registerTime" style="width: 310px">
  16. <!-- <el-input v-model="searchForm.registerTime" placeholder=""></el-input> -->
  17. <el-date-picker
  18. v-model="searchForm.registerTime"
  19. type="daterange"
  20. placeholder="选择日期"
  21. style="width: 200px"
  22. value-format="yyyy-MM-dd">
  23. </el-date-picker>
  24. </el-form-item>
  25. <el-form-item label="省市县:" prop="countyName" style="width: 310px">
  26. <el-input v-model="searchForm.countyName" placeholder="地县名/编码" style="width: 200px"></el-input>
  27. </el-form-item>
  28. <el-form-item label="牧场:" prop="farmName" style="width: 310px">
  29. <el-input v-model="searchForm.farmName" placeholder="牧场名/编码" style="width: 200px"></el-input>
  30. </el-form-item>
  31. <!-- <el-form-item label="栋舍:" prop="pigsty" style="width: 310px">
  32. <el-input v-model="searchForm.pigsty" placeholder="" style="width: 200px"></el-input>
  33. </el-form-item> -->
  34. <el-form-item label="网络通信状态:" prop="networkStatus" style="width: 310px">
  35. <el-select v-model="searchForm.networkStatus" style="width: 200px">
  36. <el-option
  37. v-for="item in networkList"
  38. :key="item.value"
  39. :label="item.label"
  40. :value="item.value">
  41. </el-option>
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item label="采集状态:" prop="acqStatus" style="width: 310px">
  45. <el-select v-model="searchForm.acqStatus" style="width: 200px">
  46. <el-option
  47. v-for="item in acqList"
  48. :key="item.value"
  49. :label="item.label"
  50. :value="item.value">
  51. </el-option>
  52. </el-select>
  53. </el-form-item>
  54. <el-form-item label="注销状态:" prop="canStatus" style="width: 310px">
  55. <el-select v-model="searchForm.canStatus" style="width: 200px">
  56. <el-option
  57. v-for="item in canList"
  58. :key="item.value"
  59. :label="item.label"
  60. :value="item.value">
  61. </el-option>
  62. </el-select>
  63. </el-form-item>
  64. <el-form-item label="设备编码:" prop="deviceCode" style="width: 310px">
  65. <el-input v-model="searchForm.deviceCode" placeholder="" style="width: 200px"></el-input>
  66. </el-form-item>
  67. <el-form-item style="margin-left: 55px">
  68. <el-button type="primary" @click="init">查询</el-button>
  69. <el-button plain type="info" @click="resetForm('searchForm')">清空</el-button>
  70. </el-form-item>
  71. </el-form>
  72. </div>
  73. <!-- 按钮栏 -->
  74. <div class="title">
  75. <div class="title-left">
  76. <i class="el-icon-s-unfold"></i>
  77. <span>设备列表</span>
  78. <el-button plain size="mini" class="button-margin">批量上传</el-button>
  79. <el-button type="primary" plain size="mini" @click="handleAddOrEdit">新增设备</el-button>
  80. </div>
  81. </div>
  82. <!-- 表格 -->
  83. <el-table
  84. :data="tableData"
  85. style="width: 100%"
  86. height="700"
  87. border
  88. stripe
  89. :default-sort="{prop: 'date', order: 'descending'}"
  90. size="mini"
  91. v-loading="dataListLoading">
  92. <el-table-column
  93. type="selection"
  94. width="40"
  95. align="center">
  96. </el-table-column>
  97. <el-table-column
  98. prop="id"
  99. label="注册ID"
  100. width="60"
  101. align="center">
  102. </el-table-column>
  103. <el-table-column
  104. prop="registerTime"
  105. sortable
  106. label="注册时间"
  107. width="100"
  108. align="center">
  109. </el-table-column>
  110. <el-table-column
  111. prop="deviceCode"
  112. label="设备编码"
  113. width="80"
  114. align="center">
  115. </el-table-column>
  116. <el-table-column
  117. prop="countyName"
  118. label="省市县"
  119. align="center">
  120. </el-table-column>
  121. <el-table-column
  122. label="省市县编码"
  123. align="center">
  124. <template slot-scope="scope">
  125. <span>{{ getCountyCode(scope.row.countyCode) }}</span>
  126. </template>
  127. </el-table-column>
  128. <el-table-column
  129. prop="farmName"
  130. label="牧场名称"
  131. width="90"
  132. align="center">
  133. </el-table-column>
  134. <el-table-column
  135. prop="farmCode"
  136. label="牧场编码"
  137. width="90"
  138. align="center">
  139. </el-table-column>
  140. <el-table-column
  141. label="阶段"
  142. width="70"
  143. align="center">
  144. <template slot-scope="scope">
  145. <span>{{ stageList[scope.row.stage - 1].label }}</span>
  146. <!-- <span>{{ scope.row.stage }}</span> -->
  147. </template>
  148. </el-table-column>
  149. <el-table-column
  150. prop="pigpenName"
  151. label="栋舍"
  152. width="100"
  153. align="center">
  154. </el-table-column>
  155. <el-table-column
  156. prop="unitName"
  157. label="单元"
  158. width="100"
  159. align="center">
  160. </el-table-column>
  161. <el-table-column
  162. prop="serverIp"
  163. label="上传服务器地址"
  164. width="105"
  165. align="center">
  166. </el-table-column>
  167. <el-table-column
  168. prop="port"
  169. label="端口"
  170. width="60"
  171. align="center">
  172. </el-table-column>
  173. <el-table-column
  174. prop="lastTime"
  175. label="最后上传时间"
  176. sortable
  177. align="center">
  178. </el-table-column>
  179. <el-table-column
  180. label="网络通信状态"
  181. width="70"
  182. align="center">
  183. <template slot-scope="scope">
  184. <span :class="{ 'normal': scope.row.networkStatus === 1, 'abnormal': scope.row.networkStatus === 0}">{{ networkList[1 - scope.row.networkStatus].label }}</span>
  185. </template>
  186. </el-table-column>
  187. <el-table-column
  188. label="采集状态"
  189. width="70"
  190. align="center">
  191. <template slot-scope="scope">
  192. <span :class="{ 'normal': scope.row.acqStatus === 1, 'abnormal': scope.row.acqStatus === 2}">{{ acqList[scope.row.acqStatus - 1].label }}</span>
  193. </template>
  194. </el-table-column>
  195. <el-table-column
  196. label="注销状态"
  197. width="70"
  198. align="center">
  199. <template slot-scope="scope">
  200. <span :class="{ 'normal': scope.row.canStatus === 1, 'logout': scope.row.canStatus === 0}">{{ canList[1 - scope.row.canStatus].label }}</span>
  201. </template>
  202. </el-table-column>
  203. <el-table-column
  204. label="操作"
  205. align="center">
  206. <template slot-scope="scope">
  207. <el-button type="text" size="small" @click="handleCheck(scope.row)">查看</el-button>
  208. <el-button type="text" size="small" @click="handleAddOrEdit(scope.row)">编辑</el-button>
  209. <el-button v-if="scope.row.canStatus === 1" type="text" size="small" @click="handleLogout(scope.row)">注销</el-button>
  210. <el-button v-else type="text" size="small" @click="handleLogin(scope.row)">在线</el-button>
  211. <el-button type="text" size="small" @click="handleDelete(scope.row)">删除</el-button>
  212. </template>
  213. <!-- TODO: 按钮 -->
  214. </el-table-column>
  215. </el-table>
  216. <table-footer
  217. :totals="totalPages"
  218. :size="pageSize"
  219. @sizeChange="sizeChange"
  220. @pageChange="pageChange">
  221. </table-footer>
  222. <!-- 新增或者编辑设备弹出框 -->
  223. <add-or-update ref="addOrUpdate" @refreshData="init"></add-or-update>
  224. </div>
  225. </div>
  226. </template>
  227. <script>
  228. import TableFooter from "../../components/TableFooter";
  229. import addOrUpdate from './addOrUpdate.vue'
  230. import {mapState} from 'vuex'
  231. export default {
  232. name: "deviceAdmin",
  233. data() {
  234. return {
  235. boxList: [ // 设备管理的方框
  236. {
  237. id: 1,
  238. name: '采集设备总数',
  239. value: 2500,
  240. },
  241. {
  242. id: 2,
  243. name: '正常设备总数',
  244. value: 2498
  245. },
  246. {
  247. id: 3,
  248. name: '异常设备总数',
  249. value: 1
  250. },
  251. {
  252. id: 4,
  253. name: '注销设备总数',
  254. value: 1
  255. }
  256. ],
  257. farmList: [ // 查询条件 - 牧场选择
  258. //
  259. ],
  260. searchForm: { // 查询条件
  261. registerTime: [],
  262. deviceCode: '',
  263. countyName: '',
  264. farmName: '',
  265. networkStatus: undefined,
  266. acqStatus: undefined,
  267. canStatus: undefined,
  268. // sortord: ''
  269. },
  270. pageSizeList: [ // 表格显示条数
  271. {
  272. value: 0,
  273. label: '显示条数'
  274. },
  275. {
  276. value: 10,
  277. label: '10条/页'
  278. },
  279. {
  280. value: 20,
  281. label: '20条/页'
  282. },
  283. {
  284. value: 50,
  285. label: '50条/页'
  286. }
  287. ],
  288. pageSize: 20, // 表格显示条数
  289. tableData: [], // 表格数据
  290. totalPages: 0, // 共 n 条数据
  291. pageIndex: 1, // 表格当前页数
  292. dataListLoading: true,
  293. stageList: [ // 阶段
  294. {
  295. value: 1,
  296. label: '配怀'
  297. },
  298. {
  299. value: 2,
  300. label: '分娩'
  301. },
  302. {
  303. value: 3,
  304. label: '保育'
  305. },
  306. {
  307. value: 4,
  308. label: '育成育肥'
  309. },
  310. {
  311. value: 5,
  312. label: '空怀'
  313. },
  314. {
  315. value: 6,
  316. label: '后备母猪'
  317. },
  318. {
  319. value: 7,
  320. label: '公猪'
  321. },
  322. {
  323. value: 8,
  324. label: '病死猪场内收集'
  325. },
  326. {
  327. value: 9,
  328. label: '病死猪无害化'
  329. }
  330. ],
  331. networkList: [ // 网络通信状态 —— 查询条件 + 表格通用
  332. {
  333. value: 1,
  334. label: '正常'
  335. },
  336. {
  337. value: 0,
  338. label: '异常'
  339. }
  340. ],
  341. acqList: [ // 采集状态 —— 查询条件 + 表格通用
  342. {
  343. value: 1,
  344. label: '正常'
  345. },
  346. {
  347. value: 2,
  348. label: '异常'
  349. }
  350. ],
  351. canList: [ // 注销状态 —— 查询条件 + 表格通用
  352. {
  353. value: 1,
  354. label: '正常'
  355. },
  356. {
  357. value: 0,
  358. label: '注销'
  359. }
  360. ]
  361. }
  362. },
  363. components: {
  364. TableFooter,
  365. addOrUpdate
  366. },
  367. computed: {
  368. ...mapState(['baseUrl'])
  369. },
  370. methods: {
  371. // 初始化
  372. init () {
  373. this.$http({
  374. url: this.$http.adornUrl(`${this.baseUrl}/manager/collectorregister/list`),
  375. method: 'get',
  376. params: this.$http.adornParams({
  377. 'page': this.pageIndex,
  378. 'limit': this.pageSize,
  379. 'farmName': this.searchForm.farmName || undefined,
  380. 'registerStartTime': this.searchForm.registerTime[0] || undefined,
  381. 'registerEndTime': this.searchForm.registerTime[1] || undefined,
  382. 'deviceCode': this.searchForm.deviceCode || undefined,
  383. 'countyName': this.searchForm.countyName || undefined,
  384. 'networkStatus': this.searchForm.networkStatus?? undefined,
  385. 'acqStatus': this.searchForm.acqStatus?? undefined,
  386. 'canStatus': this.searchForm.canStatus?? undefined
  387. }, false)
  388. }).then(({data}) => {
  389. // let res = await this.$http({
  390. // url: this.$http.adornUrl(`${this.baseUrl}/manager/collectorregister/selectPcEveryStatusCollectors`),
  391. // method: 'get'
  392. // })
  393. // this.boxList[0].value = res.data.data.total
  394. // this.boxList[1].value = res.data.data.normal
  395. // this.boxList[2].value = res.data.data.abnormal
  396. // this.boxList[3].value = res.data.data.logout
  397. this.tableData = data.page.list
  398. this.totalPages = data.page.totalCount
  399. this.dataListLoading = false
  400. }).catch(() => {
  401. this.dataListLoading = false
  402. })
  403. },
  404. initState() {
  405. this.$http({
  406. url: this.$http.adornUrl(`${this.baseUrl}/manager/collectorregister/selectPcEveryStatusCollectors`),
  407. method: 'get'
  408. })
  409. .then(res => {
  410. this.boxList[0].value = res.data.data.total
  411. this.boxList[1].value = res.data.data.normal
  412. this.boxList[2].value = res.data.data.abnormal
  413. this.boxList[3].value = res.data.data.logout
  414. })
  415. },
  416. getCountyCode (code) {
  417. let arr = code.split(',')
  418. let len = arr.length
  419. return arr[len - 1]
  420. },
  421. // 显示条数改变
  422. sizeChange (val) {
  423. this.pageSize = val
  424. this.init()
  425. },
  426. // 页数改变
  427. pageChange (val) {
  428. this.pageIndex = val
  429. this.init()
  430. },
  431. // 清空 el-form
  432. resetForm(form) {
  433. this.$refs[form].resetFields()
  434. },
  435. // 点击新增设备 or 编辑按钮
  436. handleAddOrEdit (row) {
  437. this.$nextTick(() => {
  438. this.$refs.addOrUpdate.init(row)
  439. })
  440. },
  441. // 查看按钮
  442. handleCheck (row) {
  443. // 组件间传值`/deviceInfo/${row.id}`
  444. this.$router.push({
  445. path: '/deviceInfo',
  446. query: {
  447. id: row.id,
  448. deviceCode: row.deviceCode
  449. }
  450. })
  451. },
  452. // 注销按钮
  453. handleLogout (row) {
  454. this.$confirm(`确定注销编码为{${row.deviceCode}}的设备?`, '提示', {
  455. confirmButtonText: '确定',
  456. cancelButtonText: '取消',
  457. type: 'warning'
  458. }).then(() => {
  459. this.$http({
  460. url: this.$http.adornUrl(`${this.baseUrl}/manager/collectorregister/update`),
  461. method: 'post',
  462. data: this.$http.adornData({
  463. id: row.id,
  464. canStatus: 0
  465. })
  466. }).then(result => {
  467. if (result.data.code === 0) {
  468. this.init()
  469. this.$message({
  470. message: `成功注销编码为{${row.deviceCode}}的设备`,
  471. type: 'success',
  472. duration: 1000
  473. })
  474. } else {
  475. this.$confirm(result.data.msg, '注销失败', {
  476. confirmButtonText: '确定',
  477. cancelButtonText: '取消',
  478. type: 'warning'
  479. })
  480. }
  481. })
  482. })
  483. },
  484. // 在线按钮
  485. handleLogin (row) {
  486. this.$confirm(`确定在线编码为{${row.deviceCode}}的设备?`, '提示', {
  487. confirmButtonText: '确定',
  488. cancelButtonText: '取消',
  489. type: 'warning'
  490. }).then(() => {
  491. this.$http({
  492. url: this.$http.adornUrl(`${this.baseUrl}/manager/collectorregister/update`),
  493. method: 'post',
  494. data: this.$http.adornData({
  495. id: row.id,
  496. canStatus: 1
  497. })
  498. }).then(result => {
  499. if (result.data.code === 0) {
  500. this.init()
  501. this.$message({
  502. message: `成功在线编码为{${row.deviceCode}}的设备`,
  503. type: 'success',
  504. duration: 1000
  505. })
  506. } else {
  507. this.$confirm(result.data.msg, '在线失败', {
  508. confirmButtonText: '确定',
  509. cancelButtonText: '取消',
  510. type: 'warning'
  511. })
  512. }
  513. })
  514. })
  515. },
  516. // 删除按钮
  517. handleDelete (row) {
  518. let ids = [row.id]
  519. this.$confirm(`确定删除编码为{${row.deviceCode}}的设备?`, '提示', {
  520. confirmButtonText: '确定',
  521. cancelButtonText: '取消',
  522. type: 'warning'
  523. }).then(() => {
  524. this.$http({
  525. url: this.$http.adornUrl(`${this.baseUrl}/manager/collectorregister/delete`),
  526. method: 'post',
  527. data: this.$http.adornData(ids, false)
  528. }).then(result => {
  529. if (result.data.code === 0) {
  530. this.init()
  531. this.$message({
  532. message: `成功删除编码为{${row.deviceCode}}的设备`,
  533. type: 'success',
  534. duration: 1000
  535. })
  536. } else {
  537. this.$confirm(result.data.msg, '删除失败', {
  538. confirmButtonText: '确定',
  539. cancelButtonText: '取消',
  540. type: 'warning'
  541. })
  542. }
  543. })
  544. })
  545. },
  546. },
  547. mounted() {
  548. this.init()
  549. this.initState()
  550. }
  551. }
  552. </script>
  553. <style scoped>
  554. .header_title {
  555. height: 40px;
  556. background-color: #F7F7F7;
  557. border: 1px solid #ddd;
  558. line-height: 40px;
  559. color: #6FA8C8;
  560. margin-bottom: 10px;
  561. padding-left: 20px;
  562. position: fixed;
  563. width: 1660px;
  564. z-index: 1000;
  565. }
  566. .device-management {
  567. padding-top: 40px;
  568. }
  569. .box{
  570. width: 100%;
  571. height: 140px;
  572. background-color: #F9F9F9;
  573. display: flex;
  574. justify-content: space-around;
  575. align-items: center;
  576. margin-bottom: 10px;
  577. }
  578. .box_item {
  579. width: 198px;
  580. height: 78px;
  581. border: 1px solid #ddd;
  582. text-align: center;
  583. }
  584. .box_item p {
  585. height: 39px;
  586. line-height: 39px;
  587. margin: 0;
  588. }
  589. /** 选择条件 */
  590. .conditions {
  591. width: 100%;
  592. background-color: #fff;
  593. margin: 30px 0px 10px;
  594. border: 1px solid #ddd;
  595. padding: 20px;
  596. padding-bottom: 10px;
  597. }
  598. /** 设备列表 */
  599. .title {
  600. background-color: #f3f3f3;
  601. height: 50px;
  602. line-height: 50px;
  603. border: 1px solid #ddd;
  604. font-size: 12px;
  605. }
  606. .title-left {
  607. margin-left: 20px;
  608. display: inline-block;
  609. width: 300px;
  610. }
  611. .title-left span {
  612. margin-left: 2px;
  613. }
  614. .button-margin {
  615. margin: 0 5px 0 20px;
  616. }
  617. .title-right {
  618. float: right;
  619. }
  620. /* 正常 */
  621. .normal {
  622. color: #37c20ce1;
  623. }
  624. .abnormal {
  625. color: #ff0000d3;
  626. }
  627. .logout {
  628. color: #ffd900;
  629. }
  630. </style>