thxyhisdata.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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. console.log(res.data)
  170. this.historylistdata = res.data
  171. this.pagesum = Math.ceil(res.counts / 10)
  172. if (res.data.length > 0) {
  173. this.forbidden = false
  174. } else {
  175. this.forbidden = true
  176. }
  177. },
  178. prev() { //上一页
  179. if (this.page > 1) {
  180. this.page--
  181. this.getwind()
  182. }
  183. },
  184. next() { //下一页
  185. if (this.page < this.pagesum) {
  186. this.page++
  187. this.getwind()
  188. }
  189. },
  190. showColumn(id, xtitle, xinfo) {
  191. var _self = this
  192. const ctx = uni.createCanvasContext(id, this);
  193. canvaColumnA = new uCharts({
  194. context: ctx,
  195. type: 'line',
  196. legend: {
  197. position: "top"
  198. },
  199. fontSize: 11,
  200. background: '#FFFFFF',
  201. pixelRatio: 1,
  202. animation: true,
  203. dataLabel: false,
  204. categories: xtitle,
  205. series: xinfo,
  206. enableScroll: true, //开启图表拖拽功能
  207. xAxis: {
  208. disableGrid: true,
  209. type: 'grid',
  210. gridType: 'dash',
  211. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  212. scrollShow: true, //新增是否显示滚动条,默认false
  213. // scrollAlign: 'left', //滚动条初始位置
  214. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  215. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  216. },
  217. yAxis: {},
  218. width: _self.cWidth * 1,
  219. height: _self.cHeight * 1,
  220. extra: {
  221. line: {
  222. type: 'curve'
  223. }
  224. }
  225. });
  226. },
  227. showColumn2(id, xtitle, xinfo) {
  228. var _self = this
  229. const ctx = uni.createCanvasContext(id, this);
  230. canvaColumnB = new uCharts({
  231. context: ctx,
  232. type: 'line',
  233. legend: {
  234. position: "top"
  235. },
  236. fontSize: 11,
  237. background: '#FFFFFF',
  238. pixelRatio: 1,
  239. animation: true,
  240. dataLabel: false,
  241. categories: xtitle,
  242. series: xinfo,
  243. enableScroll: true, //开启图表拖拽功能
  244. xAxis: {
  245. disableGrid: true,
  246. type: 'grid',
  247. gridType: 'dash',
  248. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  249. scrollShow: true, //新增是否显示滚动条,默认false
  250. // scrollAlign: 'left', //滚动条初始位置
  251. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  252. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  253. },
  254. yAxis: {},
  255. width: _self.cWidth * 1,
  256. height: _self.cHeight * 1,
  257. extra: {
  258. line: {
  259. type: 'curve'
  260. }
  261. }
  262. });
  263. },
  264. touchLineA(e) {
  265. console.log(e)
  266. canvaColumnA.scrollStart(e);
  267. },
  268. moveLineA(e) {
  269. canvaColumnA.scroll(e);
  270. },
  271. touchEndLineA(e) {
  272. canvaColumnA.scrollEnd(e);
  273. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  274. canvaColumnA.showToolTip(e, {
  275. format: function(item, category) {
  276. return category + ' ' + item.name + ':' + item.data
  277. }
  278. });
  279. },
  280. touchLineB(e) {
  281. console.log(e)
  282. canvaColumnB.scrollStart(e);
  283. },
  284. moveLineB(e) {
  285. canvaColumnB.scroll(e);
  286. },
  287. touchEndLineB(e) {
  288. canvaColumnB.scrollEnd(e);
  289. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  290. canvaColumnB.showToolTip(e, {
  291. format: function(item, category) {
  292. return category + ' ' + item.name + ':' + item.data
  293. }
  294. });
  295. },
  296. },
  297. onLoad(option) {
  298. this.equipInfo = option
  299. console.log(option)
  300. this.end_time = +new Date()
  301. this.start_time = +new Date() - 30 * 24 * 60 * 60 * 1000
  302. this.cWidth = uni.upx2px(650);
  303. this.cHeight = uni.upx2px(500);
  304. this.history()
  305. this.getworm()
  306. this.getwind()
  307. }
  308. }
  309. </script>
  310. <style lang="less">
  311. .timeandtype {
  312. // background-color: #F6F6FB;
  313. // padding: 20rpx;
  314. box-sizing: border-box;
  315. width: 90%;
  316. margin: 40rpx auto 0;
  317. .timebox {
  318. box-shadow: 0 0 10rpx #bcb9ca;
  319. display: flex;
  320. background-color: #fff;
  321. padding: 10px;
  322. border-top-right-radius: 5px;
  323. border-top-left-radius: 5px;
  324. .jiange {
  325. width: 5%;
  326. text-align: center;
  327. }
  328. .firsttime,
  329. .endtime {
  330. width: 45%;
  331. text-align: center;
  332. }
  333. }
  334. .warntypebox {
  335. display: flex;
  336. justify-content: space-between;
  337. background-color: #fff;
  338. padding: 10px;
  339. border-top: 1px solid #F6F6FB;
  340. border-bottom-right-radius: 5px;
  341. border-bottom-left-radius: 5px;
  342. }
  343. }
  344. .shuju_one {
  345. position: relative;
  346. width: 90%;
  347. margin: 30rpx auto;
  348. box-shadow: 0 0 10rpx #bcb9ca;
  349. padding-top: 20rpx;
  350. height: 550rpx;
  351. .canvastishi {
  352. font-size: 32rpx;
  353. position: absolute;
  354. top: 50%;
  355. left: 50%;
  356. margin-left: -64rpx;
  357. margin-top: -21rpx;
  358. .dataloading:after {
  359. overflow: hidden;
  360. display: inline-block;
  361. vertical-align: bottom;
  362. animation: ellipsis 2s infinite;
  363. content: "\2026";
  364. }
  365. @keyframes ellipsis {
  366. from {
  367. width: 2px;
  368. }
  369. to {
  370. width: 15px;
  371. }
  372. }
  373. }
  374. .shuju_one_title {
  375. width: 70%;
  376. margin: 0 auto;
  377. display: flex;
  378. .tltle_text {
  379. width: 25%;
  380. border: 2rpx solid #B2B2B2;
  381. color: #57c878;
  382. text-align: center;
  383. font-size: 24rpx;
  384. height: 50rpx;
  385. line-height: 50rpx;
  386. }
  387. .title_text_color {
  388. width: 25%;
  389. border: 2rpx solid #57c878;
  390. background-color: #57c878;
  391. color: #fff;
  392. text-align: center;
  393. font-size: 24rpx;
  394. height: 50rpx;
  395. line-height: 50rpx;
  396. }
  397. }
  398. }
  399. /deep/.u-calendar__action {
  400. display: flex;
  401. justify-content: space-around;
  402. .u-calendar__action__text {
  403. line-height: 25px;
  404. }
  405. }
  406. .condition {
  407. display: flex;
  408. flex-wrap: wrap;
  409. width: 90%;
  410. margin: 30rpx auto;
  411. box-shadow: 0 0 10rpx #bcb9ca;
  412. margin-bottom: 30rpx;
  413. .scroll-X {
  414. width: 95%;
  415. margin: 20rpx auto;
  416. .table {
  417. width: 1740rpx;
  418. }
  419. .tr {
  420. display: flex;
  421. overflow: hidden;
  422. .th,
  423. .td {
  424. display: inline-block;
  425. padding: 5rpx;
  426. width: 240rpx;
  427. text-align: center;
  428. height: 52rpx;
  429. line-height: 52rpx;
  430. border: 2rpx solid #F1F1F1;
  431. }
  432. .th:first-child,
  433. .td:first-child {
  434. width: 300rpx;
  435. }
  436. }
  437. .tr:nth-child(2n-1) {
  438. background-color: #f5fff8;
  439. }
  440. .tr:first-child {
  441. background-color: #57c878;
  442. color: #fff;
  443. }
  444. }
  445. .pagenumber {
  446. display: flex;
  447. margin: 20rpx auto;
  448. button {
  449. width: 150rpx;
  450. height: 50rpx;
  451. line-height: 50rpx;
  452. font-size: 26rpx;
  453. text-align: center;
  454. background-color: #57c878;
  455. color: #FFFFFF;
  456. }
  457. .pagenumber_page {
  458. // width: 100rpx;
  459. height: 50rpx;
  460. line-height: 50rpx;
  461. font-size: 26rpx;
  462. text-align: center;
  463. margin: 0 20rpx;
  464. }
  465. }
  466. }
  467. </style>