statistics.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 44px;">
  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. <view class="shuju_one_title">
  16. <p>害虫趋势统计</p>
  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">
  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. <highcharts :chartOptions="options" :styles="styles" ref="simpleChart"></highcharts>
  35. <p class="tishi" v-if="!tishi">暂无数据</p>
  36. <highcharts :chartOptions="optiontwos" :styles="styletwos" ref="simpleChart" v-if="tishitf"></highcharts>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <style lang="scss">
  43. .top_text {
  44. width: 90%;
  45. position: absolute;
  46. top: 54px;
  47. display: flex;
  48. left: 5%;
  49. .tltle_text {
  50. width: 50%;
  51. border: 2rpx solid #F0F0F0;
  52. text-align: center;
  53. }
  54. .title_text_color {
  55. width: 50%;
  56. border: 2rpx solid #64CC82;
  57. text-align: center;
  58. }
  59. }
  60. .tishi {
  61. position: absolute;
  62. top: 250rpx;
  63. left: 40%;
  64. font-size: 32rpx;
  65. color: #7A7373;
  66. }
  67. .shuju_one_title {
  68. width: 90%;
  69. margin: 0 auto;
  70. display: flex;
  71. justify-content: space-between;
  72. .schedule_box {
  73. display: flex;
  74. }
  75. .schedule {
  76. display: flex;
  77. width: 180rpx;
  78. height: 50rpx;
  79. border: 2rpx solid #F0F0F0;
  80. margin-left: 20rpx;
  81. .schedule_value {
  82. width: 70%;
  83. text-align: center;
  84. line-height: 50rpx;
  85. }
  86. .schedule_icon {
  87. width: 30%;
  88. background-color: #F2F2F2;
  89. text-align: center;
  90. line-height: 50rpx;
  91. }
  92. }
  93. }
  94. </style>
  95. <script>
  96. import highcharts from "@/components/highcharts/highcharts"
  97. var newtime = +new Date()
  98. var strrttime = newtime - 24 * 60 * 60 * 1000
  99. export default {
  100. data() {
  101. return {
  102. styles: {
  103. // width: "650rpx",
  104. height: "400rpx"
  105. },
  106. styletwos: {
  107. width: "650rpx",
  108. height: "600rpx"
  109. },
  110. options: {
  111. chart: {
  112. type: 'spline', //指定图表的类型,默认是折线图(line)
  113. zoomType: 'x',
  114. panning: true,
  115. panKey: 'shift'
  116. },
  117. title: {
  118. text: '' // 标题
  119. },
  120. credits: {
  121. enabled: false
  122. },
  123. xAxis: {
  124. type: 'datetime',
  125. crosshair: true, //十字基准线
  126. dateTimeLabelFormats: {
  127. //根据时间间距X轴自动显示哪种格式
  128. millisecond: "%H:%M:%S.%L",
  129. second: "%H:%M:%S",
  130. minute: "%H:%M",
  131. hour: "%H:%M",
  132. day: "%m-%d",
  133. week: "%m-%d",
  134. month: "%Y-%m",
  135. year: "%Y",
  136. },
  137. },
  138. yAxis: {
  139. title: false,
  140. },
  141. legend: {
  142. // layout: 'vertical',
  143. align: "center",
  144. verticalAlign: "top",
  145. },
  146. tooltip: {
  147. // crosshairs: true,
  148. shared: true, //折线共享
  149. headerFormat: "<b>{point.x:%Y-%m-%e %H:%M:%S}</b><br>",
  150. },
  151. plotOptions: {
  152. spline: {
  153. marker: {
  154. enabled: false
  155. },
  156. }
  157. },
  158. series: [],
  159. },
  160. d_id: '',
  161. start_time: strrttime,
  162. end_time: newtime,
  163. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  164. device_id: '',
  165. pest_name: '',
  166. wormdata: [],
  167. pickertfone: false,
  168. pickertftwo: false,
  169. indexone: 0,
  170. indextwo: 0,
  171. optiontwos: {
  172. chart: {
  173. spacing: [40, 0, 40, 0]
  174. },
  175. title: {
  176. floating: true,
  177. text: ''
  178. },
  179. credits: {
  180. enabled: false
  181. },
  182. tooltip: {
  183. pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
  184. },
  185. series: [{
  186. type: 'pie',
  187. innerSize: '60%',
  188. name: '占比',
  189. data: []
  190. }]
  191. },
  192. tishitf: false,
  193. tishi: false,
  194. toptext: ["自动统计", "手动统计"],
  195. topindex: 0
  196. }
  197. },
  198. methods: {
  199. async historys() { //获取统计虫子 自动统计
  200. const res = await this.$myRequest({
  201. url: '/api/api_gateway?method=forecast.worm_lamp.pest_statistics',
  202. data: {
  203. d_id: this.d_id,
  204. start_time: parseInt(this.start_time / 1000),
  205. end_time: parseInt(this.end_time / 1000)
  206. }
  207. })
  208. if (res.percentage.length == 0) {
  209. this.tishitf = false
  210. } else {
  211. this.tishitf = true
  212. this.wormdata = []
  213. for (var i = 0; i < res.percentage.length; i++) {
  214. this.wormdata.unshift(res.percentage[i].name_num)
  215. }
  216. }
  217. },
  218. async history() { //获取统计虫子 //自动统计
  219. const res = await this.$myRequest({
  220. url: '/api/api_gateway?method=forecast.worm_lamp.pest_statistics',
  221. data: {
  222. pest_name: this.pest_name,
  223. d_id: this.d_id,
  224. start_time: parseInt(this.start_time / 1000),
  225. end_time: parseInt(this.end_time / 1000)
  226. }
  227. })
  228. this.historydatas = res
  229. console.log(this.historydatas)
  230. // console.log(this.optiontwos.series.data)
  231. this.options.series = []
  232. var obj1 = {
  233. name: "温度(°C)",
  234. data: [],
  235. color: "#00E29D"
  236. }
  237. var obj2 = {
  238. name: "湿度(%)",
  239. data: [],
  240. color: "#6CBBFF"
  241. }
  242. var obj3 = {
  243. name: "害虫总数",
  244. data: [],
  245. color: "#f00000"
  246. }
  247. if (res.date.length == 0) {
  248. this.tishi = false
  249. } else {
  250. this.tishi = true
  251. this.optiontwos.series[0].data = []
  252. for (var i = 0; i < res.percentage.length; i++) {
  253. var arr = [res.percentage[i].name_num + ":" + res.percentage[i].sum + "头", res.percentage[i].sum]
  254. this.optiontwos.series[0].data.push(arr) /*********************************/
  255. }
  256. for (var i = 0; i < res.date.length; i++) {
  257. var arr1 = []
  258. arr1.push(res.date[i].addtime * 1000 + 8 * 3600000, Number(res.date[i].temperature))
  259. obj1.data.push(arr1)
  260. var arr2 = []
  261. arr2.push(res.date[i].addtime * 1000 + 8 * 3600000, Number(res.date[i].humidity))
  262. obj2.data.push(arr2)
  263. var arr3 = []
  264. arr3.push(res.date[i].addtime * 1000 + 8 * 3600000, Number(res.date[i]._sums))
  265. obj3.data.push(arr3)
  266. }
  267. this.options.series.push(obj1)
  268. this.options.series.push(obj2)
  269. this.options.series.push(obj3)
  270. }
  271. if (res.percentage.length == 0) {
  272. this.tishitf = false
  273. console.log(1)
  274. } else {
  275. console.log(2)
  276. this.tishitf = true
  277. this.wormdata = []
  278. for (var i = 0; i < res.percentage.length; i++) {
  279. this.wormdata.unshift(res.percentage[i].name_num)
  280. }
  281. }
  282. },
  283. //forecast.worm_lamp.pest_manual_statistics手动统计
  284. async selfhistorys() { //获取统计虫子 自动统计
  285. const res = await this.$myRequest({
  286. url: '/api/api_gateway?method=forecast.worm_lamp.pest_manual_statistics',
  287. data: {
  288. device_id: this.d_id,
  289. start_time: parseInt(this.start_time / 1000),
  290. end_time: parseInt(this.end_time / 1000)
  291. }
  292. })
  293. if (res.dat.length == 0) {
  294. this.tishitf = false
  295. } else {
  296. this.tishitf = true
  297. this.wormdata = []
  298. for (var i = 0; i < res.dat.length; i++) {
  299. this.wormdata.unshift(res.dat[i].pest_name)
  300. }
  301. }
  302. },
  303. async selfhistory() { //获取统计虫子 //自动统计
  304. const res = await this.$myRequest({
  305. url: '/api/api_gateway?method=forecast.worm_lamp.pest_manual_statistics',
  306. data: {
  307. pest_name: this.pest_name,
  308. device_id: this.d_id,
  309. start_time: parseInt(this.start_time / 1000),
  310. end_time: parseInt(this.end_time / 1000)
  311. }
  312. })
  313. this.historydatas = res
  314. console.log(this.historydatas)
  315. this.options.series = []
  316. var obj = {
  317. name: "害虫总数",
  318. data: [],
  319. color: "#f00000"
  320. }
  321. if (res.dat.length == 0) {
  322. this.tishi = false
  323. } else {
  324. this.tishi = true
  325. this.optiontwos.series[0].data = []
  326. for (var i = 0; i < res.dat.length; i++) {
  327. var arr = [res.dat[i].pest_name + ":" + res.dat[i].pest_num + "头", res.dat[i].pest_num]
  328. this.optiontwos.series[0].data.push(arr) /*********************************/
  329. }
  330. for (var i = 0; i < res.date.length; i++) {
  331. var arr1 = []
  332. arr1.push(res.date[i].add_time * 1000 + 8 * 3600000, Number(res.date[i].pest_num))
  333. obj.data.push(arr1)
  334. }
  335. this.options.series.push(obj)
  336. }
  337. },
  338. clickLeft() {
  339. uni.navigateBack({
  340. delta: 1
  341. })
  342. },
  343. confirmFun(index) {
  344. this.indexone = index[0]
  345. var now = new Date()
  346. this.$forceUpdate()
  347. if (index[0] == 0) {
  348. this.start_time = strrttime
  349. if (this.topindex == 0) {
  350. this.history()
  351. this.historys()
  352. } else {
  353. this.selfhistorys()
  354. this.selfhistory()
  355. }
  356. } else if (index[0] == 1) {
  357. var oldtime = now.setMonth(now.getMonth() - 1)
  358. this.start_time = parseInt(oldtime)
  359. if (this.topindex == 0) {
  360. this.history()
  361. this.historys()
  362. } else {
  363. this.selfhistorys()
  364. this.selfhistory()
  365. }
  366. } else if (index[0] == 2) {
  367. var oldtime = now.setMonth(now.getMonth() - 6)
  368. this.start_time = parseInt(oldtime)
  369. if (this.topindex == 0) {
  370. this.history()
  371. this.historys()
  372. } else {
  373. this.selfhistorys()
  374. this.selfhistory()
  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. this.history()
  381. this.historys()
  382. } else {
  383. this.selfhistorys()
  384. this.selfhistory()
  385. }
  386. }
  387. },
  388. confirmFun2(index) {
  389. this.indextwo = index[0]
  390. this.pest_name = this.wormdata[this.indextwo]
  391. this.history()
  392. },
  393. changeindex(index) {
  394. this.topindex = index
  395. if (this.topindex == 0) {
  396. this.pest_name = ''
  397. this.history()
  398. this.historys()
  399. } else {
  400. this.pest_name = ''
  401. this.selfhistorys()
  402. this.selfhistory()
  403. }
  404. }
  405. },
  406. onLoad(option) {
  407. this.d_id = option.d_id
  408. this.device_id = option.device_id
  409. this.history()
  410. this.historys()
  411. }
  412. }
  413. </script>
  414. <style lang="scss">
  415. .shuju_one,
  416. .shuju_two {
  417. position: absolute;
  418. top: 84px;
  419. width: 90%;
  420. left: 5%;
  421. box-shadow: 0 0 10rpx #bcb9ca;
  422. padding-top: 20rpx;
  423. }
  424. .condition {
  425. position: absolute;
  426. top: 600rpx;
  427. display: flex;
  428. flex-wrap: wrap;
  429. width: 90%;
  430. left: 5%;
  431. box-shadow: 0 0 10rpx #bcb9ca;
  432. margin-bottom: 30rpx;
  433. .scroll-X {
  434. width: 95%;
  435. margin: 20rpx auto;
  436. .tr {
  437. display: flex;
  438. overflow: hidden;
  439. .th,
  440. .td {
  441. display: inline-block;
  442. padding: 5rpx;
  443. width: 240rpx;
  444. text-align: center;
  445. height: 52rpx;
  446. line-height: 52rpx;
  447. border: 2rpx solid #F1F1F1;
  448. }
  449. }
  450. }
  451. .pagenumber {
  452. display: flex;
  453. margin: 20rpx auto;
  454. button {
  455. width: 150rpx;
  456. height: 50rpx;
  457. line-height: 50rpx;
  458. font-size: 26rpx;
  459. text-align: center;
  460. background-color: #17BB89;
  461. color: #FFFFFF;
  462. }
  463. .pagenumber_page {
  464. width: 150rpx;
  465. height: 50rpx;
  466. line-height: 50rpx;
  467. font-size: 26rpx;
  468. text-align: center;
  469. }
  470. }
  471. }
  472. </style>