device.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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.name.substr(0,1)}}</text>
  10. </view>
  11. <view class="flex justify-center align-center padding-left-20 text-lg">
  12. <text>{{item.name}}</text>
  13. <!-- <view v-if="defaultDoorValue==item.macAddress" class="margin-left-10 sm cu-tag bg-orange">
  14. 默认
  15. </view> -->
  16. </view>
  17. </view>
  18. <view class="flex justify-center align-center">
  19. <u-radio-group size="40" active-color="#5064eb" v-model="door_value">
  20. <u-radio
  21. @change.stop="radioChange"
  22. :name="item.macAddress">
  23. </u-radio>
  24. </u-radio-group>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="" style="position: fixed;bottom: 15%;left: calc( 50% - 90rpx);">
  29. <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;">
  30. <text>开门</text>
  31. </view>
  32. </view>
  33. <u-action-sheet :list="actionList" v-model="actionShow" @click="actionClick"></u-action-sheet>
  34. </view>
  35. <u-tabbar v-model="tabbarCurr"
  36. :icon-size="tabbar.iconSize"
  37. :active-color="tabbar.activeColor"
  38. :mid-button-size="tabbar.MinButtonSize"
  39. :list="tabbar.list" :mid-button="true">
  40. </u-tabbar>
  41. </view>
  42. </template>
  43. <script>
  44. var app=getApp()
  45. var that;
  46. import loading from "@/components/loading/loading.vue"
  47. import {tabbar} from "@/assets/js/tabbar.js"
  48. export default {
  49. components:{
  50. loading
  51. },
  52. data() {
  53. return {
  54. actionList: [{
  55. text: '设为默认',
  56. subText:'默认选中该门禁'
  57. }, {
  58. text: '选中'
  59. }, {
  60. text: '开门'
  61. }],
  62. actionShow: false,
  63. //操作哪一项
  64. clickItem:'',
  65. //默认选中值
  66. defaultDoorValue:'',
  67. //选中值
  68. door_value:'',
  69. //员工id
  70. userId:'',
  71. //tabbar
  72. tabbarCurr:1,
  73. tabbar:tabbar,
  74. //是否已开门
  75. isopen:false,
  76. //是否展示动画
  77. isloading:false,
  78. //设备列表
  79. device_list:[],
  80. };
  81. },
  82. onLoad() {
  83. that=this
  84. this.fetchDeviceList()
  85. let loginType=this.$cache.get('loginType')
  86. if (loginType==this.$loginType.STAFF) {
  87. this.getUserId()
  88. }
  89. },
  90. onShow() {
  91. if (this.canReset) {
  92. let list=this.$u.deepClone(this.device_list)
  93. list.forEach(item=>{
  94. item.tagColor='bg-'+this.ColorList[Math.floor(Math.random()*this.ColorList.length)]
  95. })
  96. this.device_list=list
  97. }
  98. this.canReset=true
  99. },
  100. methods:{
  101. radioChange(e){
  102. this.door_value=e
  103. },
  104. actionClick(index) {
  105. if (index==0) {
  106. //设为默认
  107. this.$cache.put('defaultDoorValue',this.clickItem)
  108. this.defaultDoorValue=this.clickItem
  109. }else if (index==1) {
  110. //选中
  111. this.door_value=this.clickItem
  112. }else if(index==2){
  113. //开门
  114. this.door_value=this.clickItem
  115. this.openDoor(this.clickItem)
  116. }
  117. },
  118. showAction(item){
  119. this.clickItem=item.macAddress;
  120. this.actionShow=true
  121. console.log(this.clickItem);
  122. },
  123. itemClick(item){
  124. this.door_value=item.macAddress
  125. },
  126. /**
  127. * 获取员工id
  128. */
  129. getUserId(){
  130. if (this.$isEmpty(getApp().globalData.userInfo)) {
  131. let phone=this.$cache.get('phone')
  132. this.$api.enterprisestaff.page({phone:phone,auditStatus:1}).then(res=>{
  133. let userInfo=res.data.records[0]
  134. this.userId=userInfo.id
  135. })
  136. }else{
  137. let userInfo=getApp().globalData.userInfo
  138. this.userId=userInfo.id
  139. }
  140. },
  141. async fetchDeviceList(){
  142. let res=await this.$api.device.page()
  143. this.device_list= res.data.records
  144. //默认选中值
  145. this.defaultDoorValue=this.$cache.get('defaultDoorValue')
  146. if (this.defaultDoorValue) {
  147. //如果默认选中值不为空,就选中该门禁
  148. this.door_value=this.defaultDoorValue
  149. }else{
  150. //如果默认选中值为空,就选中第一个门禁
  151. this.door_value=this.device_list[0].macAddress
  152. }
  153. this.device_list.forEach(item=>{
  154. item.tagColor='bg-'+this.ColorList[Math.floor(Math.random()*this.ColorList.length)]
  155. })
  156. },
  157. /**
  158. * 立即开门
  159. */
  160. openDoor(macAddress) {
  161. let params={
  162. userId:this.userId || 123,
  163. macAddress:macAddress
  164. }
  165. this.isloading=true
  166. setTimeout(()=>{
  167. this.$api.device.open(params).then(res=>{
  168. if (res.success) {
  169. this.isloading=false
  170. this.isopen=true
  171. that.$showModel('开门成功',false)
  172. }else{
  173. that.$showModel(res.msg,false)
  174. this.isloading=false
  175. that.isopen=false
  176. }
  177. }).catch(err=>{
  178. this.isloading=false
  179. that.isopen=false
  180. })
  181. },500)
  182. },
  183. }
  184. };
  185. </script>
  186. <style lang="scss" scoped>
  187. page{
  188. background-color: #F1F1F1;
  189. }
  190. .device{
  191. position: relative;
  192. background-color: #FFFFFF;
  193. padding: 35rpx;
  194. margin: 20rpx;
  195. .default{
  196. width: 60rpx;
  197. height: 60rpx;
  198. position: absolute;
  199. right: 0;
  200. top: 0;
  201. }
  202. .bg-blue{
  203. background-color: $base-color;
  204. color: #FFFFFF;
  205. }
  206. }
  207. .tag{
  208. border-radius: 50%;
  209. display: flex;
  210. justify-content: center;
  211. align-items: center;
  212. height: 80rpx;
  213. width: 80rpx;
  214. font-size: 32rpx;
  215. }
  216. .btn-open{
  217. background-image: linear-gradient(#557ffc,#3d4fb6);
  218. background-color: $base-color;
  219. box-shadow: 0rpx 0rpx 20rpx rgba(82, 159, 247, 0.8);
  220. color: #FFFFFF;
  221. }
  222. </style>