scanCodePrint.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. if(res.status == 200){
  67. let params = {
  68. shelfName: res.data&&res.data[0]&&res.data[0].shelf&&res.data[0].shelf.shelfName,
  69. productName: res.data&&res.data[0]&&res.data[0].product&&res.data[0].product.name,
  70. productCode: res.data&&res.data[0]&&res.data[0].product&&res.data[0].product.code,
  71. confirmQty: res.data&&res.data[0]&&res.data[0].confirmQty,
  72. shelfSn: res.data&&res.data[0]&&res.data[0].shelfSn,
  73. shelfSn: res.data&&res.data[0]&&res.data[0].shelfSn
  74. }
  75. uni.navigateTo({ url: "/pages/common/printTag/printTag?page=smdy&data="+JSON.stringify(params) })
  76. }else{
  77. this.confirmModal = true
  78. }
  79. uni.hideLoading()
  80. })
  81. },
  82. modalConfirm(){
  83. this.confirmModal = false
  84. this.barcode.start()
  85. },
  86. init(){
  87. const _this = this
  88. // 初始化
  89. this.barcode = plus.barcode.create('barcode', [], {
  90. top:'0px',
  91. left:'0px',
  92. width: '100%',
  93. height: '28%',
  94. position: 'static',
  95. frameColor: '#00aaff',
  96. scanbarColor: '#00aaff'
  97. })
  98. // 设置高度
  99. const query = uni.createSelectorQuery().in(this);
  100. query.select('#barcode').boundingClientRect(data => {
  101. this.barcode.setStyle({
  102. height: data.height + 'px' // 调整扫码控件的位置
  103. })
  104. }).exec()
  105. // 扫码成功后
  106. this.barcode.onmarked = function(type, result) {
  107. _this.scanResult(result)
  108. }
  109. // 扫码识别出错
  110. this.barcode.onerror = function(error){
  111. console.log(error)
  112. _this.toashMsg("条形码错误!")
  113. _this.barcode.start()
  114. }
  115. const currentWebview = this.$mp.page.$getAppWebview()
  116. currentWebview.append(this.barcode)
  117. this.barcode.start()
  118. }
  119. }
  120. }
  121. </script>
  122. <style lang="less">
  123. page{
  124. height: 100vh;
  125. }
  126. .scanCodePrint-wrap{
  127. width: 100%;
  128. height: 100%;
  129. .barCode{
  130. height: 28%;
  131. }
  132. .info-body{
  133. flex-flow: 1;
  134. overflow: auto;
  135. height: 72%;
  136. }
  137. .info{
  138. background-color: #FFFFFF;
  139. padding: 10rpx 30upx;
  140. font-size: 32rpx;
  141. margin-top: 20rpx;
  142. }
  143. }
  144. </style>