open-door.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <view class="page" style="position: relative;">
  3. <view class="content">
  4. <loading isFullScreen color="#5064eb" :active="isloading" text="开门中..."></loading>
  5. <view @click="itemClick(item)" class="device u-border-bottom" v-for="(item,index) in device_list" :key="index">
  6. <view class="flex justify-between">
  7. <view class="flex" style="width: 80%;">
  8. <view class="tag" :class="item.tagColor">
  9. <text>{{item.cameraName.substr(0,1)}}</text>
  10. </view>
  11. <view class="flex justify-center align-center padding-left-20 text-lg">
  12. <text>{{item.cameraName}}</text>
  13. </view>
  14. </view>
  15. <view class="flex justify-center align-center">
  16. <u-radio-group size="40" active-color="#5064eb" v-model="door_value">
  17. <u-radio
  18. @change.stop="radioChange"
  19. :name="item.macAddress">
  20. </u-radio>
  21. </u-radio-group>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="" style="position: fixed;bottom: 15%;left: calc( 50% - 90rpx);">
  26. <view @click="openDoor(door_value)" class="btn-open text-center flex justify-center align-center" style="border-radius: 50%;height: 180rpx;width: 180rpx;font-size: 34rpx;">
  27. <text>开门</text>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. var app=getApp()
  35. var that;
  36. import loading from "@/components/loading/loading.vue"
  37. export default {
  38. components:{
  39. loading
  40. },
  41. data() {
  42. return {
  43. //操作哪一项
  44. clickItem:'',
  45. //选中值
  46. door_value:'',
  47. //访客开门的userid为999加该访客的手机号
  48. userId:'',
  49. //是否已开门
  50. isopen:false,
  51. //是否展示动画
  52. isloading:false,
  53. //设备列表
  54. device_list:[],
  55. };
  56. },
  57. onLoad(options) {
  58. that=this
  59. if (this.$isEmpty(options.guestTel)) {
  60. this.$dialog.showModal('系统异常',false).then(res=>{
  61. this.$navigateBack()
  62. })
  63. return
  64. }
  65. this.userId='999'+options.guestTel
  66. this.fetchDeviceList()
  67. },
  68. onShow() {
  69. if (this.canReset) {
  70. let list=this.$u.deepClone(this.device_list)
  71. list.forEach(item=>{
  72. item.tagColor='bg-'+this.ColorList[Math.floor(Math.random()*this.ColorList.length)]
  73. })
  74. this.device_list=list
  75. }
  76. this.canReset=true
  77. },
  78. methods:{
  79. radioChange(e){
  80. this.door_value=e
  81. },
  82. itemClick(item){
  83. this.door_value=item.macAddress
  84. },
  85. /**
  86. * 获取员工id
  87. */
  88. getUserId(){
  89. if (this.$isEmpty(getApp().globalData.userInfo)) {
  90. let phone=this.$cache.get('phone')
  91. this.$api.enterprisestaff.page({phone:phone,auditStatus:1}).then(res=>{
  92. let userInfo=res.data.records[0]
  93. this.userId=userInfo.id
  94. })
  95. }else{
  96. let userInfo=getApp().globalData.userInfo
  97. this.userId=userInfo.id
  98. }
  99. },
  100. async fetchDeviceList(){
  101. let res=await this.$api.device.page()
  102. this.device_list= res.data.records
  103. this.door_value=this.device_list[0].macAddress
  104. this.device_list.forEach(item=>{
  105. item.tagColor='bg-'+this.ColorList[Math.floor(Math.random()*this.ColorList.length)]
  106. })
  107. },
  108. /**
  109. * 立即开门
  110. */
  111. openDoor(macAddress) {
  112. let params={
  113. userId:this.userId || 123,
  114. macAddress:macAddress
  115. }
  116. this.isloading=true
  117. setTimeout(()=>{
  118. this.$api.device.open(params).then(res=>{
  119. if (res.success) {
  120. this.isloading=false
  121. this.isopen=true
  122. that.$showModel('开门成功',false)
  123. }else{
  124. that.isopen=false
  125. }
  126. }).catch(err=>{
  127. this.isloading=false
  128. that.isopen=false
  129. })
  130. },500)
  131. },
  132. }
  133. };
  134. </script>
  135. <style lang="scss" scoped>
  136. page{
  137. background-color: #F1F1F1;
  138. }
  139. .device{
  140. position: relative;
  141. background-color: #FFFFFF;
  142. padding: 35rpx;
  143. margin: 20rpx;
  144. .default{
  145. width: 60rpx;
  146. height: 60rpx;
  147. position: absolute;
  148. right: 0;
  149. top: 0;
  150. }
  151. .bg-blue{
  152. background-color: $base-color;
  153. color: #FFFFFF;
  154. }
  155. }
  156. .tag{
  157. border-radius: 50%;
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. height: 80rpx;
  162. width: 80rpx;
  163. font-size: 32rpx;
  164. }
  165. .btn-open{
  166. background-image: linear-gradient(#557ffc,#3d4fb6);
  167. background-color: $base-color;
  168. box-shadow: 0rpx 0rpx 20rpx rgba(82, 159, 247, 0.8);
  169. color: #FFFFFF;
  170. }
  171. </style>