AccessControl.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view class="menjin">
  3. <view class="mjym" v-for="(item,index) in mjlist" :key="item.id">
  4. <view class="mjzt1" v-if="item.status==1">在线</view>
  5. <view class="mjzt2" v-if="item.status==0">离线</view>
  6. <h3 class="mjname">{{item.deviceName}}</h3>
  7. <view class="mjlx">{{item.deviceSerial}}</view>
  8. <view class="mjsh">{{item.parentCategory}}</view>
  9. <view class="mjkg">
  10. <view class="sfkq">
  11. <view class="sfkq1">是否开启</view>
  12. <view class="sfkq2">
  13. <u-switch activeColor="#2979FF" asyncChange @change="asyncChange1(item)"
  14. inactiveColor="rgb(230, 230, 230)" v-model="item.value1" size="40"></u-switch>
  15. </view>
  16. </view>
  17. <view class="sfkq">
  18. <view class="sfkq1">是否常开</view>
  19. <view class="sfkq2">
  20. <u-switch activeColor="#2979FF" asyncChange @change="asyncChange2(item)"
  21. inactiveColor="rgb(230, 230, 230)" v-model="item.value2" size="40"></u-switch>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <u-notify ref="uNotify" message=""></u-notify>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. data() {
  32. return {
  33. mjlist: [],
  34. // postdata:{},
  35. }
  36. },
  37. onLoad() {
  38. this.getalldata()
  39. },
  40. methods: {
  41. getalldata() {
  42. this.$api.get('/access/page', {})
  43. .then(res => {
  44. if (res.data.code == 0) {
  45. if (res.data.data.length == 0) {
  46. this.mjlist = []
  47. } else {
  48. for (let i = 0; i < res.data.data.length; i++) {
  49. res.data.data[i].value1 = false;
  50. res.data.data[i].value2 = false;
  51. }
  52. this.mjlist = res.data.data;
  53. }
  54. //console.log('111111111111111111',this.mjlist)
  55. } else {
  56. this.$refs.uNotify.error(res.data.msg)
  57. }
  58. })
  59. },
  60. operate(e) {
  61. this.$api.post('/access/operate', e)
  62. .then(res => {
  63. if (res.data.code == 0) {
  64. this.$refs.uNotify.success('成功')
  65. } else {
  66. this.$refs.uNotify.error(res.data.msg)
  67. }
  68. })
  69. },
  70. asyncChange1(e, ) {
  71. uni.showModal({
  72. content: e.value1 ? '确定要关闭门禁吗' : '确定要开启门禁吗',
  73. success: (res) => {
  74. if (res.confirm) {
  75. e.value1 = !e.value1;
  76. if (e.value1 == true) {
  77. let postdata = {
  78. cmd: 'open',
  79. deviceSerial: e.deviceSerial
  80. }
  81. this.operate(postdata)
  82. } else {
  83. let postdata = {
  84. cmd: 'close',
  85. deviceSerial: e.deviceSerial
  86. }
  87. this.operate(postdata)
  88. }
  89. }
  90. }
  91. })
  92. },
  93. asyncChange2(e, ) {
  94. uni.showModal({
  95. content: e.value2 ? '确定要关闭常开吗' : '确定要常开吗',
  96. success: (res) => {
  97. if (res.confirm) {
  98. e.value2 = !e.value2;
  99. if (e.value2 == true) {
  100. let postdata = {
  101. cmd: 'alwaysOpen',
  102. deviceSerial: e.deviceSerial
  103. }
  104. this.operate(postdata)
  105. } else {
  106. let postdata = {
  107. cmd: 'alwaysClose',
  108. deviceSerial: e.deviceSerial
  109. }
  110. this.operate(postdata)
  111. }
  112. }
  113. }
  114. })
  115. },
  116. }
  117. }
  118. </script>
  119. <style>
  120. .menjin {}
  121. .sfkq1 {
  122. padding-right: 25rpx;
  123. }
  124. .sfkq {
  125. width: 345rpx;
  126. height: 40rpx;
  127. display: flex;
  128. align-items: center;
  129. justify-content: center;
  130. }
  131. .mjkg {
  132. display: flex;
  133. align-items: center;
  134. margin-top: 80rpx;
  135. }
  136. .mjsh {
  137. padding: 0rpx 0 0rpx 30rpx;
  138. font-size: 26rpx;
  139. font-weight: 400;
  140. color: #697081;
  141. }
  142. .mjlx {
  143. font-size: 30rpx;
  144. padding: 0rpx 0 20rpx 30rpx;
  145. font-weight: 600;
  146. color: #0c1935;
  147. }
  148. .mjname {
  149. padding: 50rpx 0 50rpx 30rpx;
  150. }
  151. .mjym {
  152. width: 690rpx;
  153. height: 400rpx;
  154. background: #fff;
  155. margin: 20rpx auto;
  156. border-radius: 10px;
  157. position: relative;
  158. }
  159. .mjzt1 {
  160. position: absolute;
  161. right: 10rpx;
  162. top: 10rpx;
  163. background: #30D3A2;
  164. color: #fff;
  165. width: 100rpx;
  166. height: 50rpx;
  167. border-radius: 10px;
  168. line-height: 50rpx;
  169. text-align: center;
  170. }
  171. .mjzt2 {
  172. position: absolute;
  173. right: 10rpx;
  174. top: 10rpx;
  175. background: rgb(105, 112, 129);
  176. color: #fff;
  177. width: 100rpx;
  178. height: 50rpx;
  179. border-radius: 10px;
  180. line-height: 50rpx;
  181. text-align: center;
  182. }
  183. </style>