scanCodePrint.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. <view class="sendOutGoods-footer">
  11. <u-button @click="scanCode" type="success" :custom-style="customStyle" hover-class="none" shape="circle">
  12. <u-icon name="scan" size="34"></u-icon>
  13. 点击扫码
  14. </u-button>
  15. </view>
  16. <!-- 确认弹框 -->
  17. <common-modal v-if="confirmModal" :openModal="confirmModal" :title="contTitle?'扫码成功':'扫码失败'" :content="contModal" confirmText="继续扫码" @confirm="modalConfirm" @close="confirmModal=false" />
  18. </view>
  19. </template>
  20. <script>
  21. import partList from '@/pages/common/partList.vue'
  22. import commonModal from '@/pages/common/commonModal.vue'
  23. import { shelfReplenishDetailList, shelfReplenishQrCode, shelfReplenishDetailOutScan } from '@/api/shelfReplenish'
  24. export default {
  25. components: { partList, commonModal },
  26. data() {
  27. return {
  28. barcode:null,
  29. replenishBillSn: null,
  30. partList: [],
  31. contTitle: '',
  32. contModal: '',
  33. confirmModal: false,
  34. mpaasScanModule: null,
  35. customStyle: {
  36. borderRadius:'100rpx',
  37. fontSize:'30rpx',
  38. background: this.$config('primaryColor')
  39. },
  40. }
  41. },
  42. onReady() {
  43. // 初始化摄像头
  44. // this.init()
  45. },
  46. onLoad(options) {
  47. this.replenishBillSn = options.sn
  48. this.getPartList()
  49. // 监听整改完成后刷新事件
  50. uni.$on('refreshBL', this.modalConfirm)
  51. },
  52. onUnload() {
  53. uni.$off('refreshBL')
  54. },
  55. methods: {
  56. // 扫码
  57. scanCode(){
  58. // this.mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module")
  59. // this.mpaasScanModule.mpaasScan({
  60. // // 扫码识别类型,参数可多选,qrCode、barCode,不设置,默认识别所有
  61. // 'scanType': ['qrCode','barCode'],
  62. // // 是否隐藏相册,默认false不隐藏
  63. // 'hideAlbum': false
  64. // },
  65. // (ret) => {
  66. // // 返回值中,resp_code 表示返回结果值,10:用户取消,11:其他错误,1000:成功
  67. // // 返回值中,resp_message 表示返回结果信息
  68. // // 返回值中,resp_result 表示扫码结果,只有成功才会有返回
  69. // if(ret.resp_code == '1000'){
  70. // this.scanResult(ret.resp_result)
  71. // }
  72. // })
  73. this.mpaasScanModule = uni.requireNativePlugin("wss-scan")
  74. this.mpaasScanModule.scan(
  75. {
  76. "scanType":["CODABAR","CODE93","CODE39","CODE128","EAN13","EAN8","ITF14","UPCCODE_A","UPCCODE_E"],
  77. "scanMode":"Customized",
  78. "scanStyle":{
  79. "scanFrameSizePlus":{"width":250,"height":120},
  80. "scanFrameSize":200,
  81. "scanLight":"visible",
  82. "scanText":"对准物品条形码",
  83. "scanTitle":"扫码打印",
  84. }
  85. },
  86. (result) => {
  87. console.log(result)
  88. if(result.scanStatus == 1){
  89. this.scanResult(result.scanValue)
  90. }
  91. })
  92. },
  93. // 查询列表
  94. getPartList(){
  95. const _this = this
  96. shelfReplenishDetailList({ replenishBillSn: this.replenishBillSn }).then(res => {
  97. if(res.status == 200 && res.data){
  98. res.data.map(item =>{
  99. if(item.billState == 'FINISH'){
  100. item.confirmQty = item.putQty ? Number(item.putQty) : 0
  101. }else{
  102. item.confirmQty = item.confirmQty ? Number(item.confirmQty) : 0
  103. }
  104. })
  105. this.partList = res.data || []
  106. }else{
  107. this.partList = []
  108. }
  109. })
  110. },
  111. // 扫码结果
  112. scanResult(qrCode){
  113. const _this = this
  114. uni.showLoading({
  115. title: "正在查询产品信息"
  116. })
  117. console.log({
  118. productQrCode: qrCode,
  119. replenishBillSn: this.replenishBillSn
  120. })
  121. shelfReplenishQrCode({
  122. productQrCode: qrCode,
  123. replenishBillSn: this.replenishBillSn
  124. }).then(res => {
  125. console.log(res)
  126. if(res.status == 200&&res.data.length){
  127. let params = {
  128. shelfName: res.data&&res.data[0]&&res.data[0].shelf&&res.data[0].shelf.shelfName,
  129. productName: res.data&&res.data[0]&&res.data[0].product&&res.data[0].product.name,
  130. productCode: res.data&&res.data[0]&&res.data[0].product&&res.data[0].product.code,
  131. productSn: res.data&&res.data[0]&&res.data[0].product&&res.data[0].product.productSn,
  132. confirmQty: res.data&&res.data[0]&&res.data[0].confirmQty,
  133. shelfSn: res.data&&res.data[0]&&res.data[0].shelfSn,
  134. replenishBillDetailSn: res.data&&res.data[0]&&res.data[0].replenishBillDetailSn,
  135. shelfPlaceCode: res.data&&res.data[0]&&res.data[0].shelfPlaceCode,
  136. shelfPlaceSn: res.data&&res.data[0]&&res.data[0].shelfPlaceSn
  137. }
  138. uni.navigateTo({ url: "/pages/common/printTag/printTag?page=smdy&data="+JSON.stringify(params) })
  139. }else{
  140. this.contTitle = 0
  141. this.contModal = "抱歉,该产品不是此补货单的产品请更换产品重新扫描?"
  142. this.confirmModal = true
  143. }
  144. uni.hideLoading()
  145. })
  146. },
  147. modalConfirm(){
  148. this.confirmModal = false
  149. this.scanCode()
  150. },
  151. init(){
  152. const _this = this
  153. // 初始化
  154. this.barcode = plus.barcode.create('barcode', [], {
  155. top:'0px',
  156. left:'0px',
  157. width: '100%',
  158. height: '28%',
  159. position: 'static',
  160. frameColor: '#00aaff',
  161. scanbarColor: '#00aaff'
  162. })
  163. // 设置高度
  164. const query = uni.createSelectorQuery().in(this);
  165. query.select('#barcode').boundingClientRect(data => {
  166. this.barcode.setStyle({
  167. height: data.height + 'px' // 调整扫码控件的位置
  168. })
  169. }).exec()
  170. // 扫码成功后
  171. this.barcode.onmarked = function(type, result) {
  172. console.log(type,result)
  173. _this.scanResult(result)
  174. }
  175. // 扫码识别出错
  176. this.barcode.onerror = function(error){
  177. console.log(error)
  178. _this.toashMsg("条形码错误!")
  179. _this.barcode.start()
  180. }
  181. const currentWebview = this.$mp.page.$getAppWebview()
  182. currentWebview.append(this.barcode)
  183. this.barcode.start()
  184. }
  185. }
  186. }
  187. </script>
  188. <style lang="less">
  189. page{
  190. height: 100vh;
  191. }
  192. .scanCodePrint-wrap{
  193. width: 100%;
  194. height: 100%;
  195. display: flex;
  196. flex-direction: column;
  197. .barCode{
  198. height: 28%;
  199. }
  200. .info-body{
  201. flex-grow: 1;
  202. overflow: auto;
  203. padding-bottom: 120rpx;
  204. }
  205. .info{
  206. background-color: #FFFFFF;
  207. padding: 10rpx 30upx;
  208. font-size: 32rpx;
  209. margin-top: 20rpx;
  210. }
  211. .sendOutGoods-footer{
  212. padding: 26upx 32upx 30upx;
  213. background-color: #fff;
  214. position: fixed;
  215. left: 0;
  216. bottom: 0;
  217. width: 100%;
  218. box-shadow: 3px 1px 7px #eee;
  219. }
  220. }
  221. </style>