thxyhisdata.vue 14 KB

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