device.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view class="page" style="position: relative;">
  3. <view class="content">
  4. <loading isFullScreen color="#59a5f0" :active="isloading" text="开门中..."></loading>
  5. <view @click="openDoor(item.macAddress)" class="device u-border-bottom" v-for="(item,index) in device_list" :key="index">
  6. <text>{{item.cameraName}}</text>
  7. <view class="cu-btn bg-blue round sm">
  8. <text class="cuIcon-lock padding-right-10"></text>
  9. <text>开门</text>
  10. </view>
  11. </view>
  12. </view>
  13. <u-tabbar v-model="tabbarCurr"
  14. :icon-size="tabbar.iconSize"
  15. :active-color="tabbar.activeColor"
  16. :mid-button-size="tabbar.MinButtonSize"
  17. :list="tabbar.list" :mid-button="true">
  18. </u-tabbar>
  19. </view>
  20. </template>
  21. <script>
  22. var app=getApp()
  23. var that;
  24. import loading from "@/components/loading/loading.vue"
  25. import {tabbar} from "@/assets/js/tabbar.js"
  26. export default {
  27. components:{
  28. loading
  29. },
  30. data() {
  31. return {
  32. //员工id
  33. userId:'',
  34. //tabbar
  35. tabbarCurr:1,
  36. tabbar:tabbar,
  37. //是否已开门
  38. isopen:false,
  39. //是否展示动画
  40. isloading:false,
  41. //设备列表
  42. device_list:[]
  43. };
  44. },
  45. onLoad() {
  46. that=this
  47. this.fetchDeviceList()
  48. let loginType=this.$cache.get('loginType')
  49. if (loginType==this.$loginType.STAFF) {
  50. this.getUserId()
  51. }
  52. },
  53. methods:{
  54. /**
  55. * 获取员工id
  56. */
  57. getUserId(){
  58. if (this.$isEmpty(getApp().globalData.userInfo)) {
  59. let phone=this.$cache.get('phone')
  60. this.$api.enterprisestaff.page({phone:phone,examine:1}).then(res=>{
  61. let userInfo=res.data.records[0]
  62. this.userId=userInfo.id
  63. })
  64. }else{
  65. let userInfo=getApp().globalData.userInfo
  66. this.userId=userInfo.id
  67. }
  68. },
  69. fetchDeviceList(){
  70. this.$api.device.page().then(res=>{
  71. this.device_list= res.data.records
  72. })
  73. },
  74. open(){
  75. //进度条加载
  76. this.isloading=true
  77. setTimeout(()=>{
  78. that.isloading=false
  79. that.isopen=true
  80. that.$showModel('开门成功',false)
  81. },2300)
  82. },
  83. /**
  84. * 立即开门
  85. */
  86. openDoor(macAddress) {
  87. let params={
  88. userId:this.userId || 123,
  89. macAddress:macAddress
  90. }
  91. this.isloading=true
  92. setTimeout(()=>{
  93. this.$api.device.open(params).then(res=>{
  94. if (res.success) {
  95. this.isloading=false
  96. this.isopen=true
  97. that.$showModel('开门成功',false)
  98. }else{
  99. that.isopen=false
  100. }
  101. })
  102. },2300)
  103. },
  104. }
  105. };
  106. </script>
  107. <style lang="scss" scoped>
  108. page{
  109. background-color: #F1F1F1;
  110. }
  111. .device{
  112. background-color: #FFFFFF;
  113. display: flex;
  114. justify-content: space-between;
  115. padding: 30rpx;
  116. .bg-blue{
  117. background-color: #59a5f0;
  118. color: #FFFFFF;
  119. }
  120. }
  121. </style>