scanProduct.vue 9.4 KB

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