lampControls.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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. <view class="pagination">
  94. <uni-pagination :total="page.total" :pageSize="page.pageSize" :current="page.current" @change="pageTatble"
  95. style="width: 750rpx;
  96. height: 150rpx;">
  97. </uni-pagination>
  98. </view>
  99. <u-toast ref="uToast"></u-toast>
  100. </view>
  101. </template>
  102. <script>
  103. import {
  104. grouplist,
  105. list,
  106. Control,
  107. light
  108. } from '@/pages/api/lighting/lighting.js'
  109. export default {
  110. data() {
  111. return {
  112. page: {
  113. total: 80, //数据总量
  114. pageSize: 10, //每页的数据量
  115. current: 1, //当前页数
  116. thrifty: false, //节流阀
  117. },
  118. openShow: false,
  119. shutShow: false,
  120. openlist: [{
  121. label: '1分钟',
  122. value: 1
  123. },
  124. {
  125. label: '2分钟',
  126. value: 2
  127. },
  128. {
  129. label: '3分钟',
  130. value: 3
  131. },
  132. {
  133. label: '5分钟',
  134. value: 5
  135. },
  136. {
  137. label: '10分钟',
  138. value: 10
  139. },
  140. {
  141. label: '20分钟',
  142. value: 20
  143. },
  144. {
  145. label: '30分钟',
  146. value: 30
  147. },
  148. {
  149. label: '1小时',
  150. value: 60
  151. },
  152. {
  153. label: '2小时',
  154. value: 120
  155. },
  156. {
  157. label: '3小时',
  158. value: 180
  159. },
  160. {
  161. label: '5小时',
  162. value: 300
  163. },
  164. {
  165. label: '8小时',
  166. value: 480
  167. },
  168. ],
  169. shutlist: [{
  170. label: '1分钟',
  171. value: 1
  172. },
  173. {
  174. label: '2分钟',
  175. value: 2
  176. },
  177. {
  178. label: '3分钟',
  179. value: 3
  180. },
  181. {
  182. label: '5分钟',
  183. value: 5
  184. },
  185. {
  186. label: '10分钟',
  187. value: 10
  188. },
  189. {
  190. label: '20分钟',
  191. value: 20
  192. },
  193. {
  194. label: '30分钟',
  195. value: 30
  196. },
  197. {
  198. label: '1小时',
  199. value: 60
  200. },
  201. {
  202. label: '2小时',
  203. value: 120
  204. },
  205. {
  206. label: '3小时',
  207. value: 180
  208. },
  209. {
  210. label: '5小时',
  211. value: 300
  212. },
  213. {
  214. label: '8小时',
  215. value: 480
  216. },
  217. ],
  218. openTime: '', //开启时长
  219. shutTime: '', //关闭时长
  220. duration: '1', //开灯亮度
  221. openRemarks: '', //开灯备注
  222. shutRemarks: '', //关灯备注
  223. records: [],
  224. tworacords: [],
  225. topItem: '',
  226. //分组信息
  227. divide: {
  228. publicId: 0,
  229. publicName: '',
  230. groupIndex: 0, //当前的分组下标
  231. },
  232. //设备信息
  233. device: {
  234. publicId: '',
  235. publicName: '',
  236. index2: 0
  237. },
  238. //区分单个和多个开关控制
  239. distinguish: {
  240. opensh: 1,
  241. shutsh: 1,
  242. },
  243. imageAddress: 'https://cloud.long-chi.com/resource/miniprogram-lightcontrol/image',
  244. }
  245. },
  246. onLoad() {
  247. this.load()
  248. },
  249. onShow() {
  250. },
  251. methods: {
  252. load() {
  253. const current = this.page.current
  254. const pageSize = this.page.pageSize
  255. var records = []
  256. grouplist().then(get => {
  257. if (get.code == 200) {
  258. this.records = get.data
  259. records = get.data
  260. list(records[0].id, current, pageSize).then(res => {
  261. if (res.code == 200) {
  262. let children = res.data.records[0].children
  263. this.page.total = res.data.total
  264. this.tworacords = children
  265. this.divide.publicId = records[0].id
  266. this.divide.publicName = records[0].poleGroupName
  267. }
  268. })
  269. }
  270. })
  271. setInterval(this.renovate,15000)
  272. },
  273. //过度动画
  274. cartoon(title, duration) {
  275. uni.showToast({
  276. title: title,
  277. icon: 'loading',
  278. duration: duration
  279. })
  280. },
  281. //切换分组
  282. selectItem(index) {
  283. var records = this.records
  284. let pageSize = this.page.pageSize
  285. let current = 1
  286. this.divide.groupIndex = index
  287. this.divide.publicId = records[index].id
  288. this.divide.publicName = records[index].poleGroupName
  289. list(records[index].id, current, pageSize).then(res => {
  290. if (res.code == 200) {
  291. this.tworacords = res.data.records[0].children
  292. this.page.current = 1
  293. }
  294. })
  295. },
  296. open(ever, publicId, publicName, index2) {
  297. this.distinguish.opensh = ever
  298. if (ever == 1) {
  299. this.device.publicId = publicId
  300. this.device.publicName = publicName
  301. this.device.index2 = index2
  302. }
  303. this.openShow = true
  304. },
  305. shut(ever, publicId, publicName, index2) {
  306. this.distinguish.shutsh = ever
  307. if (ever == 1) {
  308. this.device.publicId = publicId
  309. this.device.publicName = publicName
  310. this.device.index2 = index2
  311. }
  312. this.shutShow = true
  313. },
  314. modify(index, item) {
  315. this.openTime = index >= 0 ? item.value : ''
  316. },
  317. durationChange(e) {
  318. this.duration = e.target.value
  319. },
  320. //时长未选择报错
  321. exError() {
  322. this.$refs.uNotify.show({
  323. top: 10,
  324. type: 'error',
  325. color: '#ffffff',
  326. bgColor: '#f56c6c',
  327. message: '请选择时长',
  328. duration: 1500,
  329. fontSize: 15,
  330. })
  331. },
  332. Success(message) {
  333. this.$refs.Success.show({
  334. top: 10,
  335. type: 'success',
  336. color: '#ffffff',
  337. message: message,
  338. duration: 1500,
  339. fontSize: 15,
  340. })
  341. },
  342. //开启
  343. openControl(handSwitch, handType) {
  344. var that = this
  345. const openTime = that.openTime
  346. const duration = that.duration
  347. const openRemarks = that.openRemarks
  348. var opensh = that.distinguish.opensh
  349. var tworacords = that.tworacords
  350. var tworacords = []
  351. if (openTime == '') {
  352. that.exError()
  353. } else {
  354. var publicId = 0
  355. var publicName = ''
  356. if (opensh == 1) {
  357. publicId = that.device.publicId
  358. publicName = that.device.publicName
  359. } else {
  360. publicId = that.divide.publicId
  361. publicName = that.divide.publicName
  362. }
  363. //handSwitch(开启:1,关闭:2)
  364. //handType(开/关:1,全开/全关:2)
  365. //publicId(分组/设备的id)
  366. //openTime(开启时间)
  367. //duration(光照度)
  368. //openRemarks(备注)
  369. //publicName(分组/设备名称)
  370. Control(handSwitch, handType, publicId, openTime, duration, openRemarks, publicName).then(res => {
  371. if (res.code == 200) {
  372. that.Success('开灯成功')
  373. }
  374. })
  375. }
  376. },
  377. shutModify(index, item) {
  378. this.shutTime = index >= 0 ? item.value : ''
  379. },
  380. //关闭
  381. shutControl(handSwitch, handType) {
  382. var that = this
  383. const shutTime = that.shutTime
  384. const shutRemarks = that.shutRemarks
  385. var tworacords = that.tworacords
  386. var index2 = that.device.index2
  387. var shutsh = that.distinguish.shutsh
  388. if (shutTime == '') {
  389. that.exError()
  390. } else {
  391. var publicId = 0
  392. var publicName = ''
  393. if (shutsh == 1) {
  394. publicId = that.device.publicId
  395. publicName = that.device.publicName
  396. } else {
  397. publicId = that.divide.publicId
  398. publicName = that.divide.publicName
  399. }
  400. Control(handSwitch, handType, publicId, shutTime, 0, shutRemarks, publicName).then(res => {
  401. if (res.code == 200) {
  402. that.Success('关灯成功')
  403. }
  404. })
  405. }
  406. },
  407. //获取输入的值(开启备注)
  408. openlightControl(e) {
  409. this.openRemarks = e.detail.value
  410. },
  411. //获取输入的值(关闭备注)
  412. shutlightControl(e) {
  413. this.shutRemarks = e.detail.value
  414. },
  415. //关联策略
  416. allTactics(publicName, publicId, relationType, lightName) {
  417. uni.navigateTo({
  418. url: '/pages/Tactics/Tactics?publicName=' + publicName + '&publicId=' + publicId +
  419. '&relationType=' + relationType + '&lightName=' + lightName
  420. })
  421. },
  422. lightDate() {
  423. uni.navigateTo({
  424. url: '/pages/Lighting_data/Lighting_data'
  425. })
  426. },
  427. //分页器页数改变
  428. pageTatble(e) {
  429. var that = this
  430. var publicId = that.divide.publicId
  431. var pageSize = that.page.pageSize
  432. that.page.current = e.current
  433. list(publicId, e.current, pageSize).then(res => {
  434. if (res.code == 200) {
  435. that.tworacords = res.data.records[0].children
  436. }
  437. })
  438. },
  439. //定时刷新
  440. renovate(){
  441. var that = this
  442. var publicId = that.divide.publicId
  443. var current = that.page.current
  444. var pageSize = that.page.pageSize
  445. list(publicId,current,pageSize).then(res => {
  446. if(res.code == 200){
  447. that.tworacords = res.data.records[0].children
  448. }
  449. })
  450. }
  451. },
  452. }
  453. </script>
  454. <style scoped lang="scss">
  455. .navigation {
  456. width: 750rpx;
  457. height: 120rpx;
  458. border-bottom: 1px solid royalblue;
  459. display: flex;
  460. }
  461. .scrolls {
  462. white-space: nowrap; // 滚动必须加的属性
  463. width: 80%;
  464. height: 120rpx;
  465. line-height: 120rpx;
  466. background-color: #363535;
  467. }
  468. .nav_item {
  469. height: 120rpx;
  470. display: inline-block;
  471. text-align: center;
  472. line-height: 120rpx;
  473. margin-left: 20rpx;
  474. margin-right: 20rpx;
  475. font-size: 36rpx;
  476. color: #ffffff;
  477. background-color: #363535;
  478. &:focus {
  479. background-color: #474747;
  480. }
  481. }
  482. .list {
  483. width: 750rpx;
  484. }
  485. .list_data {
  486. width: 100%;
  487. height: 100rpx;
  488. position: relative;
  489. border-bottom: 1px solid #363535;
  490. text {
  491. font-size: 32rpx;
  492. position: absolute;
  493. top: 34rpx;
  494. left: 110rpx;
  495. }
  496. image {
  497. width: 70rpx;
  498. height: 70rpx;
  499. position: absolute;
  500. top: 15rpx;
  501. left: 20rpx;
  502. }
  503. button {
  504. display: flex;
  505. justify-content: center;
  506. align-items: center;
  507. width: 70rpx;
  508. height: 70rpx;
  509. position: absolute;
  510. top: 15rpx;
  511. font-size: 30rpx;
  512. }
  513. }
  514. .all {
  515. width: 750rpx;
  516. height: 100rpx;
  517. border-bottom: 1px solid #363535;
  518. position: relative;
  519. button {
  520. width: 140rpx;
  521. height: 80rpx;
  522. font-size: 30rpx;
  523. position: absolute;
  524. top: 10rpx;
  525. display: flex;
  526. justify-content: center;
  527. align-items: center;
  528. }
  529. }
  530. .openPopup {
  531. width: 600rpx;
  532. height: 700rpx;
  533. background-color: #ffffff;
  534. }
  535. .openText {
  536. width: 100%;
  537. height: 120rpx;
  538. font-size: 40rpx;
  539. font-weight: 550px;
  540. text-align: center;
  541. line-height: 120rpx;
  542. }
  543. .openTime {
  544. width: 500rpx;
  545. height: 70rpx;
  546. margin: 0 auto;
  547. text-align: center;
  548. font-size: 30rpx;
  549. }
  550. .brightness {
  551. width: 500rpx;
  552. height: 120rpx;
  553. margin: 60rpx auto;
  554. display: flex;
  555. flex-direction: column;
  556. text-align: center;
  557. font-size: 32rpx;
  558. }
  559. .remarks {
  560. width: 500rpx;
  561. height: 80rpx;
  562. margin: 60rpx auto;
  563. }
  564. .remarks input {
  565. width: 100%;
  566. height: 100%;
  567. border: 1px solid #eaeaea;
  568. font-size: 30rpx;
  569. }
  570. .send {
  571. width: 500rpx;
  572. height: 80rpx;
  573. margin: 60rpx auto;
  574. font-size: 30rpx;
  575. display: flex;
  576. }
  577. .lightDate {
  578. width: 100%;
  579. height: 100rpx;
  580. position: relative;
  581. border-bottom: 1px #d2cece solid;
  582. button {
  583. width: 200rpx;
  584. height: 80rpx;
  585. display: flex;
  586. justify-content: center;
  587. align-items: center;
  588. font-size: 36rpx;
  589. position: absolute;
  590. top: 10rpx;
  591. left: 20rpx;
  592. }
  593. }
  594. .lamp_data {
  595. width: 20%;
  596. height: 100%;
  597. button {
  598. width: 100%;
  599. height: 100%;
  600. border-radius: 0;
  601. display: flex;
  602. justify-content: center;
  603. align-items: center;
  604. font-size: 36rpx;
  605. }
  606. }
  607. .pagination {
  608. width: 750rpx;
  609. height: 80rpx;
  610. margin-top: 40rpx;
  611. }
  612. </style>