scdDetail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <template>
  2. <div>
  3. <el-breadcrumb separator-class="el-icon-arrow-right">
  4. <el-breadcrumb-item>防治系统</el-breadcrumb-item>
  5. <el-breadcrumb-item :to="{ path: '/index/scd' }"
  6. >杀虫灯</el-breadcrumb-item
  7. >
  8. <el-breadcrumb-item>害虫统计</el-breadcrumb-item>
  9. </el-breadcrumb>
  10. <el-button type="success" size="small" @click="goBackPage()"
  11. ><i class="el-icon--left el-icon-d-arrow-left"></i>返回</el-button
  12. >
  13. <div class="equipInfo">
  14. <div class="equipMsg">
  15. <span>设备ID:{{ id }}</span>
  16. <span>设备名称:{{ equipStatus.equip_name || '无' }}</span>
  17. <span>位置:{{ equipStatus.lng }}</span>
  18. </div>
  19. <DateSearch @dateChange="dateChange"></DateSearch>
  20. </div>
  21. <div class="ctrl-check">
  22. <el-button type="primary" size="mini" @click="refresh">刷新</el-button>
  23. </div>
  24. <!-- 统计图 -->
  25. <div v-if="viewSwitch">
  26. <div>
  27. <el-row :gutter="10">
  28. <el-col :md="24" :lg="14">
  29. <el-card class="box-card">
  30. <div class="charts">
  31. <highcharts :options="options"></highcharts>
  32. </div>
  33. </el-card>
  34. </el-col>
  35. <el-col :md="24" :lg="10">
  36. <el-card class="box-card">
  37. <div class="pie">
  38. <highcharts :options="options2"></highcharts>
  39. </div>
  40. </el-card>
  41. </el-col>
  42. </el-row>
  43. <div class="dataTableSearch">
  44. <div>
  45. <el-button type="primary" size="mini">导出</el-button>
  46. </div>
  47. </div>
  48. </div>
  49. <el-card class="box-card">
  50. <el-table :data="tableData" stripe style="width: 100%">
  51. <el-table-column
  52. v-for="(item, index) in tableHeadTxt"
  53. :key="index"
  54. :prop="item[1]"
  55. :label="item[0]"
  56. :width="setWidth(item)"
  57. >
  58. <template slot-scope="scope">{{
  59. scope.row[scope.column.property]
  60. }}</template>
  61. </el-table-column>
  62. </el-table>
  63. <el-pagination
  64. background
  65. layout="prev, pager, next"
  66. :total="total"
  67. :current-page="queryInfo.page"
  68. @current-change="changePage"
  69. ></el-pagination>
  70. </el-card>
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. import DateSearch from '@/components/DateSearch'
  76. export default {
  77. data() {
  78. return {
  79. id: this.$route.params.e_id,
  80. lineTime: '',
  81. dataTime: '',
  82. options: {},
  83. worms: [
  84. {
  85. value: 1,
  86. label: '蛾子'
  87. },
  88. {
  89. value: 2,
  90. label: '蚊子'
  91. }
  92. ],
  93. options2: {},
  94. // 状态信息
  95. equipStatus: {},
  96. // 统计图表信息
  97. equipChartData: [],
  98. //总数据条数
  99. total: 0,
  100. // 动态表头
  101. tableHeadTxt: [
  102. ['设备开关', 'ds'],
  103. ['工作状态', 'ws'],
  104. ['灯管状态', 'tbs'],
  105. ['雨控状态', 'rps'],
  106. ['温控状态', 'tps'],
  107. ['倾倒状态', 'dps'],
  108. ['定时(h)', 'tt'],
  109. ['电击次数', 'ct'],
  110. ['温度(°C)', 'at'],
  111. ['湿度(%)', 'ah'],
  112. ['充电电压(v)', 'cv'],
  113. ['电池电压(v)', 'bv'],
  114. ['上报时间', 'addtime']
  115. ],
  116. // 表格数据
  117. tableData: [],
  118. timeRange: '',
  119. queryInfo: {
  120. begin: '',
  121. end: '',
  122. e_id: this.$route.params.e_id,
  123. d_id: this.$route.params.d_id,
  124. page: 1
  125. },
  126. viewSwitch: 1,
  127. viewSwitch2: 1,
  128. //图表实时否有数据
  129. isEchartData: true,
  130. //表格和图表按钮样式切换参数
  131. display: '0', //0代表表格、1代表图表
  132. displayView: true,
  133. // 表格和图表显示切换控制
  134. showControl: true,
  135. //echarts图表参数
  136. echartOptions: [],
  137. // 动态表头
  138. tableHead: [],
  139. // 表格数据
  140. hisData: []
  141. }
  142. },
  143. methods: {
  144. //获取折线数据
  145. getChartDataList() {
  146. this.$axios({
  147. method: 'POST',
  148. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  149. data: this.qs.stringify({
  150. device_type_id: 2,
  151. d_id: this.queryInfo.d_id,
  152. start_time: this.queryInfo.begin,
  153. end_time: this.queryInfo.end
  154. })
  155. }).then((res) => {
  156. if (res.data.message == '') {
  157. var ChartData = [
  158. {
  159. name: '温度(°C)',
  160. dat: []
  161. },
  162. {
  163. name: '湿度(%)',
  164. dat: []
  165. },
  166. {
  167. name: '击虫次数',
  168. dat: []
  169. }
  170. ]
  171. var data = res.data.data
  172. this.options = {}
  173. this.options2 = {}
  174. if (data.length > 0) {
  175. for (let item of data) {
  176. ChartData[0].dat.unshift([
  177. item.addtime * 1000 + 8 * 3600000,
  178. item.temperature
  179. ])
  180. ChartData[1].dat.unshift([
  181. item.addtime * 1000 + 8 * 3600000,
  182. item.humidity
  183. ])
  184. ChartData[2].dat.unshift([
  185. item.addtime * 1000 + 8 * 3600000,
  186. item.others
  187. ])
  188. }
  189. this.options = {
  190. title: {
  191. text: '环境温湿度',
  192. align: 'left'
  193. },
  194. subtitle: {
  195. text: ''
  196. },
  197. xAxis: {
  198. crosshair: true, //十字基准线
  199. type: 'datetime',
  200. dateTimeLabelFormats: {
  201. //根据时间间距X轴自动显示哪种格式
  202. millisecond: '%H:%M:%S.%L',
  203. second: '%H:%M:%S',
  204. minute: '%H:%M',
  205. hour: '%H:%M',
  206. day: '%m-%d',
  207. week: '%m-%d',
  208. month: '%Y-%m',
  209. year: '%Y'
  210. }
  211. },
  212. yAxis: {
  213. title: {
  214. text: ''
  215. }
  216. },
  217. legend: {
  218. // layout: 'vertical',
  219. align: 'right',
  220. verticalAlign: 'top'
  221. },
  222. plotOptions: {
  223. series: {
  224. label: {
  225. connectorAllowed: false
  226. },
  227. pointStart: 2010
  228. }
  229. },
  230. series: [
  231. {
  232. name: ChartData[0].name,
  233. data: ChartData[0].dat
  234. },
  235. {
  236. name: ChartData[1].name,
  237. data: ChartData[1].dat
  238. }
  239. ],
  240. colors: ['#00e29d', '#6cbbff', '#ff3f3f'],
  241. credits: {
  242. //去掉默认的highcharts.com
  243. enabled: false
  244. },
  245. tooltip: {
  246. // crosshairs: true,
  247. shared: true, //折线共享
  248. headerFormat: '<b>{point.x:%Y-%m-%e %H:%M:%S}</b><br>'
  249. },
  250. responsive: {
  251. rules: [
  252. {
  253. condition: {
  254. maxWidth: 500
  255. },
  256. chartOptions: {
  257. legend: {
  258. layout: 'horizontal',
  259. align: 'center',
  260. verticalAlign: 'bottom'
  261. }
  262. }
  263. }
  264. ]
  265. }
  266. }
  267. this.options2 = {
  268. title: {
  269. text: '击虫次数',
  270. align: 'left'
  271. },
  272. subtitle: {
  273. text: ''
  274. },
  275. xAxis: {
  276. crosshair: true, //十字基准线
  277. type: 'datetime',
  278. dateTimeLabelFormats: {
  279. //根据时间间距X轴自动显示哪种格式
  280. millisecond: '%H:%M:%S.%L',
  281. second: '%H:%M:%S',
  282. minute: '%H:%M',
  283. hour: '%H:%M',
  284. day: '%m-%d',
  285. week: '%m-%d',
  286. month: '%Y-%m',
  287. year: '%Y'
  288. }
  289. },
  290. yAxis: {
  291. title: {
  292. text: ''
  293. }
  294. },
  295. legend: {
  296. // layout: 'vertical',
  297. align: 'right',
  298. verticalAlign: 'top'
  299. },
  300. plotOptions: {
  301. series: {
  302. label: {
  303. connectorAllowed: false
  304. },
  305. pointStart: 2010
  306. }
  307. },
  308. series: [
  309. {
  310. name: ChartData[2].name,
  311. data: ChartData[2].dat
  312. }
  313. ],
  314. colors: ['#00e29d', '#6cbbff', '#ff3f3f'],
  315. credits: {
  316. //去掉默认的highcharts.com
  317. enabled: false
  318. },
  319. tooltip: {
  320. // crosshairs: true,
  321. shared: true, //折线共享
  322. headerFormat: '<b>{point.x:%Y-%m-%e %H:%M:%S}</b><br>'
  323. },
  324. responsive: {
  325. rules: [
  326. {
  327. condition: {
  328. maxWidth: 500
  329. },
  330. chartOptions: {
  331. legend: {
  332. layout: 'horizontal',
  333. align: 'center',
  334. verticalAlign: 'bottom'
  335. }
  336. }
  337. }
  338. ]
  339. }
  340. }
  341. }
  342. }
  343. })
  344. },
  345. //获取表格数据
  346. getHisDataList() {
  347. this.$axios({
  348. method: 'POST',
  349. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  350. data: this.qs.stringify({
  351. device_type_id: 2,
  352. device_id: this.queryInfo.e_id,
  353. start_time: this.queryInfo.begin,
  354. end_time: this.queryInfo.end,
  355. page: this.queryInfo.page
  356. })
  357. }).then((res) => {
  358. if (res.data.message == '') {
  359. this.total = res.data.data.counts
  360. var data = res.data.data.data
  361. this.tableData = []
  362. if (data.length > 0) {
  363. for (var i = 0; i < data.length; i++) {
  364. var dht = data[i].d_h_t
  365. dht.addtime = this.formatTime(dht.addtime * 1000)
  366. dht.ds = dht.ds == 0 ? '关' : '开'
  367. dht.rps = dht.rps == 0 ? '正常' : '雨控'
  368. dht.tps = dht.tps == 0 ? '正常' : '保护'
  369. dht.tbs = dht.tbs == 0 ? '正常' : '保护'
  370. dht.dps = dht.dps == 0 ? '正常' : '保护'
  371. dht.cv=dht.cv/1000
  372. dht.bv=dht.bv/1000
  373. switch (dht.ws) {
  374. case 0:
  375. dht.ws = '待机'
  376. break
  377. case 1:
  378. dht.ws = '工作'
  379. break
  380. case 2:
  381. dht.ws = '充电'
  382. break
  383. }
  384. this.tableData.push(dht)
  385. }
  386. }
  387. }
  388. })
  389. },
  390. dateChange(data) {
  391. this.queryInfo.page = 1
  392. this.queryInfo.begin = data.begin
  393. this.queryInfo.end = data.end
  394. this.getHisDataList()
  395. this.getChartDataList()
  396. },
  397. //改变page
  398. changePage(val) {
  399. this.queryInfo.page = val
  400. this.getHisDataList()
  401. },
  402. setWidth(item) {
  403. if (item[1] == 'addtime') {
  404. return 180 + 'px'
  405. }
  406. },
  407. refresh() {
  408. this.$axios({
  409. method: 'POST',
  410. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  411. data: this.qs.stringify({
  412. device_type_id: 2,
  413. d_id: this.queryInfo.d_id,
  414. control_type: 'data'
  415. })
  416. }).then((res) => {
  417. if (res.data.message==''){
  418. this.$message.success('刷新成功')
  419. } else {
  420. this.$message.err('刷新失败')
  421. }
  422. })
  423. },
  424. //返回上一页
  425. goBackPage() {
  426. this.$router.go(-1)
  427. }
  428. },
  429. components: {
  430. DateSearch
  431. }
  432. }
  433. </script>
  434. <style lang='less' scoped>
  435. .box-card {
  436. position: relative;
  437. }
  438. .equipInfo {
  439. .equipMsg {
  440. font-size: 14px;
  441. color: #3d3d3d;
  442. span {
  443. margin-left: 5px;
  444. }
  445. }
  446. display: flex;
  447. justify-content: space-between;
  448. margin-top:10px;
  449. margin-bottom: 8px;
  450. }
  451. .time-check {
  452. display: flex;
  453. justify-content: space-between;
  454. .el-input__inner {
  455. margin-left: 10px;
  456. width: 222px;
  457. }
  458. .viewSwitch {
  459. margin-left: 10px;
  460. }
  461. }
  462. .chartsSelect {
  463. text-align: right;
  464. position: absolute;
  465. z-index: 999;
  466. left: 0;
  467. right: 21px;
  468. }
  469. .charts,
  470. .pie {
  471. height: 423px;
  472. }
  473. .equipStatus {
  474. display: flex;
  475. justify-content: center;
  476. margin: 10px 0;
  477. .equipIcon {
  478. margin-right: 14%;
  479. }
  480. .equipParams {
  481. min-width: 80px;
  482. line-height: 27px;
  483. p {
  484. color: #a6a6a6;
  485. }
  486. }
  487. }
  488. .dataTableSearch {
  489. display: flex;
  490. justify-content: space-between;
  491. margin: 20px 0;
  492. .el-input__inner {
  493. width: 222px;
  494. }
  495. }
  496. .echarts {
  497. width: 100%;
  498. height: 300px;
  499. }
  500. .ctrl-check {
  501. margin-bottom: 20px;
  502. }
  503. </style>