scanProduct.vue 8.5 KB

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