thxyhisdata.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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.ds.value[items.d_h_t.ds]}}</td>
  55. <td class="td">{{Circulation.ws.value[items.d_h_t.ws]}}</td>
  56. <td class="td">{{items.d_h_t.at}}</td>
  57. <td class="td">{{items.d_h_t.ah}}</td>
  58. <td class="td">{{items.d_h_t.cc}}</td>
  59. <td class="td">{{items.d_h_t.cv}}</td>
  60. <td class="td">{{items.d_h_t.bv}}</td>
  61. <td class="td">{{Circulation.bs.value[items.d_h_t.bs]}}</td>
  62. <td class="td">{{items.d_h_t.volt_ct}}</td>
  63. <td class="td">{{items.d_h_t.csq}}</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.ds.value[items.d_h_t.ds]}}</td>
  76. <td class="td">{{Circulation.ws.value[items.d_h_t.ws]}}</td>
  77. <td class="td">{{items.d_h_t.at}}</td>
  78. <td class="td">{{items.d_h_t.ah}}</td>
  79. <td class="td">{{Circulation.bs.value[items.d_h_t.bs]}}</td>
  80. <td class="td">{{items.d_h_t.volt_ct}}</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. "上报时间","设备开关","工作状态","环境温度(℃)","环境湿度(%)","电流(mA)","充电电压(V)","电池电压(V)","电池状态","诱虫次数","信号强度",
  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.page = 1;
  139. this.history()
  140. this.getworm()
  141. this.getwind()
  142. },
  143. async history() { //历史数据列表折线图
  144. this.dataloadingtf = true
  145. const res = await this.$myRequest({
  146. url: '/api/api_gateway?method=forecast.worm_lamp.xy_three_at_ah',
  147. data: {
  148. device_type_id: 8,
  149. d_id: this.equipInfo.d_id,
  150. start_time: Math.floor(+new Date(this.start_time) / 1000),
  151. end_time: Math.floor(+new Date(this.end_time) / 1000),
  152. }
  153. })
  154. console.log(res)
  155. this.dataloadingtf = false
  156. this.historydatas = res
  157. console.log(this.historydatas)
  158. if (this.historydatas.length == 0) {
  159. this.canvastishiTF = false
  160. } else {
  161. this.canvastishiTF = true
  162. var arr1 = []
  163. var arr2 = []
  164. var arr3 = []
  165. var xtitle = []
  166. for (var i = 0; i < res.length; i++) {
  167. var times = new Date(res[i].addtime * 1000)
  168. xtitle.push(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getMinutes())
  169. arr1.push(res[i].at == "" ? "0" : res[i].at)
  170. arr2.push(res[i].ah == "" ? "0" : res[i].ah)
  171. }
  172. // console.log(arr1)
  173. var obj = [{
  174. name: '温度',
  175. data: arr1,
  176. color: '#00E29D'
  177. }, {
  178. name: '湿度',
  179. data: arr2,
  180. color: '#6CBBFF'
  181. }]
  182. this.showColumn("canvasColumnA", xtitle, obj)
  183. }
  184. },
  185. async getworm() {
  186. const res = await this.$myRequest({
  187. url: '/api/api_gateway?method=forecast.worm_lamp.xycb_pest_chart',
  188. data: {
  189. d_id: this.equipInfo.d_id,
  190. start_time: Math.floor(+new Date(this.start_time) / 1000),
  191. end_time: Math.floor(+new Date(this.end_time) / 1000),
  192. device_type_id: "8",
  193. }
  194. })
  195. console.log(res)
  196. this.dataloadingtf2 = false
  197. var data = res.pest_data
  198. if (data.length == 0) {
  199. this.canvastishiTF2 = false
  200. } else {
  201. this.canvastishiTF2 = true
  202. var arr1 = []
  203. var xtitle = []
  204. for (var i = 0; i < data.length; i++) {
  205. var times = new Date(data[i].addtime * 1000)
  206. xtitle.push(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getMinutes())
  207. arr1.push(data[i].pest_num == "" ? "0" : data[i].pest_num)
  208. }
  209. // console.log(arr1)
  210. var obj = [{
  211. name: '诱虫次数',
  212. data: arr1,
  213. color: '#00E29D'
  214. }]
  215. this.showColumn2("canvasColumnB", xtitle, obj)
  216. }
  217. },
  218. async getwind() {
  219. const res = await this.$myRequest({
  220. url: '/api/api_gateway?method=forecast.worm_lamp.xy_three_history_data',
  221. data: {
  222. d_id: this.equipInfo.d_id,
  223. start_time: Math.floor(+new Date(this.start_time) / 1000),
  224. end_time: Math.floor(+new Date(this.end_time) / 1000),
  225. device_id: this.equipInfo.imei,
  226. page: this.page,
  227. }
  228. })
  229. console.log(res)
  230. if(res.data.length){
  231. this.historylistdata = res.data
  232. this.pagesum = Math.ceil(res.counts/10)
  233. this.forbidden = false
  234. }else{
  235. this.forbidden = true
  236. }
  237. },
  238. prev() { //上一页
  239. if (this.page > 1) {
  240. this.page--
  241. this.getwind()
  242. }
  243. },
  244. next() { //下一页
  245. if(this.page < this.pagesum){
  246. this.page++
  247. this.getwind()
  248. }
  249. },
  250. showColumn(id, xtitle, xinfo) {
  251. var _self = this
  252. canvaColumnA = new uCharts({
  253. canvasId: id,
  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. canvaColumnB = new uCharts({
  289. canvasId: id,
  290. type: 'line',
  291. legend: {
  292. position: "top"
  293. },
  294. fontSize: 11,
  295. background: '#FFFFFF',
  296. pixelRatio: 1,
  297. animation: true,
  298. dataLabel: false,
  299. categories: xtitle,
  300. series: xinfo,
  301. enableScroll: true, //开启图表拖拽功能
  302. xAxis: {
  303. disableGrid: true,
  304. type: 'grid',
  305. gridType: 'dash',
  306. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  307. scrollShow: true, //新增是否显示滚动条,默认false
  308. // scrollAlign: 'left', //滚动条初始位置
  309. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  310. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  311. },
  312. yAxis: {},
  313. width: _self.cWidth * 1,
  314. height: _self.cHeight * 1,
  315. extra: {
  316. line: {
  317. type: 'curve'
  318. }
  319. }
  320. });
  321. },
  322. touchLineA(e) {
  323. console.log(e)
  324. canvaColumnA.scrollStart(e);
  325. },
  326. moveLineA(e) {
  327. canvaColumnA.scroll(e);
  328. },
  329. touchEndLineA(e) {
  330. canvaColumnA.scrollEnd(e);
  331. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  332. canvaColumnA.showToolTip(e, {
  333. format: function(item, category) {
  334. return category + ' ' + item.name + ':' + item.data
  335. }
  336. });
  337. },
  338. touchLineB(e) {
  339. console.log(e)
  340. canvaColumnB.scrollStart(e);
  341. },
  342. moveLineB(e) {
  343. canvaColumnB.scroll(e);
  344. },
  345. touchEndLineB(e) {
  346. canvaColumnB.scrollEnd(e);
  347. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  348. canvaColumnB.showToolTip(e, {
  349. format: function(item, category) {
  350. return category + ' ' + item.name + ':' + item.data
  351. }
  352. });
  353. },
  354. },
  355. onLoad(option) {
  356. this.equipInfo = option
  357. console.log(option)
  358. this.end_time = +new Date()
  359. this.start_time = +new Date()-30*24*60*60*1000
  360. this.cWidth = uni.upx2px(650);
  361. this.cHeight = uni.upx2px(500);
  362. this.history()
  363. this.getworm()
  364. this.getwind()
  365. }
  366. }
  367. </script>
  368. <style lang="less">
  369. .timeandtype {
  370. // background-color: #F6F6FB;
  371. // padding: 20rpx;
  372. box-sizing: border-box;
  373. width: 90%;
  374. margin: 40rpx auto 0;
  375. .timebox {
  376. box-shadow: 0 0 10rpx #bcb9ca;
  377. display: flex;
  378. background-color: #fff;
  379. padding: 10px;
  380. border-top-right-radius: 5px;
  381. border-top-left-radius: 5px;
  382. .jiange {
  383. width: 5%;
  384. text-align: center;
  385. }
  386. .firsttime,
  387. .endtime {
  388. width: 45%;
  389. text-align: center;
  390. }
  391. }
  392. .warntypebox {
  393. display: flex;
  394. justify-content: space-between;
  395. background-color: #fff;
  396. padding: 10px;
  397. border-top: 1px solid #F6F6FB;
  398. border-bottom-right-radius: 5px;
  399. border-bottom-left-radius: 5px;
  400. }
  401. }
  402. .shuju_one {
  403. position: relative;
  404. width: 90%;
  405. margin: 30rpx auto;
  406. box-shadow: 0 0 10rpx #bcb9ca;
  407. padding-top: 20rpx;
  408. height: 550rpx;
  409. .canvastishi {
  410. font-size: 32rpx;
  411. position: absolute;
  412. top: 50%;
  413. left: 50%;
  414. margin-left: -64rpx;
  415. margin-top: -21rpx;
  416. .dataloading:after {
  417. overflow: hidden;
  418. display: inline-block;
  419. vertical-align: bottom;
  420. animation: ellipsis 2s infinite;
  421. content: "\2026";
  422. }
  423. @keyframes ellipsis {
  424. from {
  425. width: 2px;
  426. }
  427. to {
  428. width: 15px;
  429. }
  430. }
  431. }
  432. .shuju_one_title {
  433. width: 70%;
  434. margin: 0 auto;
  435. display: flex;
  436. .tltle_text {
  437. width: 25%;
  438. border: 2rpx solid #B2B2B2;
  439. color: #57c878;
  440. text-align: center;
  441. font-size: 24rpx;
  442. height: 50rpx;
  443. line-height: 50rpx;
  444. }
  445. .title_text_color {
  446. width: 25%;
  447. border: 2rpx solid #57c878;
  448. background-color: #57c878;
  449. color: #fff;
  450. text-align: center;
  451. font-size: 24rpx;
  452. height: 50rpx;
  453. line-height: 50rpx;
  454. }
  455. }
  456. }
  457. /deep/.u-calendar__action {
  458. display: flex;
  459. justify-content: space-around;
  460. .u-calendar__action__text {
  461. line-height: 25px;
  462. }
  463. }
  464. .condition {
  465. display: flex;
  466. flex-wrap: wrap;
  467. width: 90%;
  468. margin: 30rpx auto;
  469. box-shadow: 0 0 10rpx #bcb9ca;
  470. margin-bottom: 30rpx;
  471. .scroll-X {
  472. width: 95%;
  473. margin: 20rpx auto;
  474. .table{
  475. width: 1416px;
  476. }
  477. .tr {
  478. display: flex;
  479. overflow: hidden;
  480. .th,
  481. .td {
  482. display: inline-block;
  483. padding: 5rpx;
  484. width: 240rpx;
  485. text-align: center;
  486. height: 52rpx;
  487. line-height: 52rpx;
  488. border: 2rpx solid #F1F1F1;
  489. }
  490. .th:first-child,
  491. .td:first-child {
  492. width: 300rpx;
  493. }
  494. }
  495. .tr:nth-child(2n-1){
  496. background-color: #f5fff8;
  497. }
  498. .tr:first-child{
  499. background-color: #57c878;
  500. color: #fff;
  501. }
  502. }
  503. .pagenumber {
  504. display: flex;
  505. margin: 20rpx auto;
  506. button {
  507. width: 150rpx;
  508. height: 50rpx;
  509. line-height: 50rpx;
  510. font-size: 26rpx;
  511. text-align: center;
  512. background-color: #57c878;
  513. color: #FFFFFF;
  514. }
  515. .pagenumber_page {
  516. // width: 100rpx;
  517. height: 50rpx;
  518. line-height: 50rpx;
  519. font-size: 26rpx;
  520. text-align: center;
  521. margin: 0 20rpx;
  522. }
  523. }
  524. }
  525. </style>