thxyhisdata.vue 13 KB

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