thxyhisdata.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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.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.xy_three_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.xycb_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.xy_three_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. canvaColumnA = new uCharts({
  252. canvasId: id,
  253. type: 'line',
  254. legend: {
  255. position: "top"
  256. },
  257. fontSize: 11,
  258. background: '#FFFFFF',
  259. pixelRatio: 1,
  260. animation: true,
  261. dataLabel: false,
  262. categories: xtitle,
  263. series: xinfo,
  264. enableScroll: true, //开启图表拖拽功能
  265. xAxis: {
  266. disableGrid: true,
  267. type: 'grid',
  268. gridType: 'dash',
  269. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  270. scrollShow: true, //新增是否显示滚动条,默认false
  271. // scrollAlign: 'left', //滚动条初始位置
  272. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  273. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  274. },
  275. yAxis: {},
  276. width: _self.cWidth * 1,
  277. height: _self.cHeight * 1,
  278. extra: {
  279. line: {
  280. type: 'curve'
  281. }
  282. }
  283. });
  284. },
  285. showColumn2(id, xtitle, xinfo) {
  286. var _self = this
  287. canvaColumnB = new uCharts({
  288. canvasId: id,
  289. type: 'line',
  290. legend: {
  291. position: "top"
  292. },
  293. fontSize: 11,
  294. background: '#FFFFFF',
  295. pixelRatio: 1,
  296. animation: true,
  297. dataLabel: false,
  298. categories: xtitle,
  299. series: xinfo,
  300. enableScroll: true, //开启图表拖拽功能
  301. xAxis: {
  302. disableGrid: true,
  303. type: 'grid',
  304. gridType: 'dash',
  305. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  306. scrollShow: true, //新增是否显示滚动条,默认false
  307. // scrollAlign: 'left', //滚动条初始位置
  308. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  309. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  310. },
  311. yAxis: {},
  312. width: _self.cWidth * 1,
  313. height: _self.cHeight * 1,
  314. extra: {
  315. line: {
  316. type: 'curve'
  317. }
  318. }
  319. });
  320. },
  321. touchLineA(e) {
  322. console.log(e)
  323. canvaColumnA.scrollStart(e);
  324. },
  325. moveLineA(e) {
  326. canvaColumnA.scroll(e);
  327. },
  328. touchEndLineA(e) {
  329. canvaColumnA.scrollEnd(e);
  330. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  331. canvaColumnA.showToolTip(e, {
  332. format: function(item, category) {
  333. return category + ' ' + item.name + ':' + item.data
  334. }
  335. });
  336. },
  337. touchLineB(e) {
  338. console.log(e)
  339. canvaColumnB.scrollStart(e);
  340. },
  341. moveLineB(e) {
  342. canvaColumnB.scroll(e);
  343. },
  344. touchEndLineB(e) {
  345. canvaColumnB.scrollEnd(e);
  346. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  347. canvaColumnB.showToolTip(e, {
  348. format: function(item, category) {
  349. return category + ' ' + item.name + ':' + item.data
  350. }
  351. });
  352. },
  353. },
  354. onLoad(option) {
  355. this.equipInfo = option
  356. console.log(option)
  357. this.end_time = +new Date()
  358. this.start_time = +new Date()-30*24*60*60*1000
  359. this.cWidth = uni.upx2px(650);
  360. this.cHeight = uni.upx2px(500);
  361. this.history()
  362. this.getworm()
  363. this.getwind()
  364. }
  365. }
  366. </script>
  367. <style lang="less">
  368. .timeandtype {
  369. // background-color: #F6F6FB;
  370. // padding: 20rpx;
  371. box-sizing: border-box;
  372. width: 90%;
  373. margin: 40rpx auto 0;
  374. .timebox {
  375. box-shadow: 0 0 10rpx #bcb9ca;
  376. display: flex;
  377. background-color: #fff;
  378. padding: 10px;
  379. border-top-right-radius: 5px;
  380. border-top-left-radius: 5px;
  381. .jiange {
  382. width: 5%;
  383. text-align: center;
  384. }
  385. .firsttime,
  386. .endtime {
  387. width: 45%;
  388. text-align: center;
  389. }
  390. }
  391. .warntypebox {
  392. display: flex;
  393. justify-content: space-between;
  394. background-color: #fff;
  395. padding: 10px;
  396. border-top: 1px solid #F6F6FB;
  397. border-bottom-right-radius: 5px;
  398. border-bottom-left-radius: 5px;
  399. }
  400. }
  401. .shuju_one {
  402. position: relative;
  403. width: 90%;
  404. margin: 30rpx auto;
  405. box-shadow: 0 0 10rpx #bcb9ca;
  406. padding-top: 20rpx;
  407. height: 550rpx;
  408. .canvastishi {
  409. font-size: 32rpx;
  410. position: absolute;
  411. top: 50%;
  412. left: 50%;
  413. margin-left: -64rpx;
  414. margin-top: -21rpx;
  415. .dataloading:after {
  416. overflow: hidden;
  417. display: inline-block;
  418. vertical-align: bottom;
  419. animation: ellipsis 2s infinite;
  420. content: "\2026";
  421. }
  422. @keyframes ellipsis {
  423. from {
  424. width: 2px;
  425. }
  426. to {
  427. width: 15px;
  428. }
  429. }
  430. }
  431. .shuju_one_title {
  432. width: 70%;
  433. margin: 0 auto;
  434. display: flex;
  435. .tltle_text {
  436. width: 25%;
  437. border: 2rpx solid #B2B2B2;
  438. color: #57c878;
  439. text-align: center;
  440. font-size: 24rpx;
  441. height: 50rpx;
  442. line-height: 50rpx;
  443. }
  444. .title_text_color {
  445. width: 25%;
  446. border: 2rpx solid #57c878;
  447. background-color: #57c878;
  448. color: #fff;
  449. text-align: center;
  450. font-size: 24rpx;
  451. height: 50rpx;
  452. line-height: 50rpx;
  453. }
  454. }
  455. }
  456. /deep/.u-calendar__action {
  457. display: flex;
  458. justify-content: space-around;
  459. .u-calendar__action__text {
  460. line-height: 25px;
  461. }
  462. }
  463. .condition {
  464. display: flex;
  465. flex-wrap: wrap;
  466. width: 90%;
  467. margin: 30rpx auto;
  468. box-shadow: 0 0 10rpx #bcb9ca;
  469. margin-bottom: 30rpx;
  470. .scroll-X {
  471. width: 95%;
  472. margin: 20rpx auto;
  473. .table{
  474. width: 1416px;
  475. }
  476. .tr {
  477. display: flex;
  478. overflow: hidden;
  479. .th,
  480. .td {
  481. display: inline-block;
  482. padding: 5rpx;
  483. width: 240rpx;
  484. text-align: center;
  485. height: 52rpx;
  486. line-height: 52rpx;
  487. border: 2rpx solid #F1F1F1;
  488. }
  489. .th:first-child,
  490. .td:first-child {
  491. width: 300rpx;
  492. }
  493. }
  494. .tr:nth-child(2n-1){
  495. background-color: #f5fff8;
  496. }
  497. .tr:first-child{
  498. background-color: #57c878;
  499. color: #fff;
  500. }
  501. }
  502. .pagenumber {
  503. display: flex;
  504. margin: 20rpx auto;
  505. button {
  506. width: 150rpx;
  507. height: 50rpx;
  508. line-height: 50rpx;
  509. font-size: 26rpx;
  510. text-align: center;
  511. background-color: #57c878;
  512. color: #FFFFFF;
  513. }
  514. .pagenumber_page {
  515. // width: 100rpx;
  516. height: 50rpx;
  517. line-height: 50rpx;
  518. font-size: 26rpx;
  519. text-align: center;
  520. margin: 0 20rpx;
  521. }
  522. }
  523. }
  524. </style>