index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. <template>
  2. <view>
  3. <!-- <view class="status_bar"></view>
  4. <view style="position: fixed;top:44px;z-index: 100;width: 100%;">
  5. <uni-nav-bar right-icon="search" title="设备列表" @clickRight="clickRight"></uni-nav-bar>
  6. </view> -->
  7. <view class="textbox">
  8. <view class="inputs">
  9. <!-- <u-input v-model="imports" type="text" :border="true" /> -->
  10. <u-search
  11. placeholder="请输入设备ID"
  12. v-model="imports"
  13. placeholder-color="#909696"
  14. :show-action="false"
  15. search-icon-color="#909696"
  16. @input="searchinput"
  17. >
  18. </u-search>
  19. <!-- <input type="text" value="" placeholder="请输入设备ID或设备名称" v-model="imports" @input="searchinput"
  20. class="inputbox" :clearable="false" />
  21. <u-icon name="search" size="40" class="icon" @click="search"></u-icon> -->
  22. </view>
  23. <view class="listbox">
  24. <view class="listbox_left">
  25. <view
  26. :class="
  27. currents == index
  28. ? 'listbox_left_item_act listbox_left_item'
  29. : 'listbox_left_item'
  30. "
  31. v-for="(item, index) in list"
  32. :key="index"
  33. @click="change(index)"
  34. >
  35. {{ item.name }}
  36. </view>
  37. </view>
  38. <!-- <view class="list" @scroll='showOut' ref="sollo" id="list"> -->
  39. <scroll-view
  40. :scroll-top="0"
  41. :scroll-y="true"
  42. class="list scroll-Y"
  43. @scrolltoupper="upper"
  44. @scrolltolower="lower"
  45. @scroll="scroll"
  46. >
  47. <view
  48. class="list_item"
  49. v-for="(item, index) in eqlistdata"
  50. :key="index"
  51. @click="historys(item)"
  52. >
  53. <view class="list_item_top">
  54. <p class="p1">
  55. <image
  56. :src="
  57. 'http://www.hnyfwlw.com:8006/bigdata_app/image/fourMoodBase/' +
  58. type_id +
  59. '.png'
  60. "
  61. mode=""
  62. ></image>
  63. {{ item.device_name == "" ? "--" : item.device_name }}
  64. </p>
  65. <p
  66. v-if="![11, 19, 20].includes(type_id)"
  67. :class="[item.is_online ? 'p2' : 'p_out']"
  68. >
  69. {{ item.is_online ? "在线" : "离线" }}
  70. </p>
  71. </view>
  72. <view class="list_item_text">
  73. <p>设备ID:{{ item.imei || item.device_id }}</p>
  74. <p>
  75. 适配用户:{{ item.real_name == "" ? "无" : item.real_name }}
  76. </p>
  77. <p>最新上报时间:{{ item.addtime | timeFormat() }}</p>
  78. <p v-if="item.uptime === 0">添加设备时间:- -</p>
  79. <p v-else>添加设备时间:{{ item.uptime | timeFormat() }}</p>
  80. <p>设备已运行:{{ item.days }}天</p>
  81. </view>
  82. <view
  83. class="list_item_btn"
  84. v-if="infoalter && ![13, 17, 18, 11, 19, 20].includes(type_id)"
  85. @click.stop="modification(item)"
  86. >
  87. 信息修改
  88. </view>
  89. </view>
  90. </scroll-view>
  91. <!-- </view> -->
  92. </view>
  93. </view>
  94. <!-- <view class="utabs_box">
  95. <view class="utabs">
  96. <u-tabs :list="list" :is-scroll="true" :current="currents" @change="change" item-width="140"
  97. font-size="24" gutter="20" bar-width="60" active-color="#42b983" v-if="list.length"></u-tabs>
  98. </view>
  99. </view> -->
  100. <view class="loading" v-if="loadingtf">
  101. <image
  102. src="../../static/images/ajax-loader.gif"
  103. mode=""
  104. class="img"
  105. ></image>
  106. </view>
  107. <view class="top" v-if="isTop" @click="top">
  108. <image
  109. :src="
  110. 'http://www.hnyfwlw.com:8006/bigdata_app' +
  111. '/image/6209a98f0cb3b5086f2ca36152c9269.png'
  112. "
  113. mode=""
  114. ></image>
  115. </view>
  116. </view>
  117. </template>
  118. <script>
  119. import { Debounce, Throttle } from "../../util/anitthro.js";
  120. export default {
  121. data() {
  122. return {
  123. list: [],
  124. current: 0,
  125. currents: 0,
  126. page: 1,
  127. size: 10,
  128. eqlistdata: [],
  129. isTop: false,
  130. infoalter: false, // 权限设置,
  131. type_id: 0, //设备类型,
  132. imgpath: [],
  133. loadingtf: false,
  134. width: 0, //顶部搜索栏宽度
  135. imports: "", //搜索设备ID
  136. };
  137. },
  138. methods: {
  139. async eqlist(tf) {
  140. //设备列表
  141. this.loadingtf = true;
  142. const res = await this.$myRequest({
  143. url: "/api/api_gateway?method=forecast.worm_lamp.lamp_list",
  144. data: {
  145. device_type_id: this.type_id,
  146. page: this.page,
  147. page_size: this.size,
  148. device_id: this.imports,
  149. },
  150. });
  151. this.loadingtf = false;
  152. if ([11, 19, 20].includes(Number(this.type_id))) {
  153. var newtime = +new Date() / 1000;
  154. } else {
  155. var newtime = +new Date() / 1000;
  156. }
  157. if (tf) {
  158. this.eqlistdata = this.eqlistdata.concat(res.data);
  159. } else {
  160. this.eqlistdata = res.data;
  161. }
  162. console.log(this.eqlistdata);
  163. for (var i = 0; i < this.eqlistdata.length; i++) {
  164. var days = (newtime - this.eqlistdata[i].uptime) / 60 / 60 / 24;
  165. this.eqlistdata[i].days = Math.round(days);
  166. }
  167. },
  168. async xyeqlist(tf) {
  169. //设备列表
  170. this.loadingtf = true;
  171. const res = await this.$myRequest({
  172. url: "/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_list",
  173. data: {
  174. device_type_id: this.type_id,
  175. page: this.page,
  176. page_size: this.size,
  177. device_id: this.imports,
  178. },
  179. });
  180. this.loadingtf = false;
  181. var newtime = +new Date() / 1000;
  182. if (tf) {
  183. this.eqlistdata = this.eqlistdata.concat(res.data);
  184. } else {
  185. this.eqlistdata = res.data;
  186. }
  187. for (var i = 0; i < this.eqlistdata.length; i++) {
  188. var days = (newtime - this.eqlistdata[i].uptime) / 60 / 60 / 24;
  189. this.eqlistdata[i].days = Math.round(days);
  190. }
  191. console.log(res);
  192. },
  193. //camera.camera_manage.list_camera
  194. async camera() {
  195. //监控
  196. const res = await this.$myRequest({
  197. url: "/api/api_gateway?method=camera.camera_manage.list_camera",
  198. data: {
  199. page_size: 1,
  200. },
  201. });
  202. this.accessToken = res.accessToken;
  203. },
  204. // homes.user_device_type
  205. async usertype() {
  206. //设备列表
  207. const res = await this.$myRequest({
  208. url: "/api/api_gateway?method=home.homes.user_device_type",
  209. });
  210. console.log(res);
  211. for (var i = 0; i < res.length; i++) {
  212. if (
  213. res[i].type_name == "性诱3.0" ||
  214. res[i].type_name == "吸虫塔" ||
  215. res[i].type_name == "病虫害可视监测" ||
  216. // res[i].type_name == "小麦赤霉病" ||
  217. res[i].type_name == "温室大棚"
  218. ) {
  219. continue;
  220. }
  221. var obj = {
  222. name: res[i].type_name,
  223. id: res[i].id,
  224. };
  225. this.list.push(obj);
  226. }
  227. console.log("设备列表11111111111111", this.list);
  228. if (res.length) {
  229. this.type_id = this.list[0].id;
  230. if (this.list[0].id == 10) {
  231. this.xyeqlist();
  232. } else {
  233. this.eqlist();
  234. }
  235. }
  236. },
  237. change(index) {
  238. console.log(index);
  239. //头部导航栏的点击
  240. this.imports = "";
  241. this.current = index;
  242. this.currents = index;
  243. this.page = 1;
  244. this.eqlistdata = [];
  245. this.type_id = this.list[index].id;
  246. console.log(this.type_id);
  247. if (this.list[index].id == 10) {
  248. this.xyeqlist();
  249. } else {
  250. this.eqlist();
  251. }
  252. },
  253. clickRight() {
  254. //搜索
  255. this.width = "90%";
  256. },
  257. modification(item) {
  258. uni.navigateTo({
  259. url:
  260. "./modification?data=" + JSON.stringify(item) + "&id=" + this.type_id,
  261. });
  262. },
  263. top() {
  264. uni.pageScrollTo({
  265. scrollTop: 0,
  266. duration: 500,
  267. });
  268. },
  269. historys(item) {
  270. console.log("item", item);
  271. switch (this.type_id) {
  272. case 2:
  273. uni.navigateTo({
  274. url:
  275. "../prevention/equipmentdetails?shebei=" + JSON.stringify(item),
  276. });
  277. break;
  278. case 5:
  279. console.log(item);
  280. var obj = {};
  281. obj.d_id = item.d_id;
  282. obj.equip_id = item.imei;
  283. obj.is_online = item.is_online;
  284. obj.lat = item.lat;
  285. obj.lng = item.lng;
  286. obj.equip_name = item.device_name;
  287. obj.uptime = item.addtime;
  288. uni.navigateTo({
  289. url: "../environment/equipment?shebei=" + JSON.stringify(obj),
  290. });
  291. break;
  292. case 6:
  293. uni.navigateTo({
  294. url:
  295. "/pages/webview?device_id=" +
  296. item.imei +
  297. "&accessToken=" +
  298. this.accessToken,
  299. });
  300. break;
  301. case 3:
  302. item.type = this.type_id;
  303. uni.navigateTo({
  304. url: "../cb/equip-detail/equip-detail?info=" + JSON.stringify(item),
  305. });
  306. break;
  307. case 4:
  308. item.type = this.type_id;
  309. uni.navigateTo({
  310. url: "../cb/equip-detail/equip-detail?info=" + JSON.stringify(item),
  311. });
  312. break;
  313. case 7:
  314. item.type = this.type_id;
  315. uni.navigateTo({
  316. url: "../cb/equip-detail/equip-detail?info=" + JSON.stringify(item),
  317. });
  318. break;
  319. case 13:
  320. console.log(item);
  321. var obj = {};
  322. obj.d_id = item.d_id;
  323. obj.device_id = item.imei;
  324. obj.is_online = item.is_online;
  325. obj.lat = item.lat;
  326. obj.lng = item.lng;
  327. obj.equip_name = item.device_name;
  328. obj.uptime = item.addtime;
  329. uni.navigateTo({
  330. url: "../waterandfer/datails?shebei=" + JSON.stringify(obj),
  331. });
  332. break;
  333. case 15:
  334. console.log(item);
  335. var obj = {};
  336. obj.d_id = item.d_id;
  337. obj.device_id = item.imei;
  338. obj.is_online = item.is_online;
  339. obj.lat = item.lat;
  340. obj.lng = item.lng;
  341. obj.equip_name = item.device_name;
  342. obj.uptime = item.addtime;
  343. uni.navigateTo({
  344. url: "../environment/gsequipment?shebei=" + JSON.stringify(obj),
  345. });
  346. break;
  347. case 17:
  348. break;
  349. case 18:
  350. break;
  351. case 11:
  352. var obj = {};
  353. obj.d_id = item.d_id;
  354. obj.device_id = item.imei;
  355. obj.is_online = item.is_online;
  356. obj.lat = item.lat;
  357. obj.lng = item.lng;
  358. obj.equip_name = item.device_name;
  359. obj.uptime = item.addtime;
  360. obj.location = item.address;
  361. uni.navigateTo({
  362. url: "../disease/cmb?shebei=" + JSON.stringify(obj),
  363. });
  364. break;
  365. case 19:
  366. var obj = {};
  367. obj.d_id = item.d_id;
  368. obj.device_id = item.imei;
  369. obj.is_online = item.is_online;
  370. obj.lat = item.lat;
  371. obj.lng = item.lng;
  372. obj.equip_name = item.device_name;
  373. obj.uptime = item.addtime;
  374. obj.location = item.address;
  375. uni.navigateTo({
  376. url: "../disease/cmb?shebei=" + JSON.stringify(obj),
  377. });
  378. break;
  379. case 20:
  380. var obj = {};
  381. obj.d_id = item.d_id;
  382. obj.device_id = item.imei;
  383. obj.is_online = item.is_online;
  384. obj.lat = item.lat;
  385. obj.lng = item.lng;
  386. obj.equip_name = item.device_name;
  387. obj.uptime = item.addtime;
  388. obj.location = item.address;
  389. uni.navigateTo({
  390. url: "../disease/cmb?shebei=" + JSON.stringify(obj),
  391. });
  392. break;
  393. default:
  394. item.type = this.type_id;
  395. uni.navigateTo({
  396. url: "../cb/xy2.0/particulars?info=" + JSON.stringify(item),
  397. });
  398. break;
  399. }
  400. },
  401. search() {
  402. //搜索
  403. this.eqlistdata = [];
  404. this.page = 1;
  405. if (this.list[this.currents].id == 10) {
  406. this.xyeqlist();
  407. } else {
  408. this.eqlist();
  409. }
  410. },
  411. searchinput() {
  412. Debounce(() => {
  413. this.eqlistdata = [];
  414. this.page = 1;
  415. if (this.list[this.currents].id == 10) {
  416. this.xyeqlist();
  417. } else {
  418. this.eqlist();
  419. }
  420. }, 1000)();
  421. },
  422. scrollTop(e) {
  423. console.log(e);
  424. },
  425. upper() {},
  426. lower() {
  427. console.log(11);
  428. this.page++;
  429. if (this.type_id == 10) {
  430. this.xyeqlist(true);
  431. } else {
  432. this.eqlist(true);
  433. }
  434. },
  435. scroll() {},
  436. },
  437. onShow() {
  438. this.list = [];
  439. this.camera();
  440. this.current = 0;
  441. this.currents = 0;
  442. this.page = 1;
  443. this.usertype();
  444. this.width = 0;
  445. uni.getStorage({
  446. key: "jurisdiction",
  447. success: (res) => {
  448. console.log(JSON.parse(res.data));
  449. let items = JSON.parse(res.data).filter((item) => {
  450. return item.purview_name == "设备管理";
  451. });
  452. let items2 = items[0].children.filter((item) => {
  453. return item.purview_name == "设备列表";
  454. });
  455. console.log(items2[0].children);
  456. this.infoalter = items2[0].children.some((item) => {
  457. return (
  458. item.purview_name == "修改名称" || item.purview_name == "添加位置"
  459. );
  460. });
  461. console.log(this.infoalter);
  462. },
  463. });
  464. },
  465. onReachBottom() {
  466. this.page++;
  467. if (this.type_id == 10) {
  468. this.xyeqlist(true);
  469. } else {
  470. this.eqlist(true);
  471. }
  472. },
  473. onPageScroll(e) {
  474. //nvue暂不支持滚动监听,可用bindingx代替
  475. if (e.scrollTop > 200) {
  476. //距离大于200时显示
  477. this.isTop = true;
  478. } else {
  479. //距离小于200时隐藏
  480. this.isTop = false;
  481. }
  482. },
  483. };
  484. </script>
  485. <style lang="scss">
  486. page {
  487. background-color: #00b075;
  488. }
  489. /deep/.uni-icons {
  490. font-size: 40rpx !important;
  491. }
  492. .textbox {
  493. width: 100%;
  494. padding: 20rpx 30rpx;
  495. box-sizing: border-box;
  496. border-top-left-radius: 80rpx;
  497. border-top-right-radius: 80rpx;
  498. margin-top: 30rpx;
  499. background-color: #f9f9f9;
  500. }
  501. .inputs {
  502. /deep/.u-content {
  503. background-color: #fff !important;
  504. }
  505. /deep/.uni-input-wrapper {
  506. background-color: #fff !important;
  507. }
  508. }
  509. .utabs_box {
  510. width: 100%;
  511. position: fixed;
  512. top: 88px;
  513. background-color: #ffffff;
  514. z-index: 100;
  515. .utabs {
  516. width: 95%;
  517. margin: 0 auto;
  518. }
  519. }
  520. .loading {
  521. position: fixed;
  522. top: 440px;
  523. width: 95%;
  524. left: 2.5%;
  525. text-align: center;
  526. .img {
  527. width: 300rpx;
  528. height: 40rpx;
  529. }
  530. }
  531. .listbox {
  532. display: flex;
  533. justify-content: space-around;
  534. height: calc(100vh - 84px);
  535. margin-top: 20rpx;
  536. .listbox_left {
  537. background-color: #fff;
  538. padding: 20rpx;
  539. width: 140rpx;
  540. .listbox_left_item {
  541. height: 50rpx;
  542. width: 100%;
  543. margin-bottom: 20rpx;
  544. text-align: center;
  545. border-radius: 10rpx;
  546. line-height: 50rpx;
  547. overflow: hidden; //溢出隐藏
  548. white-space: nowrap; //禁止换行
  549. text-overflow: ellipsis; //...
  550. }
  551. .listbox_left_item_act {
  552. background-color: rgba(0, 176, 117, 0.2);
  553. color: #00b075;
  554. }
  555. }
  556. }
  557. .list {
  558. width: 70%;
  559. background-color: #fdfdfd;
  560. // margin-bottom: 100rpx;
  561. overflow-y: auto;
  562. .list_item {
  563. width: 100%;
  564. margin: 0 auto 20rpx;
  565. padding: 20rpx 20rpx;
  566. box-sizing: border-box;
  567. position: relative;
  568. background-color: #ffffff;
  569. box-shadow: 0 0 10rpx #bcb9ca;
  570. .list_item_top {
  571. display: flex;
  572. justify-content: space-between;
  573. .p1 {
  574. height: 60rpx;
  575. line-height: 60rpx;
  576. font-size: 28rpx;
  577. image {
  578. width: 40rpx;
  579. height: 40rpx;
  580. vertical-align: text-top;
  581. margin-right: 20rpx;
  582. }
  583. }
  584. .p2 {
  585. height: 60rpx;
  586. line-height: 60rpx;
  587. font-size: 28rpx;
  588. color: #42b983;
  589. }
  590. .p_out {
  591. height: 60rpx;
  592. line-height: 60rpx;
  593. font-size: 28rpx;
  594. color: red;
  595. }
  596. }
  597. .list_item_text {
  598. margin-top: 20rpx;
  599. p {
  600. font-size: 24rpx;
  601. color: #636363;
  602. margin-top: 10rpx;
  603. }
  604. p:first-child {
  605. font-size: 28rpx;
  606. font-weight: 700;
  607. }
  608. }
  609. .list_item_btn {
  610. width: 126rpx;
  611. color: #42b983;
  612. height: 40rpx;
  613. text-align: center;
  614. border: 1rpx solid #42b983;
  615. border-radius: 25rpx;
  616. font-size: 24rpx;
  617. line-height: 35rpx;
  618. position: absolute;
  619. bottom: 15rpx;
  620. right: 20rpx;
  621. }
  622. }
  623. }
  624. .top {
  625. position: fixed;
  626. right: 30px;
  627. bottom: 100px;
  628. z-index: 100;
  629. image {
  630. width: 100rpx;
  631. height: 100rpx;
  632. }
  633. }
  634. </style>