equipment.vue 14 KB

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