device.vue 8.2 KB

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