xydatainfo.vue 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. <!-- 性诱2.0 数据详情 -->
  2. <template>
  3. <div class="xydatabox">
  4. <!-- 数据的详情 -->
  5. <el-breadcrumb separator-class="el-icon-arrow-right">
  6. <el-breadcrumb-item>测报系统</el-breadcrumb-item>
  7. <el-breadcrumb-item>数据详情</el-breadcrumb-item>
  8. </el-breadcrumb>
  9. <div class="basicsbox">
  10. <div class="basicsbox_title">
  11. <div class="basicsbox_title_left">
  12. <p class="title">基础数据</p>
  13. <el-button type="primary" size="mini" @click="refresh">更新数据</el-button>
  14. </div>
  15. <div class="basicsbox_title_box">
  16. <el-select
  17. v-model="yservalue"
  18. placeholder="请选择"
  19. size="small"
  20. @change="yearchange"
  21. style="width: 80px"
  22. >
  23. <el-option
  24. v-for="item in yesroptions"
  25. :key="item.value"
  26. :label="item.label"
  27. :value="item.value"
  28. >
  29. </el-option>
  30. </el-select>
  31. <el-slider
  32. v-model="slidervalue"
  33. range
  34. :max="slidermax"
  35. :marks="marks"
  36. :format-tooltip="formatTooltip"
  37. @change="sliderchange"
  38. ></el-slider>
  39. <el-date-picker
  40. v-model="datePickerValue"
  41. type="datetimerange"
  42. range-separator="至"
  43. start-placeholder="开始日期"
  44. end-placeholder="结束日期"
  45. @change="datePickerChange"
  46. :default-time="['00:00:00', '23:59:59']"
  47. align="right"
  48. >
  49. </el-date-picker>
  50. </div>
  51. </div>
  52. <div class="basicsbox_text">
  53. <p>设备ID:{{ baseinfo.device_id }}</p>
  54. <p>设备名称:{{ baseinfo.device_name }}</p>
  55. <p>设备位置:{{ baseinfo.address }}</p>
  56. <!-- <p>最新上传时间:{{ (baseinfo.uptime * 1000) | formatTime }}</p> -->
  57. </div>
  58. </div>
  59. <div class="monitordatabox">
  60. <div class="monitordatabox_title">
  61. <p class="title">监测数据</p>
  62. <div class="btn" @click="setbait">设置诱芯</div>
  63. </div>
  64. <div class="monitordatabox_text">
  65. <div v-for="(item, index) in monitordata" :key="index" class="monitordatabox_text_item">
  66. <p
  67. v-if="
  68. (item.key == 'xy_uptime' || item.key == 'xy_expire_time') && timedata[item.key] != ''
  69. "
  70. >
  71. {{ (timedata[item.key] * 1000) | formatTime }}
  72. </p>
  73. <p v-else-if="item.key == 'xy_expire_time' && timedata[item.key] == ''">
  74. <span>未设置诱芯到期时间</span>
  75. </p>
  76. <p v-else>
  77. {{ timedata[item.key] == '' ? '暂无' : timedata[item.key] }}
  78. </p>
  79. <p>{{ item.name }}</p>
  80. </div>
  81. </div>
  82. </div>
  83. <div class="highbox">
  84. <!-- <div class="anahbox" v-loading="linetf">
  85. <p class="title">环境温湿度变化</p>
  86. <highcharts :options="options" class="highcharts"></highcharts>
  87. <div class="tishi" v-show="linedatatf">暂无数据</div>
  88. </div> -->
  89. <div class="wormbox" v-loading="linetf2">
  90. <div class="title_box">
  91. <p class="title">害虫数据分析</p>
  92. <div class="btn" @click="wormexportxy">导 出</div>
  93. </div>
  94. <highcharts :options="options2" class="highcharts"></highcharts>
  95. <div class="tishi" v-show="linedatatf2">暂无数据</div>
  96. </div>
  97. </div>
  98. <div class="tablebox">
  99. <div class="tablebox_title">
  100. <p class="title">实时表单</p>
  101. <div class="btn" @click="exportxy">导 出</div>
  102. </div>
  103. <div class="tablebox_text" v-loading="tabletf">
  104. <el-table :data="tableData" stripe style="width: 100%" v-if="$QueryPermission(266)">
  105. <el-table-column
  106. v-for="(item, index) in tableHeadTxt"
  107. :key="index"
  108. :prop="item[1]"
  109. :label="item[0]"
  110. :width="setWidth(item)"
  111. >
  112. <template slot-scope="scope">
  113. <span v-if="scope.column.property == 'xy_addtime'">{{
  114. (scope.row[scope.column.property] * 1000) | formatTime
  115. }}</span>
  116. <span v-else>{{ scope.row[scope.column.property] }}</span>
  117. </template>
  118. </el-table-column>
  119. </el-table>
  120. <el-table :data="tableData" stripe style="width: 100%" v-else>
  121. <el-table-column
  122. v-for="(item, index) in tableHeadTxt2"
  123. :key="index"
  124. :prop="item[1]"
  125. :label="item[0]"
  126. :width="setWidth(item)"
  127. >
  128. <template slot-scope="scope">
  129. <span v-if="scope.column.property == 'xy_addtime'">{{
  130. (scope.row[scope.column.property] * 1000) | formatTime
  131. }}</span>
  132. <span v-else>{{ scope.row[scope.column.property] }}</span>
  133. </template>
  134. </el-table-column>
  135. </el-table>
  136. <el-pagination
  137. background
  138. layout="prev, pager, next, jumper"
  139. :current-page="currentPage"
  140. :total="total"
  141. @current-change="currentchange"
  142. >
  143. </el-pagination>
  144. </div>
  145. </div>
  146. <el-dialog
  147. title="设置诱芯"
  148. :visible.sync="dialogVisible"
  149. :close-on-click-modal="false"
  150. width="500px"
  151. >
  152. <div class="baitbox">
  153. <el-form ref="form" :rules="rules" :model="baitdata" label-width="120px">
  154. <el-form-item label="诱芯名称" prop="name">
  155. <el-input v-model="baitdata.name" size="mini" maxlength="10"></el-input>
  156. </el-form-item>
  157. <el-form-item label="诱芯到期时间">
  158. <el-date-picker
  159. v-model="baitdata.time"
  160. type="datetime"
  161. placeholder="选择日期时间"
  162. size="mini"
  163. >
  164. </el-date-picker>
  165. </el-form-item>
  166. </el-form>
  167. </div>
  168. <span slot="footer" class="dialog-footer">
  169. <el-button @click="dialogVisible = false" size="mini">取 消</el-button>
  170. <el-button type="primary" @click="sumbit" size="mini">确 定</el-button>
  171. </span>
  172. </el-dialog>
  173. </div>
  174. </template>
  175. <script>
  176. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  177. import { Debounce } from '../../../util/anitthro'
  178. import HighCharts from 'highcharts'
  179. import Circulation from '../../../../static/js/equipState_dict.json'
  180. export default {
  181. // import引入的组件需要注入到对象中才能使用
  182. components: {},
  183. data() {
  184. // 这里存放数据
  185. return {
  186. user_tag: null, // 1超级管理员,2经销商,3农林政府单位,4普通用户,5销售用户
  187. device_id: '',
  188. d_id: '',
  189. baseinfo: {},
  190. yesroptions: [], // 年份选择器
  191. yservalue: '', // 选择的年份
  192. marks: '', // 格式化滑块节点
  193. slidervalue: [], // 滑块默认值
  194. slidermax: 365,
  195. start_time: '', // 开始时间
  196. end_time: '', // 结束时间
  197. monitordata: [
  198. {
  199. name: '诱芯名称',
  200. key: 'decoy'
  201. },
  202. {
  203. name: '杀虫数量(头)',
  204. key: 'pest_count'
  205. },
  206. {
  207. name: '温度(℃)',
  208. key: 'at'
  209. },
  210. {
  211. name: '湿度(%)',
  212. key: 'ah'
  213. },
  214. {
  215. name: '风力风向(°)',
  216. key: 'wind'
  217. },
  218. {
  219. name: '是否下雨',
  220. key: 'rain'
  221. },
  222. // {
  223. // name: '设备状态',
  224. // key: 'state',
  225. // },
  226. {
  227. name: '今天天气',
  228. key: 'type'
  229. },
  230. {
  231. name: '诱芯到期时间',
  232. key: 'xy_expire_time'
  233. }
  234. ],
  235. timedata: {},
  236. tableData: [],
  237. ChartData: [],
  238. ChartData2: [],
  239. tableHeadTxt: [
  240. ['设备号', 'device_id'],
  241. ['环境温度(℃)', 'at'],
  242. ['环境湿度(%)', 'ah'],
  243. ['电池电压(V)', 'b_V'],
  244. ['电池电流', 'b_c'],
  245. ['太阳能板电压', 'p_v'],
  246. ['太阳能板电流', 'p_c'],
  247. ['上传时间', 'xy_addtime']
  248. ],
  249. tableHeadTxt2: [
  250. ['设备号', 'device_id'],
  251. ['环境温度(℃)', 'at'],
  252. ['环境湿度(%)', 'ah'],
  253. ['上传时间', 'xy_addtime']
  254. ],
  255. equipStateDict: {},
  256. currentPage: 1,
  257. total: 10,
  258. dialogVisible: false,
  259. baitdata: {
  260. name: '',
  261. time: ''
  262. },
  263. rules: {
  264. name: [{ required: true, message: '请输入诱芯名称', trigger: 'blur' }]
  265. },
  266. pest_count: 0,
  267. tabletf: false, // 表格loading
  268. linetf: false, // 折线图1loading
  269. linetf2: false, // 折线图2loading
  270. linedatatf: false,
  271. linedatatf2: false,
  272. datePickerValue: [new Date(), new Date()],
  273. pickerOptions: {
  274. shortcuts: [
  275. {
  276. text: '最近一周',
  277. onClick(picker) {
  278. const end = new Date()
  279. const start = new Date()
  280. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
  281. picker.$emit('pick', [start, end])
  282. }
  283. },
  284. {
  285. text: '最近一个月',
  286. onClick(picker) {
  287. const end = new Date()
  288. const start = new Date()
  289. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
  290. picker.$emit('pick', [start, end])
  291. }
  292. },
  293. {
  294. text: '最近三个月',
  295. onClick(picker) {
  296. const end = new Date()
  297. const start = new Date()
  298. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
  299. picker.$emit('pick', [start, end])
  300. }
  301. }
  302. ]
  303. }
  304. }
  305. },
  306. // 监听属性 类似于data概念
  307. computed: {
  308. options() {
  309. return {
  310. chart: {
  311. zoomType: 'x'
  312. // zoomType: 'y'
  313. },
  314. title: {
  315. text: '',
  316. align: 'left'
  317. },
  318. subtitle: {
  319. text: ''
  320. },
  321. xAxis: {
  322. crosshair: true, // 十字基准线
  323. type: 'datetime',
  324. dateTimeLabelFormats: {
  325. // 根据时间间距X轴自动显示哪种格式
  326. millisecond: '%H:%M:%S',
  327. second: '%H:%M:%S',
  328. minute: '%H:%M',
  329. hour: '%H:%M',
  330. day: '%m-%d',
  331. week: '%m-%d',
  332. month: '%Y-%m',
  333. year: '%Y'
  334. }
  335. },
  336. yAxis: {
  337. title: {
  338. text: ''
  339. }
  340. },
  341. legend: {
  342. // layout: 'vertical',
  343. align: 'center',
  344. verticalAlign: 'top'
  345. },
  346. plotOptions: {
  347. series: {
  348. label: {
  349. connectorAllowed: false
  350. },
  351. pointStart: 2010
  352. }
  353. },
  354. series: this.ChartData,
  355. colors: ['#00e29d', '#6cbbff', '#ff3f3f'],
  356. credits: {
  357. // 去掉默认的highcharts.com
  358. enabled: false
  359. },
  360. tooltip: {
  361. // crosshairs: true,
  362. shared: true, // 折线共享
  363. headerFormat: '<b>{point.x:%Y-%m-%e %H:%M:%S}</b><br>'
  364. },
  365. responsive: {
  366. rules: [
  367. {
  368. condition: {
  369. maxWidth: 500
  370. },
  371. chartOptions: {
  372. legend: {
  373. layout: 'horizontal',
  374. align: 'center',
  375. verticalAlign: 'bottom'
  376. }
  377. }
  378. }
  379. ]
  380. }
  381. }
  382. },
  383. options2() {
  384. return {
  385. chart: {
  386. zoomType: 'x'
  387. // zoomType: 'y'
  388. },
  389. title: {
  390. text: '',
  391. align: 'left'
  392. },
  393. subtitle: {
  394. text: ''
  395. },
  396. xAxis: {
  397. crosshair: true, // 十字基准线
  398. type: 'datetime',
  399. dateTimeLabelFormats: {
  400. // 根据时间间距X轴自动显示哪种格式
  401. millisecond: '%H:%M:%S',
  402. second: '%H:%M:%S',
  403. minute: '%H:%M',
  404. hour: '%H:%M',
  405. day: '%m-%d',
  406. week: '%m-%d',
  407. month: '%Y-%m',
  408. year: '%Y'
  409. }
  410. },
  411. yAxis: {
  412. title: {
  413. text: ''
  414. }
  415. },
  416. legend: {
  417. // layout: 'vertical',
  418. align: 'center',
  419. verticalAlign: 'top'
  420. },
  421. plotOptions: {
  422. series: {
  423. label: {
  424. connectorAllowed: false
  425. },
  426. pointStart: 2010
  427. }
  428. },
  429. series: this.ChartData2,
  430. colors: ['#00e29d', '#6cbbff', '#ff3f3f'],
  431. credits: {
  432. // 去掉默认的highcharts.com
  433. enabled: false
  434. },
  435. tooltip: {
  436. // crosshairs: true,
  437. shared: true, // 折线共享
  438. headerFormat: '<b>{point.x:%Y-%m-%e %H:%M:%S}</b><br>'
  439. },
  440. responsive: {
  441. rules: [
  442. {
  443. condition: {
  444. maxWidth: 500
  445. },
  446. chartOptions: {
  447. legend: {
  448. layout: 'horizontal',
  449. align: 'center',
  450. verticalAlign: 'bottom'
  451. }
  452. }
  453. }
  454. ]
  455. }
  456. }
  457. }
  458. },
  459. // 监控data中的数据变化
  460. watch: {},
  461. // 方法集合
  462. methods: {
  463. datePickerChange(e) {
  464. // console.log(+new Date(e[0]).getTime()/1000)
  465. // console.log(+new Date(e[1]).getTime()/1000)
  466. if (!e) {
  467. return
  468. }
  469. const oldMonth = new Date(e[0]).getMonth()
  470. const olddate = new Date(e[0]).getDate()
  471. const Month = new Date(e[1]).getMonth()
  472. const date = new Date(e[1]).getDate()
  473. if (Month == 0) {
  474. this.slidervalue = [0, this.getsliserindex(Month, date)]
  475. } else {
  476. this.slidervalue = [
  477. this.getsliserindex(oldMonth, olddate),
  478. this.getsliserindex(Month, date)
  479. ]
  480. }
  481. this.linetf = true
  482. this.linetf2 = true
  483. this.tabletf = true
  484. this.total = 10
  485. this.currentPage = 1
  486. this.start_time = +new Date(e[0]).getTime() / 1000
  487. this.end_time = +new Date(e[1]).getTime() / 1000
  488. this.gethighatdata()
  489. this.gethighatdata2()
  490. this.getHisDataList()
  491. },
  492. dateTimeFormat(timestamp) {
  493. // 时间戳转 yyyy-MM-dd hh:mm:ss
  494. let time = new Date(timestamp * 1000)
  495. let year = time.getFullYear()
  496. let month = time.getMonth() + 1
  497. let date = time.getDate()
  498. let hours = time.getHours()
  499. let minute = time.getMinutes()
  500. let second = time.getSeconds()
  501. if (month < 10) {
  502. month = '0' + month
  503. }
  504. if (date < 10) {
  505. date = '0' + date
  506. }
  507. if (hours < 10) {
  508. hours = '0' + hours
  509. }
  510. if (minute < 10) {
  511. minute = '0' + minute
  512. }
  513. if (second < 10) {
  514. second = '0' + second
  515. }
  516. return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second
  517. },
  518. // 年份发生改变
  519. yearchange(e) {
  520. // console.log(e);
  521. this.leapyear(e)
  522. },
  523. // 计算闰年和平年
  524. leapyear(year) {
  525. var Month = new Date().getMonth()
  526. var date = new Date().getDate()
  527. var time = new Date(new Date().setMonth(Month - 1))
  528. var oldMonth = time.getMonth()
  529. var olddate = time.getDate()
  530. this.slidermax = ''
  531. if ((year % 400 == 0 || year % 4 == 0) && year % 100 != 0) {
  532. this.slidermax = 366
  533. } else {
  534. this.slidermax = 365
  535. }
  536. if (this.slidermax == 366) {
  537. this.marks = {
  538. 0: '1月1日',
  539. 31: '1月31日',
  540. 60: '2月29日',
  541. 91: '3月31日',
  542. 121: '4月30日',
  543. 152: '5月31日',
  544. 182: '6月30日',
  545. 213: '7月31日',
  546. 244: '8月31日',
  547. 274: '9月30日',
  548. 305: '10月31日',
  549. 335: '11月30日',
  550. 366: '12月31日'
  551. }
  552. } else if (this.slidermax == 365) {
  553. this.marks = {
  554. 0: '1月1日',
  555. 31: '1月31日',
  556. 59: '2月28日',
  557. 90: '3月31日',
  558. 120: '4月30日',
  559. 151: '5月31日',
  560. 181: '6月30日',
  561. 212: '7月31日',
  562. 243: '8月31日',
  563. 273: '9月30日',
  564. 304: '10月31日',
  565. 334: '11月30日',
  566. 365: '12月31日'
  567. }
  568. }
  569. if (Month == 0) {
  570. this.slidervalue = [0, this.getsliserindex(Month, date)]
  571. } else {
  572. this.slidervalue = [
  573. this.getsliserindex(oldMonth, olddate),
  574. this.getsliserindex(Month, date)
  575. ]
  576. }
  577. var state = this.formatTooltip(this.slidervalue[0])
  578. var end = this.formatTooltip(this.slidervalue[1])
  579. state = state.replace('月', '-')
  580. state = state.replace('日', '')
  581. state = this.yservalue + '-' + state + ' 00:00:00'
  582. end = end.replace('月', '-')
  583. end = end.replace('日', '')
  584. end = this.yservalue + '-' + end + ' 23:59:59'
  585. this.start_time = +new Date(state) / 1000
  586. this.end_time = +new Date(end) / 1000
  587. this.datePickerValue = [
  588. new Date(this.dateTimeFormat(this.start_time)),
  589. new Date(this.dateTimeFormat(this.end_time))
  590. ]
  591. // console.log(this.start_time, this.end_time);
  592. // this.getallwormlist();
  593. // this.search();
  594. this.gethighatdata()
  595. this.gethighatdata2()
  596. this.getHisDataList()
  597. },
  598. // 格式化滑块标签
  599. formatTooltip(val) {
  600. for (var key in this.marks) {
  601. if (val < key) {
  602. // //console.log(key);
  603. var index = key - val
  604. var monindex = this.marks[key].indexOf('月')
  605. var dataindex = this.marks[key].indexOf('日')
  606. var data = this.marks[key].slice(monindex + 1, dataindex)
  607. var str = this.marks[key].slice(0, monindex + 1)
  608. return str + (data - index + 1) + '日'
  609. } else if (val == 365 || val == 366) {
  610. return '12月31日'
  611. }
  612. }
  613. },
  614. getsliserindex(month, date) {
  615. // //console.log(month);
  616. var arr = []
  617. for (var key in this.marks) {
  618. arr.push(key)
  619. }
  620. if (month == 0) {
  621. return Number(date) - 1
  622. } else {
  623. return Number(arr[month]) + Number(date) - 1
  624. }
  625. },
  626. sliderchange(e) {
  627. this.linetf = true
  628. this.linetf2 = true
  629. this.tabletf = true
  630. this.total = 10
  631. this.currentPage = 1
  632. this.sliderchange2(e)
  633. },
  634. // 滑块更改后地值
  635. sliderchange2: Debounce(function (e) {
  636. var state = this.formatTooltip(e[0])
  637. var end = this.formatTooltip(e[1])
  638. state = state.replace('月', '-')
  639. state = state.replace('日', '')
  640. state = this.yservalue + '-' + state + ' 00:00:00'
  641. end = end.replace('月', '-')
  642. end = end.replace('日', '')
  643. end = this.yservalue + '-' + end + ' 23:59:59'
  644. this.start_time = +new Date(state) / 1000
  645. this.end_time = +new Date(end) / 1000
  646. this.datePickerValue = [
  647. new Date(this.dateTimeFormat(this.start_time)),
  648. new Date(this.dateTimeFormat(this.end_time))
  649. ]
  650. // //console.log(this.start_time, this.end_time);
  651. this.page = 1
  652. // this.currentPage = 1;
  653. this.gethighatdata()
  654. this.gethighatdata2()
  655. this.getHisDataList()
  656. }, 2000),
  657. getbaseinfo() {
  658. this.$axios({
  659. method: 'post',
  660. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_list',
  661. data: this.qs.stringify({
  662. page_size: 8,
  663. device_id: this.device_id,
  664. page: 1
  665. })
  666. }).then((res) => {
  667. if (res.data.message == '') {
  668. if (res.data.data) {
  669. // //console.log(res.data.data)
  670. this.baseinfo = res.data.data.data[0]
  671. // this.monitordata[0].key = this.baseinfo.decoy
  672. // this.getweather();
  673. }
  674. } else {
  675. this.$message.error(res.data.message)
  676. }
  677. })
  678. },
  679. gethighatdata() {
  680. this.linetf = true
  681. this.$axios({
  682. method: 'post',
  683. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_line_chart',
  684. data: this.qs.stringify({
  685. device_id: this.device_id,
  686. start_time: this.start_time,
  687. end_time: this.end_time,
  688. status: 'at_ah',
  689. device_code: this.device_code
  690. })
  691. }).then((res) => {
  692. this.linetf = false
  693. if (res.data.message == '') {
  694. if (res.data.data) {
  695. var data = res.data.data
  696. if (data.length == 0) {
  697. this.linedatatf = true
  698. } else {
  699. this.linedatatf = false
  700. }
  701. if (data.length != 0) {
  702. var arr = []
  703. var arr2 = []
  704. for (var i = 0; i < data.length; i++) {
  705. arr.push([+new Date(data[i].xy_addtime) + 8 * 60 * 60 * 1000, Number(data[i].at)])
  706. arr2.push([+new Date(data[i].xy_addtime) + 8 * 60 * 60 * 1000, Number(data[i].ah)])
  707. }
  708. // console.log(arr);
  709. this.ChartData = [
  710. {
  711. name: '温度',
  712. data: arr
  713. },
  714. {
  715. name: '湿度',
  716. data: arr2
  717. }
  718. ]
  719. // //console.log(this.ChartData)
  720. } else {
  721. this.ChartData = [
  722. {
  723. name: '温度',
  724. data: []
  725. },
  726. {
  727. name: '湿度',
  728. data: []
  729. }
  730. ]
  731. }
  732. }
  733. } else {
  734. this.$message.error(res.data.message)
  735. }
  736. })
  737. },
  738. gethighatdata2() {
  739. this.linetf2 = true
  740. this.$axios({
  741. method: 'post',
  742. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_line_chart',
  743. data: this.qs.stringify({
  744. device_id: this.device_id,
  745. start_time: this.start_time,
  746. end_time: this.end_time,
  747. status: 'pest',
  748. device_code: this.device_code
  749. })
  750. }).then((res) => {
  751. this.linetf2 = false
  752. if (res.data.message == '') {
  753. if (res.data.data) {
  754. // console.log(res.data.data);
  755. var data = res.data.data.data
  756. if (data.length == 0) {
  757. this.linedatatf2 = true
  758. } else {
  759. this.linedatatf2 = false
  760. }
  761. this.pest_count = res.data.data.pest_count
  762. this.timedata['pest_count'] = this.pest_count
  763. var arr = []
  764. if (data.length != 0) {
  765. for (var i = 0; i < data.length; i++) {
  766. arr.push([+new Date(data[i].xy_addtime), Number(data[i].pest_num)])
  767. }
  768. // console.log(this.ChartData2);
  769. }
  770. this.ChartData2 = [
  771. {
  772. name: '诱虫次数',
  773. data: arr
  774. }
  775. ]
  776. }
  777. } else {
  778. this.$message.error(res.data.message)
  779. }
  780. })
  781. },
  782. setWidth(item) {
  783. if (item[1] == 'addtime') {
  784. return 180 + 'px'
  785. } else if (item[1] == 'proj') {
  786. return 150 + 'px'
  787. }
  788. },
  789. currentchange(e) {
  790. this.page = e
  791. this.getHisDataList()
  792. },
  793. // 获取表格数据
  794. getHisDataList() {
  795. this.tabletf = true
  796. this.$axios({
  797. method: 'POST',
  798. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_history',
  799. data: this.qs.stringify({
  800. device_id: this.device_id,
  801. start_time: this.start_time,
  802. end_time: this.end_time,
  803. page: this.page,
  804. page_size: 10,
  805. device_code: this.device_code
  806. })
  807. }).then((res) => {
  808. this.tabletf = false
  809. console.log('res.data')
  810. if (res.data.message == '') {
  811. // console.log(res.data.data.data);
  812. var arr = res.data.data.data
  813. // var list = []
  814. // for (var i = 0; i < arr.length; i++) {
  815. // var obj = {}
  816. // // obj['device_id'] = res.data.data.data[0].device_id
  817. // obj['device_id'] = res.data.data.data[i].device_id
  818. // obj['at'] = res.data.data.data[i].at
  819. // obj['ah'] = res.data.data.data[i].ah
  820. // obj['warn'] =
  821. // res.data.data.data[i].warn == ''
  822. // ? '无'
  823. // : res.data.data.data[0].warn
  824. // obj['b_V'] = res.data.data.data[i].b_V
  825. // obj['b_c'] = res.data.data.data[i].b_c
  826. // obj['p_v'] = res.data.data.data[i].p_v
  827. // obj['p_c'] = res.data.data.data[i].p_c
  828. // obj['xy_addtime'] = this.formatTime(
  829. // res.data.data.data[i].xy_addtime * 1000
  830. // )
  831. // list.push(obj)
  832. // }
  833. if (arr.length > 0) {
  834. let obj = arr[0]
  835. let newHeader = []
  836. Object.keys(obj).forEach((key) => {
  837. let matchItem = this.tableHeadTxt.filter((item) => {
  838. return item[1] === key
  839. })
  840. if (matchItem.length > 0) {
  841. newHeader.push(matchItem[0])
  842. }
  843. })
  844. this.tableHeadTxt = newHeader
  845. this.tableHeadTxt2 = newHeader
  846. }
  847. this.tableData = arr
  848. // console.log(this.tableData);
  849. this.total = res.data.data.nums
  850. }
  851. })
  852. },
  853. gettimedata() {
  854. this.$axios({
  855. method: 'post',
  856. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_details',
  857. data: this.qs.stringify({
  858. d_id: this.d_id
  859. })
  860. }).then((res) => {
  861. if (res.data.message == '') {
  862. if (res.data.data) {
  863. // console.log(res.data.data);
  864. this.timedata = res.data.data[0]
  865. this.timedata['state'] = this.baseinfo.is_online == 0 ? '离线' : '在线'
  866. this.timedata['pest_count'] = this.pest_count
  867. }
  868. }
  869. })
  870. },
  871. setbait() {
  872. this.dialogVisible = true
  873. // console.log(this.baseinfo);
  874. this.baitdata.name = this.baseinfo.decoy
  875. },
  876. sumbit() {
  877. // console.log(this.baitdata.time);
  878. this.$refs['form'].validate((valid) => {
  879. if (valid) {
  880. var time = ''
  881. if (this.baitdata.time == '') {
  882. time = ''
  883. } else {
  884. time = Math.floor(+new Date(this.baitdata.time) / 1000)
  885. }
  886. this.$axios({
  887. method: 'POST',
  888. url: '/api/api_gateway?method=forecast.worm_lamp.set_decopy',
  889. data: this.qs.stringify({
  890. device_type_id: 10,
  891. device_id: this.device_id,
  892. decoy: this.baitdata.name,
  893. expire_time: time
  894. })
  895. }).then((res) => {
  896. this.dialogVisible = false
  897. if (res.data.message == '') {
  898. if (res.data.data.status) {
  899. if (document.getElementsByClassName('el-message').length == 0) {
  900. this.$message.success('设置诱芯成功')
  901. }
  902. } else {
  903. if (document.getElementsByClassName('el-message').length == 0) {
  904. this.$message.warning('设置诱芯失败')
  905. }
  906. }
  907. }
  908. })
  909. } else {
  910. // console.log('error submit!!');
  911. return false
  912. }
  913. })
  914. },
  915. // 表格数据导出
  916. exportxy() {
  917. const permission = this.$QueryPermission(266)
  918. let arr = []
  919. let table_header = ''
  920. if (permission) {
  921. arr = this.tableHeadTxt
  922. } else {
  923. arr = this.tableHeadTxt2
  924. }
  925. arr.forEach((item) => {
  926. table_header = table_header + '' + item[1] + '|'
  927. })
  928. table_header = table_header.substring(0, table_header.length - 1)
  929. window.location.href =
  930. this.$deriveData +
  931. // "http://192.168.1.23:8000" +
  932. '/api/nl_export?device_id=' +
  933. this.device_id +
  934. '&filename=' +
  935. '性诱2.0表单数据' +
  936. '&start_time=' +
  937. this.start_time +
  938. '&end_time=' +
  939. this.end_time +
  940. '&table_header=' +
  941. table_header
  942. },
  943. // 害虫折线图数据导出
  944. wormexportxy() {
  945. var username = localStorage.getItem('cUsername')
  946. window.location.href =
  947. this.$deriveData +
  948. // "http://192.168.1.77:8002" +
  949. '/api/nl_pest_export?device_id=' +
  950. this.device_id +
  951. '&filename=' +
  952. '性诱2.0诱虫次数' +
  953. '&start_time=' +
  954. this.start_time +
  955. '&end_time=' +
  956. this.end_time +
  957. '&username=' +
  958. username
  959. },
  960. refresh() {
  961. this.page = 1
  962. this.currentPage = 1
  963. if (document.getElementsByClassName('el-message').length == 0) {
  964. this.$message.success('刷新成功')
  965. }
  966. this.gethighatdata()
  967. this.gethighatdata2()
  968. this.getHisDataList()
  969. }
  970. },
  971. beforeCreate() {}, // 生命周期 - 创建之前
  972. // 生命周期 - 创建完成(可以访问当前this实例)
  973. created() {
  974. this.device_id = this.$route.query.e_id
  975. this.d_id = this.$route.query.d_id
  976. this.device_code = this.$route.query.device_code
  977. var Year = new Date().getFullYear()
  978. var num = Year - 2019
  979. for (var i = 0; i < num + 1; i++) {
  980. var obj = {
  981. value: 2019 + i,
  982. label: 2019 + i
  983. }
  984. this.yesroptions.push(obj)
  985. }
  986. this.yservalue = this.yesroptions[this.yesroptions.length - 1].label
  987. this.leapyear(Year)
  988. this.getbaseinfo()
  989. this.gettimedata()
  990. },
  991. beforeMount() {}, // 生命周期 - 挂载之前
  992. // 生命周期 - 挂载完成(可以访问DOM元素)
  993. mounted() {
  994. this.equipStateDict = Circulation
  995. },
  996. beforeUpdate() {}, // 生命周期 - 更新之前
  997. updated() {}, // 生命周期 - 更新之后
  998. beforeDestroy() {}, // 生命周期 - 销毁之前
  999. destroyed() {}, // 生命周期 - 销毁完成
  1000. activated() {} // 如果页面有keep-alive缓存功能,这个函数会触发
  1001. }
  1002. </script>
  1003. <style lang="less" scoped>
  1004. .basicsbox {
  1005. width: 100%;
  1006. background-color: #fff;
  1007. padding: 20px 30px;
  1008. box-sizing: border-box;
  1009. .basicsbox_title {
  1010. display: flex;
  1011. justify-content: space-between;
  1012. .title {
  1013. font-weight: 700;
  1014. }
  1015. .basicsbox_title_left {
  1016. display: flex;
  1017. height: 26px;
  1018. /deep/.el-button {
  1019. margin-left: 15px;
  1020. }
  1021. }
  1022. .basicsbox_title_box {
  1023. width: 90%;
  1024. display: flex;
  1025. align-items: center;
  1026. justify-content: flex-end;
  1027. /deep/.el-slider {
  1028. margin-left: 40px;
  1029. margin-right: 40px;
  1030. width: 50%;
  1031. .el-slider__marks-text:last-child {
  1032. display: none;
  1033. }
  1034. }
  1035. }
  1036. }
  1037. .basicsbox_text {
  1038. display: flex;
  1039. margin-top: 30px;
  1040. p {
  1041. margin-right: 25px;
  1042. font-size: 14px;
  1043. color: #909399;
  1044. }
  1045. }
  1046. }
  1047. .monitordatabox {
  1048. width: 100%;
  1049. background-color: #fff;
  1050. padding: 20px 30px;
  1051. box-sizing: border-box;
  1052. margin-top: 16px;
  1053. .monitordatabox_title {
  1054. display: flex;
  1055. justify-content: space-between;
  1056. .title {
  1057. font-weight: 700;
  1058. }
  1059. .btn {
  1060. width: 100px;
  1061. height: 32px;
  1062. background-color: #14a478;
  1063. font-size: 14px;
  1064. text-align: center;
  1065. line-height: 32px;
  1066. border-radius: 5px;
  1067. color: #fff;
  1068. cursor: pointer;
  1069. }
  1070. }
  1071. .monitordatabox_text {
  1072. display: flex;
  1073. flex-wrap: wrap;
  1074. .monitordatabox_text_item {
  1075. width: 20%;
  1076. text-align: center;
  1077. margin-top: 20px;
  1078. p:first-child {
  1079. font-size: 18px;
  1080. font-weight: 700;
  1081. height: 24px;
  1082. }
  1083. p:last-child {
  1084. font-size: 14px;
  1085. margin-top: 10px;
  1086. }
  1087. }
  1088. }
  1089. }
  1090. .highbox {
  1091. width: 100%;
  1092. // background-color: #fff;
  1093. margin-top: 15px;
  1094. display: flex;
  1095. justify-content: space-between;
  1096. .title {
  1097. font-weight: 700;
  1098. }
  1099. .wormbox {
  1100. background-color: #fff;
  1101. padding: 20px 30px;
  1102. box-sizing: border-box;
  1103. width: 100%;
  1104. position: relative;
  1105. .title_box {
  1106. width: 100%;
  1107. display: flex;
  1108. justify-content: space-between;
  1109. .btn {
  1110. width: 100px;
  1111. height: 32px;
  1112. background-color: #14a478;
  1113. font-size: 14px;
  1114. text-align: center;
  1115. line-height: 32px;
  1116. border-radius: 5px;
  1117. color: #fff;
  1118. cursor: pointer;
  1119. }
  1120. }
  1121. .tishi {
  1122. position: absolute;
  1123. top: 45%;
  1124. left: 45%;
  1125. }
  1126. .highcharts {
  1127. width: 100%;
  1128. height: 300px;
  1129. /deep/.highcharts-credits {
  1130. display: none;
  1131. }
  1132. }
  1133. }
  1134. }
  1135. .tablebox {
  1136. width: 100%;
  1137. background-color: #fff;
  1138. padding: 20px 30px;
  1139. box-sizing: border-box;
  1140. margin-top: 15px;
  1141. .tablebox_title {
  1142. display: flex;
  1143. justify-content: space-between;
  1144. .title {
  1145. font-weight: 700;
  1146. }
  1147. .btn {
  1148. width: 100px;
  1149. height: 32px;
  1150. background-color: #14a478;
  1151. font-size: 14px;
  1152. text-align: center;
  1153. line-height: 32px;
  1154. border-radius: 5px;
  1155. color: #fff;
  1156. cursor: pointer;
  1157. }
  1158. }
  1159. .tablebox_text {
  1160. /deep/.cell {
  1161. text-align: center;
  1162. }
  1163. }
  1164. }
  1165. .baitbox {
  1166. width: 100%;
  1167. /deep/.el-date-editor {
  1168. width: 100%;
  1169. }
  1170. }
  1171. </style>