device.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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="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. /**
  75. * 立即开门
  76. */
  77. openDoor(macAddress) {
  78. let params={
  79. userId:this.userId || 123,
  80. macAddress:macAddress
  81. }
  82. this.isloading=true
  83. setTimeout(()=>{
  84. this.$api.device.open(params).then(res=>{
  85. if (res.success) {
  86. this.isloading=false
  87. this.isopen=true
  88. that.$showModel('开门成功',false)
  89. }else{
  90. that.isopen=false
  91. }
  92. }).catch(err=>{
  93. this.isloading=false
  94. that.isopen=false
  95. })
  96. },20)
  97. },
  98. }
  99. };
  100. </script>
  101. <style lang="scss" scoped>
  102. page{
  103. background-color: #F1F1F1;
  104. }
  105. .device{
  106. background-color: #FFFFFF;
  107. display: flex;
  108. justify-content: space-between;
  109. padding: 30rpx;
  110. .bg-blue{
  111. background-color: $base-color;
  112. color: #FFFFFF;
  113. }
  114. }
  115. </style>