bindDevice.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="container">
  3. <u-navbar leftIconColor="#fff" titleStyle="color:#fff;fontSize:36rpx;" :autoBack="true" bgColor="#2C6FF3"
  4. :placeholder="true" title="设备激活">
  5. </u-navbar>
  6. <view class="img">
  7. <u-image width="147rpx" src="https://cdn.ossfile.mxrvending.com/assets/xy_merc_mini/images/device.png"
  8. mode="widthFix" :lazy-load="true">
  9. </u-image>
  10. </view>
  11. <view class="device-msg">
  12. <view class="msg-item">
  13. <view class="">
  14. 设备编号
  15. </view>
  16. <view class="">
  17. {{deviceId}}
  18. </view>
  19. </view>
  20. <view class="msg-item">
  21. <view class="">
  22. 机器状态
  23. </view>
  24. <view class="" style="color: #2C6FF3;">
  25. {{err}}
  26. </view>
  27. </view>
  28. </view>
  29. <view class="btn safe-bottom" v-if="!isActive">
  30. <xbutton size="large" @click="activeDeviceNow">激活货柜</xbutton>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import {
  36. deviceActive,
  37. getActiveInfo
  38. } from "@/api/device/device.js"
  39. export default {
  40. data() {
  41. return {
  42. deviceId: '请扫描二维码',
  43. err: '未激活',
  44. isActive: false //true已激活false未激活
  45. }
  46. },
  47. onLoad(o) {
  48. this.deviceId = o.id;
  49. this.getDeviceStatus()
  50. },
  51. methods: {
  52. getDeviceStatus() {
  53. getActiveInfo({
  54. deviceId: this.deviceId
  55. }).then(res => {
  56. this.isActive = false
  57. this.err = '未激活'
  58. }).catch(err => {
  59. this.isActive = true
  60. if(err.length>10){
  61. this.err = '请重新扫码~'
  62. }else{
  63. this.err = err
  64. }
  65. })
  66. },
  67. scan() {
  68. uni.scanCode({
  69. success: (res) => {
  70. console.log('条码内容:' + res.result);
  71. let deviceId = res.result.split('=')[1]
  72. this.deviceId = deviceId
  73. }
  74. });
  75. },
  76. activeDeviceNow() {
  77. deviceActive({
  78. deviceId: this.deviceId
  79. }).then(res => {
  80. this.$modal.msg('激活成功~')
  81. setTimeout(() => {
  82. this.$tab.redirectTo(`/pages/equipment/detail?id=${this.deviceId}`)
  83. }, 1500)
  84. }).catch(err => {
  85. if (err.indeOf('com.netflix') == -1) {
  86. this.err = err
  87. } else {
  88. this.err = '获取失败'
  89. }
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .container {
  97. position: relative;
  98. text-align: center;
  99. .img {
  100. width: 147rpx;
  101. height: 281rpx;
  102. margin-top: 75rpx;
  103. margin-left: 292rpx;
  104. }
  105. .device-msg {
  106. width: 724rpx;
  107. margin-left: 13rpx;
  108. margin-top: 115rpx;
  109. background-color: #F5F5F5;
  110. border-radius: 14rpx;
  111. padding: 0 37rpx;
  112. .msg-item {
  113. line-height: 92rpx;
  114. font-size: 28rpx;
  115. color: #333;
  116. display: flex;
  117. justify-content: space-between;
  118. &+.msg-item {
  119. border-top: 1rpx solid #E2E2E2;
  120. }
  121. >view:nth-child(1) {}
  122. >view:nth-child(2) {
  123. color: #777777;
  124. }
  125. }
  126. }
  127. .device-code {
  128. font-size: 54rpx;
  129. font-weight: bold;
  130. margin-top: 46%;
  131. color: #333;
  132. }
  133. .device-tips {
  134. font-size: 28rpx;
  135. margin-top: 30rpx;
  136. }
  137. .device-err {
  138. font-size: 22rpx;
  139. color: red;
  140. margin-top: 40rpx;
  141. }
  142. .scan {
  143. margin-top: 36rpx;
  144. }
  145. .btn {
  146. width: 100%;
  147. position: fixed;
  148. left: 0;
  149. bottom: 24rpx;
  150. padding: 0 24rpx;
  151. }
  152. }
  153. </style>