thxyhisdata.vue 11 KB

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