scanProduct.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. this.barcode = plus.barcode.create('barcode', [
  225. plus.barcode.QR,
  226. plus.barcode.EAN13,
  227. plus.barcode.EAN8,
  228. plus.barcode.UPCA,
  229. plus.barcode.UPCE,
  230. plus.barcode.CODABAR,
  231. plus.barcode.CODE39,
  232. plus.barcode.CODE128,
  233. plus.barcode.ITF
  234. ], {
  235. top:'0px',
  236. left:'0px',
  237. width: '100%',
  238. height: '45%',
  239. position: 'static',
  240. frameColor: '#00aaff',
  241. scanbarColor: '#00aaff'
  242. })
  243. // 扫码成功后
  244. this.barcode.onmarked = function(type, result) {
  245. console.log(type,result)
  246. _this.qrCode = result
  247. _this.scanResult()
  248. }
  249. // 扫码识别出错
  250. this.barcode.onerror = function(error){
  251. console.log(error)
  252. _this.toashMsg("条形码错误!")
  253. _this.barcode.start()
  254. }
  255. const currentWebview = this.$scope.$getAppWebview()
  256. currentWebview.append(this.barcode)
  257. this.barcode.start()
  258. }
  259. }
  260. }
  261. </script>
  262. <style lang="less">
  263. page{
  264. height: 100vh;
  265. }
  266. .scanCode-wrap{
  267. width: 100%;
  268. height: 100vh;
  269. display: flex;
  270. flex-direction: column;
  271. .barCode{
  272. height: 45%;
  273. }
  274. .info-body{
  275. flex-grow: 1;
  276. overflow: auto;
  277. .noData{
  278. padding: 100rpx 20rpx 0;
  279. text-align: center;
  280. color: #999;
  281. }
  282. .info{
  283. background-color: #FFFFFF;
  284. padding: 10rpx 30upx;
  285. font-size: 32rpx;
  286. margin-top: 20rpx;
  287. .shelfPlaceCode{
  288. background-color: #f6f6f6;
  289. text-align: center;
  290. padding: 10rpx 20rpx;
  291. border-radius: 50rpx;
  292. margin-bottom: 15rpx;
  293. }
  294. .pimgs{
  295. padding:0.1rem;
  296. background:#f8f8f8;
  297. border-radius:0.3rem;
  298. }
  299. .pinfo{
  300. line-height:normal;
  301. padding-left: 20rpx;
  302. color: #666;
  303. .pcode{
  304. color:#999;
  305. text{
  306. color: #000;
  307. }
  308. }
  309. }
  310. .product-nums{
  311. border-top: 10rpx solid #eee;
  312. margin-top: 20rpx;
  313. > view{
  314. &:first-child{
  315. text-align: center;
  316. color: #999;
  317. margin-top: 20rpx;
  318. text{
  319. font-size: 24rpx;
  320. }
  321. }
  322. }
  323. .numsBox{
  324. .scroll-nums{
  325. width: 80%;
  326. padding: 10rpx 0;
  327. .ntabs-box{
  328. margin: 10rpx 0;
  329. }
  330. .ntabs{
  331. background-color: #fff;
  332. border:1rpx solid #aeaeae;
  333. box-shadow: 2rpx 4rpx 6rpx #eee;
  334. border-radius: 15rpx;
  335. padding: 10rpx 15rpx;
  336. margin: 10rpx 20rpx;
  337. }
  338. .active{
  339. border-color: crimson;
  340. background-color: crimson;
  341. color: #FFFFFF;
  342. }
  343. .a-left,.a-right{
  344. color: #666;
  345. }
  346. }
  347. }
  348. }
  349. .infoTits{
  350. padding: 30rpx;
  351. text-align: center;
  352. color: red;
  353. font-size: 24rpx;
  354. }
  355. }
  356. }
  357. }
  358. </style>