scanProduct.vue 8.4 KB

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