scanProduct.vue 9.4 KB

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