lampControls.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. <template>
  2. <view>
  3. <!-- 警告提示 -->
  4. <u-notify ref="uNotify"></u-notify>
  5. <!-- 成功提示 -->
  6. <u-notify ref="Success"></u-notify>
  7. <view class="navigation">
  8. <scroll-view class="scrolls" scroll-x="true">
  9. <view v-for="(item,index) in records" :key="item.id" class="nav_item" @click="selectItem(index)"
  10. tabindex="1">
  11. {{item.poleGroupName}}
  12. </view>
  13. </scroll-view>
  14. <view class="lamp_data">
  15. <button type="primary" @click="lightDate()">数据</button>
  16. </view>
  17. </view>
  18. <view class="all">
  19. <button type="default" @click="allTactics()" style="width: 220rpx;left: 265rpx;">关联策略</button>
  20. <button @click="open(2)" style="left: 20rpx;" type="primary">全开</button>
  21. <button @click="shut(2)" style="right: 20rpx;" type="warn">全关</button>
  22. </view>
  23. <view class="list">
  24. <view v-for="(item2,index2) in tworacords" :key="item2.id" class="list_data">
  25. <image :src="item2.lightControlState == '2' ? imageAddress + '/lamp.png' : imageAddress + '/lamp1.png'">
  26. </image>
  27. <text>{{item2.publicName}}</text>
  28. <button type="default" @click="allTactics(item2.publicName,item2.publicId,1,item2.lightName)"
  29. style="right: 220rpx; width: 120rpx;">策略</button>
  30. <button type="primary" @click="open(1,item2.publicId,item2.publicName,index2)"
  31. style="right: 120rpx;">开</button>
  32. <button type="warn" @click="shut(1,item2.publicId,item2.publicName,index2)"
  33. style="right: 20rpx;">关</button>
  34. </view>
  35. <!-- 开启控制 -->
  36. <u-popup :show="openShow" mode="center" duration="0">
  37. <view class="openPopup">
  38. <view class="openText">
  39. 开灯控制
  40. </view>
  41. <view class="openTime">
  42. <select-lay slabel="label" :options="openlist" placeholder="开启时长" :value="openTime"
  43. @selectitem="modify" class="select-lay">
  44. </select-lay>
  45. </view>
  46. <view class="brightness">
  47. 开灯亮度:{{duration}}%
  48. <slider @change="durationChange" :value="duration" min="1" max="100">
  49. </slider>
  50. </view>
  51. <view class="remarks">
  52. <input placeholder="请输入备注(可不填)" @input="openlightControl" :value="openRemarks" type="text" />
  53. </view>
  54. <view class="send">
  55. <view style="width: 200rpx;">
  56. <u-button @click="openShow = false">取消</u-button>
  57. </view>
  58. <view style="width: 200rpx;margin-left: 100rpx;">
  59. <u-button type="primary" @click="distinguish.opensh == 1?
  60. openControl(1,1):openControl(1,2)">
  61. 确定</u-button>
  62. </view>
  63. </view>
  64. </view>
  65. </u-popup>
  66. <!-- 关闭控制 -->
  67. <u-popup :show="shutShow" mode="center" duration="0">
  68. <view class="openPopup" style="height: 500rpx;">
  69. <view class="openText">
  70. 关灯控制
  71. </view>
  72. <view class="openTime">
  73. <select-lay slabel="label" :options="shutlist" placeholder="关闭时长" :value="shutTime"
  74. @selectitem="shutModify" class="select-lay">
  75. </select-lay>
  76. </view>
  77. <view class="remarks">
  78. <input placeholder="请输入备注(可不填)" @input="shutlightControl" :value="shutRemarks" type="text" />
  79. </view>
  80. <view class="send">
  81. <view style="width: 200rpx;">
  82. <u-button @click="shutShow = false">取消</u-button>
  83. </view>
  84. <view style="width: 200rpx;margin-left: 100rpx;">
  85. <u-button type="primary" @click="distinguish.opensh == 1?
  86. shutControl(2,1):shutControl(2,2)">
  87. 确定</u-button>
  88. </view>
  89. </view>
  90. </view>
  91. </u-popup>
  92. </view>
  93. <u-toast ref="uToast"></u-toast>
  94. </view>
  95. </template>
  96. <script>
  97. import {
  98. grouplist,
  99. list,
  100. Control,
  101. light
  102. } from '@/pages/api/lighting/lighting.js'
  103. export default {
  104. data() {
  105. return {
  106. page: {
  107. total: 80, //数据总量
  108. pageSize: 15, //每页的数据量
  109. current: 1, //当前页数
  110. thrifty: false ,//节流阀
  111. },
  112. openShow: false,
  113. shutShow: false,
  114. openlist: [{
  115. label: '1分钟',
  116. value: 1
  117. },
  118. {
  119. label: '2分钟',
  120. value: 2
  121. },
  122. {
  123. label: '3分钟',
  124. value: 3
  125. },
  126. {
  127. label: '5分钟',
  128. value: 5
  129. },
  130. {
  131. label: '10分钟',
  132. value: 10
  133. },
  134. {
  135. label: '20分钟',
  136. value: 20
  137. },
  138. {
  139. label: '30分钟',
  140. value: 30
  141. },
  142. {
  143. label: '1小时',
  144. value: 60
  145. },
  146. {
  147. label: '2小时',
  148. value: 120
  149. },
  150. {
  151. label: '3小时',
  152. value: 180
  153. },
  154. {
  155. label: '5小时',
  156. value: 300
  157. },
  158. {
  159. label: '8小时',
  160. value: 480
  161. },
  162. ],
  163. shutlist: [{
  164. label: '1分钟',
  165. value: 1
  166. },
  167. {
  168. label: '2分钟',
  169. value: 2
  170. },
  171. {
  172. label: '3分钟',
  173. value: 3
  174. },
  175. {
  176. label: '5分钟',
  177. value: 5
  178. },
  179. {
  180. label: '10分钟',
  181. value: 10
  182. },
  183. {
  184. label: '20分钟',
  185. value: 20
  186. },
  187. {
  188. label: '30分钟',
  189. value: 30
  190. },
  191. {
  192. label: '1小时',
  193. value: 60
  194. },
  195. {
  196. label: '2小时',
  197. value: 120
  198. },
  199. {
  200. label: '3小时',
  201. value: 180
  202. },
  203. {
  204. label: '5小时',
  205. value: 300
  206. },
  207. {
  208. label: '8小时',
  209. value: 480
  210. },
  211. ],
  212. openTime: '', //开启时长
  213. shutTime: '', //关闭时长
  214. duration: '1', //开灯亮度
  215. openRemarks: '', //开灯备注
  216. shutRemarks: '', //关灯备注
  217. records: [],
  218. tworacords: [],
  219. topItem: '',
  220. //分组信息
  221. divide: {
  222. publicId: 0,
  223. publicName: '',
  224. groupIndex:0,//当前的分组下标
  225. },
  226. //设备信息
  227. device: {
  228. publicId: '',
  229. publicName: '',
  230. index2: 0
  231. },
  232. //区分单个和多个开关控制
  233. distinguish: {
  234. opensh: 1,
  235. shutsh: 1,
  236. },
  237. imageAddress: 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image',
  238. }
  239. },
  240. onLoad() {
  241. this.load()
  242. },
  243. onShow() {
  244. },
  245. methods: {
  246. load() {
  247. const current = this.page.current
  248. const pageSize = this.page.pageSize
  249. var records = []
  250. grouplist().then(get => {
  251. if (get.code == 200) {
  252. this.records = get.data
  253. records = get.data
  254. list(records[0].id, current, pageSize).then(res => {
  255. if (res.code == 200) {
  256. let children = res.data.records[0].children
  257. this.page.total = res.data.total
  258. this.tworacords = children
  259. this.divide.publicId = records[0].id
  260. this.divide.publicName = records[0].poleGroupName
  261. }
  262. })
  263. }
  264. })
  265. },
  266. //上拉加载
  267. twoload() {
  268. var that = this
  269. const current = that.page.current
  270. const pageSize = that.page.pageSize
  271. const groupId = that.divide.publicId
  272. that.page.thrifty = true
  273. list(groupId, current, pageSize).then(res => {
  274. if (res.code == 200) {
  275. let records = res.data.records
  276. let children = records[0].children
  277. uni.showToast({
  278. title:'数据加载中',
  279. duration:1000,
  280. icon:'loading'
  281. })
  282. setTimeout(function(){
  283. that.tworacords = [...that.tworacords, ...children]
  284. },1000)
  285. }
  286. })
  287. that.page.thrifty = false
  288. },
  289. //切换分组
  290. selectItem(index) {
  291. var records = this.records
  292. let pageSize = this.page.pageSize
  293. let current = 1
  294. this.divide.groupIndex = index
  295. this.divide.publicId = records[index].id
  296. this.divide.publicName = records[index].poleGroupName
  297. list(records[index].id, current, pageSize).then(res => {
  298. if (res.code == 200) {
  299. this.tworacords = res.data.records[0].children
  300. this.page.current = 1
  301. }
  302. })
  303. },
  304. open(ever, publicId, publicName, index2) {
  305. this.distinguish.opensh = ever
  306. if (ever == 1) {
  307. this.device.publicId = publicId
  308. this.device.publicName = publicName
  309. this.device.index2 = index2
  310. }
  311. this.openShow = true
  312. },
  313. shut(ever, publicId, publicName,index2) {
  314. this.distinguish.shutsh = ever
  315. if (ever == 1) {
  316. this.device.publicId = publicId
  317. this.device.publicName = publicName
  318. this.device.index2 = index2
  319. }
  320. this.shutShow = true
  321. },
  322. modify(index, item) {
  323. this.openTime = index >= 0 ? item.value : ''
  324. },
  325. durationChange(e) {
  326. this.duration = e.target.value
  327. },
  328. //时长未选择报错
  329. exError() {
  330. this.$refs.uNotify.show({
  331. top: 10,
  332. type: 'error',
  333. color: '#ffffff',
  334. bgColor: '#f56c6c',
  335. message: '请选择时长',
  336. duration: 1500,
  337. fontSize: 15,
  338. })
  339. },
  340. Success(message) {
  341. this.$refs.Success.show({
  342. top: 10,
  343. type: 'success',
  344. color: '#ffffff',
  345. message: message,
  346. duration: 1500,
  347. fontSize: 15,
  348. })
  349. },
  350. //延时请求(全开)
  351. delayedOpen(publicId,records){
  352. var that = this
  353. var index = that.divide.groupIndex
  354. list(publicId,1,15).then(res => {
  355. if(res.code == 200){
  356. that.page.current = 1
  357. let children = records[index].children
  358. }
  359. })
  360. },
  361. openControl(handSwitch, handType) {
  362. var that = this
  363. const openTime = that.openTime
  364. const duration = that.duration
  365. const openRemarks = that.openRemarks
  366. var opensh = that.distinguish.opensh
  367. var tworacords = that.tworacords
  368. var index2 = that.device.index2
  369. if (openTime == '') {
  370. that.exError()
  371. } else {
  372. var publicId = 0
  373. var publicName = ''
  374. if (opensh == 1) {
  375. publicId = that.device.publicId
  376. publicName = that.device.publicName
  377. } else {
  378. publicId = that.divide.publicId
  379. publicName = that.divide.publicName
  380. }
  381. //handSwitch(开启:1,关闭:2)
  382. //handType(开/关:1,全开/全关:2)
  383. //publicId(分组/设备的id)
  384. //openTime(开启时间)
  385. //duration(光照度)
  386. //openRemarks(备注)
  387. //publicName(分组/设备名称)
  388. Control(handSwitch, handType, publicId, openTime, duration, openRemarks, publicName).then(res => {
  389. if (res.code == 200) {
  390. if(opensh == 1){
  391. tworacords[index2].lightControlState = "1"
  392. that.tworacords = tworacords
  393. that.Success('开灯成功')
  394. }else{
  395. uni.showToast({
  396. title:'发送指令中',
  397. duration:10000,
  398. icon:'loading',
  399. })
  400. setTimeout(function(){
  401. that.load()
  402. },10000)
  403. }
  404. }
  405. })
  406. }
  407. },
  408. shutModify(index, item) {
  409. this.shutTime = index >= 0 ? item.value : ''
  410. },
  411. shutControl(handSwitch, handType) {
  412. var that = this
  413. const shutTime = that.shutTime
  414. const shutRemarks = that.shutRemarks
  415. var tworacords = that.tworacords
  416. var index2 = that.device.index2
  417. var opensh = that.distinguish.opensh
  418. if (shutTime == '') {
  419. that.exError()
  420. } else {
  421. var publicId = 0
  422. var publicName = ''
  423. if (opensh == 1) {
  424. publicId = that.device.publicId
  425. publicName = that.device.publicName
  426. } else {
  427. publicId = that.divide.publicId
  428. publicName = that.divide.publicName
  429. }
  430. Control(handSwitch, handType, publicId, shutTime, 0, shutRemarks, publicName).then(res => {
  431. if (res.code == 200) {
  432. if(opensh == 1){
  433. tworacords[index2].lightControlState = '2'
  434. that.tworacords = tworacords
  435. }else{
  436. uni.showToast({
  437. title:'发送指令中',
  438. duration:10000,
  439. icon:'loading',
  440. })
  441. setTimeout(function(){
  442. that.delayedOpen(publicId,that.records,)
  443. },10000)
  444. }
  445. }
  446. })
  447. }
  448. },
  449. //获取输入的值(开启备注)
  450. openlightControl(e) {
  451. this.openRemarks = e.detail.value
  452. },
  453. //获取输入的值(关闭备注)
  454. shutlightControl(e) {
  455. this.shutRemarks = e.detail.value
  456. },
  457. //关联策略
  458. allTactics(publicName, publicId, relationType, lightName) {
  459. uni.navigateTo({
  460. url: '/pages/Tactics/Tactics?publicName=' + publicName + '&publicId=' + publicId +
  461. '&relationType=' + relationType + '&lightName=' + lightName
  462. })
  463. // let poraryObj = {
  464. // publicName:publicName,
  465. // publicId:publicId,
  466. // relationType:relationType,
  467. // lightName:lightName,
  468. // index:index2,
  469. // pageSize:this.page.pageSize,
  470. // current:this.page.current
  471. // }
  472. // uni.navigateTo({
  473. // url:'/pages/Tactics/Tactics?data=' + ${encodeURIComponent(JSON.stringify(temporaryObj))}
  474. // })
  475. },
  476. lightDate() {
  477. uni.navigateTo({
  478. url: '/pages/Lighting_data/Lighting_data'
  479. })
  480. }
  481. },
  482. //触底事件(如果节流阀打开则不执行加载)
  483. onReachBottom() {
  484. if (this.page.current * this.page.pageSize >= this.page.total) {
  485. this.$refs.uToast.show({
  486. type: 'default',
  487. message: '数据加载完毕',
  488. duration: 2000
  489. })
  490. return
  491. }
  492. if (this.page.thrifty == true) return
  493. this.page.current = this.page.current + 1
  494. this.twoload()
  495. }
  496. }
  497. </script>
  498. <style scoped lang="scss">
  499. .navigation {
  500. width: 750rpx;
  501. height: 120rpx;
  502. border-bottom: 1px solid royalblue;
  503. display: flex;
  504. }
  505. .scrolls {
  506. white-space: nowrap; // 滚动必须加的属性
  507. width: 80%;
  508. height: 120rpx;
  509. line-height: 120rpx;
  510. background-color: #363535;
  511. }
  512. .nav_item {
  513. height: 120rpx;
  514. display: inline-block;
  515. text-align: center;
  516. line-height: 120rpx;
  517. margin-left: 20rpx;
  518. margin-right: 20rpx;
  519. font-size: 36rpx;
  520. color: #ffffff;
  521. background-color: #363535;
  522. &:focus {
  523. background-color: #474747;
  524. }
  525. }
  526. .list {
  527. width: 750rpx;
  528. }
  529. .list_data {
  530. width: 100%;
  531. height: 100rpx;
  532. position: relative;
  533. border-bottom: 1px solid #363535;
  534. text {
  535. font-size: 32rpx;
  536. position: absolute;
  537. top: 34rpx;
  538. left: 110rpx;
  539. }
  540. image {
  541. width: 70rpx;
  542. height: 70rpx;
  543. position: absolute;
  544. top: 15rpx;
  545. left: 20rpx;
  546. }
  547. button {
  548. display: flex;
  549. justify-content: center;
  550. align-items: center;
  551. width: 70rpx;
  552. height: 70rpx;
  553. position: absolute;
  554. top: 15rpx;
  555. font-size: 30rpx;
  556. }
  557. }
  558. .all {
  559. width: 750rpx;
  560. height: 100rpx;
  561. border-bottom: 1px solid #363535;
  562. position: relative;
  563. button {
  564. width: 140rpx;
  565. height: 80rpx;
  566. font-size: 30rpx;
  567. position: absolute;
  568. top: 10rpx;
  569. display: flex;
  570. justify-content: center;
  571. align-items: center;
  572. }
  573. }
  574. .openPopup {
  575. width: 600rpx;
  576. height: 700rpx;
  577. background-color: #ffffff;
  578. }
  579. .openText {
  580. width: 100%;
  581. height: 120rpx;
  582. font-size: 40rpx;
  583. font-weight: 550px;
  584. text-align: center;
  585. line-height: 120rpx;
  586. }
  587. .openTime {
  588. width: 500rpx;
  589. height: 70rpx;
  590. margin: 0 auto;
  591. text-align: center;
  592. font-size: 30rpx;
  593. }
  594. .brightness {
  595. width: 500rpx;
  596. height: 120rpx;
  597. margin: 60rpx auto;
  598. display: flex;
  599. flex-direction: column;
  600. text-align: center;
  601. font-size: 32rpx;
  602. }
  603. .remarks {
  604. width: 500rpx;
  605. height: 80rpx;
  606. margin: 60rpx auto;
  607. }
  608. .remarks input {
  609. width: 100%;
  610. height: 100%;
  611. border: 1px solid #eaeaea;
  612. font-size: 30rpx;
  613. }
  614. .send {
  615. width: 500rpx;
  616. height: 80rpx;
  617. margin: 60rpx auto;
  618. font-size: 30rpx;
  619. display: flex;
  620. }
  621. .lightDate {
  622. width: 100%;
  623. height: 100rpx;
  624. position: relative;
  625. border-bottom: 1px #d2cece solid;
  626. button {
  627. width: 200rpx;
  628. height: 80rpx;
  629. display: flex;
  630. justify-content: center;
  631. align-items: center;
  632. font-size: 36rpx;
  633. position: absolute;
  634. top: 10rpx;
  635. left: 20rpx;
  636. }
  637. }
  638. .lamp_data {
  639. width: 20%;
  640. height: 100%;
  641. button {
  642. width: 100%;
  643. height: 100%;
  644. border-radius: 0;
  645. display: flex;
  646. justify-content: center;
  647. align-items: center;
  648. font-size: 36rpx;
  649. }
  650. }
  651. </style>