thxyhisdata.vue 11 KB

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