scanProduct.vue 9.9 KB

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