scanCodePrint.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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.qty = item.putQty ? Number(item.putQty) : 0
  101. }else{
  102. item.qty = item.qty ? Number(item.qty) : 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. qty: res.data&&res.data[0]&&res.data[0].qty,
  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. if(!(res.data[0].billState == 'FINISH'&&!params.qty)){
  139. uni.navigateTo({ url: "/pages/common/printTag/printTag?page=smdy&data="+JSON.stringify(params) })
  140. }else{
  141. this.toashMsg("签收数量为0,不可打印")
  142. }
  143. }else{
  144. this.contTitle = 0
  145. this.contModal = "抱歉,该产品不是此补货单的产品请更换产品重新扫描?"
  146. this.confirmModal = true
  147. }
  148. uni.hideLoading()
  149. })
  150. },
  151. modalConfirm(){
  152. this.confirmModal = false
  153. this.scanCode()
  154. },
  155. init(){
  156. const _this = this
  157. // 初始化
  158. //#ifdef APP-PLUS
  159. this.barcode = plus.barcode.create('barcode', [], {
  160. top:'0px',
  161. left:'0px',
  162. width: '100%',
  163. height: '28%',
  164. position: 'static',
  165. frameColor: '#00aaff',
  166. scanbarColor: '#00aaff'
  167. })
  168. //#endif
  169. // 设置高度
  170. const query = uni.createSelectorQuery().in(this);
  171. query.select('#barcode').boundingClientRect(data => {
  172. this.barcode.setStyle({
  173. height: data.height + 'px' // 调整扫码控件的位置
  174. })
  175. }).exec()
  176. // 扫码成功后
  177. this.barcode.onmarked = function(type, result) {
  178. console.log(type,result)
  179. _this.scanResult(result)
  180. }
  181. // 扫码识别出错
  182. this.barcode.onerror = function(error){
  183. console.log(error)
  184. _this.toashMsg("条形码错误!")
  185. _this.barcode.start()
  186. }
  187. const currentWebview = this.$scope.$getAppWebview()
  188. currentWebview.append(this.barcode)
  189. this.barcode.start()
  190. }
  191. }
  192. }
  193. </script>
  194. <style lang="less">
  195. page{
  196. height: 100vh;
  197. }
  198. .scanCodePrint-wrap{
  199. width: 100%;
  200. height: 100%;
  201. display: flex;
  202. flex-direction: column;
  203. .barCode{
  204. height: 28%;
  205. }
  206. .info-body{
  207. flex-grow: 1;
  208. overflow: auto;
  209. padding-bottom: 120rpx;
  210. }
  211. .info{
  212. background-color: #FFFFFF;
  213. padding: 10rpx 30upx;
  214. font-size: 32rpx;
  215. margin-top: 20rpx;
  216. }
  217. .sendOutGoods-footer{
  218. padding: 26upx 32upx 30upx;
  219. background-color: #fff;
  220. position: fixed;
  221. left: 0;
  222. bottom: 0;
  223. width: 100%;
  224. box-shadow: 3px 1px 7px #eee;
  225. }
  226. }
  227. </style>