scanProduct.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <view class="scanCode-wrap">
  3. <view class="barCode" id="barcode"></view>
  4. <view class="info-body">
  5. <view class="info" v-if="productInfo">
  6. <view>
  7. <view class="shelfPlaceCode">{{shelfPlaceCode}}</view>
  8. <view class="flex flex_1 align_center">
  9. <view class="pimgs">
  10. <u-image :src="productInfo.images?productInfo.images:`../../static/${$config('themePath')}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
  11. </view>
  12. <view class="pinfo flex_1">
  13. <view class="ptxt flex align_center justify_between">
  14. <view>{{productInfo.code}}</view>
  15. <view class="pcode">
  16. 可用库存:<text>{{productInfo.shelfCartApi?productInfo.shelfCartApi.qty:0}} </text> {{productInfo.unit}}
  17. </view>
  18. </view>
  19. <view class="pname">
  20. {{productInfo.productName}}
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="product-nums">
  26. <view>本次上架数量</view>
  27. <view class="numsBox flex align_center justify_between">
  28. <view class="a-left" @click="numsBoxScroll(0)"><u-icon name="arrow-left"></u-icon></view>
  29. <scroll-view class="scroll-nums" scroll-x="true" :scroll-left="scleft">
  30. <view class="ntabs-box flex align_center">
  31. <view class="ntabs" @click="saveData(item)" :class="curQty==item?'active':''" v-for="item in 100" :key="item">{{item}}</view>
  32. </view>
  33. </scroll-view>
  34. <view class="a-right" @click="numsBoxScroll(1)"><u-icon name="arrow-right"></u-icon></view>
  35. </view>
  36. </view>
  37. <view class="infoTits" v-if="productInfo.shelfCartApi">产品已录入,请确认数量</view>
  38. </view>
  39. <view class="noData" v-else>
  40. 暂无扫描结果
  41. </view>
  42. </view>
  43. <!-- 确认弹框 -->
  44. <u-popup v-model="confirmModal" closeable mode="bottom" border-radius="14" width="80%" @close="modalConfirm">
  45. <view style="display: flex;flex-direction:column;justify-content: center;padding: 30rpx 30rpx 120rpx;">
  46. <view style="margin-top: 40rpx;text-align: center;">没有找到该产品,请重新扫描</view>
  47. <view style="color: #999;padding: 30upx 30upx 50upx;text-align: center;">试一试</view>
  48. <view style="text-align: center;display: flex;justify-content: space-between;">
  49. <u-button style="width: 40%;" type='primary' shape="circle" @click="searchProduct()" size="medium">按产品编码搜索</u-button>
  50. <!-- <u-button style="width: 40%;" @click="modalConfirm" type='primary' shape="circle" size="medium">继续扫码</u-button> -->
  51. </view>
  52. </view>
  53. </u-popup>
  54. </view>
  55. </template>
  56. <script>
  57. import { queryProduct, shelfCartSave } from '@/api/shelfCart'
  58. export default {
  59. components: { },
  60. data() {
  61. return {
  62. barcode:null,
  63. shelfSn: null,
  64. shelfName: '',
  65. layer:'',
  66. confirmModal: false,
  67. productInfo: null,
  68. shelfPlaceCode: '',
  69. shelfCartSn: '',
  70. curQty: '',
  71. scleft: 0,
  72. fromPage: null,
  73. qrCode: ''
  74. }
  75. },
  76. onReady() {
  77. uni.setNavigationBarTitle({
  78. title: '扫描条形码—' +this.layer+'层'
  79. })
  80. // 设置高度
  81. const query = uni.createSelectorQuery().in(this);
  82. query.select('#barcode').boundingClientRect(data => {
  83. this.barcode.setStyle({
  84. width: data.width + 'px',
  85. height: data.height + 'px' // 调整扫码控件的位置
  86. })
  87. }).exec()
  88. },
  89. onLoad(options) {
  90. this.shelfSn = options.shelfSn
  91. this.layer = options.layer
  92. this.shelfName = options.shelfName
  93. this.customerSn = options.customerSn
  94. this.fromPage = options.from
  95. // 初始化摄像头
  96. this.init()
  97. },
  98. onBackPress(e) {
  99. uni.$emit("updateTempHw")
  100. if(!this.fromPage){
  101. uni.redirectTo({
  102. url: "/pages/batchShelves/cartList?shelfSn="+this.shelfSn+'&layer='+this.layer+'&shelfName='+this.shelfName+'&customerSn='+this.customerSn
  103. })
  104. }else{
  105. return false
  106. }
  107. return true
  108. },
  109. onNavigationBarButtonTap(e) {
  110. this.searchProduct()
  111. },
  112. methods: {
  113. numsBoxScroll(type){
  114. this.scleft = type ? (this.scleft+150) : (this.scleft-150)
  115. },
  116. searchProduct(){
  117. uni.redirectTo({
  118. url: "/pages/batchShelves/searchProduct?shelfSn="+this.shelfSn+'&layer='+this.layer+'&shelfName='+this.shelfName+'&customerSn='+this.customerSn+'&from='+this.fromPage
  119. })
  120. },
  121. // 扫码结果
  122. scanResult(){
  123. const _this = this
  124. uni.showLoading({
  125. title: "正在查询产品信息"
  126. })
  127. let params = {
  128. qrCode: this.qrCode,
  129. shelfSn: this.shelfSn,
  130. shelfTierCode: this.layer
  131. }
  132. console.log(params)
  133. queryProduct(params).then(res => {
  134. console.log(res)
  135. if(res.status == 200&&res.data&&res.data.productList&&res.data.productList.length){
  136. const ret = res.data.productList[0]
  137. this.productInfo = ret
  138. this.shelfPlaceCode = res.data.shelfPlaceCode
  139. // 已录入
  140. if(ret.shelfCartApi){
  141. this.curQty = ret.shelfCartApi.qty
  142. this.scleft = this.curQty * 30
  143. this.shelfCartSn = ret.shelfCartApi.shelfCartSn
  144. }else{
  145. this.curQty = ''
  146. this.scleft = 0
  147. this.shelfCartSn =''
  148. }
  149. setTimeout(()=>{
  150. this.barcode.start()
  151. },2000)
  152. }else{
  153. this.confirmModal = true
  154. }
  155. uni.hideLoading()
  156. })
  157. },
  158. // 保存
  159. saveData(nums){
  160. uni.showLoading({
  161. title: '正在保存...'
  162. })
  163. const a = this.productInfo.shelfCartApi || this.productInfo.shelfProductApi
  164. const params = {
  165. shelfSn: this.shelfSn,
  166. shelfName: this.shelfName,
  167. shelfTierCode: a ? a.shelfTierCode : this.layer,
  168. shelfPlaceSn: a ? a.shelfPlaceSn : undefined,
  169. shelfPlaceCode: a?a.shelfPlaceCode:this.shelfPlaceCode,
  170. productSn: this.productInfo.productSn,
  171. productCode: this.productInfo.code,
  172. qty: nums,
  173. price: this.productInfo.price,
  174. cost: this.productInfo.terminalPrice,
  175. shelfCartSn: this.shelfCartSn
  176. }
  177. console.log(params)
  178. shelfCartSave(params).then(res => {
  179. console.log(res)
  180. if(res.status == 200){
  181. this.toashMsg('保存成功,继续扫描')
  182. this.curQty = nums
  183. this.shelfCartSn = res.data.shelfCartSn
  184. this.scanResult()
  185. }
  186. setTimeout(()=>{
  187. uni.hideLoading()
  188. },4000)
  189. })
  190. },
  191. modalConfirm(){
  192. this.confirmModal = false
  193. this.barcode.start()
  194. },
  195. startScan(){
  196. this.barcode.start()
  197. },
  198. init(){
  199. const _this = this
  200. // 初始化
  201. this.barcode = plus.barcode.create('barcode', [
  202. plus.barcode.QR,
  203. plus.barcode.EAN13,
  204. plus.barcode.EAN8,
  205. plus.barcode.UPCA,
  206. plus.barcode.UPCE,
  207. plus.barcode.CODABAR,
  208. plus.barcode.CODE39,
  209. plus.barcode.CODE128,
  210. plus.barcode.ITF
  211. ], {
  212. top:'0px',
  213. left:'0px',
  214. width: '100%',
  215. height: '45%',
  216. position: 'static',
  217. frameColor: '#00aaff',
  218. scanbarColor: '#00aaff'
  219. })
  220. // 扫码成功后
  221. this.barcode.onmarked = function(type, result) {
  222. console.log(type,result)
  223. _this.qrCode = result
  224. _this.scanResult()
  225. }
  226. // 扫码识别出错
  227. this.barcode.onerror = function(error){
  228. console.log(error)
  229. _this.toashMsg("条形码错误!")
  230. _this.barcode.start()
  231. }
  232. const currentWebview = this.$mp.page.$getAppWebview()
  233. currentWebview.append(this.barcode)
  234. this.barcode.start()
  235. }
  236. }
  237. }
  238. </script>
  239. <style lang="less">
  240. page{
  241. height: 100vh;
  242. }
  243. .scanCode-wrap{
  244. width: 100%;
  245. height: 100vh;
  246. display: flex;
  247. flex-direction: column;
  248. .barCode{
  249. height: 45%;
  250. }
  251. .info-body{
  252. flex-grow: 1;
  253. overflow: auto;
  254. .noData{
  255. padding: 100rpx 20rpx 0;
  256. text-align: center;
  257. color: #999;
  258. }
  259. .info{
  260. background-color: #FFFFFF;
  261. padding: 10rpx 30upx;
  262. font-size: 32rpx;
  263. margin-top: 20rpx;
  264. .shelfPlaceCode{
  265. background-color: #f6f6f6;
  266. text-align: center;
  267. padding: 10rpx 20rpx;
  268. border-radius: 50rpx;
  269. margin-bottom: 15rpx;
  270. }
  271. .pimgs{
  272. padding:0.1rem;
  273. background:#f8f8f8;
  274. border-radius:0.3rem;
  275. }
  276. .pinfo{
  277. line-height:normal;
  278. padding-left: 20rpx;
  279. color: #666;
  280. .pcode{
  281. color:#999;
  282. text{
  283. color: #000;
  284. }
  285. }
  286. }
  287. .product-nums{
  288. border-top: 10rpx solid #eee;
  289. margin-top: 20rpx;
  290. > view{
  291. &:first-child{
  292. text-align: center;
  293. color: #999;
  294. margin-top: 20rpx;
  295. }
  296. }
  297. .numsBox{
  298. .scroll-nums{
  299. width: 85%;
  300. padding: 10rpx 0;
  301. .ntabs-box{
  302. margin: 10rpx 0;
  303. }
  304. .ntabs{
  305. background-color: #fff;
  306. border:1rpx solid #aeaeae;
  307. box-shadow: 2rpx 4rpx 6rpx #eee;
  308. border-radius: 15rpx;
  309. padding: 10rpx 15rpx;
  310. margin: 10rpx 2%;
  311. width: 100rpx;
  312. }
  313. .active{
  314. border-color: crimson;
  315. background-color: crimson;
  316. color: #FFFFFF;
  317. }
  318. .a-left,.a-right{
  319. color: #666;
  320. }
  321. }
  322. }
  323. }
  324. .infoTits{
  325. padding: 30rpx;
  326. text-align: center;
  327. color: red;
  328. font-size: 24rpx;
  329. }
  330. }
  331. }
  332. }
  333. </style>