equipment-new.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 40px;">
  5. <view style="position: fixed;z-index: 100;width: 100%;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="设备详情"></uni-nav-bar>
  7. </view>
  8. <view class="info">
  9. <view class="info_item">
  10. <image
  11. :src="eqinfo.item.is_online==1?$imageURL+'/bigdata_app/image/cb/onBg.png':$imageURL+'/bigdata_app/image/cb/offBg.png'"
  12. mode="" class="bgi"></image>
  13. <p style="font-size: 32rpx;" @click="copy(eqinfo.item)">设备
  14. ID:{{eqinfo.item.imei}}
  15. <image :src="$imageURL+'/bigdata_app/image/environment/fuzhi.png'" mode=""
  16. class="tishi"></image>
  17. </p>
  18. <p>设备名称:{{eqinfo.item.device_name?eqinfo.item.device_name:"无"}}</p>
  19. <p>最近上报时间:<span v-if="eqinfo.item.uptime">{{eqinfo.item.uptime|timeFormat()}}</span><span
  20. v-else>{{eqinfo.item.addtime|timeFormat()}}</span></p>
  21. <p>地址:{{eqinfo.item.address||"--"}}</p>
  22. </view>
  23. </view>
  24. <view class="control">
  25. <view class="control_item" @click="control">
  26. <image :src="$imageURL+'/bigdata_app'+'/image/environment/8.png'" mode=""></image>
  27. <p>设备控制</p>
  28. </view>
  29. <view class="control_item" @click="repairs">
  30. <image :src="$imageURL+'/bigdata_app'+'/image/environment/7.png'" mode=""></image>
  31. <p>一键报修</p>
  32. </view>
  33. <view class="control_item" v-if="$QueryPermission(397)" @click="charts">
  34. <image :src="$imageURL+'/bigdata_app'+'/image/environment/10.png'" mode=""></image>
  35. <p>历史数据</p>
  36. </view>
  37. <view class="control_item" @click="siminfo(eqinfo.item.d_id)">
  38. <image :src="$imageURL+'/bigdata_app'+'/image/cb/6.png'" mode=""></image>
  39. <p>SIM卡信息</p>
  40. </view>
  41. </view>
  42. <view class="realtime">
  43. <p class="realtime_title"><span>实时数据</span></p>
  44. <view class="realtime_text">
  45. <view class="realtime_text_item">
  46. <view class="realtime_text_item_info" v-for="(item,index) in olddata" :key="index"
  47. @click="oneday(index,item)">
  48. <view class="item_info_img" :style="{'background-color':olddatas[1]}">
  49. <image
  50. :src="$imageURL+'/bigdata_app'+'/image/environment/icon_'+item.num+'.png'"
  51. mode=""></image>
  52. </view>
  53. <view class="item_info_text">
  54. <p>{{item.name+item.unit}}</p>
  55. <p style="margin-top: 20rpx;">
  56. {{parseFloat(item.value) == -99.99 ?'N/A':parseFloat(item.value)}}
  57. </p>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. <view class="realtime_tishi" v-if="realtimeTF && !dataloadingtf">
  63. 暂无数据
  64. </view>
  65. <view class="realtime_tishi" v-if="dataloadingtf">
  66. <p class="dataloading">加载中</p>
  67. </view>
  68. </view>
  69. </view>
  70. <u-modal v-model="show" :title-style="{color: 'red'}" :mask-close-able="true" title="24小时数据">
  71. <p class="tishiTF" v-if="tishiTF">暂无24小时数据</p>
  72. <view class="slot-content" v-else>
  73. <canvas canvas-id="canvasColumnA" id="canvasColumnA" class="charts" @touchstart="touchLineA($event)"
  74. @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)" disable-scroll=true
  75. :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>
  76. <view class="maxdata">
  77. <view class="maxdata_box">
  78. <p class="dian"></p>
  79. <p>当天最大值:{{onedatasMax}}&nbsp&nbsp{{onedatasMaxtime|timeFormat()}}</p>
  80. </view>
  81. <view class="maxdata_box">
  82. <p class="dian diantwo"></p>
  83. <p>当天最小值:{{onedatasMin}}&nbsp&nbsp{{onedatasMintime|timeFormat()}}</p>
  84. </view>
  85. </view>
  86. </view>
  87. </u-modal>
  88. </view>
  89. </template>
  90. <script>
  91. import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
  92. var canvasColumnA = null;
  93. export default {
  94. data() {
  95. return {
  96. eqinfo: {
  97. item: {
  98. }
  99. },
  100. olddata: [],
  101. olddatas: ["#fba825", "#53d67c", "#008cf2", "#fb504d", "#d87ffc", "#4ec5f0"],
  102. city: "",
  103. kongtf: false,
  104. daydatatf: false,
  105. shujutf: false,
  106. onedatas: [],
  107. canvastishiTF: true,
  108. cWidth: '300',
  109. cHeight: '200',
  110. pixelRatio: 1,
  111. show: false,
  112. onedatasMax: 0,
  113. onedatasMin: 0,
  114. onedatasMaxtime: "",
  115. onedatasMintime: "",
  116. tishiTF: false,
  117. realtimeTF: false, //暂无数据提示
  118. dataloadingtf: true, //加载中提示
  119. }
  120. },
  121. methods: {
  122. clickLeft() {
  123. uni.navigateBack({
  124. delta: 1
  125. })
  126. },
  127. async history() { //实时数据
  128. this.dataloadingtf = true
  129. const res = await this.$myRequest({
  130. url: '/api/api_gateway?method=greenhouse.env_first.recent_data',
  131. data: {
  132. device_id: this.eqinfo.item.imei || this.eqinfo.item.equip_id
  133. }
  134. })
  135. this.dataloadingtf = false
  136. this.olddata = res.recent
  137. this.realtimeTF = false
  138. },
  139. // weather.weather.qxz_data_chart 一天的数据
  140. async onehistory() { //设备列表
  141. var date = new Date()
  142. var newtime = +date / 1000
  143. // var oldtime = newtime - 24 * 60 * 60
  144. var oldtime = Number(new Date(date.toLocaleDateString()).getTime()) / 1000;
  145. const res = await this.$myRequest({
  146. url: '/api/api_gateway?method=weather.weather.qxz_data_chart',
  147. data: {
  148. device_id: this.eqinfo.item.imei || this.eqinfo.item.device_id,
  149. begin: parseInt(oldtime - 24 * 60 * 60),
  150. end: parseInt(newtime - 24 * 60 * 60)
  151. }
  152. })
  153. this.onedatas = res.data
  154. console.log(this.onedatas)
  155. },
  156. control() { //设备控制
  157. console.log(this.eqinfo.item)
  158. uni.navigateTo({
  159. url: "./contros?id=" + this.eqinfo.item.d_id+'&device_type_id=38'+'&device_id='+this.eqinfo.item.imei
  160. })
  161. },
  162. charts() { //历史数据
  163. var device_id = this.eqinfo.item.imei || this.eqinfo.item.device_id
  164. uni.navigateTo({
  165. url: "./history-new?device_id=" + device_id+'&device_type_id=38'
  166. })
  167. },
  168. reverseGeocode(lat, lng) {
  169. uni.request({
  170. type: "GET",
  171. url: "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=" + lng + "," + lat +
  172. "&key=27273b81090f78759e4057f94474516f&radius=1000&extensions=all",
  173. dataType: "json",
  174. complete: ress => {
  175. console.log(ress)
  176. this.city = ress.data.regeocode.formatted_address
  177. }
  178. });
  179. },
  180. copy(item) {
  181. uni.setClipboardData({
  182. data: item.imei || item.device_id,
  183. success: function() {
  184. console.log('success');
  185. }
  186. });
  187. },
  188. repairs() {
  189. console.log(this.eqinfo.item)
  190. var device_id = this.eqinfo.item.imei || this.eqinfo.item.device_id
  191. uni.navigateTo({
  192. url: "../afterSale/addafter?device_id=" + device_id + "&device_type=" + 38
  193. })
  194. },
  195. oneday(key,item) {
  196. // console.log(key)
  197. var obj = {
  198. name: item.lable=="PM255(ug/m3)"?"PM2.5(ug/m3)":item.lable,
  199. data: [],
  200. }
  201. var xtitle = []
  202. var linearr = []
  203. var arr = []
  204. var timearr = []
  205. // console.log(key)
  206. // console.log(this.olddata)
  207. // console.log(this.onedatas)
  208. // return
  209. for (var i = 0; i < this.onedatas.length; i++) {
  210. var times = new Date(this.onedatas[i].time * 1000)
  211. // console.log(this.onedatas[i].dat[this.olddata[key].value[2]].split("#")[0])
  212. arr.unshift(Number(this.onedatas[i].dat[this.olddata[key].value[2]].split("#")[0]))
  213. if(times.getMinutes().toString().length>=2){
  214. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getMinutes())
  215. } else{
  216. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":0" + times.getMinutes())
  217. }
  218. timearr.unshift(+new Date(times) / 1000)
  219. obj.data.unshift(Number(this.onedatas[i].dat[this.olddata[key].value[2]].split("#")[0]))
  220. }
  221. arr.sort(function(a, b) {
  222. return a - b
  223. })
  224. // console.log(arr)
  225. this.onedatasMin = arr[0]
  226. this.onedatasMax = arr[arr.length - 1]
  227. for (var i = 0; i < obj.data.length; i++) {
  228. if (this.onedatasMax == obj.data[i]) {
  229. this.onedatasMaxtime = timearr[i]
  230. }
  231. if (this.onedatasMin == obj.data[i]) {
  232. this.onedatasMintime = timearr[i]
  233. }
  234. }
  235. console.log(obj)
  236. linearr.push(obj)
  237. if (obj.data.length == 0) {
  238. this.tishiTF = true
  239. } else {
  240. this.tishiTF = false
  241. }
  242. console.log(xtitle)
  243. // console.log(linearr)
  244. // return
  245. this.showColumn("canvasColumnA", xtitle, linearr)
  246. this.show = true
  247. },
  248. showColumn(id, xtitle, xinfo) {
  249. var _self = this
  250. const ctx = uni.createCanvasContext(id, this);
  251. canvasColumnA = new uCharts({
  252. context: ctx,
  253. type: 'line',
  254. legend: {
  255. position: "top"
  256. },
  257. fontSize: 11,
  258. background: '#FFFFFF',
  259. pixelRatio: 1,
  260. animation: true,
  261. dataLabel: false,
  262. categories: xtitle,
  263. series: xinfo,
  264. enableScroll: true, //开启图表拖拽功能
  265. xAxis: {
  266. disableGrid: true,
  267. type: 'grid',
  268. gridType: 'dash',
  269. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  270. scrollShow: true, //新增是否显示滚动条,默认false
  271. // scrollAlign: 'left', //滚动条初始位置
  272. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  273. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  274. },
  275. yAxis: {
  276. format: (val) => {
  277. return val.toFixed(2)
  278. }
  279. },
  280. width: _self.cWidth * 1,
  281. height: _self.cHeight * 1,
  282. extra: {
  283. line: {
  284. type: 'curve'
  285. },
  286. },
  287. });
  288. },
  289. touchLineA(e) {
  290. canvasColumnA.scrollStart(e);
  291. },
  292. moveLineA(e) {
  293. canvasColumnA.scroll(e);
  294. },
  295. touchEndLineA(e) {
  296. canvasColumnA.scrollEnd(e);
  297. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  298. canvasColumnA.showToolTip(e, {
  299. format: function(item, category) {
  300. return category + ' ' + item.name + ':' + item.data
  301. }
  302. });
  303. },
  304. siminfo(sim) {
  305. uni.navigateTo({
  306. url: "/pages/prevention/sim?id=" + sim
  307. })
  308. },
  309. async getbaseinfo(id) {
  310. const res = await this.$myRequest({
  311. url: '/api/api_gateway?method=forecast.worm_lamp.lamp_list',
  312. data: {
  313. device_type_id:38,
  314. page: 1,
  315. page_size: 10,
  316. device_id: id,
  317. }
  318. })
  319. // console.log(res.ids.id)
  320. this.eqinfo.item = res.data[0] || {}
  321. }
  322. },
  323. onLoad(option) {
  324. this.$forceUpdate()
  325. this.eqinfo.item = JSON.parse(option.shebei)
  326. console.log(JSON.parse(option.shebei))
  327. if (!this.eqinfo.item.iccid) {
  328. this.getbaseinfo(this.eqinfo.item.equip_id)
  329. }
  330. this.history()
  331. // this.onehistory()
  332. // if (this.eqinfo.item.lat == '' || this.eqinfo.item.lng == "") {
  333. // console.log(1)
  334. // } else {
  335. // this.reverseGeocode(this.eqinfo.item.lat, this.eqinfo.item.lng)
  336. // }
  337. // uni.getStorage({
  338. // key: "jurisdiction",
  339. // success: (res) => {
  340. // console.log(JSON.parse(res.data))
  341. // let items = JSON.parse(res.data).filter((item) => {
  342. // return item.pur_id == 40
  343. // })
  344. // let items2 = items[0].children.filter((item) => {
  345. // return item.pur_id == 41
  346. // })
  347. // var arr = items2[0].children
  348. // console.log(arr)
  349. // for (var i = 0; i < arr.length; i++) {
  350. // switch (arr[i].pur_id) {
  351. // case 144:
  352. // this.kongtf = true
  353. // break
  354. // case 145:
  355. // this.daydatatf = true
  356. // break
  357. // case 147:
  358. // this.shujutf = true
  359. // break
  360. // }
  361. // }
  362. // },
  363. // })
  364. }
  365. }
  366. </script>
  367. <style lang="scss">
  368. .info {
  369. width: 100%;
  370. position: absolute;
  371. top: 44px;
  372. .info_item {
  373. width: 90%;
  374. margin: 0 auto;
  375. height: 250rpx;
  376. padding: 26rpx 50rpx;
  377. position: relative;
  378. box-sizing: border-box;
  379. .bgi {
  380. width: 100%;
  381. height: 250rpx;
  382. position: absolute;
  383. top: 0;
  384. left: 0;
  385. z-index: -1;
  386. }
  387. p {
  388. font-size: 24rpx;
  389. color: #FFFFFF;
  390. margin-bottom: 10rpx;
  391. .tishi {
  392. width: 30rpx;
  393. height: 30rpx;
  394. margin: 0rpx 0 0 20rpx;
  395. }
  396. }
  397. }
  398. }
  399. .control {
  400. width: 90%;
  401. position: absolute;
  402. top: 372rpx;
  403. left: 5%;
  404. display: flex;
  405. text-align: center;
  406. // padding: 0 30rpx;
  407. box-sizing: border-box;
  408. .control_item {
  409. width: 128rpx;
  410. height: 120rpx;
  411. width: 33%;
  412. image {
  413. width: 70rpx;
  414. height: 70rpx;
  415. }
  416. p {
  417. font-size: 24rpx;
  418. }
  419. }
  420. }
  421. .realtime {
  422. width: 100%;
  423. position: absolute;
  424. top: 500rpx;
  425. .realtime_title {
  426. font-weight: 700;
  427. width: 90%;
  428. margin: 0 auto;
  429. }
  430. .dataloading:after {
  431. overflow: hidden;
  432. display: inline-block;
  433. vertical-align: bottom;
  434. animation: ellipsis 2s infinite;
  435. content: "\2026";
  436. }
  437. @keyframes ellipsis {
  438. from {
  439. width: 2px;
  440. }
  441. to {
  442. width: 15px;
  443. }
  444. }
  445. .realtime_tishi {
  446. width: 90%;
  447. margin: 0 auto;
  448. text-align: center;
  449. font-size: 32rpx;
  450. padding-top: 40rpx;
  451. }
  452. .realtime_text {
  453. width: 90%;
  454. margin: 0 auto;
  455. .realtime_text_item {
  456. width: 100%;
  457. display: flex;
  458. justify-content: space-between;
  459. flex-wrap: wrap;
  460. margin-bottom: 50rpx;
  461. .realtime_text_item_info {
  462. width: 48%;
  463. box-shadow: 0 0 10rpx #bcb9ca;
  464. margin-top: 20rpx;
  465. display: flex;
  466. padding: 20rpx 0rpx 20rpx 20rpx;
  467. box-sizing: border-box;
  468. .item_info_img {
  469. width: 90rpx;
  470. text-align: center;
  471. margin-right: 28rpx;
  472. border-radius: 50%;
  473. height: 90rpx;
  474. image {
  475. width: 64rpx;
  476. height: 64rpx;
  477. margin-top: 15rpx
  478. }
  479. }
  480. .item_info_text {
  481. font-size: 24rpx;
  482. }
  483. }
  484. }
  485. }
  486. }
  487. .charts {
  488. // width: 650upx;
  489. // height: 400upx;
  490. background-color: #FFFFFF;
  491. }
  492. .tishiTF {
  493. text-align: center;
  494. margin-top: 20rpx;
  495. }
  496. .maxdata {
  497. font-size: 26rpx;
  498. .maxdata_box {
  499. display: flex;
  500. padding-left: 30rpx;
  501. box-sizing: border-box;
  502. }
  503. .dian {
  504. width: 20rpx;
  505. height: 20rpx;
  506. background-color: red;
  507. margin: 8rpx 10rpx 0 0;
  508. border-radius: 50%;
  509. }
  510. .diantwo {
  511. background-color: #16c60d;
  512. }
  513. }
  514. </style>