thxyhisdata.vue 14 KB

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