tag-init-scan.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!-- 新建标签 扫描Rfid -->
  2. <template>
  3. <view class="container-wrap">
  4. <uni-nav-bar title="扫描添加" :status-bar="true" background-color="#3F92F9" color="#FFF">
  5. <view slot="left">
  6. <u-icon name="account-fill" color="#FFF" size="35"></u-icon>
  7. <span style="padding: 0 5rpx;color: #FFFFFF;">{{ userInfo.name }}</span>
  8. </view>
  9. <view slot="right" @tap="$utils.back()">
  10. <span style="color: #FFFFFF;">返回</span>
  11. </view>
  12. </uni-nav-bar>
  13. <view class="container">
  14. <!-- 扫描rfid -->
  15. <view class="reading">
  16. <view class="title">请扫描新的物料RFID标签</view>
  17. <u-image height="300rpx" mode="aspectFit" src="../../static/images/rfid.png"></u-image>
  18. <view class="title" v-if="isReading">扫描中...</view>
  19. <view class="title" v-if="!isReading">扫描结果</view>
  20. </view>
  21. <view class="btn" v-if="!isReading">
  22. <view class="row">
  23. <u-button throttleTime="300" type="primary" style="width: 100%;" @click="bind">绑定并继续</u-button>
  24. </view>
  25. <view class="row">
  26. <u-button throttleTime="300" type="primary" style="width: 100%;" @click="$utils.back(2)">取消</u-button>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. // #ifdef APP-PLUS
  34. // #endif
  35. export default {
  36. data() {
  37. return {
  38. rfidCode: '',
  39. isReading: true,
  40. option: {}
  41. };
  42. },
  43. methods: {
  44. bind() {
  45. this.$http.CreateRfidStockTag({
  46. rfidCode: this.rfidCode,
  47. bindingRfidWay: 1,
  48. ...this.option
  49. }).then(res => {
  50. if(res.code === 0) {
  51. this.$msg.showToast('创建成功!', 'success' )
  52. // 绑定成功后清除上个页面已选择的数据并返回
  53. uni.$emit('clear')
  54. setTimeout(() => {
  55. this.$utils.back()
  56. }, 2000)
  57. } else {
  58. this.isReading = true
  59. this.scanRfid()
  60. }
  61. })
  62. },
  63. scanRfid () {
  64. this.$pda.uhfScan().then(res => {
  65. console.log(res)
  66. this.isReading = false
  67. this.rfidCode = res[0].epc
  68. console.log(this.rfidCode)
  69. }).catch(() => {
  70. this.$msg.showToast('未识别到有效RFID标签!')
  71. setTimeout(() => {
  72. this.$utils.back()
  73. }, 1000)
  74. })
  75. }
  76. },
  77. onLoad(option) {
  78. this.option = this.$utils.code2Object(option.data)
  79. this.scanRfid()
  80. },
  81. onUnload() {
  82. this.$pda.uhfStop()
  83. }
  84. }
  85. </script>
  86. <style lang="scss" scoped>
  87. .container-wrap {
  88. overflow: hidden;
  89. .container {
  90. padding: 0 60rpx;
  91. padding-bottom: 80rpx;
  92. height: calc(100vh - var(--status-bar-height) - 44px);
  93. overflow: auto;
  94. .title {
  95. padding: 20rpx 0;
  96. font-size: 36rpx;
  97. font-weight: bold;
  98. text-align: center;
  99. }
  100. .reading {
  101. padding: 40rpx 0;
  102. }
  103. .info {
  104. padding: 20rpx 60rpx;
  105. border-radius: 10rpx ;
  106. background-color: #FFFFFF;
  107. .row {
  108. align-items: flex-start;
  109. .label {
  110. font-size: 32rpx;
  111. width: 160rpx;
  112. }
  113. .value {
  114. font-size: 32rpx;
  115. flex: 1;
  116. overflow: hidden;
  117. word-wrap: break-word;
  118. }
  119. }
  120. }
  121. .btn {
  122. .row {
  123. padding: 0;
  124. padding-bottom: 10rpx;
  125. width: 100%;
  126. &:last-child {
  127. padding-bottom: 0;
  128. }
  129. }
  130. }
  131. }
  132. }
  133. </style>