scanProduct.vue 8.7 KB

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