index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="灌溉控制系统" right-icon="search"
  7. @clickRight="clickRight" size="16"></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>
  14. <image :src="'http://www.hnyfwlw.com:8006/bigdata_app/image/irrigate/1.png'" mode="" class="image">
  15. </image>
  16. <view class="loading" v-if="loadingtf">
  17. <image src="../../static/images/ajax-loader.gif" mode="" class="img"></image>
  18. </view>
  19. <view class="tab-box">
  20. <view v-for="(item,index) in equipArr" :key="item.type" v-if="item.tf"
  21. @click="tabClick(index,item.type)" :class="['tab-item',active==index?'active':'']">
  22. <text>{{item.name}}</text>
  23. <text class="bottom-line"></text>
  24. </view>
  25. </view>
  26. <view class="prevents">
  27. <view class="prevents_item" v-for="item,index in eqlistdata" :key="index" @click="eqdetails(item)">
  28. <view class="" v-if="side_type == 18">
  29. <image
  30. :src="item.device_status==1?'http://www.hnyfwlw.com:8006/bigdata_app/image/prevention/6.png':'http://www.hnyfwlw.com:8006/bigdata_app/image/prevention/7.png'"
  31. mode="" class="prevents_item_img"></image>
  32. <view class="prevents_item_top">
  33. <p>设备名称:{{item.device_name}}</p>
  34. <view class="" style="display: flex;">
  35. <view class="" :style="{'margin-right': '10rpx','color':item.status2?'#00B075':'#f00'}">
  36. {{item.status2?"已启用":"已禁用"}}
  37. </view>
  38. <u-switch v-model="item.status2" v-if="$QueryPermission(256)" size="35" active-color="#00B075"
  39. style="margin-top: 10rpx;" inactive-color="#f00"
  40. @change="switchchange2($event,item.d_id,index)">
  41. </u-switch>
  42. </view>
  43. </view>
  44. <view class="prevents_item_bot">
  45. <view class="prevents_item_bot_item">
  46. <p>设备 ID:{{item.device_id}}</p>
  47. <p @click="newdata(item)" v-if="$QueryPermission(205)">数据查看</p>
  48. </view>
  49. <p style="color:#909696;height: 60rpx;line-height: 60rpx;">
  50. 设备状态:{{item.device_status==1?"在线":"离线"}}</p>
  51. <p style="color:#909696;height: 60rpx;line-height: 60rpx;">设备备注:{{item.device_notes}}
  52. <u-icon name="edit-pen" size="36" color="#00B075" @click="changeremark(item,index)">
  53. </u-icon>
  54. </p>
  55. <view class="prevents_item_bot_item">
  56. <p>地址:{{item.city}}</p>
  57. <u-icon name="map" size="40" color="#00B075"
  58. @click="selectaddress(item.city,item.device_name)"></u-icon>
  59. </view>
  60. </view>
  61. </view>
  62. <view class="" v-if="side_type == 17">
  63. <image src="http://www.hnyfwlw.com:8006/bigdata_app/image/prevention/6.png" mode=""
  64. class="prevents_item_img"></image>
  65. <view class="prevents_item_top">
  66. <p>设备名称:{{item.device_name}}</p>
  67. <view class="" style="display: flex;">
  68. <view class=""
  69. :style="{'margin-right': '10rpx','color':item.water_pump_switch2?'#00B075':'#f00'}">
  70. {{item.water_pump_switch2?"已开泵":"已关泵"}}
  71. </view>
  72. <u-switch v-model="item.water_pump_switch2" v-if="$QueryPermission(254)" size="35" active-color="#00B075"
  73. inactive-color="#f00" style="margin-top: 10rpx;"
  74. @change="switchchange($event,item.device_id,index)">
  75. </u-switch>
  76. </view>
  77. </view>
  78. <view class="prevents_item_bot">
  79. <view class="prevents_item_bot_item">
  80. <p>设备 ID:{{item.device_id}}</p>
  81. <p @click="newdata(item)" v-if="item.water_pump_switch2">实时数据</p>
  82. </view>
  83. <p style="color:#909696;height: 60rpx;line-height: 60rpx;">
  84. 设备状态:{{item.device_status==1?"在线":"离线"}}</p>
  85. <p style="color:#909696;height: 60rpx;line-height: 60rpx;">设备备注:{{item.device_notes}}
  86. <u-icon name="edit-pen" size="36" color="#00B075" @click="changeremark(item,index)">
  87. </u-icon>
  88. </p>
  89. <view class="prevents_item_bot_item">
  90. <p>地址:{{item.city}}</p>
  91. <u-icon name="map" size="40" color="#00B075"
  92. @click="selectaddress(item.city,item.device_name)"></u-icon>
  93. </view>
  94. </view>
  95. </view>
  96. <view class="" v-if="side_type == 13">
  97. <image src="http://www.hnyfwlw.com:8006/bigdata_app/image/prevention/6.png" mode=""
  98. class="prevents_item_img"></image>
  99. <view class="prevents_item_top">
  100. <p>设备名称:{{item.device_name}}</p>
  101. </view>
  102. <view class="prevents_item_bot">
  103. <p>设备 ID:{{item.equip_id || item.device_id}}</p>
  104. <p>最新上报时间:{{item.uptime|timeFormat()}}</p>
  105. </view>
  106. </view>
  107. </view>
  108. </view>
  109. </view>
  110. <u-modal v-model="show" :show-cancel-button="true" title="请设置开泵时间" @confirm="modalconfirm"
  111. @cancel="modalcancel">
  112. <view class="slot-content">
  113. <u-input v-model="timevalue" type="number" />分钟
  114. </view>
  115. </u-modal>
  116. <u-modal v-model="showremark" :show-cancel-button="true" title="请填写设备备注" @confirm="modalconfirmremark"
  117. @cancel="modalcancelremark">
  118. <view class="slot-contentremark">
  119. <u-input v-model="timevalueremark" maxlength="12" />
  120. </view>
  121. </u-modal>
  122. <view class="top">
  123. <view class="backtop" @click="top" v-if="isTop">
  124. <image src="../../static/images/1.png" mode="" class="img0"></image>
  125. </view>
  126. </view>
  127. </view>
  128. </template>
  129. <script>
  130. import {
  131. Debounce
  132. } from "../../util/anitthro.js"
  133. export default {
  134. data() {
  135. return {
  136. page: 1,
  137. size: 10,
  138. eqlistdata: [],
  139. isTop: false,
  140. filtrateTF: false,
  141. device_status: "",
  142. width: 0, //顶部搜索栏宽度
  143. imports: "", //搜索设备id
  144. loadingtf: false,
  145. equipArr: [{
  146. name: '机井水电双控',
  147. type: 17, //5 环境监测 15 管式墒情
  148. list: [],
  149. pageIndex: 1,
  150. tf: false,
  151. }, {
  152. name: '水肥一体化(L)',
  153. type: 18, //5 环境监测 15 管式墒情
  154. list: [],
  155. pageIndex: 1,
  156. tf: false,
  157. }, {
  158. name: '水肥一体化(X)',
  159. type: 13, //5 环境监测 15 管式墒情
  160. list: [],
  161. pageIndex: 1,
  162. tf: false,
  163. }],
  164. active: 0, //tab选中的下标
  165. side_type: 17, //当前选中的设备类型
  166. show: false,
  167. timevalue: "",
  168. selindex: "", //选中的设备index
  169. selid: "", //选中的设备id
  170. showremark: false,
  171. timevalueremark: ""
  172. }
  173. },
  174. methods: {
  175. async eqlist() { //设备列表 水肥一体化 L
  176. this.loadingtf = true
  177. const res = await this.$myRequest({
  178. url: '/api/api_gateway?method=irrigation_system.waterfertilizer.water_fertilizer_list',
  179. data: {
  180. page: this.page,
  181. page_size: 10,
  182. content: this.imports
  183. }
  184. })
  185. console.log(res)
  186. this.loadingtf = false
  187. for (var i = 0; i < res.data.length; i++) {
  188. res.data[i]["status2"] = res.data[i].status == 1 ? true : false
  189. }
  190. this.eqlistdata = this.eqlistdata.concat(res.data)
  191. },
  192. async tubulareqlist() { //水电双计
  193. this.loadingtf = true
  194. const res = await this.$myRequest({
  195. url: '/api/api_gateway?method=irrigation_system.hydropower.hydropower_list',
  196. data: {
  197. page: this.page,
  198. page_size: 10,
  199. content: this.imports
  200. }
  201. })
  202. console.log(res)
  203. this.loadingtf = false
  204. for (var i = 0; i < res.data.length; i++) {
  205. res.data[i]["water_pump_switch2"] = res.data[i].water_pump_switch == 1 ? true : false
  206. }
  207. this.eqlistdata = this.eqlistdata.concat(res.data)
  208. // console.log(res)
  209. },
  210. async sfeqlist() { //设备列表
  211. this.loadingtf = true
  212. const res = await this.$myRequest({
  213. url: '/api/api_gateway?method=weather.weather.sf_page',
  214. data: {
  215. page: this.page,
  216. page_size: "10",
  217. device_id: this.imports,
  218. }
  219. })
  220. this.loadingtf = false
  221. this.eqlistdata = this.eqlistdata.concat(res.ids)
  222. console.log(this.eqlistdata)
  223. },
  224. clickRight() {
  225. this.width = 600
  226. },
  227. clickLeft() {
  228. uni.switchTab({
  229. url: "../index/index"
  230. })
  231. },
  232. eqdetails(data) {
  233. if (this.side_type == 13) {
  234. uni.navigateTo({
  235. url: "../waterandfer/datails?shebei=" + JSON.stringify(data)
  236. })
  237. }
  238. },
  239. top() {
  240. uni.pageScrollTo({
  241. scrollTop: 0,
  242. duration: 500
  243. })
  244. },
  245. search() { //搜索按钮搜索
  246. this.searchinp()
  247. },
  248. searchinp() { //自动搜索
  249. Debounce(() => {
  250. this.page = 1
  251. this.eqlistdata = []
  252. if (this.side_type == 18) {
  253. this.eqlist()
  254. } else if (this.side_type == 17) {
  255. this.tubulareqlist()
  256. } else if (this.side_type == 13) {
  257. this.sfeqlist()
  258. }
  259. }, 1000)()
  260. },
  261. tabClick(index, type) {
  262. this.active = index
  263. this.side_type = type
  264. this.imports =''
  265. this.page = 1
  266. if (type == 18) {
  267. this.eqlistdata = []
  268. this.eqlist()
  269. } else if (type == 17) {
  270. this.eqlistdata = []
  271. this.tubulareqlist()
  272. } else if (type == 13) {
  273. this.eqlistdata = []
  274. this.sfeqlist()
  275. }
  276. },
  277. timezhuan(time) {
  278. function fun(a) {
  279. return String(a).length == 1 ? '0' + a : a
  280. }
  281. let date = new Date(time * 1000)
  282. let y = date.getFullYear()
  283. let m = date.getMonth() + 1
  284. let d = date.getDate()
  285. let h = date.getHours()
  286. let min = date.getMinutes()
  287. let sec = date.getSeconds()
  288. return `${y}-${fun(m)}-${fun(d)} ${fun(h)}:${fun(min)}:${fun(sec)}`
  289. },
  290. newdata(item) {
  291. if (this.side_type == 17) {
  292. uni.navigateTo({
  293. url: "realtimedata?item=" + JSON.stringify(item)
  294. })
  295. } else {
  296. uni.navigateTo({
  297. url: "weathdata?item=" + JSON.stringify(item)
  298. })
  299. }
  300. },
  301. selectaddress(city, name) { //获取分布位置
  302. uni.request({
  303. type: "GET",
  304. url: "https://restapi.amap.com/v3/geocode/geo?address=" + city +
  305. "&key=78ce288400f4fc6d9458989875c833c2",
  306. dataType: "json",
  307. complete: ress => {
  308. console.log(ress)
  309. if (ress.data.status == 1) {
  310. // ress.data.geocodes[0].location
  311. uni.navigateTo({
  312. url: "./irrmap?lnglat=" + ress.data.geocodes[0].location +
  313. "&basename=" + name
  314. })
  315. } else {
  316. uni.showToast({
  317. title: "地址编译失败",
  318. icon: "none"
  319. })
  320. }
  321. }
  322. });
  323. },
  324. async pumpcontrol(en) { //水肥开关
  325. console.log(en)
  326. const res = await this.$myRequest({
  327. url: '/api/api_gateway?method=irrigation_system.hydropower.water_pump_control',
  328. data: {
  329. times: Math.floor(this.timevalue * 60),
  330. device_id: this.selid,
  331. status: en ? 1 : 0
  332. }
  333. })
  334. console.log(res)
  335. if (res.code == 200) {
  336. uni.showToast({
  337. title: "操作成功",
  338. icon: "none"
  339. })
  340. } else {
  341. uni.showToast({
  342. title: res.msg,
  343. icon: "none"
  344. })
  345. this.eqlistdata[this.selindex].water_pump_switch2 = !this.eqlistdata[this.selindex]
  346. .water_pump_switch2
  347. }
  348. this.timevalue = ""
  349. },
  350. switchchange(e, id, index) { //水肥 开关
  351. console.log(e)
  352. if (e) {
  353. this.show = true
  354. this.selindex = index
  355. this.selid = id
  356. } else {
  357. this.selid = id
  358. this.pumpcontrol(false)
  359. }
  360. },
  361. async switchchange2(e, id, index) { //水电开关
  362. console.log(id)
  363. const res = await this.$myRequest({
  364. url: '/api/api_gateway?method=irrigation_system.waterfertilizer.water_fertilizer_control',
  365. data: {
  366. device_ids: id,
  367. isopen: e ? 1 : 0
  368. }
  369. })
  370. console.log(res)
  371. if (res.info == "ok") {
  372. uni.showToast({
  373. title: "操作成功",
  374. icon: "none"
  375. })
  376. } else {
  377. uni.showToast({
  378. title: res.msg,
  379. icon: "none"
  380. })
  381. this.eqlistdata[index].status2 = !this.eqlistdata[index].status2
  382. }
  383. },
  384. modalcancel() { //水肥开关 确定
  385. this.eqlistdata[this.selindex].water_pump_switch2 = !this.eqlistdata[this.selindex].water_pump_switch2
  386. this.timevalue = ""
  387. },
  388. modalconfirm() { //水肥开关 取消
  389. this.show = true
  390. if (this.timevalue == "") {
  391. uni.showToast({
  392. title: "请输入开泵时间",
  393. icon: "none"
  394. })
  395. } else {
  396. this.show = false
  397. this.pumpcontrol(true)
  398. }
  399. },
  400. changeremark(item, index) { //修改备注
  401. this.timevalueremark = item.device_notes
  402. this.showremark = true
  403. this.selindex = index
  404. this.selid = item.device_id
  405. },
  406. modalcancelremark() { //修改备注 取消
  407. },
  408. modalconfirmremark() { //修改备注 确定
  409. this.showremark = true
  410. if (this.timevalueremark == "") {
  411. uni.showToast({
  412. title: "请输入设备备注",
  413. icon: "none"
  414. })
  415. } else {
  416. this.showremark = false
  417. this.setchangeremark()
  418. }
  419. },
  420. async setchangeremark() { //水肥开关
  421. const res = await this.$myRequest({
  422. url: '/api/api_gateway?method=irrigation_system.hydropower.water_pump_modify_device_notes',
  423. data: {
  424. device_id: this.selid,
  425. content: this.timevalueremark
  426. }
  427. })
  428. console.log(res)
  429. if (res) {
  430. uni.showToast({
  431. title: "操作成功",
  432. icon: "none"
  433. })
  434. this.eqlistdata[this.selindex].device_notes = this.timevalueremark
  435. }
  436. },
  437. },
  438. onLoad() {
  439. // this.tubulareqlist()
  440. uni.getStorage({
  441. key: "jurisdiction",
  442. success: (res) => {
  443. let items = JSON.parse(res.data).filter((item) => {
  444. return item.pur_id == 202
  445. })
  446. var itemarr = items[0].children
  447. console.log(itemarr)
  448. for (var i = 0; i < itemarr.length; i++) {
  449. switch (itemarr[i].pur_id) {
  450. case 204:
  451. this.equipArr[0].tf = true
  452. break
  453. case 203:
  454. this.equipArr[1].tf = true
  455. break
  456. case 195:
  457. this.equipArr[2].tf = true
  458. break;
  459. }
  460. }
  461. for (var i = 0; i < this.equipArr.length; i++) {
  462. if (this.equipArr[i].tf) {
  463. if (i == 0) {
  464. this.tubulareqlist();
  465. } else if (i == 1) {
  466. this.eqlist();
  467. } else {
  468. this.sfeqlist();
  469. }
  470. this.active = i
  471. this.side_type = this.equipArr[i].type
  472. break
  473. }
  474. }
  475. }
  476. })
  477. },
  478. onReachBottom() {
  479. this.page++
  480. // this.eqlist()
  481. if (this.side_type == 18) {
  482. this.eqlist()
  483. } else if (this.side_type == 17) {
  484. this.tubulareqlist()
  485. } else if (this.side_type == 13) {
  486. this.sfeqlist()
  487. }
  488. },
  489. onPageScroll(e) { //nvue暂不支持滚动监听,可用bindingx代替
  490. if (e.scrollTop > 200) { //距离大于200时显示
  491. this.isTop = true
  492. } else { //距离小于200时隐藏
  493. this.isTop = false
  494. }
  495. },
  496. }
  497. </script>
  498. <style lang="scss">
  499. page {
  500. background: $uni-bg-color-grey;
  501. }
  502. .inputs {
  503. height: 54rpx;
  504. background-color: #E4E4E4;
  505. border-radius: 27rpx;
  506. position: absolute;
  507. right: 20rpx;
  508. top: 20rpx;
  509. transition: width 0.5s;
  510. overflow: hidden;
  511. padding-top: 8rpx;
  512. box-sizing: border-box;
  513. .inputbox {
  514. width: 85%;
  515. text-indent: 1rem;
  516. font-size: 26rpx;
  517. }
  518. .icon {
  519. position: absolute;
  520. top: 8rpx;
  521. right: 26rpx;
  522. }
  523. }
  524. /deep/.uni-icons {
  525. font-size: 40rpx !important;
  526. }
  527. .image {
  528. position: fixed;
  529. top: 84px;
  530. width: 100%;
  531. height: 160rpx;
  532. z-index: 555;
  533. }
  534. .loading {
  535. position: fixed;
  536. top: 440px;
  537. width: 95%;
  538. left: 2.5%;
  539. text-align: center;
  540. z-index: 9;
  541. .img {
  542. width: 300rpx;
  543. height: 40rpx;
  544. }
  545. }
  546. .tab-box {
  547. position: fixed;
  548. top: 170px;
  549. display: flex;
  550. justify-content: space-around;
  551. font-size: 30rpx;
  552. line-height: 80rpx;
  553. background-color: #FFFFFF;
  554. width: 100%;
  555. z-index: 2;
  556. .tab-item {
  557. cursor: pointer;
  558. position: relative;
  559. }
  560. ;
  561. .tab-item.active {
  562. .bottom-line {
  563. bottom: 0;
  564. position: absolute;
  565. display: inline-block;
  566. width: 90rpx;
  567. height: 6rpx;
  568. left: 0;
  569. right: 0;
  570. margin: auto;
  571. background: $uni-color-success;
  572. }
  573. }
  574. }
  575. .prevents {
  576. width: 100%;
  577. position: absolute;
  578. top: 180px;
  579. .prevents_item {
  580. width: 95%;
  581. margin: 0 auto 30rpx;
  582. border-radius: 10rpx;
  583. box-shadow: 0 0 10rpx #bcb9ca;
  584. padding: 20rpx 40rpx 20rpx 80rpx;
  585. box-sizing: border-box;
  586. position: relative;
  587. background-color: #fff;
  588. .prevents_item_img {
  589. width: 30rpx;
  590. height: 50rpx;
  591. position: absolute;
  592. top: -4rpx;
  593. left: 30rpx;
  594. }
  595. .prevents_item_top {
  596. display: flex;
  597. justify-content: space-between;
  598. height: 60rpx;
  599. border-bottom: 2rpx solid #F4F4F4;
  600. line-height: 60rpx;
  601. font-size: 26rpx;
  602. .red {
  603. color: #ff0000;
  604. }
  605. .green {
  606. color: #7DBB91;
  607. }
  608. }
  609. .prevents_item_bot {
  610. margin-top: 20rpx;
  611. font-size: 26rpx;
  612. color: #BDBDBD;
  613. .prevents_item_bot_item {
  614. height: 60rpx;
  615. line-height: 60rpx;
  616. display: flex;
  617. justify-content: space-between;
  618. color: #909696;
  619. p:first-child {
  620. width: 80%;
  621. overflow: hidden; //溢出隐藏
  622. white-space: nowrap; //禁止换行
  623. text-overflow: ellipsis; //...
  624. }
  625. p:nth-child(2) {
  626. height: 45rpx;
  627. color: #00B075;
  628. border-bottom: 1px solid #00B075;
  629. }
  630. }
  631. .prevents_item_bot_sapn0 {
  632. color: #00B075;
  633. }
  634. .prevents_item_bot_sapn1 {
  635. color: #FF4747;
  636. }
  637. .prevents_item_bot_sapn2 {
  638. color: #FFAB00;
  639. }
  640. }
  641. }
  642. }
  643. .top {
  644. position: fixed;
  645. right: 10px;
  646. bottom: 40px;
  647. z-index: 100;
  648. image {
  649. width: 100rpx;
  650. height: 100rpx;
  651. }
  652. .backtop {
  653. display: flex;
  654. justify-content: flex-end;
  655. margin-bottom: 10rpx;
  656. }
  657. .more {
  658. display: flex;
  659. }
  660. .box {
  661. width: 80rpx;
  662. height: 80rpx;
  663. background-color: rgba(161, 161, 161, 0.45);
  664. border-radius: 50%;
  665. text-align: center;
  666. line-height: 80rpx;
  667. box-sizing: border-box;
  668. margin: 14rpx 10rpx 0 0;
  669. color: #fff;
  670. }
  671. }
  672. .slot-content {
  673. width: 50%;
  674. margin: 30rpx auto;
  675. display: flex;
  676. line-height: 70rpx;
  677. }
  678. .slot-contentremark {
  679. width: 70%;
  680. margin: 30rpx auto;
  681. display: flex;
  682. line-height: 70rpx;
  683. }
  684. </style>