scanProduct.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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">
  8. <text v-if="productInfo.shelfCartApi">{{productInfo.shelfCartApi.shelfPlaceCode}}</text>
  9. <text v-else-if="productInfo.shelfProductApi">{{productInfo.shelfProductApi.shelfPlaceCode}}</text>
  10. <text v-else>{{shelfPlaceCode}}</text>
  11. </view>
  12. <view class="flex flex_1 align_center">
  13. <view class="pimgs">
  14. <u-image :src="productInfo.images?productInfo.images:`../../static/${$config('themePath')}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
  15. </view>
  16. <view class="pinfo flex_1">
  17. <view class="ptxt flex align_center justify_between">
  18. <view>{{productInfo.code}}</view>
  19. <view class="pcode" v-if="productInfo.shelfProductApi">
  20. 可用库存:
  21. <text>{{productInfo.shelfProductApi.qty}}</text>
  22. {{productInfo.unit}}
  23. </view>
  24. </view>
  25. <view class="pname">
  26. {{productInfo.productName}}
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="product-nums">
  32. <view>本次上架数量<text>(左右滑动选择)</text></view>
  33. <view class="numsBox flex align_center justify_between">
  34. <view class="a-left" @click="numsBoxScroll(0)"><u-icon name="arrow-left"></u-icon></view>
  35. <scroll-view class="scroll-nums" scroll-x="true" :scroll-left="scleft">
  36. <view class="ntabs-box flex align_center">
  37. <view :id="'nums'+item" class="ntabs" @click="saveData(item)" :class="curQty==item?'active':''" v-for="item in 99" :key="item">
  38. {{item<10?('&nbsp;'+item+'&nbsp;'):item}}
  39. </view>
  40. </view>
  41. </scroll-view>
  42. <view class="a-right" @click="numsBoxScroll(1)"><u-icon name="arrow-right"></u-icon></view>
  43. </view>
  44. </view>
  45. <view class="infoTits" v-if="productInfo.shelfCartApi">产品已录入,请确认数量</view>
  46. </view>
  47. <view class="noData" v-else>
  48. 暂无扫描结果
  49. </view>
  50. </view>
  51. <!-- 确认弹框 -->
  52. <u-popup v-model="confirmModal" closeable mode="bottom" border-radius="14" width="80%" @close="modalConfirm">
  53. <view style="display: flex;flex-direction:column;justify-content: center;padding: 30rpx 30rpx 120rpx;">
  54. <view style="margin-top: 40rpx;text-align: center;">扫描结果:{{qrCode}}</view>
  55. <view style="margin-top: 40rpx;text-align: center;">没有找到该产品,请重新扫描</view>
  56. <view style="color: #999;padding: 30upx 30upx 50upx;text-align: center;">试一试</view>
  57. <view style="text-align: center;display: flex;justify-content: space-between;">
  58. <u-button style="width: 40%;" type='primary' shape="circle" @click="searchProduct()" size="medium">按产品编码搜索</u-button>
  59. <!-- <u-button style="width: 40%;" @click="modalConfirm" type='primary' shape="circle" size="medium">继续扫码</u-button> -->
  60. </view>
  61. </view>
  62. </u-popup>
  63. </view>
  64. </template>
  65. <script>
  66. import { queryProduct, shelfCartSave } from '@/api/shelfCart'
  67. export default {
  68. components: { },
  69. data() {
  70. return {
  71. barcode:null,
  72. shelfSn: null,
  73. shelfName: '',
  74. layer:'',
  75. confirmModal: false,
  76. productInfo: null,
  77. shelfPlaceCode: '',
  78. shelfCartSn: '',
  79. curQty: '',
  80. scleft: 0,
  81. fromPage: null,
  82. qrCode: '',
  83. numsWidth: 52
  84. }
  85. },
  86. onReady() {
  87. uni.setNavigationBarTitle({
  88. title: '扫描条形码—' +this.layer+'层'
  89. })
  90. // 设置高度
  91. const query = uni.createSelectorQuery().in(this);
  92. query.select('#barcode').boundingClientRect(data => {
  93. this.barcode.setStyle({
  94. width: data.width + 'px',
  95. height: data.height + 'px' // 调整扫码控件的位置
  96. })
  97. }).exec()
  98. },
  99. onLoad(options) {
  100. this.shelfSn = options.shelfSn
  101. this.layer = options.layer
  102. this.shelfName = options.shelfName
  103. this.customerSn = options.customerSn
  104. this.fromPage = options.from||''
  105. console.log(options)
  106. // 初始化摄像头
  107. this.init()
  108. },
  109. onBackPress(e) {
  110. if(!this.fromPage){
  111. uni.redirectTo({
  112. url: "/pages/batchShelves/cartList?shelfSn="+this.shelfSn+'&layer='+this.layer+'&shelfName='+this.shelfName+'&customerSn='+this.customerSn
  113. })
  114. }else{
  115. return false
  116. }
  117. return true
  118. },
  119. onNavigationBarButtonTap(e) {
  120. this.searchProduct()
  121. },
  122. methods: {
  123. numsBoxScroll(type){
  124. this.scleft = type ? (this.scleft+this.numsWidth*3) : (this.scleft-this.numsWidth*3)
  125. },
  126. searchProduct(){
  127. uni.redirectTo({
  128. url: "/pages/batchShelves/searchProduct?shelfSn="+this.shelfSn+'&layer='+this.layer+'&shelfName='+this.shelfName+'&customerSn='+this.customerSn+'&from='+this.fromPage
  129. })
  130. },
  131. // 扫码结果
  132. scanResult(){
  133. const _this = this
  134. uni.showLoading({
  135. title: "正在查询产品信息"
  136. })
  137. let params = {
  138. qrCode: this.qrCode,
  139. shelfSn: this.shelfSn,
  140. shelfTierCode: this.layer
  141. }
  142. console.log(params)
  143. queryProduct(params).then(res => {
  144. console.log(res)
  145. if(res.status == 200&&res.data&&res.data.productList&&res.data.productList.length){
  146. const ret = res.data.productList[0]
  147. this.productInfo = ret
  148. this.shelfPlaceCode = res.data.shelfPlaceCode
  149. // 数量区域宽度
  150. const query = uni.createSelectorQuery().in(_this);
  151. query.select('#nums1').boundingClientRect(data => {
  152. _this.numsWidth = data ? (data.width + 20) : 52
  153. }).exec()
  154. // 已录入
  155. if(ret.shelfCartApi){
  156. this.curQty = ret.shelfCartApi.qty
  157. _this.scleft = (_this.curQty -1) * _this.numsWidth
  158. }else{
  159. this.curQty = ''
  160. this.scleft = 0
  161. }
  162. setTimeout(()=>{
  163. this.barcode.start()
  164. },2000)
  165. }else{
  166. this.confirmModal = true
  167. }
  168. uni.hideLoading()
  169. })
  170. },
  171. // 保存
  172. saveData(nums){
  173. uni.showLoading({
  174. title: '正在保存...'
  175. })
  176. const row = this.productInfo
  177. const item = row.shelfCartApi || row.shelfProductApi
  178. const params = {
  179. shelfSn: this.shelfSn,
  180. shelfName: this.shelfName,
  181. shelfTierCode: item?item.shelfTierCode:this.layer,
  182. shelfPlaceSn: item?item.shelfPlaceSn:undefined,
  183. shelfPlaceCode: item?item.shelfPlaceCode:this.shelfPlaceCode,
  184. productSn: row.productSn,
  185. productCode: row.code,
  186. qty: nums,
  187. price: row.price,
  188. cost: row.terminalPrice,
  189. shelfCartSn: item?item.shelfCartSn:undefined
  190. }
  191. console.log(params)
  192. shelfCartSave(params).then(res => {
  193. console.log(res)
  194. if(res.status == 200){
  195. this.toashMsg('保存成功,继续扫描')
  196. this.curQty = nums
  197. this.scanResult()
  198. }
  199. setTimeout(()=>{
  200. uni.hideLoading()
  201. },4000)
  202. })
  203. },
  204. modalConfirm(){
  205. this.confirmModal = false
  206. this.barcode.start()
  207. },
  208. startScan(){
  209. this.barcode.start()
  210. },
  211. init(){
  212. const _this = this
  213. // 初始化
  214. this.barcode = plus.barcode.create('barcode', [
  215. plus.barcode.QR,
  216. plus.barcode.EAN13,
  217. plus.barcode.EAN8,
  218. plus.barcode.UPCA,
  219. plus.barcode.UPCE,
  220. plus.barcode.CODABAR,
  221. plus.barcode.CODE39,
  222. plus.barcode.CODE128,
  223. plus.barcode.ITF
  224. ], {
  225. top:'0px',
  226. left:'0px',
  227. width: '100%',
  228. height: '45%',
  229. position: 'static',
  230. frameColor: '#00aaff',
  231. scanbarColor: '#00aaff'
  232. })
  233. // 扫码成功后
  234. this.barcode.onmarked = function(type, result) {
  235. console.log(type,result)
  236. _this.qrCode = result
  237. _this.scanResult()
  238. }
  239. // 扫码识别出错
  240. this.barcode.onerror = function(error){
  241. console.log(error)
  242. _this.toashMsg("条形码错误!")
  243. _this.barcode.start()
  244. }
  245. const currentWebview = this.$mp.page.$getAppWebview()
  246. currentWebview.append(this.barcode)
  247. this.barcode.start()
  248. }
  249. }
  250. }
  251. </script>
  252. <style lang="less">
  253. page{
  254. height: 100vh;
  255. }
  256. .scanCode-wrap{
  257. width: 100%;
  258. height: 100vh;
  259. display: flex;
  260. flex-direction: column;
  261. .barCode{
  262. height: 45%;
  263. }
  264. .info-body{
  265. flex-grow: 1;
  266. overflow: auto;
  267. .noData{
  268. padding: 100rpx 20rpx 0;
  269. text-align: center;
  270. color: #999;
  271. }
  272. .info{
  273. background-color: #FFFFFF;
  274. padding: 10rpx 30upx;
  275. font-size: 32rpx;
  276. margin-top: 20rpx;
  277. .shelfPlaceCode{
  278. background-color: #f6f6f6;
  279. text-align: center;
  280. padding: 10rpx 20rpx;
  281. border-radius: 50rpx;
  282. margin-bottom: 15rpx;
  283. }
  284. .pimgs{
  285. padding:0.1rem;
  286. background:#f8f8f8;
  287. border-radius:0.3rem;
  288. }
  289. .pinfo{
  290. line-height:normal;
  291. padding-left: 20rpx;
  292. color: #666;
  293. .pcode{
  294. color:#999;
  295. text{
  296. color: #000;
  297. }
  298. }
  299. }
  300. .product-nums{
  301. border-top: 10rpx solid #eee;
  302. margin-top: 20rpx;
  303. > view{
  304. &:first-child{
  305. text-align: center;
  306. color: #999;
  307. margin-top: 20rpx;
  308. text{
  309. font-size: 24rpx;
  310. }
  311. }
  312. }
  313. .numsBox{
  314. .scroll-nums{
  315. width: 80%;
  316. padding: 10rpx 0;
  317. .ntabs-box{
  318. margin: 10rpx 0;
  319. }
  320. .ntabs{
  321. background-color: #fff;
  322. border:1rpx solid #aeaeae;
  323. box-shadow: 2rpx 4rpx 6rpx #eee;
  324. border-radius: 15rpx;
  325. padding: 10rpx 15rpx;
  326. margin: 10rpx 20rpx;
  327. }
  328. .active{
  329. border-color: crimson;
  330. background-color: crimson;
  331. color: #FFFFFF;
  332. }
  333. .a-left,.a-right{
  334. color: #666;
  335. }
  336. }
  337. }
  338. }
  339. .infoTits{
  340. padding: 30rpx;
  341. text-align: center;
  342. color: red;
  343. font-size: 24rpx;
  344. }
  345. }
  346. }
  347. }
  348. </style>