device.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. <button @click="openDoor(door_value)" class="cu-btn u-reset-button btn-open text-center flex justify-center align-center" style="border-radius: 50%;height: 180rpx;width: 180rpx;font-size: 34rpx;">
  30. <text>开门</text>
  31. </button>
  32. </view>
  33. <u-action-sheet :list="actionList" v-model="actionShow" @click="actionClick"></u-action-sheet>
  34. </view>
  35. <u-tabbar
  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. tabbar:tabbar,
  73. //是否已开门
  74. isopen:false,
  75. //是否展示动画
  76. isloading:false,
  77. //设备列表
  78. device_list:[],
  79. };
  80. },
  81. onLoad() {
  82. that=this
  83. this.fetchDeviceList()
  84. this.userId=this.$cache.get('loginuser').id
  85. },
  86. onShow() {
  87. if (this.canReset) {
  88. let list=this.$u.deepClone(this.device_list)
  89. list.forEach(item=>{
  90. item.tagColor='bg-'+this.ColorList[Math.floor(Math.random()*this.ColorList.length)]
  91. })
  92. this.device_list=list
  93. }
  94. this.canReset=true
  95. },
  96. methods:{
  97. radioChange(e){
  98. this.door_value=e
  99. },
  100. actionClick(index) {
  101. if (index==0) {
  102. //设为默认
  103. this.$cache.put('defaultDoorValue',this.clickItem)
  104. this.defaultDoorValue=this.clickItem
  105. }else if (index==1) {
  106. //选中
  107. this.door_value=this.clickItem
  108. }else if(index==2){
  109. //开门
  110. this.door_value=this.clickItem
  111. this.openDoor(this.clickItem)
  112. }
  113. },
  114. showAction(item){
  115. this.clickItem=item.macAddress;
  116. this.actionShow=true
  117. console.log(this.clickItem);
  118. },
  119. itemClick(item){
  120. this.door_value=item.macAddress
  121. },
  122. /**
  123. * 获取员工id
  124. */
  125. getUserId(){
  126. if (this.$isEmpty(getApp().globalData.userInfo)) {
  127. let phone=this.$cache.get('phone')
  128. this.$api.enterprisestaff.page({phone:phone,auditStatus:1}).then(res=>{
  129. let userInfo=res.data.records[0]
  130. this.userId=userInfo.id
  131. })
  132. }else{
  133. let userInfo=getApp().globalData.userInfo
  134. this.userId=userInfo.id
  135. }
  136. },
  137. async fetchDeviceList(){
  138. let res=await this.$api.device.page()
  139. this.device_list= res.data.records
  140. //默认选中值
  141. this.defaultDoorValue=this.$cache.get('defaultDoorValue')
  142. if (this.defaultDoorValue) {
  143. //如果默认选中值不为空,就选中该门禁
  144. this.door_value=this.defaultDoorValue
  145. }else{
  146. //如果默认选中值为空,就选中第一个门禁
  147. this.door_value=this.device_list[0].macAddress
  148. }
  149. this.device_list.forEach(item=>{
  150. item.tagColor='bg-'+this.ColorList[Math.floor(Math.random()*this.ColorList.length)]
  151. })
  152. },
  153. /**
  154. * 立即开门
  155. */
  156. openDoor(macAddress) {
  157. let params={
  158. userType:2,
  159. userId:this.userId,
  160. macAddress:macAddress
  161. }
  162. this.isloading=true
  163. this.$api.device.open(params).then(res=>{
  164. if (res.success) {
  165. this.isloading=false
  166. this.isopen=true
  167. this.$u.toast('开门成功')
  168. }else{
  169. this.$u.toast('开门失败')
  170. this.isloading=false
  171. that.isopen=false
  172. }
  173. }).catch(err=>{
  174. this.$u.toast('开门失败')
  175. this.isloading=false
  176. that.isopen=false
  177. })
  178. },
  179. }
  180. };
  181. </script>
  182. <style lang="scss" scoped>
  183. page{
  184. background-color: #F1F1F1;
  185. }
  186. .device{
  187. position: relative;
  188. background-color: #FFFFFF;
  189. padding: 35rpx;
  190. margin: 20rpx;
  191. .default{
  192. width: 60rpx;
  193. height: 60rpx;
  194. position: absolute;
  195. right: 0;
  196. top: 0;
  197. }
  198. .bg-blue{
  199. background-color: $base-color;
  200. color: #FFFFFF;
  201. }
  202. }
  203. .tag{
  204. border-radius: 50%;
  205. display: flex;
  206. justify-content: center;
  207. align-items: center;
  208. height: 80rpx;
  209. width: 80rpx;
  210. font-size: 32rpx;
  211. }
  212. .btn-open{
  213. background-image: linear-gradient(#557ffc,#3d4fb6);
  214. background-color: $base-color;
  215. box-shadow: 0rpx 0rpx 20rpx rgba(82, 159, 247, 0.8);
  216. color: #FFFFFF;
  217. }
  218. </style>