statistics.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 64px;">
  5. <view style="position: fixed;z-index: 100;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" title="害虫统计"></uni-nav-bar>
  7. </view>
  8. <view class="statistics">
  9. <view class="top_text">
  10. <view :class="topindex==index?'title_text_color':'tltle_text'" v-for="(item,index) in toptext" :key="index" @click="changeindex(index)">
  11. {{item}}
  12. </view>
  13. </view>
  14. <view class="shuju_one">
  15. <p class="shuju_one_title">害虫趋势统计</p>
  16. <view class="shuju_one_btn">
  17. <view class="schedule_box">
  18. <view class="schedule" @click="pickertfone=!pickertfone">
  19. <p class="schedule_value">{{titletext[indexone]}}</p>
  20. <p class="schedule_icon">
  21. <u-icon name="arrow-down"></u-icon>
  22. </p>
  23. </view>
  24. <u-picker v-model="pickertfone" mode="selector" @confirm="confirmFun" :default-selector="[indexone]" :range="titletext"></u-picker>
  25. <view class="schedule" @click="pickertftwo=!pickertftwo" v-if="tishitf">
  26. <p class="schedule_value">{{wormdata[indextwo]}}</p>
  27. <p class="schedule_icon">
  28. <u-icon name="arrow-down"></u-icon>
  29. </p>
  30. <u-picker v-model="pickertftwo" mode="selector" @confirm="confirmFun2" :default-selector="[indextwo]" :range="wormdata"></u-picker>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="canvastishi" v-if="!canvastishiTF">
  35. 暂无数据
  36. </view>
  37. <canvas v-if="canvastishiTF" canvas-id="canvasColumnA" id="canvasColumnA" class="charts" @touchstart="touchLineA($event)"
  38. @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)" disable-scroll=true :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>
  39. </view>
  40. <view class="shuju_two">
  41. <p class="shuju_one_title">害虫比例</p>
  42. <view class="canvastishi" v-if="!canvastishiTF">
  43. 暂无数据
  44. </view>
  45. <canvas v-if="canvastishiTF" canvas-id="canvasRing" id="canvasRing" class="charts" @touchstart="touchRing" :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>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </template>
  51. <style lang="scss">
  52. .top_text {
  53. width: 90%;
  54. position: absolute;
  55. top: 54px;
  56. display: flex;
  57. left: 5%;
  58. .tltle_text {
  59. width: 50%;
  60. border: 2rpx solid #F0F0F0;
  61. text-align: center;
  62. }
  63. .title_text_color {
  64. width: 50%;
  65. border: 2rpx solid #64CC82;
  66. text-align: center;
  67. }
  68. }
  69. .tishi {
  70. position: absolute;
  71. top: 250rpx;
  72. left: 40%;
  73. font-size: 32rpx;
  74. color: #7A7373;
  75. }
  76. .shuju_one_title {
  77. font-size: 32rpx;
  78. font-weight: 700;
  79. width: 100%;
  80. text-align: center;
  81. margin-bottom: 20rpx;
  82. }
  83. .shuju_one_btn {
  84. width: 90%;
  85. margin: 0 auto;
  86. display: flex;
  87. justify-content: space-between;
  88. .schedule_box {
  89. display: flex;
  90. }
  91. .schedule {
  92. display: flex;
  93. width: 280rpx;
  94. height: 50rpx;
  95. border: 2rpx solid #F0F0F0;
  96. margin-left: 20rpx;
  97. .schedule_value {
  98. width: 70%;
  99. text-align: center;
  100. line-height: 50rpx;
  101. font-size: 24rpx;
  102. }
  103. .schedule_icon {
  104. width: 30%;
  105. background-color: #F2F2F2;
  106. text-align: center;
  107. line-height: 50rpx;
  108. }
  109. }
  110. }
  111. </style>
  112. <script>
  113. import uCharts from '../../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  114. var canvaColumnA = null;
  115. var canvasRing = null;
  116. var newtime = +new Date()
  117. var strrttime = newtime - 24 * 60 * 60 * 1000
  118. export default {
  119. data() {
  120. return {
  121. cWidth: '400',
  122. cHeight: '400',
  123. pixelRatio: 1,
  124. canvastishiTF: false,
  125. d_id: '',
  126. start_time: strrttime,
  127. end_time: newtime,
  128. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  129. device_id: '',
  130. pest_name: '',
  131. wormdata: [],
  132. pickertfone: false,
  133. pickertftwo: false,
  134. indexone: 0,
  135. indextwo: 0,
  136. tishitf: false,
  137. tishi: false,
  138. toptext: ["自动统计", "手动统计"],
  139. topindex: 0
  140. }
  141. },
  142. methods: {
  143. async historys() { //获取统计虫子 自动统计 初始化统计 没有传入害虫名称
  144. const res = await this.$myRequest({
  145. url: '/api/api_gateway?method=forecast.worm_lamp.pest_statistics',
  146. data: {
  147. d_id: this.d_id,
  148. start_time: parseInt(this.start_time / 1000),
  149. end_time: parseInt(this.end_time / 1000),
  150. }
  151. })
  152. this.historydatas = res
  153. console.log(this.historydatas)
  154. if (this.historydatas.date.length == 0) {
  155. this.canvastishiTF = false
  156. this.tishitf = false
  157. } else {
  158. this.canvastishiTF = true
  159. this.tishitf = true
  160. this.wormdata = []
  161. for (var i = 0; i < res.percentage.length; i++) {
  162. this.wormdata.unshift(res.percentage[i].name_num)
  163. }
  164. var arr1 = []
  165. var arr2 = []
  166. var arr3 = []
  167. var xtitle = []
  168. var ringarr = []
  169. for (var i = 0; i < res.date.length; i++) {
  170. var times = new Date(res.date[i].addtime * 1000)
  171. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getSeconds())
  172. arr1.unshift(res.date[i].temperature == "" ? "0" : res.date[i].temperature)
  173. arr2.unshift(res.date[i].humidity == "" ? "0" : res.date[i].humidity)
  174. arr3.unshift(res.date[i]._sums == "" ? "0" : res.date[i]._sums)
  175. }
  176. for(var i = 0; i < res.percentage.length; i++){
  177. var obj = {}
  178. obj.name = res.percentage[i].name_num
  179. obj.data = Number(res.percentage[i].num)
  180. ringarr.unshift(obj)
  181. }
  182. console.log(ringarr)
  183. var obj = [{
  184. name: '温度',
  185. data: arr1,
  186. color: '#00E29D'
  187. }, {
  188. name: '湿度',
  189. data: arr2,
  190. color: '#6CBBFF'
  191. }, {
  192. name: '害虫总数',
  193. data: arr3,
  194. color: '#FF3F3F'
  195. }]
  196. this.showColumn("canvasColumnA", xtitle, obj)
  197. this.showRing(ringarr)
  198. }
  199. },
  200. async history() { //获取统计虫子 //自动统计 传入害虫名称统计 在historys之后
  201. const res = await this.$myRequest({
  202. url: '/api/api_gateway?method=forecast.worm_lamp.pest_statistics',
  203. data: {
  204. pest_name: this.pest_name,
  205. d_id: this.d_id,
  206. start_time: parseInt(this.start_time / 1000),
  207. end_time: parseInt(this.end_time / 1000)
  208. }
  209. })
  210. this.historydatas = res
  211. console.log(this.historydatas)
  212. if (this.historydatas.date.length == 0) {
  213. this.canvastishiTF = false
  214. this.tishitf = false
  215. } else {
  216. this.canvastishiTF = true
  217. this.tishitf = true
  218. var arr1 = []
  219. var arr2 = []
  220. var arr3 = []
  221. var xtitle = []
  222. for (var i = 0; i < res.date.length; i++) {
  223. var times = new Date(res.date[i].addtime * 1000)
  224. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getSeconds())
  225. arr1.unshift(res.date[i].temperature == "" ? "0" : res.date[i].temperature)
  226. arr2.unshift(res.date[i].humidity == "" ? "0" : res.date[i].humidity)
  227. arr3.unshift(res.date[i]._sums == "" ? "0" : res.date[i]._sums)
  228. }
  229. var obj = [{
  230. name: '温度',
  231. data: arr1,
  232. color: '#00E29D'
  233. }, {
  234. name: '湿度',
  235. data: arr2,
  236. color: '#6CBBFF'
  237. }, {
  238. name: '害虫总数',
  239. data: arr3,
  240. color: '#FF3F3F'
  241. }]
  242. this.showColumn("canvasColumnA", xtitle, obj)
  243. }
  244. },
  245. // forecast.worm_lamp.pest_manual_statistics手动统计
  246. async selfhistorys() { //获取统计虫子 手动统计 初始化统计 不传入害虫名称
  247. const res = await this.$myRequest({
  248. url: '/api/api_gateway?method=forecast.worm_lamp.pest_manual_statistics',
  249. data: {
  250. device_id: this.d_id,
  251. start_time: parseInt(this.start_time / 1000),
  252. end_time: parseInt(this.end_time / 1000)
  253. }
  254. })
  255. console.log(res)
  256. if (res.date.length == 0) {
  257. this.tishitf = false
  258. this.canvastishiTF = false
  259. } else {
  260. this.tishitf = true
  261. this.canvastishiTF = true
  262. this.wormdata = []
  263. for (var i = 0; i < res.date.length; i++) {
  264. this.wormdata.unshift(res.date[i].pest_name)
  265. }
  266. var arr1 = []
  267. var xtitle = []
  268. var ringarr = []
  269. for (var i = 0; i < res.date.length; i++) {
  270. var times = new Date(res.date[i].add_time * 1000)
  271. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getSeconds())
  272. arr1.unshift(res.date[i].pest_num == "" ? "0" : res.date[i].pest_num)
  273. var obj ={}
  274. obj.name = res.date[i].pest_name
  275. obj.data = Number(res.date[i].pest_num)
  276. ringarr.unshift(obj)
  277. }
  278. var obj = [{
  279. name: '害虫总数',
  280. data: arr1,
  281. color: '#00E29D'
  282. }]
  283. this.showColumn("canvasColumnA", xtitle, obj)
  284. this.showRing(ringarr)
  285. }
  286. },
  287. async selfhistory() { //获取统计虫子 //手动统计 传入害虫名称
  288. const res = await this.$myRequest({
  289. url: '/api/api_gateway?method=forecast.worm_lamp.pest_manual_statistics',
  290. data: {
  291. pest_name: this.pest_name,
  292. device_id: this.d_id,
  293. start_time: parseInt(this.start_time / 1000),
  294. end_time: parseInt(this.end_time / 1000)
  295. }
  296. })
  297. this.historydatas = res
  298. console.log(this.historydatas)
  299. if (res.date.length == 0) {
  300. this.tishitf = false
  301. this.canvastishiTF = false
  302. } else {
  303. this.tishitf = true
  304. this.canvastishiTF = true
  305. var arr1 = []
  306. var xtitle = []
  307. for (var i = 0; i < res.pests.pest_list.length; i++) {
  308. var times = new Date(res.pests.pest_list[i].add_time * 1000)
  309. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getSeconds())
  310. arr1.unshift(res.pests.pest_list[i].pest_num == "" ? "0" : res.pests.pest_list[i].pest_num)
  311. }
  312. var obj = [{
  313. name: '害虫总数',
  314. data: arr1,
  315. color: '#00E29D'
  316. }]
  317. this.showColumn("canvasColumnA", xtitle, obj)
  318. }
  319. },
  320. clickLeft() {
  321. uni.navigateBack({
  322. delta: 1
  323. })
  324. },
  325. confirmFun(index) {
  326. this.indexone = index[0]
  327. var now = new Date()
  328. this.$forceUpdate()
  329. if (index[0] == 0) {
  330. this.start_time = strrttime
  331. if (this.topindex == 0) {
  332. if (this.pest_name == '') {
  333. this.historys()
  334. } else {
  335. this.history()
  336. }
  337. } else {
  338. if (this.pest_name == '') {
  339. this.selfhistorys()
  340. } else {
  341. this.selfhistory()
  342. }
  343. }
  344. } else if (index[0] == 1) {
  345. var oldtime = now.setMonth(now.getMonth() - 1)
  346. this.start_time = parseInt(oldtime)
  347. if (this.topindex == 0) {
  348. if (this.pest_name == '') {
  349. this.historys()
  350. } else {
  351. this.history()
  352. }
  353. } else {
  354. if (this.pest_name == '') {
  355. this.selfhistorys()
  356. } else {
  357. this.selfhistory()
  358. }
  359. }
  360. } else if (index[0] == 2) {
  361. var oldtime = now.setMonth(now.getMonth() - 6)
  362. this.start_time = parseInt(oldtime)
  363. if (this.topindex == 0) {
  364. if (this.pest_name == '') {
  365. this.historys()
  366. } else {
  367. this.history()
  368. }
  369. } else {
  370. if (this.pest_name == '') {
  371. this.selfhistorys()
  372. } else {
  373. this.selfhistory()
  374. }
  375. }
  376. } else if (index[0] == 3) {
  377. var oldtime = now.setFullYear(now.getFullYear() - 1)
  378. this.start_time = parseInt(oldtime)
  379. if (this.topindex == 0) {
  380. if (this.pest_name == '') {
  381. this.historys()
  382. } else {
  383. this.history()
  384. }
  385. } else {
  386. if (this.pest_name == '') {
  387. this.selfhistorys()
  388. } else {
  389. this.selfhistory()
  390. }
  391. }
  392. }
  393. },
  394. confirmFun2(index) {
  395. console.log(index)
  396. console.log(this.wormdata)
  397. this.indextwo = index[0]
  398. this.pest_name = this.wormdata[this.indextwo]
  399. if (this.topindex == 0) {
  400. this.history()
  401. } else {
  402. this.selfhistory()
  403. }
  404. },
  405. changeindex(index) {
  406. this.topindex = index
  407. if (this.topindex == 0) {
  408. this.pest_name = ''
  409. this.tishitf = false
  410. this.historys()
  411. } else {
  412. this.pest_name = ''
  413. this.tishitf = false
  414. this.selfhistorys()
  415. }
  416. },
  417. showColumn(id, xtitle, xinfo) {
  418. var _self = this
  419. canvaColumnA = new uCharts({
  420. canvasId: id,
  421. type: 'line',
  422. legend: {
  423. position: "top"
  424. },
  425. fontSize: 11,
  426. background: '#FFFFFF',
  427. pixelRatio: 1,
  428. animation: true,
  429. dataLabel: false,
  430. categories: xtitle,
  431. series: xinfo,
  432. enableScroll: true, //开启图表拖拽功能
  433. xAxis: {
  434. disableGrid: true,
  435. type: 'grid',
  436. gridType: 'dash',
  437. itemCount: 5, //x轴单屏显示数据的数量,默认为5个
  438. scrollShow: true, //新增是否显示滚动条,默认false
  439. // scrollAlign: 'left', //滚动条初始位置
  440. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  441. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  442. },
  443. yAxis: {},
  444. width: _self.cWidth * 1,
  445. height: _self.cHeight * 1,
  446. extra: {
  447. line: {
  448. type: 'curve'
  449. }
  450. }
  451. });
  452. },
  453. touchLineA(e) {
  454. console.log(e)
  455. canvaColumnA.scrollStart(e);
  456. },
  457. moveLineA(e) {
  458. canvaColumnA.scroll(e);
  459. },
  460. touchEndLineA(e) {
  461. canvaColumnA.scrollEnd(e);
  462. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  463. canvaColumnA.showToolTip(e, {
  464. format: function(item, category) {
  465. return category + ' ' + item.name + ':' + item.data
  466. }
  467. });
  468. },
  469. showRing(data) {
  470. var _self = this
  471. canvasRing = new uCharts({
  472. canvasId: "canvasRing",
  473. type: 'ring',
  474. fontSize: 11,
  475. legend: true,
  476. extra: {
  477. pie: {
  478. offsetAngle: -45,
  479. ringWidth: 40 * _self.pixelRatio,
  480. labelWidth: 15
  481. }
  482. },
  483. background: '#FFFFFF',
  484. pixelRatio: _self.pixelRatio,
  485. series: data,
  486. animation: true,
  487. width: _self.cWidth * _self.pixelRatio,
  488. height: _self.cHeight * _self.pixelRatio,
  489. disablePieStroke: true,
  490. dataLabel: true,
  491. });
  492. },
  493. touchRing(e) {
  494. canvasRing.showToolTip(e, {
  495. format: function(item) {
  496. return item.name + ':' + item.data
  497. }
  498. });
  499. },
  500. },
  501. onLoad(option) {
  502. this.d_id = option.d_id
  503. this.device_id = option.device_id
  504. this.cWidth = uni.upx2px(650);
  505. this.cHeight = uni.upx2px(500);
  506. this.historys()
  507. }
  508. }
  509. </script>
  510. <style lang="scss">
  511. .shuju_one{
  512. position: absolute;
  513. top: 84px;
  514. width: 90%;
  515. left: 5%;
  516. box-shadow: 0 0 10rpx #bcb9ca;
  517. padding-top: 20rpx;
  518. box-sizing: border-box;
  519. height: 650rpx;
  520. .canvastishi {
  521. font-size: 32rpx;
  522. position: absolute;
  523. top: 50%;
  524. left: 50%;
  525. margin-left: -64rpx;
  526. margin-top: -21rpx;
  527. }
  528. }
  529. .shuju_two{
  530. position: absolute;
  531. top: 840rpx;
  532. width: 90%;
  533. left: 5%;
  534. box-shadow: 0 0 10rpx #bcb9ca;
  535. padding-top: 20rpx;
  536. box-sizing: border-box;
  537. height: 650rpx;
  538. margin-bottom: 40rpx;
  539. .canvastishi {
  540. font-size: 32rpx;
  541. position: absolute;
  542. top: 50%;
  543. left: 50%;
  544. margin-left: -64rpx;
  545. margin-top: -21rpx;
  546. }
  547. }
  548. .condition {
  549. position: absolute;
  550. top: 600rpx;
  551. display: flex;
  552. flex-wrap: wrap;
  553. width: 90%;
  554. left: 5%;
  555. box-shadow: 0 0 10rpx #bcb9ca;
  556. margin-bottom: 30rpx;
  557. .scroll-X {
  558. width: 95%;
  559. margin: 20rpx auto;
  560. .tr {
  561. display: flex;
  562. overflow: hidden;
  563. .th,
  564. .td {
  565. display: inline-block;
  566. padding: 5rpx;
  567. width: 240rpx;
  568. text-align: center;
  569. height: 52rpx;
  570. line-height: 52rpx;
  571. border: 2rpx solid #F1F1F1;
  572. }
  573. }
  574. }
  575. .pagenumber {
  576. display: flex;
  577. margin: 20rpx auto;
  578. button {
  579. width: 150rpx;
  580. height: 50rpx;
  581. line-height: 50rpx;
  582. font-size: 26rpx;
  583. text-align: center;
  584. background-color: #17BB89;
  585. color: #FFFFFF;
  586. }
  587. .pagenumber_page {
  588. width: 150rpx;
  589. height: 50rpx;
  590. line-height: 50rpx;
  591. font-size: 26rpx;
  592. text-align: center;
  593. }
  594. }
  595. }
  596. </style>