AccessControl.vue 3.8 KB

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