thxyhisdata.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <template>
  2. <view>
  3. <view class="timeandtype">
  4. <view class="timebox">
  5. <view class="firsttime" @click="timeshow=true">
  6. <view class="" v-if="start_time!=''">
  7. {{start_time/1000|timeFormat()}}
  8. </view>
  9. <view class="" v-else>
  10. {{start_time==""?'请选择开始时间':start_time}}
  11. </view>
  12. </view>
  13. <view class="jiange">
  14. -
  15. </view>
  16. <view class="endtime" @click="timeshow=true">
  17. <view class="" v-if="end_time!=''">
  18. {{end_time/1000|timeFormat()}}
  19. </view>
  20. <view class="" v-else>
  21. {{end_time==""?'请选择结束时间':end_time}}
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="shuju_one">
  27. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  28. 暂无数据
  29. </view>
  30. <view class="canvastishi" v-if="dataloadingtf">
  31. <p class="dataloading">加载中</p>
  32. </view>
  33. <canvas v-if="canvastishiTF" v-show="!timeshow" canvas-id="canvasColumnA" id="canvasColumnA" class="charts" @touchstart="touchLineA($event)"
  34. @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)" disable-scroll=true :style="{'width':cWidth*pixelRatio+'px','height':cHeight*pixelRatio+'px', 'transform': 'scale('+(1/pixelRatio)+')','margin-left':-cWidth*(pixelRatio-1)/2+'px','margin-top':-cHeight*(pixelRatio-1)/2+'px'}"></canvas>
  35. </view>
  36. <view class="shuju_one">
  37. <view class="canvastishi" v-if="!canvastishiTF2 && !dataloadingtf2">
  38. 暂无数据
  39. </view>
  40. <view class="canvastishi" v-if="dataloadingtf2">
  41. <p class="dataloading">加载中</p>
  42. </view>
  43. <canvas v-if="canvastishiTF2" v-show="!timeshow" canvas-id="canvasColumnB" id="canvasColumnB" class="charts" @touchstart="touchLineB($event)"
  44. @touchmove="moveLineB($event)" @touchend="touchEndLineB($event)" disable-scroll=true :style="{'width':cWidth*pixelRatio+'px','height':cHeight*pixelRatio+'px', 'transform': 'scale('+(1/pixelRatio)+')','margin-left':-cWidth*(pixelRatio-1)/2+'px','margin-top':-cHeight*(pixelRatio-1)/2+'px'}"></canvas>
  45. </view>
  46. <view class="condition">
  47. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  48. <table class="table" v-if="$QueryPermission(267)">
  49. <tr class="tr">
  50. <th class="th" v-for="(item,index) in thdata" :key="'a'+index">{{item}}</th>
  51. </tr>
  52. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  53. <td class="td">{{items.d_h_t.addtime|timeFormat()}}</td>
  54. <td class="td">{{Circulation.highVolt.value[items.d_h_t.highVolt]}}</td>
  55. <td class="td">{{Circulation.light.value[items.d_h_t.light]}}</td>
  56. <td class="td">{{items.d_h_t.temperature}}</td>
  57. <td class="td">{{items.d_h_t.humidity}}</td>
  58. <td class="td">{{items.d_h_t.illumination}}</td>
  59. <td class="td">{{Circulation.rainFall.value[items.d_h_t.rainFall]}}</td>
  60. <td class="td">{{Circulation.rectifier.value[items.d_h_t.rectifier]}}</td>
  61. <td class="td">{{Circulation.chargeStatus.value[items.d_h_t.chargeStatus]}}</td>
  62. <td class="td">{{items.d_h_t.bugCount}}</td>
  63. <td class="td">{{Circulation.rectifier.value[items.d_h_t.solarStatus]}}</td>
  64. </tr>
  65. <tr class="tr" v-if="forbidden">
  66. <td class="td" v-for="item in 11">暂无数据</td>
  67. </tr>
  68. </table>
  69. <table class="table" v-else>
  70. <tr class="tr">
  71. <th class="th" v-for="(item,index) in thdata2" :key="'a'+index">{{item}}</th>
  72. </tr>
  73. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  74. <td class="td">{{items.d_h_t.addtime|timeFormat()}}</td>
  75. <td class="td">{{Circulation.highVolt.value[items.d_h_t.highVolt]}}</td>
  76. <td class="td">{{Circulation.light.value[items.d_h_t.light]}}</td>
  77. <td class="td">{{items.d_h_t.temperature}}</td>
  78. <td class="td">{{items.d_h_t.humidity}}</td>
  79. <td class="td">{{Circulation.chargeStatus.value[items.d_h_t.chargeStatus]}}</td>
  80. <td class="td">{{items.d_h_t.bugCount}}</td>
  81. </tr>
  82. <tr class="tr" v-if="forbidden">
  83. <td class="td" v-for="item in 7">暂无数据</td>
  84. </tr>
  85. </table>
  86. </scroll-view>
  87. <view class="pagenumber">
  88. <button @click="prev">上一页</button>
  89. <view class="pagenumber_page">
  90. 第 {{page}} 页
  91. </view>
  92. <view class="pagenumber_page">
  93. 共 {{pagesum}} 页
  94. </view>
  95. <button @click="next" :disabled="forbidden">下一页</button>
  96. </view>
  97. </view>
  98. <u-calendar v-model="timeshow" :mode="mode" @change="timechange"></u-calendar>
  99. </view>
  100. </template>
  101. <script>
  102. import uCharts from '../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  103. import Circulation from "../../../static/js/equipState_dict.json"
  104. var canvaColumnA = null;
  105. var canvaColumnB = null
  106. export default {
  107. data() {
  108. return {
  109. start_time:"",
  110. end_time:"",
  111. timeshow:false,
  112. mode: 'range',
  113. cWidth: '400',
  114. cHeight: '400',
  115. pixelRatio: 1,
  116. canvastishiTF:false,
  117. dataloadingtf:false,
  118. canvastishiTF2:false,
  119. dataloadingtf2:false,
  120. equipInfo:{},
  121. historylistdata: [],
  122. thdata: [
  123. "上报时间","高压网状态","灯管状态","环境温度(℃)","环境湿度(%)","光照度LUX","下雨传感","整流器状态","充电状态","杀虫数(累计)","太阳板状态",
  124. ],
  125. thdata2: [
  126. "上报时间","高压网状态","灯管状态","环境温度(℃)","环境湿度(%)","充电状态","杀虫数(累计)",
  127. ],
  128. page:1,
  129. pagesum:"10",
  130. Circulation:Circulation,
  131. forbidden:false
  132. }
  133. },
  134. methods: {
  135. timechange(e){
  136. this.start_time = +new Date(e.startDate)
  137. this.end_time = +new Date(e.endDate)
  138. this.history()
  139. this.getworm()
  140. this.getwind()
  141. },
  142. async history() { //历史数据列表折线图
  143. this.dataloadingtf = true
  144. const res = await this.$myRequest({
  145. url: '/api/api_gateway?method=forecast.worm_lamp.zjxy_at_ah',
  146. data: {
  147. device_type_id: 8,
  148. d_id: this.equipInfo.d_id,
  149. start_time: Math.floor(+new Date(this.start_time) / 1000),
  150. end_time: Math.floor(+new Date(this.end_time) / 1000),
  151. }
  152. })
  153. console.log(res)
  154. this.dataloadingtf = false
  155. this.historydatas = res
  156. console.log(this.historydatas)
  157. if (this.historydatas.length == 0) {
  158. this.canvastishiTF = false
  159. } else {
  160. this.canvastishiTF = true
  161. var arr1 = []
  162. var arr2 = []
  163. var arr3 = []
  164. var xtitle = []
  165. for (var i = 0; i < res.length; i++) {
  166. var times = new Date(res[i].addtime * 1000)
  167. xtitle.push(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getMinutes())
  168. arr1.push(res[i].at == "" ? "0" : res[i].at)
  169. arr2.push(res[i].ah == "" ? "0" : res[i].ah)
  170. }
  171. // console.log(arr1)
  172. var obj = [{
  173. name: '温度',
  174. data: arr1,
  175. color: '#00E29D'
  176. }, {
  177. name: '湿度',
  178. data: arr2,
  179. color: '#6CBBFF'
  180. }]
  181. this.showColumn("canvasColumnA", xtitle, obj)
  182. }
  183. },
  184. async getworm() {
  185. const res = await this.$myRequest({
  186. url: '/api/api_gateway?method=forecast.worm_lamp.zjxycb_pest_chart',
  187. data: {
  188. d_id: this.equipInfo.d_id,
  189. start_time: Math.floor(+new Date(this.start_time) / 1000),
  190. end_time: Math.floor(+new Date(this.end_time) / 1000),
  191. device_type_id: "8",
  192. }
  193. })
  194. console.log(res)
  195. this.dataloadingtf2 = false
  196. var data = res.pest_data
  197. if (data.length == 0) {
  198. this.canvastishiTF2 = false
  199. } else {
  200. this.canvastishiTF2 = true
  201. var arr1 = []
  202. var xtitle = []
  203. for (var i = 0; i < data.length; i++) {
  204. var times = new Date(data[i].addtime * 1000)
  205. xtitle.push(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getMinutes())
  206. arr1.push(data[i].pest_num == "" ? "0" : data[i].pest_num)
  207. }
  208. // console.log(arr1)
  209. var obj = [{
  210. name: '诱虫次数',
  211. data: arr1,
  212. color: '#00E29D'
  213. }]
  214. this.showColumn2("canvasColumnB", xtitle, obj)
  215. }
  216. },
  217. async getwind() {
  218. const res = await this.$myRequest({
  219. url: '/api/api_gateway?method=forecast.worm_lamp.zjxy_history_data',
  220. data: {
  221. d_id: this.equipInfo.d_id,
  222. start_time: Math.floor(+new Date(this.start_time) / 1000),
  223. end_time: Math.floor(+new Date(this.end_time) / 1000),
  224. device_id: this.equipInfo.imei,
  225. page: this.page,
  226. }
  227. })
  228. console.log(res)
  229. if(res.data.length){
  230. this.historylistdata = res.data
  231. this.pagesum = Math.ceil(res.counts/10)
  232. this.forbidden = false
  233. }else{
  234. this.forbidden = true
  235. }
  236. },
  237. prev() { //上一页
  238. if (this.page > 1) {
  239. this.page--
  240. this.getwind()
  241. }
  242. },
  243. next() { //下一页
  244. if(this.page < this.pagesum){
  245. this.page++
  246. this.getwind()
  247. }
  248. },
  249. showColumn(id, xtitle, xinfo) {
  250. var _self = this
  251. const ctx = uni.createCanvasContext(id, this);
  252. canvaColumnA = new uCharts({
  253. context: ctx,
  254. type: 'line',
  255. legend: {
  256. position: "top"
  257. },
  258. fontSize: 11,
  259. background: '#FFFFFF',
  260. pixelRatio: 1,
  261. animation: true,
  262. dataLabel: false,
  263. categories: xtitle,
  264. series: xinfo,
  265. enableScroll: true, //开启图表拖拽功能
  266. xAxis: {
  267. disableGrid: true,
  268. type: 'grid',
  269. gridType: 'dash',
  270. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  271. scrollShow: true, //新增是否显示滚动条,默认false
  272. // scrollAlign: 'left', //滚动条初始位置
  273. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  274. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  275. },
  276. yAxis: {},
  277. width: _self.cWidth * 1,
  278. height: _self.cHeight * 1,
  279. extra: {
  280. line: {
  281. type: 'curve'
  282. }
  283. }
  284. });
  285. },
  286. showColumn2(id, xtitle, xinfo) {
  287. var _self = this
  288. const ctx = uni.createCanvasContext(id, this);
  289. canvaColumnB = new uCharts({
  290. context: ctx,
  291. type: 'line',
  292. legend: {
  293. position: "top"
  294. },
  295. fontSize: 11,
  296. background: '#FFFFFF',
  297. pixelRatio: 1,
  298. animation: true,
  299. dataLabel: false,
  300. categories: xtitle,
  301. series: xinfo,
  302. enableScroll: true, //开启图表拖拽功能
  303. xAxis: {
  304. disableGrid: true,
  305. type: 'grid',
  306. gridType: 'dash',
  307. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  308. scrollShow: true, //新增是否显示滚动条,默认false
  309. // scrollAlign: 'left', //滚动条初始位置
  310. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  311. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  312. },
  313. yAxis: {},
  314. width: _self.cWidth * 1,
  315. height: _self.cHeight * 1,
  316. extra: {
  317. line: {
  318. type: 'curve'
  319. }
  320. }
  321. });
  322. },
  323. touchLineA(e) {
  324. console.log(e)
  325. canvaColumnA.scrollStart(e);
  326. },
  327. moveLineA(e) {
  328. canvaColumnA.scroll(e);
  329. },
  330. touchEndLineA(e) {
  331. canvaColumnA.scrollEnd(e);
  332. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  333. canvaColumnA.showToolTip(e, {
  334. format: function(item, category) {
  335. return category + ' ' + item.name + ':' + item.data
  336. }
  337. });
  338. },
  339. touchLineB(e) {
  340. console.log(e)
  341. canvaColumnB.scrollStart(e);
  342. },
  343. moveLineB(e) {
  344. canvaColumnB.scroll(e);
  345. },
  346. touchEndLineB(e) {
  347. canvaColumnB.scrollEnd(e);
  348. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  349. canvaColumnB.showToolTip(e, {
  350. format: function(item, category) {
  351. return category + ' ' + item.name + ':' + item.data
  352. }
  353. });
  354. },
  355. },
  356. onLoad(option) {
  357. this.equipInfo = option
  358. console.log(option)
  359. this.end_time = +new Date()
  360. this.start_time = +new Date()-30*24*60*60*1000
  361. this.cWidth = uni.upx2px(650);
  362. this.cHeight = uni.upx2px(500);
  363. this.history()
  364. this.getworm()
  365. this.getwind()
  366. }
  367. }
  368. </script>
  369. <style lang="less">
  370. .timeandtype {
  371. // background-color: #F6F6FB;
  372. // padding: 20rpx;
  373. box-sizing: border-box;
  374. width: 90%;
  375. margin: 40rpx auto 0;
  376. .timebox {
  377. box-shadow: 0 0 10rpx #bcb9ca;
  378. display: flex;
  379. background-color: #fff;
  380. padding: 10px;
  381. border-top-right-radius: 5px;
  382. border-top-left-radius: 5px;
  383. .jiange {
  384. width: 5%;
  385. text-align: center;
  386. }
  387. .firsttime,
  388. .endtime {
  389. width: 45%;
  390. text-align: center;
  391. }
  392. }
  393. .warntypebox {
  394. display: flex;
  395. justify-content: space-between;
  396. background-color: #fff;
  397. padding: 10px;
  398. border-top: 1px solid #F6F6FB;
  399. border-bottom-right-radius: 5px;
  400. border-bottom-left-radius: 5px;
  401. }
  402. }
  403. .shuju_one {
  404. position: relative;
  405. width: 90%;
  406. margin: 30rpx auto;
  407. box-shadow: 0 0 10rpx #bcb9ca;
  408. padding-top: 20rpx;
  409. height: 550rpx;
  410. .canvastishi {
  411. font-size: 32rpx;
  412. position: absolute;
  413. top: 50%;
  414. left: 50%;
  415. margin-left: -64rpx;
  416. margin-top: -21rpx;
  417. .dataloading:after {
  418. overflow: hidden;
  419. display: inline-block;
  420. vertical-align: bottom;
  421. animation: ellipsis 2s infinite;
  422. content: "\2026";
  423. }
  424. @keyframes ellipsis {
  425. from {
  426. width: 2px;
  427. }
  428. to {
  429. width: 15px;
  430. }
  431. }
  432. }
  433. .shuju_one_title {
  434. width: 70%;
  435. margin: 0 auto;
  436. display: flex;
  437. .tltle_text {
  438. width: 25%;
  439. border: 2rpx solid #B2B2B2;
  440. color: #57c878;
  441. text-align: center;
  442. font-size: 24rpx;
  443. height: 50rpx;
  444. line-height: 50rpx;
  445. }
  446. .title_text_color {
  447. width: 25%;
  448. border: 2rpx solid #57c878;
  449. background-color: #57c878;
  450. color: #fff;
  451. text-align: center;
  452. font-size: 24rpx;
  453. height: 50rpx;
  454. line-height: 50rpx;
  455. }
  456. }
  457. }
  458. /deep/.u-calendar__action {
  459. display: flex;
  460. justify-content: space-around;
  461. .u-calendar__action__text {
  462. line-height: 25px;
  463. }
  464. }
  465. .condition {
  466. display: flex;
  467. flex-wrap: wrap;
  468. width: 90%;
  469. margin: 30rpx auto;
  470. box-shadow: 0 0 10rpx #bcb9ca;
  471. margin-bottom: 30rpx;
  472. .scroll-X {
  473. width: 95%;
  474. margin: 20rpx auto;
  475. .table{
  476. width: 1416px;
  477. }
  478. .tr {
  479. display: flex;
  480. overflow: hidden;
  481. .th,
  482. .td {
  483. display: inline-block;
  484. padding: 5rpx;
  485. width: 240rpx;
  486. text-align: center;
  487. height: 52rpx;
  488. line-height: 52rpx;
  489. border: 2rpx solid #F1F1F1;
  490. }
  491. .th:first-child,
  492. .td:first-child {
  493. width: 300rpx;
  494. }
  495. }
  496. .tr:nth-child(2n-1){
  497. background-color: #f5fff8;
  498. }
  499. .tr:first-child{
  500. background-color: #57c878;
  501. color: #fff;
  502. }
  503. }
  504. .pagenumber {
  505. display: flex;
  506. margin: 20rpx auto;
  507. button {
  508. width: 150rpx;
  509. height: 50rpx;
  510. line-height: 50rpx;
  511. font-size: 26rpx;
  512. text-align: center;
  513. background-color: #57c878;
  514. color: #FFFFFF;
  515. }
  516. .pagenumber_page {
  517. // width: 100rpx;
  518. height: 50rpx;
  519. line-height: 50rpx;
  520. font-size: 26rpx;
  521. text-align: center;
  522. margin: 0 20rpx;
  523. }
  524. }
  525. }
  526. </style>