index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <template>
  2. <view class="">
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 44px;">
  5. <view style="position: fixed;z-index: 100;">
  6. <uni-nav-bar @clickRight="clickRight" @clickLeft="clickLeft" left-icon="back" left-text="返回"
  7. right-icon="search" title="测报系统"></uni-nav-bar>
  8. <view class="inputs" :style="{'width':width+'rpx'}">
  9. <input type="text" value="" placeholder="请输入设备ID或设备名称" v-model="imports" @input="searchinp"
  10. class="inputbox" :clearable="false" />
  11. <u-icon name="search" size="40" class="icon" @click="search"></u-icon>
  12. </view>
  13. <view style="width: 100%;">
  14. <image :src="'http://www.hnyfwlw.com:8006/bigdata_app'+'/image/cb/banner.jpg'" mode="widthFix">
  15. </image>
  16. </view>
  17. </view>
  18. <view class="tab-box">
  19. <view v-for="(item,index) in equipArr" :key="item.type" v-if="item.tf" @click="tabClick(index)"
  20. :class="['tab-item',active==index?'active':'']">
  21. <text>{{item.name}}</text>
  22. <text class="bottom-line"></text>
  23. </view>
  24. </view>
  25. <view class="loading" v-if="loadingtf">
  26. <image src="../../../static/images/ajax-loader.gif" mode="" class="img"></image>
  27. </view>
  28. <view class="" style="position: absolute;top: 180px;width: 100%;">
  29. <view class="content">
  30. <template v-for="(item,index) in equipArr[active].list">
  31. <equipItem @click.native="itemClick(item)" v-bind:item="item" :key="index">
  32. <view class="date">
  33. <p>设备ID:{{item.imei || item.device_id}}</p>
  34. <p>最新上报时间:{{item.uptime|timeFormat}}</p>
  35. <view class="" style="display: flex;justify-content: space-between;"
  36. v-if="(device_type == 3 || device_type==7) && showLastTime">
  37. <p>设备到期情况:<span
  38. :class="'prevents_item_bot_sapn'+item.device_expire">{{item.device_expiretext}}</span>
  39. </p>
  40. <p style="color: #3C84FE;" v-if="item.device_expire!=0" @click.stop="examine(item)">
  41. 查看详情</p>
  42. </view>
  43. </view>
  44. </equipItem>
  45. </template>
  46. </view>
  47. </view>
  48. </view>
  49. <u-modal v-model="show" :title="title" :showConfirmButton="false"
  50. :title-style="{'text-align':'left','padding-left':'10px','font-weight':700}" :mask-close-able="true">
  51. <view class="slot-content">
  52. <rich-text :nodes="content"></rich-text>
  53. </view>
  54. </u-modal>
  55. <view class="top">
  56. <view class="backtop" @click="top" v-if="isTop">
  57. <image src="../../../static/images/1.png" mode="" class="img0"></image>
  58. </view>
  59. <view class="more">
  60. <view class="box" @click="online" v-show="filtrateTF">
  61. <p>在线</p>
  62. </view>
  63. <view class="box" @click="offline" v-show="filtrateTF">
  64. <p>离线</p>
  65. </view>
  66. <view class="box" @click="complete" v-show="filtrateTF">
  67. <p>全部</p>
  68. </view>
  69. <view @click="filtrate">
  70. <image src="../../../static/images/b0bcdb0e3fe8690520f743aa8303bf2.png" mode="" class="img1">
  71. </image>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import {
  79. Debounce
  80. } from "../../../util/anitthro.js"
  81. import equipItem from "../../../components/equip-item/equip-item"
  82. import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
  83. export default {
  84. data() {
  85. return {
  86. active: 0, //默认选中虫情测报
  87. equipArr: [{
  88. name: '虫情测报',
  89. type: 3, //3虫情测报灯 7孢子仪 4智能性诱
  90. list: [],
  91. pageIndex: 1,
  92. tf: false,
  93. }, {
  94. name: '孢子仪',
  95. type: 7, //3虫情测报灯 7孢子仪 4智能性诱
  96. list: [],
  97. pageIndex: 1,
  98. tf: false,
  99. }, {
  100. name: '性诱测报',
  101. type: 4, //3虫情测报灯 7孢子仪 4智能性诱
  102. list: [],
  103. pageIndex: 1,
  104. device_model: 1,
  105. tf: false,
  106. },
  107. {
  108. name: '性诱2.0',
  109. type: 10, //3虫情测报灯 7孢子仪 4智能性诱 性诱2.0
  110. list: [],
  111. pageIndex: 1,
  112. tf: false
  113. },
  114. {
  115. name: '性诱3.0',
  116. type: 8, //3虫情测报灯 7孢子仪 4智能性诱 性诱2.0
  117. list: [],
  118. pageIndex: 1,
  119. tf: false
  120. }, {
  121. name: '吸虫塔',
  122. type: 12, //3虫情测报灯 7孢子仪 4智能性诱 性诱2.0
  123. list: [],
  124. pageIndex: 1,
  125. tf: false
  126. }, {
  127. name: '病虫害可视监测',
  128. type: 14, //3虫情测报灯 7孢子仪 4智能性诱 性诱2.0
  129. list: [],
  130. pageIndex: 1,
  131. tf: false
  132. }
  133. ],
  134. device_type: '3', //筛选的设备id
  135. isTop: false,
  136. filtrateTF: false,
  137. device_status: "",
  138. width: 0, //顶部搜索栏宽度
  139. imports: "", //搜索id
  140. loadingtf: false, //loading
  141. show: false,
  142. title: "",
  143. content: "",
  144. showLastTime: false,
  145. }
  146. },
  147. onLoad() {
  148. uni.getStorage({
  149. key: "jurisdiction",
  150. success: (res) => {
  151. let list = res.data;
  152. this.showLastTime = this.testId(325, JSON.parse(res.data));
  153. console.log(this.showLastTime);
  154. let items = JSON.parse(res.data).filter((item) => {
  155. return item.pur_id == 36
  156. })
  157. var arr = items[0].children
  158. for (var i = 0; i < arr.length; i++) {
  159. switch (arr[i].pur_id) {
  160. case 37:
  161. this.equipArr[0].tf = true //"虫情测报灯"
  162. this.getEquipList(0)
  163. break
  164. case 38:
  165. this.equipArr[2].tf = true //"性诱测报"
  166. this.getEquipList(2)
  167. break
  168. case 39:
  169. this.equipArr[1].tf = true //"孢子仪"
  170. this.getEquipList(1)
  171. break
  172. case 161:
  173. this.equipArr[3].tf = true //"性诱2.0"
  174. this.getxyEquipList(3)
  175. break
  176. case 198:
  177. this.equipArr[4].tf = true //"性诱2.0"
  178. this.getthxyEquipList(4)
  179. break
  180. case 171:
  181. this.equipArr[5].tf = true //"性诱3.0"
  182. this.getxctEquipList(5)
  183. break
  184. case 167:
  185. this.equipArr[6].tf = true //"性诱3.0"
  186. this.getEquipList(6)
  187. break
  188. }
  189. }
  190. for (var i = 0; i < this.equipArr.length; i++) {
  191. if (this.equipArr[i].tf) {
  192. this.active = i
  193. this.device_type = this.equipArr[i].type
  194. console.log(i)
  195. break
  196. }
  197. }
  198. }
  199. })
  200. },
  201. onShow() {
  202. },
  203. onHide() {
  204. },
  205. onUnload() {
  206. },
  207. onPullDownRefresh() {
  208. this.equipArr[this.active].pageIndex = 1
  209. this.equipArr[this.active].list = []
  210. if (this.active == 4) {
  211. this.getthxyEquipList(4)
  212. } else if (this.active == 5) {
  213. this.getxctEquipList(5)
  214. } else if (this.active == 3) {
  215. this.getxyEquipList(3)
  216. } else {
  217. this.getEquipList(this.active)
  218. }
  219. setTimeout(() => {
  220. uni.stopPullDownRefresh()
  221. }, 1000)
  222. },
  223. onReachBottom() {
  224. let act = this.active
  225. if (this.equipArr[act].list.length < this.equipArr[act].pageIndex * 10) { //判断是否数据请求完
  226. return false
  227. }
  228. this.equipArr[act].pageIndex++;
  229. if (this.active == 4) {
  230. this.getthxyEquipList(4)
  231. } else if (this.active == 5) {
  232. this.getxctEquipList(5)
  233. } else if (this.active == 3) {
  234. this.getxyEquipList(3)
  235. } else {
  236. this.getEquipList(act)
  237. }
  238. },
  239. onPageScroll(e) { //nvue暂不支持滚动监听,可用bindingx代替
  240. if (e.scrollTop > 200) { //距离大于200时显示
  241. this.isTop = true
  242. } else { //距离小于200时隐藏
  243. this.isTop = false
  244. }
  245. },
  246. onBackPress(options) {
  247. if (options.from === 'navigateBack') {
  248. return false;
  249. }
  250. this.clickLeft();
  251. return true;
  252. },
  253. methods: {
  254. testId(id, list) {
  255. for (var i = 0; i < list.length; i++) {
  256. if (list[i].children) {
  257. var data = list[i].children
  258. for (var j = 0; j < data.length; j++) {
  259. if (data[j].children) {
  260. var item = data[j].children
  261. for (var k = 0; k < item.length; k++) {
  262. if (item[k].pur_id == id) {
  263. return true
  264. }
  265. }
  266. }
  267. }
  268. }
  269. };
  270. },
  271. async getEquipList(act) {
  272. this.loadingtf = true
  273. const res = await this.$myRequest({
  274. url: '/api/api_gateway?method=forecast.worm_lamp.lamp_list',
  275. data: {
  276. device_type_id: this.equipArr[act].type,
  277. page: this.equipArr[act].pageIndex,
  278. page_size: 10,
  279. device_status: this.device_status,
  280. device_id: this.imports,
  281. device_model: this.equipArr[act].device_model ? this.equipArr[act].device_model : 0
  282. }
  283. })
  284. this.loadingtf = false
  285. console.log(res)
  286. this.equipArr[act].list = [...this.equipArr[act].list, ...res.data]
  287. for (var i = 0; i < this.equipArr[act].list.length; i++) {
  288. if (this.equipArr[act].list[i].device_expire == 0) {
  289. this.equipArr[act].list[i]['device_expiretext'] = "未到期"
  290. } else if (this.equipArr[act].list[i].device_expire == 1) {
  291. this.equipArr[act].list[i]['device_expiretext'] = "已到期"
  292. } else if (this.equipArr[act].list[i].device_expire == 2) {
  293. this.equipArr[act].list[i]['device_expiretext'] = "即将到期"
  294. }
  295. }
  296. this.equipArr[act].list.forEach(item => {
  297. item.uptime = item.addtime;
  298. })
  299. console.log(this.equipArr[act].list)
  300. },
  301. async getxyEquipList(act) {
  302. this.loadingtf = true
  303. const res = await this.$myRequest({
  304. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_list',
  305. data: {
  306. device_type_id: this.equipArr[act].type,
  307. page: this.equipArr[act].pageIndex,
  308. page_size: 10,
  309. device_status: this.device_status,
  310. device_id: this.imports,
  311. }
  312. })
  313. this.loadingtf = false
  314. console.log(res)
  315. this.equipArr[act].list = [...this.equipArr[act].list, ...res.data]
  316. // this.equipArr[act].list.forEach(item => {
  317. // item.addtime = item.uptime;
  318. // })
  319. console.log(this.equipArr[act].list)
  320. },
  321. async getthxyEquipList(act) {
  322. this.loadingtf = true
  323. const res = await this.$myRequest({
  324. url: '/api/api_gateway?method=forecast.worm_lamp.xy_three_list',
  325. data: {
  326. device_type_id: this.equipArr[act].type,
  327. page: this.equipArr[act].pageIndex,
  328. page_size: 10,
  329. device_status: this.device_status,
  330. device_id: this.imports,
  331. }
  332. })
  333. this.loadingtf = false
  334. console.log(res)
  335. this.equipArr[act].list = [...this.equipArr[act].list, ...res.data];
  336. // this.equipArr[act].list.forEach(item => {
  337. // item.addtime = item.uptime;
  338. // })
  339. console.log(this.equipArr[act].list)
  340. },
  341. async getxctEquipList(act) {
  342. this.loadingtf = true
  343. const res = await this.$myRequest({
  344. url: '/api/api_gateway?method=forecast.worm_lamp.xct_list',
  345. data: {
  346. device_type_id: this.equipArr[act].type,
  347. page: this.equipArr[act].pageIndex,
  348. page_size: 10,
  349. device_status: this.device_status,
  350. device_id: this.imports,
  351. }
  352. })
  353. this.loadingtf = false
  354. console.log(res)
  355. this.equipArr[act].list = [...this.equipArr[act].list, ...res.data];
  356. // this.equipArr[act].list.forEach(item => {
  357. // item.addtime = item.uptime;
  358. // })
  359. },
  360. tabClick(index) {
  361. this.width = 0
  362. this.imports = ""
  363. this.active = index;
  364. this.device_type = this.equipArr[index].type
  365. },
  366. clickRight() {
  367. this.width = 600
  368. },
  369. itemClick(item) {
  370. item.type = this.equipArr[this.active].type
  371. let data = JSON.stringify(item)
  372. if (item.type == 10) {
  373. uni.navigateTo({
  374. url: '/pages/cb/xy2.0/particulars?info=' + data
  375. });
  376. } else if (item.type == 8) {
  377. console.log(data)
  378. uni.navigateTo({
  379. url: '/pages/cb/thxydetail/thxydetail?imei=' + item.imei
  380. });
  381. } else if (item.type == 12) {
  382. uni.navigateTo({
  383. url: '/pages/cb/xctdetail/xctdetail?info=' + data
  384. });
  385. } else if (item.type == 14) {
  386. uni.navigateTo({
  387. url: '/pages/cb/sy/detail?detail=' + data
  388. });
  389. } else {
  390. uni.navigateTo({
  391. url: '/pages/cb/equip-detail/equip-detail?info=' + data
  392. });
  393. }
  394. },
  395. clickLeft() {
  396. uni.switchTab({
  397. url: "../../index/index"
  398. })
  399. },
  400. filtrate() {
  401. this.filtrateTF = !this.filtrateTF
  402. },
  403. top() {
  404. uni.pageScrollTo({
  405. scrollTop: 0,
  406. duration: 500
  407. })
  408. },
  409. online() {
  410. this.equipArr[this.active].pageIndex = 1
  411. this.equipArr[this.active].list = []
  412. this.device_status = 1
  413. if (this.active == 4) {
  414. this.getthxyEquipList(4)
  415. } else if (this.active == 5) {
  416. this.getxctEquipList(5)
  417. } else if (this.active == 3) {
  418. this.getxyEquipList(3)
  419. } else {
  420. this.getEquipList(this.active)
  421. }
  422. this.filtrateTF = !this.filtrateTF
  423. },
  424. offline() {
  425. this.equipArr[this.active].pageIndex = 1
  426. this.equipArr[this.active].list = []
  427. this.device_status = 0
  428. if (this.active == 4) {
  429. this.getthxyEquipList(4)
  430. } else if (this.active == 5) {
  431. this.getxctEquipList(5)
  432. } else if (this.active == 3) {
  433. this.getxyEquipList(3)
  434. } else {
  435. this.getEquipList(this.active)
  436. }
  437. this.filtrateTF = !this.filtrateTF
  438. },
  439. complete() {
  440. this.equipArr[this.active].pageIndex = 1
  441. this.equipArr[this.active].list = []
  442. this.device_status = ""
  443. if (this.active == 4) {
  444. this.getthxyEquipList(4)
  445. } else if (this.active == 5) {
  446. this.getxctEquipList(5)
  447. } else if (this.active == 3) {
  448. this.getxyEquipList(3)
  449. } else {
  450. this.getEquipList(this.active)
  451. }
  452. this.filtrateTF = !this.filtrateTF
  453. },
  454. search() { //搜索按钮搜索
  455. this.searchinp()
  456. },
  457. searchinp() { //自动搜索
  458. Debounce(() => {
  459. this.equipArr[this.active].pageIndex = 1
  460. if (this.active == 4) {
  461. this.equipArr[this.active].list = []
  462. this.getthxyEquipList(this.active)
  463. } else if (this.active == 5) {
  464. this.equipArr[this.active].list = []
  465. this.getxctEquipList(this.active)
  466. } else if (this.active == 3) {
  467. this.equipArr[this.active].list = []
  468. this.getxyEquipList(this.active)
  469. } else {
  470. this.equipArr[this.active].list = []
  471. this.getEquipList(this.active)
  472. }
  473. }, 1000)()
  474. },
  475. examine(e) {
  476. // console.log(this)
  477. this.show = true
  478. this.title = e.device_expiretext
  479. this.content =
  480. `<p style="padding-left:10px;margin:10px 0;font-size:14px;">到期时间 ${this.timezhuan(e.device_expire_time)}
  481. </p><p style="font-size:14px;text-align:right;color:#3C84FE;margin-bottom:10px;padding-right:10px">注:请前往PC端进行充值</p>`
  482. },
  483. timezhuan(time) {
  484. function fun(a) {
  485. return String(a).length == 1 ? '0' + a : a
  486. }
  487. let date = new Date(time * 1000)
  488. let y = date.getFullYear()
  489. let m = date.getMonth() + 1
  490. let d = date.getDate()
  491. let h = date.getHours()
  492. let min = date.getMinutes()
  493. let sec = date.getSeconds()
  494. return `${y}-${fun(m)}-${fun(d)} ${fun(h)}:${fun(min)}:${fun(sec)}`
  495. },
  496. },
  497. components: {
  498. equipItem,
  499. uniNavBar
  500. }
  501. }
  502. </script>
  503. <style lang="scss">
  504. page {
  505. background: $uni-bg-color-grey;
  506. .content {
  507. padding: 0 20rpx 20rpx 20rpx;
  508. box-sizing: border-box;
  509. .prevents_item_bot_sapn0 {
  510. color: #00B075;
  511. }
  512. .prevents_item_bot_sapn1 {
  513. color: #FF4747;
  514. }
  515. .prevents_item_bot_sapn2 {
  516. color: #FFAB00;
  517. }
  518. }
  519. }
  520. image {
  521. width: 100%;
  522. }
  523. .inputs {
  524. height: 54rpx;
  525. background-color: #E4E4E4;
  526. border-radius: 27rpx;
  527. position: absolute;
  528. right: 20rpx;
  529. top: 20rpx;
  530. transition: width 0.5s;
  531. overflow: hidden;
  532. padding-top: 8rpx;
  533. box-sizing: border-box;
  534. .inputbox {
  535. width: 85%;
  536. text-indent: 1rem;
  537. font-size: 26rpx;
  538. }
  539. .icon {
  540. position: absolute;
  541. top: 8rpx;
  542. right: 26rpx;
  543. }
  544. }
  545. .loading {
  546. position: fixed;
  547. top: 440px;
  548. width: 95%;
  549. left: 2.5%;
  550. text-align: center;
  551. .img {
  552. width: 300rpx;
  553. height: 40rpx;
  554. }
  555. }
  556. .tab-box {
  557. position: fixed;
  558. top: 170px;
  559. font-size: 30rpx;
  560. line-height: 80rpx;
  561. background-color: #ffffff;
  562. width: 100vw;
  563. z-index: 2;
  564. overflow-y: hidden;
  565. overflow-x: auto;
  566. white-space: nowrap;
  567. .tab-item {
  568. cursor: pointer;
  569. position: relative;
  570. padding: 10rpx 20rpx;
  571. text-align: center;
  572. display: inline-block;
  573. span {
  574. display: inline-block;
  575. }
  576. }
  577. .tab-item.active {
  578. .bottom-line {
  579. bottom: 0;
  580. position: absolute;
  581. display: inline-block;
  582. width: 90rpx;
  583. height: 6rpx;
  584. left: 0;
  585. right: 0;
  586. margin: auto;
  587. background: $uni-color-success;
  588. }
  589. }
  590. }
  591. .top {
  592. position: fixed;
  593. right: 10px;
  594. bottom: 40px;
  595. z-index: 100;
  596. image {
  597. width: 100rpx;
  598. height: 100rpx;
  599. }
  600. .backtop {
  601. display: flex;
  602. justify-content: flex-end;
  603. margin-bottom: 10rpx;
  604. }
  605. .more {
  606. display: flex;
  607. }
  608. .box {
  609. width: 80rpx;
  610. height: 80rpx;
  611. background-color: rgba(161, 161, 161, 0.45);
  612. border-radius: 50%;
  613. text-align: center;
  614. line-height: 80rpx;
  615. box-sizing: border-box;
  616. margin: 14rpx 10rpx 0 0;
  617. color: #fff;
  618. }
  619. }
  620. </style>