search.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <template>
  2. <view>
  3. <view class="search_top">
  4. <view class="search_top_input">
  5. <input type="text" value="" placeholder="请输入设备ID或设备名称" v-model="imports" @input="searchinp" />
  6. <u-icon name="search" size="40" class="icon" @click="searchinp"></u-icon>
  7. </view>
  8. </view>
  9. <view class="prevents">
  10. <view class="prevents_item" v-for="item,index in eqlistdata" :key="item.d_id" @click="eqdetails(item)">
  11. <view class="" v-if="side_type == 18">
  12. <image
  13. :src="item.device_status==1?$imageURL+ '/bigdata_app/image/prevention/6.png':$imageURL+ '/bigdata_app/image/prevention/7.png'"
  14. mode="" class="prevents_item_img"></image>
  15. <view class="prevents_item_top">
  16. <p>设备名称:{{item.device_name}}</p>
  17. <view class="" style="display: flex;">
  18. <view class="" :style="{'margin-right': '10rpx','color':item.status2?'#00B075':'#f00'}">
  19. {{item.status2?"已启用":"已禁用"}}
  20. </view>
  21. <switch @change="switchchange2($event,item.d_id,index)" color="#00B075" :checked="item.status2" style="zoom:0.6" />
  22. </view>
  23. </view>
  24. <view class="prevents_item_bot">
  25. <view class="prevents_item_bot_item">
  26. <p>设备 ID:{{item.device_id}}</p>
  27. <p @click="newdata(item)">数据查看</p>
  28. </view>
  29. <p style="color:#909696;height: 60rpx;line-height: 60rpx;">
  30. 设备状态:{{item.device_status==1?"在线":"离线"}}</p>
  31. <p style="color:#909696;height: 60rpx;line-height: 60rpx;">设备备注:{{item.device_notes}}
  32. <u-icon name="edit-pen" size="36" color="#00B075" @click="changeremark(item,index)">
  33. </u-icon>
  34. </p>
  35. <view class="prevents_item_bot_item">
  36. <p>地址:{{item.city}}</p>
  37. <u-icon name="map" size="40" color="#00B075"
  38. @click="selectaddress(item.city,item.device_name)"></u-icon>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="" v-if="side_type == 17">
  43. <image :src="$imageURL+ '/bigdata_app/image/prevention/6.png'" mode=""
  44. class="prevents_item_img"></image>
  45. <view class="prevents_item_top">
  46. <p>设备名称:{{item.device_name}}</p>
  47. <view class="" style="display: flex;">
  48. <view class=""
  49. :style="{'margin-right': '10rpx','color':item.water_pump_switch2?'#00B075':'#f00'}">
  50. {{item.water_pump_switch2?"已开泵":"已关泵"}}
  51. </view>
  52. <switch @change="switchchange($event,item.d_id,index)" color="#00B075" :checked="item.water_pump_switch2" style="zoom:0.6" />
  53. </view>
  54. </view>
  55. <view class="prevents_item_bot">
  56. <view class="prevents_item_bot_item">
  57. <p>设备 ID:{{item.device_id}}</p>
  58. <p @click="newdata(item)" v-if="item.water_pump_switch2">实时数据</p>
  59. </view>
  60. <p style="color:#909696;height: 60rpx;line-height: 60rpx;">
  61. 设备状态:{{item.device_status==1?"在线":"离线"}}</p>
  62. <p style="color:#909696;height: 60rpx;line-height: 60rpx;">设备备注:{{item.device_notes}}
  63. <u-icon name="edit-pen" size="36" color="#00B075" @click="changeremark(item,index)">
  64. </u-icon>
  65. </p>
  66. <view class="prevents_item_bot_item">
  67. <p>地址:{{item.city}}</p>
  68. <u-icon name="map" size="40" color="#00B075"
  69. @click="selectaddress(item.city,item.device_name)"></u-icon>
  70. </view>
  71. </view>
  72. </view>
  73. <view class="" v-if="side_type == 13">
  74. <image :src="$imageURL+ '/bigdata_app/image/prevention/6.png'" mode=""
  75. class="prevents_item_img"></image>
  76. <view class="prevents_item_top">
  77. <p>设备名称:{{item.device_name}}</p>
  78. </view>
  79. <view class="prevents_item_bot">
  80. <p>设备 ID:{{item.equip_id || item.device_id}}</p>
  81. <p>最新上报时间:{{item.uptime|timeFormat()}}</p>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. <u-modal v-model="show" :showCancelButton="true" title="请设置开泵时间" @confirm="modalconfirm" @cancel="modalcancel">
  87. <view class="slot-content">
  88. <u-input v-model="timevalue" type="number" style="width: 80%;"/>
  89. <p style="font-size: 12px;">分钟</p>
  90. </view>
  91. </u-modal>
  92. <u-modal v-model="showremark" :showCancelButton="true" title="请填写设备备注" @confirm="modalconfirmremark"
  93. @cancel="modalcancelremark">
  94. <view class="slot-contentremark">
  95. <u-input v-model="timevalueremark" maxlength="12" />
  96. </view>
  97. </u-modal>
  98. <view class="top">
  99. <view class="backtop" @click="top" v-if="isTop">
  100. <image src="../../static/images/1.png" mode="" class="img0"></image>
  101. </view>
  102. </view>
  103. </view>
  104. </template>
  105. <script>
  106. import {
  107. Debounce,
  108. Throttle
  109. } from "../../util/anitthro.js"
  110. export default {
  111. data() {
  112. return {
  113. eqlistdata:[],
  114. imports:"",
  115. side_type:"",
  116. page:1,
  117. show: false,
  118. showremark: false,
  119. isTop:false
  120. }
  121. },
  122. methods: {
  123. async eqlist() { //设备列表 水肥一体化 L
  124. this.loadingtf = true
  125. const res = await this.$myRequest({
  126. url: '/api/api_gateway?method=irrigation_system.waterfertilizer.water_fertilizer_list',
  127. data: {
  128. page: this.page,
  129. page_size: 10,
  130. content: this.imports
  131. }
  132. })
  133. console.log(res)
  134. this.loadingtf = false
  135. for (var i = 0; i < res.data.length; i++) {
  136. res.data[i]["status2"] = res.data[i].status == 1 ? true : false
  137. }
  138. this.eqlistdata = this.eqlistdata.concat(res.data)
  139. },
  140. async tubulareqlist() { //水电双计
  141. this.loadingtf = true
  142. const res = await this.$myRequest({
  143. url: '/api/api_gateway?method=irrigation_system.hydropower.hydropower_list',
  144. data: {
  145. page: this.page,
  146. page_size: 10,
  147. content: this.imports
  148. }
  149. })
  150. console.log(res)
  151. this.loadingtf = false
  152. for (var i = 0; i < res.data.length; i++) {
  153. res.data[i]["water_pump_switch2"] = res.data[i].water_pump_switch == 1 ? true : false
  154. }
  155. this.eqlistdata = this.eqlistdata.concat(res.data)
  156. console.log(this.eqlistdata)
  157. },
  158. async sfeqlist() { //设备列表
  159. this.loadingtf = true
  160. const res = await this.$myRequest({
  161. url: '/api/api_gateway?method=weather.weather.sf_page',
  162. data: {
  163. page: this.page,
  164. page_size: "10",
  165. device_id: this.imports,
  166. }
  167. })
  168. this.loadingtf = false
  169. this.eqlistdata = this.eqlistdata.concat(res.ids)
  170. console.log(this.eqlistdata)
  171. },
  172. eqdetails(data) {
  173. if (this.side_type == 13) {
  174. uni.navigateTo({
  175. url: "../waterandfer/datails?shebei=" + JSON.stringify(data)
  176. })
  177. }
  178. },
  179. top() {
  180. uni.pageScrollTo({
  181. scrollTop: 0,
  182. duration: 500
  183. })
  184. },
  185. search() { //搜索按钮搜索
  186. // this.searchinp()
  187. console.log(111)
  188. uni.navigateTo({
  189. url:"./search?side_type="+this.side_type
  190. })
  191. },
  192. searchinp() { //自动搜索
  193. Debounce(() => {
  194. this.page = 1
  195. this.eqlistdata = []
  196. if (this.side_type == 18) {
  197. this.eqlist()
  198. } else if (this.side_type == 17) {
  199. this.tubulareqlist()
  200. } else if (this.side_type == 13) {
  201. this.sfeqlist()
  202. }
  203. }, 1000)()
  204. },
  205. tabClick(index, type) {
  206. this.active = index
  207. this.side_type = type
  208. this.page = 1
  209. if (type == 18) {
  210. this.eqlistdata = []
  211. this.eqlist()
  212. } else if (type == 17) {
  213. this.eqlistdata = []
  214. this.tubulareqlist()
  215. } else if (type == 13) {
  216. this.eqlistdata = []
  217. this.sfeqlist()
  218. }
  219. },
  220. timezhuan(time) {
  221. function fun(a) {
  222. return String(a).length == 1 ? '0' + a : a
  223. }
  224. let date = new Date(time * 1000)
  225. let y = date.getFullYear()
  226. let m = date.getMonth() + 1
  227. let d = date.getDate()
  228. let h = date.getHours()
  229. let min = date.getMinutes()
  230. let sec = date.getSeconds()
  231. return `${y}-${fun(m)}-${fun(d)} ${fun(h)}:${fun(min)}:${fun(sec)}`
  232. },
  233. newdata(item) {
  234. if (this.side_type == 17) {
  235. uni.navigateTo({
  236. url: "realtimedata?item=" + JSON.stringify(item)
  237. })
  238. } else {
  239. uni.navigateTo({
  240. url: "weathdata?item=" + JSON.stringify(item)
  241. })
  242. }
  243. },
  244. selectaddress(city, name) { //获取分布位置
  245. uni.request({
  246. type: "GET",
  247. url: "https://restapi.amap.com/v3/geocode/geo?address=" + city +
  248. "&key=78ce288400f4fc6d9458989875c833c2",
  249. dataType: "json",
  250. complete: ress => {
  251. console.log(ress)
  252. if (ress.data.status == 1) {
  253. // ress.data.geocodes[0].location
  254. uni.navigateTo({
  255. url: "./irrmap?lnglat=" + ress.data.geocodes[0].location +
  256. "&basename=" + name
  257. })
  258. } else {
  259. uni.showToast({
  260. title: "地址编译失败",
  261. icon: "none"
  262. })
  263. }
  264. }
  265. });
  266. },
  267. async pumpcontrol(en) { //水肥开关
  268. console.log(en)
  269. const res = await this.$myRequest({
  270. url: '/api/api_gateway?method=irrigation_system.hydropower.water_pump_control',
  271. data: {
  272. times: Math.floor(this.timevalue * 60),
  273. device_id: this.selid,
  274. status: en ? 1 : 0
  275. }
  276. })
  277. console.log(res)
  278. if (res.code == 200) {
  279. uni.showToast({
  280. title: "操作成功",
  281. icon: "none"
  282. })
  283. } else {
  284. uni.showToast({
  285. title: res.msg,
  286. icon: "none"
  287. })
  288. this.eqlistdata[this.selindex].water_pump_switch2 = !this.eqlistdata[this.selindex]
  289. .water_pump_switch2
  290. }
  291. this.timevalue = ""
  292. },
  293. switchchange(e, id, index) { //水肥 开关
  294. // console.log(e.detail.value)
  295. // console.log(this.eqlistdata[index].water_pump_switch2)
  296. this.eqlistdata[index].water_pump_switch2 = e.detail.value
  297. if (e.detail.value) {
  298. this.show = true
  299. this.selindex = index
  300. this.selid = id
  301. } else {
  302. this.selid = id
  303. this.pumpcontrol(false)
  304. }
  305. },
  306. async switchchange2(e, id, index) { //水电开关
  307. console.log(id)
  308. const res = await this.$myRequest({
  309. url: '/api/api_gateway?method=irrigation_system.waterfertilizer.water_fertilizer_control',
  310. data: {
  311. device_ids: id,
  312. isopen: e ? 1 : 0
  313. }
  314. })
  315. console.log(res)
  316. if (res.info == "ok") {
  317. uni.showToast({
  318. title: "操作成功",
  319. icon: "none"
  320. })
  321. } else {
  322. uni.showToast({
  323. title: res.msg,
  324. icon: "none"
  325. })
  326. this.eqlistdata[index].status2 = !this.eqlistdata[index].status2
  327. }
  328. },
  329. modalcancel() { //水肥开关 确定
  330. this.eqlistdata[this.selindex].water_pump_switch2 = !this.eqlistdata[this.selindex].water_pump_switch2
  331. this.timevalue = ""
  332. },
  333. modalconfirm() { //水肥开关 取消
  334. this.show = true
  335. if (this.timevalue == "") {
  336. uni.showToast({
  337. title: "请输入开泵时间",
  338. icon: "none"
  339. })
  340. } else {
  341. this.show = false
  342. this.pumpcontrol(true)
  343. }
  344. },
  345. changeremark(item, index) { //修改备注
  346. this.timevalueremark = item.device_notes
  347. this.showremark = true
  348. this.selindex = index
  349. this.selid = item.device_id
  350. },
  351. modalcancelremark() { //修改备注 取消
  352. },
  353. modalconfirmremark() { //修改备注 确定
  354. this.showremark = true
  355. if (this.timevalueremark == "") {
  356. uni.showToast({
  357. title: "请输入设备备注",
  358. icon: "none"
  359. })
  360. } else {
  361. this.showremark = false
  362. this.setchangeremark()
  363. }
  364. },
  365. async setchangeremark() { //水肥开关
  366. const res = await this.$myRequest({
  367. url: '/api/api_gateway?method=irrigation_system.hydropower.water_pump_modify_device_notes',
  368. data: {
  369. device_id: this.selid,
  370. content: this.timevalueremark
  371. }
  372. })
  373. console.log(res)
  374. if (res) {
  375. uni.showToast({
  376. title: "操作成功",
  377. icon: "none"
  378. })
  379. this.eqlistdata[this.selindex].device_notes = this.timevalueremark
  380. }
  381. },
  382. },
  383. onLoad(option) {
  384. this.side_type = option.side_type
  385. console.log(this.side_type)
  386. },
  387. onReachBottom() {
  388. this.page++
  389. // this.eqlist()
  390. if (this.side_type == 18) {
  391. this.eqlist()
  392. } else if (this.side_type == 17) {
  393. this.tubulareqlist()
  394. } else if (this.side_type == 13) {
  395. this.sfeqlist()
  396. }
  397. },
  398. onPageScroll(e) { //nvue暂不支持滚动监听,可用bindingx代替
  399. if (e.scrollTop > 200) { //距离大于200时显示
  400. this.isTop = true
  401. } else { //距离小于200时隐藏
  402. this.isTop = false
  403. }
  404. },
  405. }
  406. </script>
  407. <style lang="scss">
  408. .search_top{
  409. width: 100%;
  410. background-color: #fff;
  411. position: fixed;
  412. top: 0;
  413. z-index: 999;
  414. }
  415. .search_top_input {
  416. width: 90%;
  417. height: 54rpx;
  418. background-color: #E4E4E4;
  419. border-radius: 27rpx;
  420. padding-top: 8rpx;
  421. box-sizing: border-box;
  422. margin: 0 auto;
  423. position: relative;
  424. input {
  425. width: 85%;
  426. // text-indent: 1rem;
  427. font-size: 26rpx;
  428. padding-left: 20px;
  429. box-sizing: border-box;
  430. }
  431. .icon {
  432. position: absolute;
  433. top: 8rpx;
  434. right: 26rpx;
  435. }
  436. }
  437. .prevents {
  438. width: 100%;
  439. margin-top: 40px;
  440. .prevents_item {
  441. width: 95%;
  442. margin: 0 auto 30rpx;
  443. border-radius: 10rpx;
  444. box-shadow: 0 0 10rpx #bcb9ca;
  445. padding: 20rpx 40rpx 20rpx 80rpx;
  446. box-sizing: border-box;
  447. position: relative;
  448. background-color: #fff;
  449. .prevents_item_img {
  450. width: 30rpx;
  451. height: 50rpx;
  452. position: absolute;
  453. top: -4rpx;
  454. left: 30rpx;
  455. }
  456. .prevents_item_top {
  457. display: flex;
  458. justify-content: space-between;
  459. height: 60rpx;
  460. border-bottom: 2rpx solid #F4F4F4;
  461. line-height: 60rpx;
  462. font-size: 26rpx;
  463. .red {
  464. color: #ff0000;
  465. }
  466. .green {
  467. color: #7DBB91;
  468. }
  469. }
  470. .prevents_item_bot {
  471. margin-top: 20rpx;
  472. font-size: 26rpx;
  473. color: #BDBDBD;
  474. .prevents_item_bot_item {
  475. height: 60rpx;
  476. line-height: 60rpx;
  477. display: flex;
  478. justify-content: space-between;
  479. color: #909696;
  480. p:first-child {
  481. width: 80%;
  482. overflow: hidden; //溢出隐藏
  483. white-space: nowrap; //禁止换行
  484. text-overflow: ellipsis; //...
  485. }
  486. p:nth-child(2) {
  487. height: 45rpx;
  488. color: #00B075;
  489. border-bottom: 1px solid #00B075;
  490. }
  491. }
  492. .prevents_item_bot_sapn0 {
  493. color: #00B075;
  494. }
  495. .prevents_item_bot_sapn1 {
  496. color: #FF4747;
  497. }
  498. .prevents_item_bot_sapn2 {
  499. color: #FFAB00;
  500. }
  501. }
  502. }
  503. }
  504. .top {
  505. position: fixed;
  506. right: 10px;
  507. bottom: 40px;
  508. z-index: 100;
  509. image {
  510. width: 100rpx;
  511. height: 100rpx;
  512. }
  513. .backtop {
  514. display: flex;
  515. justify-content: flex-end;
  516. margin-bottom: 10rpx;
  517. }
  518. .more {
  519. display: flex;
  520. }
  521. .box {
  522. width: 80rpx;
  523. height: 80rpx;
  524. background-color: rgba(161, 161, 161, 0.45);
  525. border-radius: 50%;
  526. text-align: center;
  527. line-height: 80rpx;
  528. box-sizing: border-box;
  529. margin: 14rpx 10rpx 0 0;
  530. color: #fff;
  531. }
  532. }
  533. .slot-content {
  534. width: 60%;
  535. margin: 30rpx auto;
  536. display: flex;
  537. line-height: 70rpx;
  538. }
  539. .slot-contentremark {
  540. width: 70%;
  541. margin: 30rpx auto;
  542. display: flex;
  543. line-height: 70rpx;
  544. }
  545. </style>