scanProduct.vue 8.2 KB

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