scanProduct.vue 9.9 KB

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