scanCodePrint.vue 4.2 KB

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