scanCodePrint.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view class="scanCodePrint-wrap">
  3. <view class="barCode" id="barcode"></view>
  4. <view class="info-body">
  5. <view class="info partList">
  6. <!-- 补货产品 -->
  7. <partList :list="partList" title="补货产品" model="view" fromPage="scanCodePrint" ref="partList" noDataText="暂无产品"></partList>
  8. </view>
  9. </view>
  10. <!-- 确认弹框 -->
  11. <common-modal v-if="confirmModal" :openModal="confirmModal" title="扫码失败" content="确认对该数字货架进行补货吗?" confirmText="好的" :isCancel="false" @confirm="modalConfirm" @close="confirmModal=false" />
  12. </view>
  13. </template>
  14. <script>
  15. import partList from '@/pages/common/partList.vue'
  16. import commonModal from '@/pages/common/commonModal.vue'
  17. import { shelfReplenishDetailList, shelfReplenishQrCode } from '@/api/shelfReplenish'
  18. export default {
  19. components: { partList, commonModal },
  20. data() {
  21. return {
  22. barcode:null,
  23. replenishBillSn: null,
  24. partList: [],
  25. confirmModal: false
  26. }
  27. },
  28. onReady() {
  29. // 初始化摄像头
  30. this.init()
  31. },
  32. onLoad(options) {
  33. this.replenishBillSn = options.replenishBillSn
  34. this.getPartList()
  35. },
  36. methods: {
  37. // 查询列表
  38. getPartList(){
  39. const _this = this
  40. shelfReplenishDetailList({ replenishBillSn: this.replenishBillSn }).then(res => {
  41. if(res.status == 200 && res.data){
  42. this.partList = res.data || []
  43. }else{
  44. this.partList = []
  45. }
  46. })
  47. },
  48. // 扫码结果
  49. scanResult(qrCode){
  50. const _this = this
  51. shelfReplenishQrCode({
  52. qrCode: qrCode,
  53. replenishBillSn: this.replenishBillSn
  54. }).then(res => {
  55. if(res.status == 200){
  56. _this.toashMsg("扫码成功!")
  57. uni.navigateTo({ url: "/pages/common/printTag/printTag?sn="+item.replenishBillSn })
  58. }else{
  59. this.confirmModal = true
  60. // clzConfirm({
  61. // title: '扫码失败',
  62. // content: res.message,
  63. // showCancel: false,
  64. // success: (ret) => {
  65. // _this.barcode.start()
  66. // }
  67. // })
  68. }
  69. })
  70. },
  71. modalConfirm(){
  72. this.confirmModal = false
  73. this.barcode.start()
  74. },
  75. init(){
  76. const _this = this
  77. // 初始化
  78. this.barcode = plus.barcode.create('barcode', ['EAN13'], {
  79. top:'0px',
  80. left:'0px',
  81. width: '100%',
  82. height: '28%',
  83. position: 'static',
  84. frameColor: '#00aaff',
  85. scanbarColor: '#00aaff'
  86. })
  87. // 设置高度
  88. const query = uni.createSelectorQuery().in(this);
  89. query.select('#barcode').boundingClientRect(data => {
  90. this.barcode.setStyle({
  91. height: data.height + 'px' // 调整扫码控件的位置
  92. })
  93. }).exec()
  94. // 扫码成功后
  95. this.barcode.onmarked = function(type, result) {
  96. _this.scanResult(result)
  97. }
  98. // 扫码识别出错
  99. this.barcode.onerror = function(error){
  100. console.log(error)
  101. _this.toashMsg("条形码错误!")
  102. _this.barcode.start()
  103. }
  104. const currentWebview = this.$mp.page.$getAppWebview()
  105. currentWebview.append(this.barcode)
  106. this.barcode.start()
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="less">
  112. page{
  113. height: 100vh;
  114. }
  115. .scanCodePrint-wrap{
  116. width: 100%;
  117. height: 100%;
  118. .barCode{
  119. height: 28%;
  120. }
  121. .info-body{
  122. flex-flow: 1;
  123. overflow: auto;
  124. height: 72%;
  125. }
  126. .info{
  127. background-color: #FFFFFF;
  128. padding: 10rpx 30upx;
  129. font-size: 32rpx;
  130. margin-top: 20rpx;
  131. }
  132. }
  133. </style>