scanCodePrint.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.sn
  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. res.data.map(item =>{
  43. item.confirmQty = item.confirmQty ? Number(item.confirmQty) : 0
  44. })
  45. this.partList = res.data || []
  46. console.log(this.partList,'this.partList')
  47. }else{
  48. this.partList = []
  49. }
  50. })
  51. },
  52. // 扫码结果
  53. scanResult(qrCode){
  54. const _this = this
  55. console.log(qrCode)
  56. uni.showLoading({
  57. title: "正在查询产品信息"
  58. })
  59. shelfReplenishQrCode({
  60. qrCode: qrCode,
  61. replenishBillSn: this.replenishBillSn
  62. }).then(res => {
  63. console.log(res)
  64. if(res.status == 200){
  65. uni.navigateTo({ url: "/pages/common/printTag/printTag?sn="+item.replenishBillSn })
  66. }else{
  67. this.confirmModal = true
  68. // clzConfirm({
  69. // title: '扫码失败',
  70. // content: res.message,
  71. // showCancel: false,
  72. // success: (ret) => {
  73. // _this.barcode.start()
  74. // }
  75. // })
  76. }
  77. uni.hideLoading()
  78. })
  79. },
  80. modalConfirm(){
  81. this.confirmModal = false
  82. this.barcode.start()
  83. },
  84. init(){
  85. const _this = this
  86. // 初始化
  87. this.barcode = plus.barcode.create('barcode', [], {
  88. top:'0px',
  89. left:'0px',
  90. width: '100%',
  91. height: '28%',
  92. position: 'static',
  93. frameColor: '#00aaff',
  94. scanbarColor: '#00aaff'
  95. })
  96. // 设置高度
  97. const query = uni.createSelectorQuery().in(this);
  98. query.select('#barcode').boundingClientRect(data => {
  99. this.barcode.setStyle({
  100. height: data.height + 'px' // 调整扫码控件的位置
  101. })
  102. }).exec()
  103. // 扫码成功后
  104. this.barcode.onmarked = function(type, result) {
  105. _this.scanResult(result)
  106. }
  107. // 扫码识别出错
  108. this.barcode.onerror = function(error){
  109. console.log(error)
  110. _this.toashMsg("条形码错误!")
  111. _this.barcode.start()
  112. }
  113. const currentWebview = this.$mp.page.$getAppWebview()
  114. currentWebview.append(this.barcode)
  115. this.barcode.start()
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="less">
  121. page{
  122. height: 100vh;
  123. }
  124. .scanCodePrint-wrap{
  125. width: 100%;
  126. height: 100%;
  127. .barCode{
  128. height: 28%;
  129. }
  130. .info-body{
  131. flex-flow: 1;
  132. overflow: auto;
  133. height: 72%;
  134. }
  135. .info{
  136. background-color: #FFFFFF;
  137. padding: 10rpx 30upx;
  138. font-size: 32rpx;
  139. margin-top: 20rpx;
  140. }
  141. }
  142. </style>