index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  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.page = 1
  265. if (type == 18) {
  266. this.eqlistdata = []
  267. this.eqlist()
  268. } else if (type == 17) {
  269. this.eqlistdata = []
  270. this.tubulareqlist()
  271. } else if (type == 13) {
  272. this.eqlistdata = []
  273. this.sfeqlist()
  274. }
  275. },
  276. timezhuan(time) {
  277. function fun(a) {
  278. return String(a).length == 1 ? '0' + a : a
  279. }
  280. let date = new Date(time * 1000)
  281. let y = date.getFullYear()
  282. let m = date.getMonth() + 1
  283. let d = date.getDate()
  284. let h = date.getHours()
  285. let min = date.getMinutes()
  286. let sec = date.getSeconds()
  287. return `${y}-${fun(m)}-${fun(d)} ${fun(h)}:${fun(min)}:${fun(sec)}`
  288. },
  289. newdata(item) {
  290. if (this.side_type == 17) {
  291. uni.navigateTo({
  292. url: "realtimedata?item=" + JSON.stringify(item)
  293. })
  294. } else {
  295. uni.navigateTo({
  296. url: "weathdata?item=" + JSON.stringify(item)
  297. })
  298. }
  299. },
  300. selectaddress(city, name) { //获取分布位置
  301. uni.request({
  302. type: "GET",
  303. url: "https://restapi.amap.com/v3/geocode/geo?address=" + city +
  304. "&key=78ce288400f4fc6d9458989875c833c2",
  305. dataType: "json",
  306. complete: ress => {
  307. console.log(ress)
  308. if (ress.data.status == 1) {
  309. // ress.data.geocodes[0].location
  310. uni.navigateTo({
  311. url: "./irrmap?lnglat=" + ress.data.geocodes[0].location +
  312. "&basename=" + name
  313. })
  314. } else {
  315. uni.showToast({
  316. title: "地址编译失败",
  317. icon: "none"
  318. })
  319. }
  320. }
  321. });
  322. },
  323. async pumpcontrol(en) { //水肥开关
  324. console.log(en)
  325. const res = await this.$myRequest({
  326. url: '/api/api_gateway?method=irrigation_system.hydropower.water_pump_control',
  327. data: {
  328. times: Math.floor(this.timevalue * 60),
  329. device_id: this.selid,
  330. status: en ? 1 : 0
  331. }
  332. })
  333. console.log(res)
  334. if (res.code == 200) {
  335. uni.showToast({
  336. title: "操作成功",
  337. icon: "none"
  338. })
  339. } else {
  340. uni.showToast({
  341. title: res.msg,
  342. icon: "none"
  343. })
  344. this.eqlistdata[this.selindex].water_pump_switch2 = !this.eqlistdata[this.selindex]
  345. .water_pump_switch2
  346. }
  347. this.timevalue = ""
  348. },
  349. switchchange(e, id, index) { //水肥 开关
  350. console.log(e)
  351. if (e) {
  352. this.show = true
  353. this.selindex = index
  354. this.selid = id
  355. } else {
  356. this.selid = id
  357. this.pumpcontrol(false)
  358. }
  359. },
  360. async switchchange2(e, id, index) { //水电开关
  361. console.log(id)
  362. const res = await this.$myRequest({
  363. url: '/api/api_gateway?method=irrigation_system.waterfertilizer.water_fertilizer_control',
  364. data: {
  365. device_ids: id,
  366. isopen: e ? 1 : 0
  367. }
  368. })
  369. console.log(res)
  370. if (res.info == "ok") {
  371. uni.showToast({
  372. title: "操作成功",
  373. icon: "none"
  374. })
  375. } else {
  376. uni.showToast({
  377. title: res.msg,
  378. icon: "none"
  379. })
  380. this.eqlistdata[index].status2 = !this.eqlistdata[index].status2
  381. }
  382. },
  383. modalcancel() { //水肥开关 确定
  384. this.eqlistdata[this.selindex].water_pump_switch2 = !this.eqlistdata[this.selindex].water_pump_switch2
  385. this.timevalue = ""
  386. },
  387. modalconfirm() { //水肥开关 取消
  388. this.show = true
  389. if (this.timevalue == "") {
  390. uni.showToast({
  391. title: "请输入开泵时间",
  392. icon: "none"
  393. })
  394. } else {
  395. this.show = false
  396. this.pumpcontrol(true)
  397. }
  398. },
  399. changeremark(item, index) { //修改备注
  400. this.timevalueremark = item.device_notes
  401. this.showremark = true
  402. this.selindex = index
  403. this.selid = item.device_id
  404. },
  405. modalcancelremark() { //修改备注 取消
  406. },
  407. modalconfirmremark() { //修改备注 确定
  408. this.showremark = true
  409. if (this.timevalueremark == "") {
  410. uni.showToast({
  411. title: "请输入设备备注",
  412. icon: "none"
  413. })
  414. } else {
  415. this.showremark = false
  416. this.setchangeremark()
  417. }
  418. },
  419. async setchangeremark() { //水肥开关
  420. const res = await this.$myRequest({
  421. url: '/api/api_gateway?method=irrigation_system.hydropower.water_pump_modify_device_notes',
  422. data: {
  423. device_id: this.selid,
  424. content: this.timevalueremark
  425. }
  426. })
  427. console.log(res)
  428. if (res) {
  429. uni.showToast({
  430. title: "操作成功",
  431. icon: "none"
  432. })
  433. this.eqlistdata[this.selindex].device_notes = this.timevalueremark
  434. }
  435. },
  436. },
  437. onLoad() {
  438. // this.tubulareqlist()
  439. uni.getStorage({
  440. key: "jurisdiction",
  441. success: (res) => {
  442. let items = JSON.parse(res.data).filter((item) => {
  443. return item.pur_id == 202
  444. })
  445. var itemarr = items[0].children
  446. console.log(itemarr)
  447. for (var i = 0; i < itemarr.length; i++) {
  448. switch (itemarr[i].pur_id) {
  449. case 204:
  450. this.equipArr[0].tf = true
  451. break
  452. case 203:
  453. this.equipArr[1].tf = true
  454. break
  455. case 195:
  456. this.equipArr[2].tf = true
  457. break;
  458. }
  459. }
  460. for (var i = 0; i < this.equipArr.length; i++) {
  461. if (this.equipArr[i].tf) {
  462. if (i == 0) {
  463. this.tubulareqlist();
  464. } else if (i == 1) {
  465. this.eqlist();
  466. } else {
  467. this.sfeqlist();
  468. }
  469. this.active = i
  470. this.side_type = this.equipArr[i].type
  471. break
  472. }
  473. }
  474. }
  475. })
  476. },
  477. onReachBottom() {
  478. this.page++
  479. // this.eqlist()
  480. if (this.side_type == 18) {
  481. this.eqlist()
  482. } else if (this.side_type == 17) {
  483. this.tubulareqlist()
  484. } else if (this.side_type == 13) {
  485. this.sfeqlist()
  486. }
  487. },
  488. onPageScroll(e) { //nvue暂不支持滚动监听,可用bindingx代替
  489. if (e.scrollTop > 200) { //距离大于200时显示
  490. this.isTop = true
  491. } else { //距离小于200时隐藏
  492. this.isTop = false
  493. }
  494. },
  495. }
  496. </script>
  497. <style lang="scss">
  498. page {
  499. background: $uni-bg-color-grey;
  500. }
  501. .inputs {
  502. height: 54rpx;
  503. background-color: #E4E4E4;
  504. border-radius: 27rpx;
  505. position: absolute;
  506. right: 20rpx;
  507. top: 20rpx;
  508. transition: width 0.5s;
  509. overflow: hidden;
  510. padding-top: 8rpx;
  511. box-sizing: border-box;
  512. .inputbox {
  513. width: 85%;
  514. text-indent: 1rem;
  515. font-size: 26rpx;
  516. }
  517. .icon {
  518. position: absolute;
  519. top: 8rpx;
  520. right: 26rpx;
  521. }
  522. }
  523. /deep/.uni-icons {
  524. font-size: 40rpx !important;
  525. }
  526. .image {
  527. position: fixed;
  528. top: 84px;
  529. width: 100%;
  530. height: 160rpx;
  531. z-index: 555;
  532. }
  533. .loading {
  534. position: fixed;
  535. top: 440px;
  536. width: 95%;
  537. left: 2.5%;
  538. text-align: center;
  539. z-index: 9;
  540. .img {
  541. width: 300rpx;
  542. height: 40rpx;
  543. }
  544. }
  545. .tab-box {
  546. position: fixed;
  547. top: 170px;
  548. display: flex;
  549. justify-content: space-around;
  550. font-size: 30rpx;
  551. line-height: 80rpx;
  552. background-color: #FFFFFF;
  553. width: 100%;
  554. z-index: 2;
  555. .tab-item {
  556. cursor: pointer;
  557. position: relative;
  558. }
  559. ;
  560. .tab-item.active {
  561. .bottom-line {
  562. bottom: 0;
  563. position: absolute;
  564. display: inline-block;
  565. width: 90rpx;
  566. height: 6rpx;
  567. left: 0;
  568. right: 0;
  569. margin: auto;
  570. background: $uni-color-success;
  571. }
  572. }
  573. }
  574. .prevents {
  575. width: 100%;
  576. position: absolute;
  577. top: 180px;
  578. .prevents_item {
  579. width: 95%;
  580. margin: 0 auto 30rpx;
  581. border-radius: 10rpx;
  582. box-shadow: 0 0 10rpx #bcb9ca;
  583. padding: 20rpx 40rpx 20rpx 80rpx;
  584. box-sizing: border-box;
  585. position: relative;
  586. background-color: #fff;
  587. .prevents_item_img {
  588. width: 30rpx;
  589. height: 50rpx;
  590. position: absolute;
  591. top: -4rpx;
  592. left: 30rpx;
  593. }
  594. .prevents_item_top {
  595. display: flex;
  596. justify-content: space-between;
  597. height: 60rpx;
  598. border-bottom: 2rpx solid #F4F4F4;
  599. line-height: 60rpx;
  600. font-size: 26rpx;
  601. .red {
  602. color: #ff0000;
  603. }
  604. .green {
  605. color: #7DBB91;
  606. }
  607. }
  608. .prevents_item_bot {
  609. margin-top: 20rpx;
  610. font-size: 26rpx;
  611. color: #BDBDBD;
  612. .prevents_item_bot_item {
  613. height: 60rpx;
  614. line-height: 60rpx;
  615. display: flex;
  616. justify-content: space-between;
  617. color: #909696;
  618. p:first-child {
  619. width: 80%;
  620. overflow: hidden; //溢出隐藏
  621. white-space: nowrap; //禁止换行
  622. text-overflow: ellipsis; //...
  623. }
  624. p:nth-child(2) {
  625. height: 45rpx;
  626. color: #00B075;
  627. border-bottom: 1px solid #00B075;
  628. }
  629. }
  630. .prevents_item_bot_sapn0 {
  631. color: #00B075;
  632. }
  633. .prevents_item_bot_sapn1 {
  634. color: #FF4747;
  635. }
  636. .prevents_item_bot_sapn2 {
  637. color: #FFAB00;
  638. }
  639. }
  640. }
  641. }
  642. .top {
  643. position: fixed;
  644. right: 10px;
  645. bottom: 40px;
  646. z-index: 100;
  647. image {
  648. width: 100rpx;
  649. height: 100rpx;
  650. }
  651. .backtop {
  652. display: flex;
  653. justify-content: flex-end;
  654. margin-bottom: 10rpx;
  655. }
  656. .more {
  657. display: flex;
  658. }
  659. .box {
  660. width: 80rpx;
  661. height: 80rpx;
  662. background-color: rgba(161, 161, 161, 0.45);
  663. border-radius: 50%;
  664. text-align: center;
  665. line-height: 80rpx;
  666. box-sizing: border-box;
  667. margin: 14rpx 10rpx 0 0;
  668. color: #fff;
  669. }
  670. }
  671. .slot-content {
  672. width: 50%;
  673. margin: 30rpx auto;
  674. display: flex;
  675. line-height: 70rpx;
  676. }
  677. .slot-contentremark {
  678. width: 70%;
  679. margin: 30rpx auto;
  680. display: flex;
  681. line-height: 70rpx;
  682. }
  683. </style>