detail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <view class="device-detail">
  3. <view class="device-detail__header">
  4. <u-icon
  5. size="36"
  6. class="arrow-left"
  7. name="arrow-left"
  8. @click="handleBack"
  9. ></u-icon>
  10. {{ title }}
  11. </view>
  12. <view class="device-detail__body">
  13. <DeviceCard
  14. :dataSource="deviceInfo"
  15. :collectTime="time"
  16. :title="title"
  17. :deviceType="deviceType"
  18. />
  19. <view class="tabs">
  20. <view class="tab-container">
  21. <view class="tab-item" :class="activeTab === 'pestAnalysis'?'active':''" @click="handleTabClick('pestAnalysis')">
  22. 害虫分析
  23. </view>
  24. <view class="tab-item" :class="activeTab === 'viewImage'?'active':''" @click="handleTabClick('viewImage')">
  25. 查看图片
  26. </view>
  27. <view class="tab-item" :class="activeTab === 'deviceData'?'active':''" @click="handleTabClick('deviceData')">
  28. 设备数据
  29. </view>
  30. </view>
  31. <view class="select-timer-container">
  32. <view class="select-year">
  33. <view class="select-year-item" @click="showPicker = true">
  34. {{ currentYear }}
  35. <u-icon name="arrow-down" size="18" class="arrow-down"></u-icon>
  36. </view>
  37. </view>
  38. <view class="tabs-timer-container" @click="showCalendar">
  39. <view class="tabs-timer-item">
  40. {{startDate}}
  41. </view>
  42. <view class="tabs-timer-item">
  43. {{endDate}}
  44. </view>
  45. <u-icon name="calendar" size="36" class="calendar-icon"></u-icon>
  46. </view>
  47. </view>
  48. </view>
  49. <view v-if="activeTab === 'pestAnalysis'" class="tab-content">
  50. <PestDiscern
  51. :total="total"
  52. :pest_order="pest_order"
  53. />
  54. <PestEchart
  55. :pest_order="pest_order"
  56. @getInfo="getInfo"
  57. :endDate="endDate"
  58. :d_id="deviceInfo.d_id"
  59. :day="day"
  60. :pest="pest"
  61. />
  62. <PestArchive
  63. :pest_info="pestInfo"
  64. />
  65. </view>
  66. <view v-if="activeTab === 'viewImage'">
  67. <photoImage
  68. :images="imageList"
  69. :pestList="pestList"
  70. @changeTab="changeTab"
  71. :currentYear="currentYear"
  72. :id="deviceInfo.id"
  73. />
  74. </view>
  75. <view v-if="activeTab === 'deviceData'">
  76. <DeviceData
  77. :deviceStatic="deviceStatic"
  78. :deviceInfo="deviceInfo"
  79. :polylineList="polylineList"
  80. :deviceHistoryList="deviceHistoryList"
  81. />
  82. </view>
  83. </view>
  84. <u-calendar v-model="show" :mode="mode" @change="handleChange" :max-date="maxDate" :min-date="minDate"></u-calendar>
  85. <u-picker v-model="showPicker" mode="selector" :range="selectorRange" range-key="id" :default-selector="[0]" @confirm="confirmHandler"></u-picker>
  86. </view>
  87. </template>
  88. <script>
  89. import DeviceCard from './components/DeviceCard.vue';
  90. import PestDiscern from './components/pestDiscern.vue';
  91. import PestEchart from './components/pestEchart.vue';
  92. import PestArchive from './components/pestArchive.vue';
  93. import photoImage from './components/photoImage.vue';
  94. import DeviceData from './components/deviceData.vue';
  95. export default {
  96. components: {
  97. DeviceCard,
  98. PestDiscern,
  99. PestEchart,
  100. PestArchive,
  101. photoImage,
  102. DeviceData
  103. },
  104. data(){
  105. return {
  106. showPicker: false,
  107. currentYear: new Date().getFullYear(),
  108. selectorRange: [],
  109. maxDate: this.formatDate(new Date()),
  110. minDate: this.formatDate(new Date(new Date().getFullYear(), 0, 1)),
  111. show: false,
  112. // 当前年份的第一天 格式2026-01-01 月份和日期小于10的时候前面加个0
  113. startDate: this.formatDate(new Date(new Date().getFullYear(), 0, 1)),
  114. endDate: this.formatDate(new Date()),
  115. mode: 'range',
  116. imageList: [],
  117. pest_order:{},
  118. deviceInfo: {},
  119. pestInfo: {},
  120. time: '',
  121. activeTab: 'pestAnalysis',
  122. title: '虫情测报灯详情',
  123. deviceType: '',
  124. location: '',
  125. total: 0,
  126. day: [],
  127. pest: [],
  128. page:1,
  129. is_pest:'',
  130. page_size:24,
  131. pestList:[],
  132. pest_names:'',
  133. polylineList:[],
  134. deviceHistoryList:[],
  135. deviceStatic:{}
  136. }
  137. },
  138. onLoad(options){
  139. this.deviceInfo = JSON.parse(options.info);
  140. this.getPestAnalysis();
  141. const currentYear = new Date().getFullYear();
  142. this.selectorRange = [];
  143. for(let i = 0;i<50;i++){
  144. const item = {
  145. label: currentYear - i,
  146. id: currentYear - i
  147. }
  148. this.selectorRange.push(item);
  149. }
  150. },
  151. methods: {
  152. changeTab(pestList){
  153. let pest_names = pestList.map(item => item.pest_name);
  154. this.pest_names = pest_names.join(',');
  155. this.initImageList();
  156. },
  157. confirmHandler(e){
  158. this.currentYear = this.selectorRange[e].id;
  159. if(this.currentYear == new Date().getFullYear()){
  160. this.startDate = this.formatDate(new Date(new Date().getFullYear(), 0, 1));
  161. this.endDate = this.formatDate(new Date());
  162. this.maxDate = this.formatDate(new Date());
  163. this.minDate = this.formatDate(new Date(new Date().getFullYear(), 0, 1));
  164. }else{
  165. this.startDate = this.formatDate(new Date(this.currentYear, 0, 1));
  166. this.endDate = this.formatDate(new Date(this.currentYear, 11, 31));
  167. this.maxDate = this.formatDate(new Date(this.currentYear, 11, 31));
  168. this.minDate = this.formatDate(new Date(this.currentYear, 0, 1));
  169. }
  170. this.initAction();
  171. this.showPicker = false;
  172. },
  173. getInfo(info){
  174. this.pestInfo = info;
  175. },
  176. // 格式化日期为YYYY-MM-DD格式,月份和日期小于10时前面加0
  177. formatDate(date) {
  178. const year = date.getFullYear();
  179. const month = String(date.getMonth() + 1).padStart(2, '0');
  180. const day = String(date.getDate()).padStart(2, '0');
  181. return `${year}-${month}-${day}`;
  182. },
  183. handleChange(e){
  184. this.startDate = e.startDate;
  185. this.endDate = e.endDate;
  186. this.initAction();
  187. },
  188. showCalendar(){
  189. this.show = true;
  190. },
  191. handleBack() {
  192. uni.navigateBack({
  193. delta: 1
  194. });
  195. },
  196. initAction(){
  197. if(this.activeTab === 'pestAnalysis'){
  198. this.getPestAnalysis();
  199. }else if(this.activeTab === 'viewImage'){
  200. this.initPest();
  201. this.initImageList();
  202. }else if(this.activeTab === 'deviceData'){
  203. this.getDeviceData();
  204. this.getPolylineData();
  205. this.getDeviceHistoryData();
  206. }
  207. },
  208. handleTabClick(tab) {
  209. this.activeTab = tab;
  210. this.initAction();
  211. },
  212. async getDeviceData(){
  213. const res = await this.$myRequest({
  214. url: '/api/api_gateway?method=forecast.worm_lamp.device_status_data',
  215. method: 'POST',
  216. data: {
  217. device_id: this.deviceInfo.id,
  218. },
  219. });
  220. this.deviceStatic = res;
  221. },
  222. async initImageList(){
  223. const res = await this.$myRequest({
  224. url: '/api/api_gateway?method=forecast.new_cbd.photo_list',
  225. method: 'POST',
  226. data: {
  227. page:this.page,
  228. page_size:this.page_size,
  229. device_id: this.deviceInfo.id,
  230. is_pest: this.is_pest,
  231. identify_model: 'B',
  232. pest_names: this.pest_names,
  233. time_begin: this.formatDate(new Date(this.startDate)) + ' 00:00:00',// 格式化开始时间YYYY-MM-DD HH:MM:SS
  234. time_end: this.formatDate(new Date(this.endDate)) + ' 23:59:59',// 格式化结束时间YYYY-MM-DD HH:MM:SS
  235. },
  236. });
  237. const data = res?.data || [];
  238. this.imageList = data
  239. },
  240. async initPest(){
  241. const res = await this.$myRequest({
  242. url: '/api/api_gateway?method=forecast.new_cbd.pest_type_list',
  243. method: 'POST',
  244. data:{
  245. page:1,
  246. page_size:999999,
  247. device_id: this.deviceInfo.id,
  248. identify_model: 'B',
  249. time_begin: this.formatDate(new Date(this.startDate)) + ' 00:00:00',// 格式化开始时间YYYY-MM-DD HH:MM:SS
  250. time_end: this.formatDate(new Date(this.endDate)) + ' 23:59:59',// 格式化结束时间YYYY-MM-DD HH:MM:SS
  251. },
  252. });
  253. const data = res?.data || [];
  254. this.pestList = data
  255. },
  256. async getPolylineData(){
  257. const res = await this.$myRequest({
  258. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  259. method: 'POST',
  260. data: {
  261. device_type_id: this.deviceInfo.type_id,
  262. d_id: this.deviceInfo.d_id,
  263. start_time: new Date(this.startDate).getTime()/1000,// 转成毫秒
  264. end_time: new Date(this.endDate).getTime()/1000,// 转成毫秒
  265. },
  266. });
  267. const data = res || [];
  268. this.polylineList = data
  269. },
  270. async getDeviceHistoryData(){
  271. const res = await this.$myRequest({
  272. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  273. method: 'POST',
  274. data: {
  275. device_type_id: this.deviceInfo.type_id,
  276. device_id: this.deviceInfo.id,
  277. start_time: new Date(this.startDate).getTime()/1000,
  278. end_time: new Date(this.endDate).getTime()/1000,
  279. page: this.page,
  280. page_size: this.page_size,
  281. },
  282. });
  283. const data = res?.data || [];
  284. this.deviceHistoryList = data
  285. },
  286. async getPestAnalysis(){
  287. const res = await this.$myRequest({
  288. url: '/api/api_gateway?method=forecast.cbd_analysis.analysis_pest_result',
  289. method: 'POST',
  290. data: {
  291. d_id: this.deviceInfo.d_id,
  292. start: this.startDate,
  293. end: this.endDate,
  294. model: 'B'
  295. },
  296. });
  297. const pest_order = res?.pest_order;
  298. let total = 0;
  299. for(let key in pest_order){
  300. total += pest_order[key] || 0;
  301. }
  302. this.pest_order = pest_order;
  303. this.day = res?.day || [];
  304. const pest = res?.pest || [];
  305. this.pest = [];
  306. pest.forEach(p =>{
  307. for(let i = 0;i< p.length;i++){
  308. this.pest.push(p[i]);
  309. }
  310. })
  311. this.total = total;
  312. }
  313. }
  314. }
  315. </script>
  316. <style scoped lang="scss">
  317. ::v-deep .u-calendar__action{
  318. display:flex;
  319. justify-content: space-between;
  320. }
  321. ::v-deep .u-hover-class{
  322. .u-calendar__content__item__inner{
  323. color:#aaa !important;
  324. }
  325. }
  326. .device-detail {
  327. display: flex;
  328. width: 100%;
  329. height: 100vh;
  330. padding-top: 112rpx;
  331. flex-direction: column;
  332. align-items: center;
  333. background: linear-gradient(180deg, #ffffff00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  334. .device-detail__header {
  335. width: 100%;
  336. font-size: 28rpx;
  337. color: #999;
  338. color: #042118;
  339. font-family: 'Source Han Sans CN VF';
  340. font-weight: 700;
  341. position: relative;
  342. text-align: center;
  343. .arrow-left {
  344. position: absolute;
  345. left: 32rpx;
  346. margin-right: 12rpx;
  347. }
  348. }
  349. .device-detail__body {
  350. width: calc(100% - 64rpx);
  351. margin: 0 auto;
  352. border-radius: 16rpx;
  353. overflow-x: hidden;
  354. overflow-y: auto;
  355. // 隐藏滚动条
  356. -ms-overflow-style: none;
  357. scrollbar-width: none;
  358. }
  359. .tab-content{
  360. width: 100%;
  361. padding-bottom: 32rpx;
  362. }
  363. .tabs {
  364. background: #ffffff;
  365. margin: 24rpx 0;
  366. border-radius: 16rpx;
  367. padding: 16rpx 0;
  368. padding-top: 0;
  369. .tab-container{
  370. display: flex;
  371. width: 100%;
  372. height: 88rpx;
  373. line-height: 88rpx;
  374. text-align: center;
  375. font-size: 28rpx;
  376. font-weight: 700;
  377. color: #042118;
  378. font-family: 'Source Han Sans CN VF';
  379. }
  380. .select-timer-container{
  381. display:flex;
  382. align-items: center;
  383. padding-left: 32rpx;
  384. .select-year{
  385. width: 128rpx;
  386. text-align: center;
  387. height: 64rpx;
  388. border-radius: 32rpx;
  389. font-family: 'Source Han Sans CN VF';
  390. line-height: 64rpx;
  391. background: #F1F4F8;
  392. padding: 0 32rpx;
  393. .select-year-item{
  394. color: #656565;
  395. font-size: 24rpx;
  396. display: flex;
  397. align-items: center;
  398. justify-content: space-around;
  399. }
  400. }
  401. }
  402. .tabs-timer-container{
  403. display: flex;
  404. width: calc(100% - 256rpx);
  405. height: 64rpx;
  406. line-height: 64rpx;
  407. text-align: center;
  408. font-size: 24rpx;
  409. font-weight: 500;
  410. font-family: 'Source Han Sans CN VF';
  411. border-radius: 32rpx;
  412. background: #F1F4F8;
  413. padding: 0 32rpx;
  414. color: #656565;
  415. margin: 16rpx 32rpx;
  416. position: relative;
  417. .tabs-timer-item{
  418. width: 40%;
  419. text-align: center;
  420. color: #656565;
  421. text-align: center;
  422. font-family: "Source Han Sans CN VF";
  423. font-size: 24rpx;
  424. font-weight: 400;
  425. }
  426. .calendar-icon{
  427. position: absolute;
  428. right: 78rpx;
  429. margin-top: 4rpx;
  430. top: 12rpx;
  431. right: 24rpx;
  432. }
  433. }
  434. .tab-item {
  435. flex: 1;
  436. }
  437. .active{
  438. position: relative;
  439. color: #303133;
  440. text-align: center;
  441. font-family: "Source Han Sans CN VF";
  442. font-size: 28rpx;
  443. font-weight: 700;
  444. &::after {
  445. content: '';
  446. position: absolute;
  447. bottom: 0;
  448. left: 50%;
  449. -webkit-transform: translateX(-50%);
  450. transform: translateX(-50%);
  451. width: 36rpx;
  452. height: 36rpx;
  453. border: 6rpx solid #0BBC58;
  454. border-radius: 50%;
  455. border-color: transparent;
  456. border-bottom-color: #0BBC58;
  457. }
  458. }
  459. }
  460. }
  461. </style>