statistics.vue 11 KB

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