AccessControl.vue 5.0 KB

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