thxyhisdata.vue 11 KB

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