scanProduct.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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.currQty||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="center" border-radius="14" width="80%" @close="modalConfirm">
  45. <view style="display: flex;flex-direction:column;justify-content: center;padding: 30rpx;">
  46. <view style="margin-top: 40rpx;text-align: center;">没有找到该产品,请重新扫描</view>
  47. <view style="color: dodgerblue;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%;" 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. }
  73. },
  74. onReady() {
  75. // 初始化摄像头
  76. this.init()
  77. },
  78. onLoad(options) {
  79. this.shelfSn = options.shelfSn
  80. this.layer = options.layer
  81. this.shelfName = options.shelfName
  82. this.customerSn = options.customerSn
  83. uni.setNavigationBarTitle({
  84. title: '扫描条形码——' +this.layer+'层'
  85. })
  86. },
  87. onBackPress() {
  88. uni.redirectTo({
  89. url: "/pages/batchShelves/cartList?shelfSn="+this.shelfSn+'&layer='+this.layer+'&shelfName='+this.shelfName+'&customerSn='+this.customerSn
  90. })
  91. },
  92. onNavigationBarButtonTap(e) {
  93. this.searchProduct()
  94. },
  95. methods: {
  96. numsBoxScroll(type){
  97. this.scleft = type ? (this.scleft+150) : (this.scleft-150)
  98. },
  99. searchProduct(){
  100. uni.redirectTo({
  101. url: "/pages/batchShelves/searchProduct?shelfSn="+this.shelfSn+'&layer='+this.layer+'&shelfName='+this.shelfName+'&customerSn='+this.customerSn
  102. })
  103. },
  104. // 扫码结果
  105. scanResult(qrCode){
  106. const _this = this
  107. uni.showLoading({
  108. title: "正在查询产品信息"
  109. })
  110. let params = {
  111. qrCode: qrCode,
  112. shelfSn: this.shelfSn,
  113. shelfTierCode: this.layer
  114. }
  115. console.log(params)
  116. queryProduct(params).then(res => {
  117. console.log(res)
  118. if(res.status == 200&&res.data&&res.data.productList&&res.data.productList.length){
  119. const ret = res.data.productList[0]
  120. this.productInfo = ret
  121. this.shelfPlaceCode = res.data.shelfPlaceCode
  122. // 已录入
  123. if(ret.shelfCartApi){
  124. this.curQty = ret.shelfCartApi.qty
  125. this.scleft = this.curQty * 30
  126. this.shelfCartSn = ret.shelfCartApi.shelfCartSn
  127. }else{
  128. this.curQty = ''
  129. this.scleft = 0
  130. this.shelfCartSn =''
  131. }
  132. setTimeout(()=>{
  133. this.barcode.start()
  134. },2000)
  135. }else{
  136. this.confirmModal = true
  137. }
  138. uni.hideLoading()
  139. })
  140. },
  141. // 保存
  142. saveData(nums){
  143. uni.showLoading({
  144. title: '正在保存...'
  145. })
  146. const a = this.productInfo.shelfCartApi || this.productInfo.shelfProductApi
  147. const params = {
  148. shelfSn: this.shelfSn,
  149. shelfName: this.shelfName,
  150. shelfTierCode: a ? a.shelfTierCode : this.layer,
  151. shelfPlaceSn: a ? a.shelfPlaceSn : undefined,
  152. shelfPlaceCode: a?a.shelfPlaceCode:this.shelfPlaceCode,
  153. productSn: this.productInfo.productSn,
  154. productCode: this.productInfo.code,
  155. qty: nums,
  156. price: this.productInfo.price,
  157. cost: this.productInfo.cost,
  158. shelfCartSn: this.shelfCartSn
  159. }
  160. console.log(params)
  161. shelfCartSave(params).then(res => {
  162. console.log(res)
  163. if(res.status == 200){
  164. this.toashMsg('保存成功,继续扫描')
  165. this.curQty = nums
  166. this.shelfCartSn = res.data.shelfCartSn
  167. }
  168. setTimeout(()=>{
  169. uni.hideLoading()
  170. },4000)
  171. })
  172. },
  173. modalConfirm(){
  174. this.confirmModal = false
  175. this.barcode.start()
  176. },
  177. startScan(){
  178. this.barcode.start()
  179. },
  180. init(){
  181. const _this = this
  182. // 初始化
  183. this.barcode = plus.barcode.create('barcode', [], {
  184. top:'0px',
  185. left:'0px',
  186. width: '100%',
  187. height: '35%',
  188. position: 'static',
  189. frameColor: '#00aaff',
  190. scanbarColor: '#00aaff'
  191. })
  192. // 设置高度
  193. const query = uni.createSelectorQuery().in(this);
  194. query.select('#barcode').boundingClientRect(data => {
  195. this.barcode.setStyle({
  196. height: data.height + 'px' // 调整扫码控件的位置
  197. })
  198. }).exec()
  199. // 扫码成功后
  200. this.barcode.onmarked = function(type, result) {
  201. console.log(type,result)
  202. _this.scanResult(result)
  203. }
  204. // 扫码识别出错
  205. this.barcode.onerror = function(error){
  206. console.log(error)
  207. _this.toashMsg("条形码错误!")
  208. _this.barcode.start()
  209. }
  210. const currentWebview = this.$mp.page.$getAppWebview()
  211. currentWebview.append(this.barcode)
  212. this.barcode.start()
  213. }
  214. }
  215. }
  216. </script>
  217. <style lang="less">
  218. page{
  219. height: 100vh;
  220. }
  221. .scanCode-wrap{
  222. width: 100%;
  223. height: 100vh;
  224. display: flex;
  225. flex-direction: column;
  226. .barCode{
  227. height: 35%;
  228. }
  229. .info-body{
  230. flex-grow: 1;
  231. overflow: auto;
  232. .noData{
  233. padding: 100rpx 20rpx 0;
  234. text-align: center;
  235. color: #999;
  236. }
  237. .info{
  238. background-color: #FFFFFF;
  239. padding: 10rpx 30upx;
  240. font-size: 32rpx;
  241. margin-top: 20rpx;
  242. .shelfPlaceCode{
  243. background-color: #f6f6f6;
  244. text-align: center;
  245. padding: 10rpx 20rpx;
  246. border-radius: 50rpx;
  247. margin-bottom: 15rpx;
  248. }
  249. .pimgs{
  250. padding:0.1rem;
  251. background:#f8f8f8;
  252. border-radius:0.3rem;
  253. }
  254. .pinfo{
  255. line-height:normal;
  256. padding-left: 20rpx;
  257. color: #666;
  258. .pcode{
  259. color:#999;
  260. text{
  261. color: #000;
  262. }
  263. }
  264. }
  265. .product-nums{
  266. border-top: 10rpx solid #eee;
  267. margin-top: 20rpx;
  268. > view{
  269. &:first-child{
  270. text-align: center;
  271. color: #999;
  272. margin-top: 20rpx;
  273. }
  274. }
  275. .numsBox{
  276. .scroll-nums{
  277. width: 85%;
  278. padding: 10rpx 0;
  279. .ntabs-box{
  280. margin: 10rpx 0;
  281. }
  282. .ntabs{
  283. background-color: #fff;
  284. border:1rpx solid #aeaeae;
  285. box-shadow: 2rpx 4rpx 6rpx #eee;
  286. border-radius: 15rpx;
  287. padding: 10rpx 15rpx;
  288. margin: 10rpx 2%;
  289. width: 100rpx;
  290. }
  291. .active{
  292. border-color: crimson;
  293. background-color: crimson;
  294. color: #FFFFFF;
  295. }
  296. .a-left,.a-right{
  297. color: #666;
  298. }
  299. }
  300. }
  301. }
  302. .infoTits{
  303. padding: 30rpx;
  304. text-align: center;
  305. color: red;
  306. font-size: 24rpx;
  307. }
  308. }
  309. }
  310. }
  311. </style>