index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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.addtime|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. console.log(this.equipArr[act].list)
  297. },
  298. async getxyEquipList(act) {
  299. this.loadingtf = true
  300. const res = await this.$myRequest({
  301. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_list',
  302. data: {
  303. device_type_id: this.equipArr[act].type,
  304. page: this.equipArr[act].pageIndex,
  305. page_size: 10,
  306. device_status: this.device_status,
  307. device_id: this.imports,
  308. }
  309. })
  310. this.loadingtf = false
  311. console.log(res)
  312. this.equipArr[act].list = [...this.equipArr[act].list, ...res.data]
  313. console.log(this.equipArr[act].list)
  314. },
  315. async getthxyEquipList(act) {
  316. this.loadingtf = true
  317. const res = await this.$myRequest({
  318. url: '/api/api_gateway?method=forecast.worm_lamp.xy_three_list',
  319. data: {
  320. device_type_id: this.equipArr[act].type,
  321. page: this.equipArr[act].pageIndex,
  322. page_size: 10,
  323. device_status: this.device_status,
  324. device_id: this.imports,
  325. }
  326. })
  327. this.loadingtf = false
  328. console.log(res)
  329. this.equipArr[act].list = [...this.equipArr[act].list, ...res.data]
  330. console.log(this.equipArr[act].list)
  331. },
  332. async getxctEquipList(act) {
  333. this.loadingtf = true
  334. const res = await this.$myRequest({
  335. url: '/api/api_gateway?method=forecast.worm_lamp.xct_list',
  336. data: {
  337. device_type_id: this.equipArr[act].type,
  338. page: this.equipArr[act].pageIndex,
  339. page_size: 10,
  340. device_status: this.device_status,
  341. device_id: this.imports,
  342. }
  343. })
  344. this.loadingtf = false
  345. console.log(res)
  346. this.equipArr[act].list = [...this.equipArr[act].list, ...res.data];
  347. this.equipArr[act].list.forEach(item => {
  348. item.addtime = item.uptime;
  349. })
  350. },
  351. tabClick(index) {
  352. this.width = 0
  353. this.imports = ""
  354. this.active = index;
  355. this.device_type = this.equipArr[index].type
  356. },
  357. clickRight() {
  358. this.width = 600
  359. },
  360. itemClick(item) {
  361. item.type = this.equipArr[this.active].type
  362. let data = JSON.stringify(item)
  363. if (item.type == 10) {
  364. uni.navigateTo({
  365. url: '/pages/cb/xy2.0/particulars?info=' + data
  366. });
  367. } else if (item.type == 8) {
  368. console.log(data)
  369. uni.navigateTo({
  370. url: '/pages/cb/thxydetail/thxydetail?imei=' + item.imei
  371. });
  372. } else if (item.type == 12) {
  373. uni.navigateTo({
  374. url: '/pages/cb/xctdetail/xctdetail?info=' + data
  375. });
  376. } else if (item.type == 14) {
  377. uni.navigateTo({
  378. url: '/pages/cb/sy/detail?detail=' + data
  379. });
  380. } else {
  381. uni.navigateTo({
  382. url: '/pages/cb/equip-detail/equip-detail?info=' + data
  383. });
  384. }
  385. },
  386. clickLeft() {
  387. uni.switchTab({
  388. url: "../../index/index"
  389. })
  390. },
  391. filtrate() {
  392. this.filtrateTF = !this.filtrateTF
  393. },
  394. top() {
  395. uni.pageScrollTo({
  396. scrollTop: 0,
  397. duration: 500
  398. })
  399. },
  400. online() {
  401. this.equipArr[this.active].pageIndex = 1
  402. this.equipArr[this.active].list = []
  403. this.device_status = 1
  404. if (this.active == 4) {
  405. this.getthxyEquipList(4)
  406. } else if (this.active == 5) {
  407. this.getxctEquipList(5)
  408. } else if (this.active == 3) {
  409. this.getxyEquipList(3)
  410. } else {
  411. this.getEquipList(this.active)
  412. }
  413. this.filtrateTF = !this.filtrateTF
  414. },
  415. offline() {
  416. this.equipArr[this.active].pageIndex = 1
  417. this.equipArr[this.active].list = []
  418. this.device_status = 0
  419. if (this.active == 4) {
  420. this.getthxyEquipList(4)
  421. } else if (this.active == 5) {
  422. this.getxctEquipList(5)
  423. } else if (this.active == 3) {
  424. this.getxyEquipList(3)
  425. } else {
  426. this.getEquipList(this.active)
  427. }
  428. this.filtrateTF = !this.filtrateTF
  429. },
  430. complete() {
  431. this.equipArr[this.active].pageIndex = 1
  432. this.equipArr[this.active].list = []
  433. this.device_status = ""
  434. if (this.active == 4) {
  435. this.getthxyEquipList(4)
  436. } else if (this.active == 5) {
  437. this.getxctEquipList(5)
  438. } else if (this.active == 3) {
  439. this.getxyEquipList(3)
  440. } else {
  441. this.getEquipList(this.active)
  442. }
  443. this.filtrateTF = !this.filtrateTF
  444. },
  445. search() { //搜索按钮搜索
  446. this.searchinp()
  447. },
  448. searchinp() { //自动搜索
  449. Debounce(() => {
  450. this.equipArr[this.active].pageIndex = 1
  451. if (this.active == 4) {
  452. this.equipArr[this.active].list = []
  453. this.getthxyEquipList(this.active)
  454. } else if (this.active == 5) {
  455. this.equipArr[this.active].list = []
  456. this.getxctEquipList(this.active)
  457. } else if (this.active == 3) {
  458. this.equipArr[this.active].list = []
  459. this.getxyEquipList(this.active)
  460. } else {
  461. this.equipArr[this.active].list = []
  462. this.getEquipList(this.active)
  463. }
  464. }, 1000)()
  465. },
  466. examine(e) {
  467. // console.log(this)
  468. this.show = true
  469. this.title = e.device_expiretext
  470. this.content =
  471. `<p style="padding-left:10px;margin:10px 0;font-size:14px;">到期时间 ${this.timezhuan(e.device_expire_time)}
  472. </p><p style="font-size:14px;text-align:right;color:#3C84FE;margin-bottom:10px;padding-right:10px">注:请前往PC端进行充值</p>`
  473. },
  474. timezhuan(time) {
  475. function fun(a) {
  476. return String(a).length == 1 ? '0' + a : a
  477. }
  478. let date = new Date(time * 1000)
  479. let y = date.getFullYear()
  480. let m = date.getMonth() + 1
  481. let d = date.getDate()
  482. let h = date.getHours()
  483. let min = date.getMinutes()
  484. let sec = date.getSeconds()
  485. return `${y}-${fun(m)}-${fun(d)} ${fun(h)}:${fun(min)}:${fun(sec)}`
  486. },
  487. },
  488. components: {
  489. equipItem,
  490. uniNavBar
  491. }
  492. }
  493. </script>
  494. <style lang="scss">
  495. page {
  496. background: $uni-bg-color-grey;
  497. .content {
  498. padding: 0 20rpx 20rpx 20rpx;
  499. box-sizing: border-box;
  500. .prevents_item_bot_sapn0 {
  501. color: #00B075;
  502. }
  503. .prevents_item_bot_sapn1 {
  504. color: #FF4747;
  505. }
  506. .prevents_item_bot_sapn2 {
  507. color: #FFAB00;
  508. }
  509. }
  510. }
  511. image {
  512. width: 100%;
  513. }
  514. .inputs {
  515. height: 54rpx;
  516. background-color: #E4E4E4;
  517. border-radius: 27rpx;
  518. position: absolute;
  519. right: 20rpx;
  520. top: 20rpx;
  521. transition: width 0.5s;
  522. overflow: hidden;
  523. padding-top: 8rpx;
  524. box-sizing: border-box;
  525. .inputbox {
  526. width: 85%;
  527. text-indent: 1rem;
  528. font-size: 26rpx;
  529. }
  530. .icon {
  531. position: absolute;
  532. top: 8rpx;
  533. right: 26rpx;
  534. }
  535. }
  536. .loading {
  537. position: fixed;
  538. top: 440px;
  539. width: 95%;
  540. left: 2.5%;
  541. text-align: center;
  542. .img {
  543. width: 300rpx;
  544. height: 40rpx;
  545. }
  546. }
  547. .tab-box {
  548. position: fixed;
  549. top: 170px;
  550. font-size: 30rpx;
  551. line-height: 80rpx;
  552. background-color: #ffffff;
  553. width: 100vw;
  554. z-index: 2;
  555. overflow-y: hidden;
  556. overflow-x: auto;
  557. white-space: nowrap;
  558. .tab-item {
  559. cursor: pointer;
  560. position: relative;
  561. padding: 10rpx 20rpx;
  562. text-align: center;
  563. display: inline-block;
  564. span {
  565. display: inline-block;
  566. }
  567. }
  568. .tab-item.active {
  569. .bottom-line {
  570. bottom: 0;
  571. position: absolute;
  572. display: inline-block;
  573. width: 90rpx;
  574. height: 6rpx;
  575. left: 0;
  576. right: 0;
  577. margin: auto;
  578. background: $uni-color-success;
  579. }
  580. }
  581. }
  582. .top {
  583. position: fixed;
  584. right: 10px;
  585. bottom: 40px;
  586. z-index: 100;
  587. image {
  588. width: 100rpx;
  589. height: 100rpx;
  590. }
  591. .backtop {
  592. display: flex;
  593. justify-content: flex-end;
  594. margin-bottom: 10rpx;
  595. }
  596. .more {
  597. display: flex;
  598. }
  599. .box {
  600. width: 80rpx;
  601. height: 80rpx;
  602. background-color: rgba(161, 161, 161, 0.45);
  603. border-radius: 50%;
  604. text-align: center;
  605. line-height: 80rpx;
  606. box-sizing: border-box;
  607. margin: 14rpx 10rpx 0 0;
  608. color: #fff;
  609. }
  610. }
  611. </style>