index.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  1. <template>
  2. <div class="container">
  3. <van-nav-bar
  4. title="复核-活动单" left-arrow fixed placeholder @click-left="goBack">
  5. <template #left>
  6. <van-icon name="arrow-left" size="25" />
  7. <div style="color: #fff">返回</div>
  8. </template>
  9. <template #right>
  10. <div
  11. v-if="bluetoothConnected && connectedBluetoothDevice"
  12. @click="handleDisconnectBluetooth"
  13. class="nav-bluetooth-connected"
  14. >
  15. <div class="bluetooth-device-info">
  16. <van-icon name="bluetooth" size="14px" />
  17. <span class="device-name">{{ connectedBluetoothDevice.name }}</span>
  18. </div>
  19. <div class="bluetooth-disconnect-text">蓝牙断开</div>
  20. </div>
  21. <div
  22. v-else
  23. @click="handleOpenBluetoothScan"
  24. class="nav-bluetooth-scan"
  25. >
  26. <van-icon name="bluetooth" size="16px" />
  27. <span>蓝牙扫描</span>
  28. </div>
  29. </template>
  30. </van-nav-bar>
  31. <div class="activity">
  32. <div class="wave-title">
  33. <div><span style="font-size: 12px">波次/容器号:</span>{{ waveNo || '--' }}</div>
  34. <div class="wave-tips">
  35. <van-notice-bar :background="'none'" :speed="50" :text="tips" />
  36. </div>
  37. <van-button plain size="mini" type="primary" @click="_setWaveNo()">更换</van-button>
  38. </div>
  39. <div class="scan-barcode">
  40. <van-field v-model.lazy="scanBarcode" label-align="left" placeholder="请扫描商品条码/SKU" label="商品条码:"
  41. class="input-barcode" autocomplete="off" @keydown.enter="_handlerScan(scanBarcode)" />
  42. <div class="weight-input-wrapper">
  43. <van-field v-model.lazy="totalWeight" ref="weightRef" label-align="left" required placeholder="请输入商品重量KG" label="重&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;量:"
  44. autocomplete="off" type="number" @input="handleWeightInput" @focus="handleWeightFocus" @keydown="handleWeightKeydown"
  45. :class="{ 'weight-confirmed': weightConfirmed }">
  46. <template #button>
  47. <div>KG</div>
  48. </template>
  49. </van-field>
  50. <van-button
  51. v-if="bluetoothConnected"
  52. type="warning"
  53. size="small"
  54. class="weight-reset-btn"
  55. @click="resetWeight"
  56. >
  57. 重置
  58. </van-button>
  59. <van-button
  60. v-if="bluetoothConnected"
  61. type="primary"
  62. size="small"
  63. class="weight-confirm-btn"
  64. @click="confirmWeight"
  65. >
  66. 确认
  67. </van-button>
  68. </div>
  69. <!-- :class="[totalWeight>0?'success-input-barcode':'error-input-barcode']"-->
  70. </div>
  71. <div class="order-detail">
  72. <div class="picking-no">
  73. <div class="picking-code">
  74. <div><van-icon name="stop-circle-o" /></div>
  75. <div style="flex: 1"><van-notice-bar :background="'none'" color="#419bff" :speed="50" :text="orderDetail.pickingCode||'--'" /></div>
  76. </div>
  77. <div>{{ orderDetail.carrierName || '--' }}</div>
  78. </div>
  79. <div class="picking-container ">
  80. <div class="container-item"><span style="color:#666">拣货容器/波次号:</span><div style="flex:1"> <van-notice-bar :background="'none'" color="#000" :speed="50" :text="formattedOrderDetails" /></div></div>
  81. <div class="container-item"><span style="color:#666">返拣容器:</span>{{ reversePickingContainerNo || '--' }}</div>
  82. <div style="display: flex;padding-top: 5px" @click="setPrinter()">
  83. <div>打印机:</div>
  84. <div v-if="printer">{{printer.printer}}</div>
  85. <div style="text-decoration: underline;color: #0077ff">设置打印机<van-icon name="edit" color="#0077ff"/> </div>
  86. </div>
  87. <div class="picking-order-count ">
  88. <div>
  89. <span style="font-size: 12px">已复核数/总复核数:</span>
  90. <span style="color: #333;font-weight: bold;font-size: 18px" v-if="orderMap.dataGroup">{{ successNumber }}/{{Object.keys(orderMap.dataGroup).length ||0}}</span>
  91. <span v-else>0</span>
  92. </div>
  93. <div>
  94. <span style="font-size: 12px">取消单:</span>
  95. <span style="color: #333;font-weight: bold;font-size: 18px" v-if="orderMap.cancelGroup">{{Object.keys(orderMap.cancelGroup).length ||0}}</span>
  96. <span v-else>0</span>
  97. </div>
  98. <div>
  99. <span style="font-size: 12px">冻结单:</span>
  100. <span style="color: #333;font-weight: bold;font-size: 18px" v-if="orderMap.freezeGroup">{{Object.keys(orderMap.freezeGroup).length ||0}}</span>
  101. <span v-else>0</span>
  102. </div>
  103. </div>
  104. </div>
  105. <div class="picking-button">
  106. <div class="picking-button-item" @click="print('A3012_RF_WIFI_HDQD',orderDetail.waveNo)">波次清单</div>
  107. <div class="picking-button-item" @click="print('PRINT_WAYBILL',orderDetail.waveNo)">打印面单</div>
  108. <div class="picking-button-item" @click="endCheck()" >结束复核</div>
  109. <van-popover :actions="actions" placement="bottom-end" @select="onSelect" theme="dark">
  110. <template #reference>
  111. <div class="picking-button-item" style="padding: 0 5px">更多操作<van-icon name="play" /></div>
  112. </template>
  113. </van-popover>
  114. </div>
  115. </div>
  116. <div class="order-list-box">
  117. <van-divider style="margin: 0;padding: 5px 15px">订单明细</van-divider>
  118. <div class="order-list">
  119. <table class="task-table">
  120. <thead>
  121. <tr>
  122. <th style="width: 40%">商品条码</th>
  123. <th>数量</th>
  124. <th>剩余</th>
  125. <th>状态</th>
  126. <th v-if="isUniqueCode || isQualityCheck">标记</th>
  127. </tr>
  128. </thead>
  129. <tbody>
  130. <template v-if="orderList.length>0">
  131. <tr v-for="(item, index) in orderList" :key="index" :style="rowStyle(item)" >
  132. <td>{{ item.barcode }} <van-tag type="success" v-if="item.universalCode">万用</van-tag></td>
  133. <td>{{item.qty}}/{{item.qtyOrdered}}</td>
  134. <td>{{ item.qty }}</td>
  135. <td>{{ statusMap[item.status] || '' }}</td>
  136. <td v-if="isUniqueCode || isQualityCheck">
  137. <van-tag v-if="item.uniqueRegExp" type="warning" >唯一码</van-tag>
  138. <van-tag v-if="item.imeiRegExp" type="primary" >IMEI码</van-tag>
  139. <van-tag v-if="item.qualityCheck" type="warning" >质检</van-tag>
  140. </td>
  141. </tr>
  142. </template>
  143. <tr v-else>
  144. <td colspan="4">
  145. <div>暂无数据</div>
  146. </td>
  147. </tr>
  148. </tbody>
  149. </table>
  150. </div>
  151. </div>
  152. </div>
  153. <!-- 条码输入组件 -->
  154. <input-barcode :back="back" @setBarcode="setBarcode" ref="inputBarcodeRef" />
  155. <!-- 打印面单-->
  156. <printer ref="printerRef" @onPrint="onPrint" />
  157. <!-- 订单列表-->
  158. <order-list-table ref="orderListRef" />
  159. <!-- 返拣-->
  160. <reverse-picking ref="reversePickingRef" :warehouse="warehouse" :reversePickingContainerNo="reversePickingContainerNo" @load-data="loadData" @reversePickingReset="reversePickingReset" />
  161. <!-- 耗材-->
  162. <related-materia ref="relatedMateriaRef" @cut-barcode="cutBarcode" />
  163. <!-- 复核组合商品-->
  164. <check-barcode-combine ref="checkBarcodeCombineRef" @cutBarcode="cutBarcode" />
  165. <!-- 蓝牙扫描-->
  166. <bluetooth-scan :model-value="showBluetoothScan" @update:model-value="showBluetoothScan = $event" @connected="handleBluetoothConnected" @disconnected="handleBluetoothDisconnected" ref="bluetoothScanRef" />
  167. </div>
  168. </template>
  169. <script setup>
  170. import { computed, onMounted, onUnmounted, ref } from 'vue'
  171. import { androidFocus, getHeader, goBack, scanError, scanSuccess } from '@/utils/android'
  172. import { useStore } from '@/store/modules/user'
  173. import { closeListener, openListener, scanInit } from '@/utils/keydownListener'
  174. import { getPendingReviewTask, packingReview } from '@/api/check/index'
  175. import { barcodeToUpperCase, toMap } from '@/utils/dataType.js'
  176. import { closeToast, showConfirmDialog, showDialog, showLoadingToast, showNotify, showToast } from 'vant'
  177. import { closeLoading, showLoading } from '@/utils/loading'
  178. import { fluxPrint, getListCombineSku } from '@/api/picking/index'
  179. import InputBarcode from '@/views/outbound/picking/components/InputBarcode.vue'
  180. import Printer from '@/components/Printer.vue'
  181. import orderListTable from '@/views/outbound/check/components/OrderListTable.vue'
  182. import ReversePicking from '@/views/outbound/check/components/ReversePicking.vue'
  183. import RelatedMateria from '@/views/outbound/check/components/RelatedMateria.vue'
  184. import CheckBarcodeCombine from '@/views/outbound/check/components/CheckBarcodeCombine.vue'
  185. import BluetoothScan from '@/views/outbound/check/components/BluetoothScan.vue'
  186. const store = useStore()
  187. try {
  188. getHeader()
  189. androidFocus()
  190. } catch (error) {
  191. }
  192. // 打开蓝牙扫描(立即开始扫描)
  193. const handleOpenBluetoothScan = () => {
  194. showBluetoothScan.value = true
  195. // 延迟一下确保弹窗已打开,然后开始扫描
  196. setTimeout(() => {
  197. if (bluetoothScanRef.value) {
  198. bluetoothScanRef.value.startScan()
  199. }
  200. }, 300)
  201. }
  202. // 蓝牙连接处理
  203. const handleBluetoothConnected = (device) => {
  204. bluetoothConnected.value = true
  205. connectedBluetoothDevice.value = device
  206. weightConfirmed.value = false // 连接成功时重置确认状态,允许接收新的重量数据
  207. // showNotify({ type: 'success', message: `已连接: ${device.name}` })
  208. }
  209. // 蓝牙断开处理
  210. const handleBluetoothDisconnected = () => {
  211. bluetoothConnected.value = false
  212. connectedBluetoothDevice.value = null
  213. weightConfirmed.value = false // 断开时重置确认状态
  214. }
  215. // 停止接收蓝牙重量(用户输入或确认时调用)
  216. const stopReceivingBluetoothWeight = () => {
  217. if (bluetoothConnected.value) {
  218. weightConfirmed.value = true
  219. }
  220. }
  221. // 处理重量输入(手动输入时立即停止接收蓝牙重量)
  222. const handleWeightInput = () => {
  223. stopReceivingBluetoothWeight()
  224. }
  225. // 处理重量输入框获得焦点(用户开始输入时立即停止接收蓝牙重量)
  226. const handleWeightFocus = () => {
  227. stopReceivingBluetoothWeight()
  228. }
  229. // 处理键盘输入(按下任何键时立即停止接收蓝牙重量)
  230. const handleWeightKeydown = () => {
  231. stopReceivingBluetoothWeight()
  232. }
  233. // 重置重量(重置后继续接收蓝牙重量)
  234. const resetWeight = () => {
  235. weightConfirmed.value = false
  236. totalWeight.value = ''
  237. showNotify({ type: 'success', duration: 2000, message: '已重置,继续接收蓝牙重量' })
  238. }
  239. // 确认重量(确认后不再接收蓝牙重量)
  240. const confirmWeight = () => {
  241. if (!totalWeight.value || Number(totalWeight.value) <= 0) {
  242. showNotify({ type: 'warning', duration: 3000, message: '请输入有效的重量值' })
  243. return
  244. }
  245. stopReceivingBluetoothWeight()
  246. showNotify({ type: 'success', duration: 2000, message: '重量已确认' })
  247. }
  248. // 蓝牙重量数据回调(仅在未输入且未确认时接收蓝牙重量)
  249. const handleBluetoothWeight = (weight, unit) => {
  250. console.log(weight,unit,'handleBluetoothWeight')
  251. // 只有在未确认重量(未输入且未点击确认)时才自动更新
  252. if (!weightConfirmed.value && weight !== null && weight !== undefined) {
  253. totalWeight.value = weight.toString()
  254. }
  255. }
  256. // 蓝牙连接状态回调
  257. const handleBluetoothConnectionState = (isConnected) => {
  258. bluetoothConnected.value = isConnected
  259. if (bluetoothScanRef.value) {
  260. bluetoothScanRef.value.handleConnectionState(isConnected)
  261. }
  262. if (!isConnected) {
  263. // 断开连接时清除状态
  264. handleBluetoothDisconnected()
  265. // 确保组件内的状态也被清除
  266. if (bluetoothScanRef.value) {
  267. bluetoothScanRef.value.clearConnectedDevice()
  268. }
  269. } else {
  270. // 连接成功时,从组件获取设备信息
  271. const saved = localStorage.getItem('bluetooth-device')
  272. if (saved) {
  273. try {
  274. const device = JSON.parse(saved)
  275. handleBluetoothConnected(device)
  276. } catch (error) {
  277. console.error('解析保存的设备失败:', error)
  278. }
  279. }
  280. }
  281. }
  282. // 蓝牙错误回调
  283. const handleBluetoothError = (errorMessage) => {
  284. showNotify({ type: 'danger', message: `蓝牙错误: ${errorMessage}` })
  285. }
  286. // 初始化蓝牙回调
  287. const initBluetoothCallbacks = () => {
  288. // 连接状态回调
  289. window.onScaleConnectionState = handleBluetoothConnectionState
  290. // 重量数据回调
  291. window.onScaleWeight = handleBluetoothWeight
  292. // 错误回调
  293. window.onScaleError = handleBluetoothError
  294. }
  295. // 断开蓝牙连接
  296. const disconnectBluetooth = () => {
  297. if (window.AndroidScale && bluetoothConnected.value) {
  298. try {
  299. window.AndroidScale.disconnect()
  300. // 立即清除主页面状态
  301. handleBluetoothDisconnected()
  302. // 立即清除组件内的状态
  303. if (bluetoothScanRef.value) {
  304. bluetoothScanRef.value.clearConnectedDevice()
  305. }
  306. } catch (error) {
  307. console.error('断开连接失败:', error)
  308. showNotify({ type: 'danger', message: '断开连接失败' })
  309. // 即使出错也清除状态
  310. handleBluetoothDisconnected()
  311. if (bluetoothScanRef.value) {
  312. bluetoothScanRef.value.clearConnectedDevice()
  313. }
  314. }
  315. } else {
  316. // 如果没有 AndroidScale 或未连接,也清除状态
  317. handleBluetoothDisconnected()
  318. if (bluetoothScanRef.value) {
  319. bluetoothScanRef.value.clearConnectedDevice()
  320. }
  321. }
  322. }
  323. // 处理断开连接(带确认)
  324. const handleDisconnectBluetooth = () => {
  325. if (!bluetoothConnected.value) {
  326. return
  327. }
  328. showConfirmDialog({
  329. title: '温馨提示',
  330. message: '确定要断开蓝牙连接吗?',
  331. }).then(() => {
  332. disconnectBluetooth()
  333. }).catch(() => {
  334. // 取消操作
  335. })
  336. }
  337. // 页面初始化
  338. onMounted(() => {
  339. openListener()
  340. scanInit(_handlerScan)
  341. initBluetoothCallbacks()
  342. loadData()
  343. // 延迟加载已保存的蓝牙设备,确保组件已挂载
  344. setTimeout(() => {
  345. if (bluetoothScanRef.value) {
  346. bluetoothScanRef.value.loadSavedDevice()
  347. }
  348. }, 100)
  349. })
  350. const warehouse = store.warehouse
  351. //收货容器号
  352. // JH-WH99-990
  353. const waveNo = ref('')
  354. const isUniqueCode=ref(false)
  355. const isQualityCheck=ref(false)
  356. // 错误提示
  357. const tips = ref('')
  358. //强制返回
  359. const back = ref(true)
  360. const scanBarcode=ref('')
  361. const totalWeight=ref('')
  362. const showBluetoothScan=ref(false)
  363. const bluetoothConnected=ref(false)
  364. const bluetoothScanRef=ref(null)
  365. const connectedBluetoothDevice=ref(null)
  366. const weightConfirmed=ref(false) // 重量是否已确认
  367. const containerNoMap={
  368. 'WH01':'FJ-WH01-20',
  369. 'WH02':'FJ-WH02-20',
  370. 'WH10':'FJ-WH10-01',
  371. 'WH99':'FJ-WH99-01',
  372. }
  373. //返拣容器
  374. const reversePickingContainerNo=containerNoMap[warehouse]
  375. // 订单明细
  376. const orderDetail=ref({})
  377. //订单详情
  378. const orderMap=ref({})
  379. const dataList=ref([])
  380. const orderList = computed(() => {
  381. return dataList.value
  382. .sort((a, b) => {
  383. const statusPriority = {
  384. '60': 0,
  385. '600': 1,
  386. '50': 2,
  387. '40': 3,
  388. '30': 4,
  389. '20': 5,
  390. '00': 6,
  391. }
  392. if (statusPriority[a.status] !== statusPriority[b.status]) {
  393. return statusPriority[a.status] - statusPriority[b.status]
  394. }
  395. return 0
  396. })
  397. })
  398. // 计算已格式化的拣货容器和波次号字符串
  399. const formattedOrderDetails = computed(() => {
  400. const pickingContainer = orderDetail.value.pickingContainer || '--'
  401. const waveNo = orderDetail.value.waveNo || '--'
  402. return `${pickingContainer}/${waveNo}`
  403. })
  404. const statusMap = {
  405. '00': '创建',
  406. '20': '预配',
  407. '30': '部分分配',
  408. '40': '已分配',
  409. '50': '待拣货',
  410. '60': '已拣货',
  411. '61': '分拣完成',
  412. '90': '订单取消',
  413. }
  414. //匹配条码
  415. const matchBarcodeList=ref([])
  416. const actions = [
  417. { text: '重新开始',value:'reset' },
  418. { text: '装箱清单',value:'packing' },
  419. { text: '取消单列表',value:'cancel' },
  420. { text: '冻结单列表',value: 'freeze' },
  421. // { text: '结束复核',value: 'end' },
  422. ];
  423. // 扫描条码监听
  424. const relatedMateriaRef=ref(null)
  425. const matchedSku=ref([])
  426. const checkBarcodeCombineRef=ref(null)
  427. const _handlerScan = (code) => {
  428. if (code) {
  429. if (isUniqueCode.value) {
  430. scanError()
  431. scanBarcode.value = ''
  432. showNotify({ type: 'warning', duration: 3000, message: `此单包含唯一码/IMEI码,请到PC复核` })
  433. return
  434. }
  435. const barcode = [...new Set(
  436. orderList.value
  437. .filter(item => (item.status == '60'))
  438. .flatMap(item => [item.barcode, item.barcode2, item.sku, item.universalCode])
  439. .filter(value => value !== null && value !== '' && value !== undefined),
  440. )];
  441. const checkBarcode = barcodeToUpperCase(code);
  442. if (barcode.some(item => barcodeToUpperCase(item) === checkBarcode)) {
  443. matchBarcodeList.value=orderList.value.filter(item=>((item.barcode===checkBarcode || item.sku===checkBarcode || item.barcode2===checkBarcode || item.universalCode==checkBarcode) && item.status == '60' && item.qty>0) )
  444. if(matchBarcodeList.value.length>0){
  445. const itemActive = matchBarcodeList.value[0]
  446. scanBarcode.value=code
  447. if(itemActive.relatedMaterial && itemActive.relatedMaterial.length>0){
  448. relatedMateriaRef.value.show(itemActive)
  449. return
  450. }
  451. cutBarcode(itemActive,1)
  452. }else {
  453. scanBarcode.value=''
  454. scanError()
  455. showNotify({ type: 'warning', duration: 3000, message: `商品条码${code},已全部扫描完成`})
  456. }
  457. }else {
  458. //查询组合条码
  459. matchedSku.value=[]
  460. getListCombineSku({combineSku:code, workEnvironment:'check'}).then(res=>{
  461. if(res.data.length>0){
  462. const combineSkuMap=toMap(res.data,'barcode')
  463. const matchedSkuList=getBarcodeCombine(orderList.value,combineSkuMap)
  464. if(matchedSkuList.length>0){
  465. if(matchedSkuList.length==res.data.length){
  466. matchedSku.value=matchedSkuList
  467. checkBarcodeCombineRef.value.show(matchedSku.value,orderList.value)
  468. }else{
  469. scanError()
  470. showDialog({
  471. title:'温馨提示',
  472. message:'组合商品与拣货任务不匹配,请检查组合商品配置!'
  473. })
  474. }
  475. }else {
  476. scanError()
  477. showDialog({
  478. title:'温馨提示',
  479. message:'组合商品与拣货任务不匹配,请检查组合商品配置!'
  480. })
  481. }
  482. }else {
  483. scanError()
  484. scanBarcode.value=''
  485. showNotify({ type: 'warning', duration: 3000, message: `商品条码${code},不匹配请重新扫描!`})
  486. }
  487. })
  488. }
  489. }
  490. }
  491. //组合商品匹配到的商品
  492. const getBarcodeCombine=(goodsList, combineSkuMap)=>{
  493. const result = goodsList.map(item => {
  494. const barcode = item.barcode || item.barcodeAs;
  495. // 如果有匹配数据添加到 item 中
  496. if (combineSkuMap[barcode] && item.qty >= combineSkuMap[barcode].quantity ) {
  497. return {
  498. ...item,
  499. matchedJson: combineSkuMap[barcode]
  500. };
  501. }
  502. return null
  503. })
  504. .filter(item => item !== null) // 过滤掉 null 元素,保留匹配到的项
  505. return result.length > 0 ? result : []
  506. }
  507. //扣除商品数量
  508. const weightRef=ref(null)
  509. const cutBarcode = (itemActive, count) => {
  510. if (itemActive.qty > 0) {
  511. itemActive.qty -= count;
  512. itemActive.qty = Math.max(itemActive.qty, 0)
  513. itemActive.quantity+=count
  514. }
  515. // 计算所有商品的总数量
  516. const allCount = orderList.value.reduce((sum, item) => sum + Math.max(Number(item.qty), 0), 0);
  517. // 根据所有商品总数量判断是否继续扫描
  518. if (allCount > 0) {
  519. scanBarcode.value = '';
  520. tips.value = '请继续扫描条码';
  521. showNotify({ type: 'success', duration: 3000, message: '数量已扣除,请继续扫描条码' });
  522. } else {
  523. if (!totalWeight.value) {
  524. tips.value = '请输入重量';
  525. weightRef.value?.focus()
  526. showNotify({ type: 'success', duration: 3000, message: '商品扫描完成,请输入重量' });
  527. } else {
  528. endCheck()
  529. tips.value = '商品扫描完成,请点击结束复核';
  530. }
  531. }
  532. scanSuccess();
  533. };
  534. //重新开始
  535. const reset=()=>{
  536. showConfirmDialog({
  537. title: '温馨提示',
  538. message: '您正在进行重新开始操作,是否继续?',
  539. }).then(() => {
  540. waveNo.value=''
  541. scanBarcode.value=''
  542. totalWeight.value=''
  543. weightConfirmed.value = false // 重置确认状态
  544. orderDetail.value={}
  545. orderMap.value={}
  546. dataList.value=[]
  547. matchBarcodeList.value=[]
  548. tips.value='请扫描商品条码'
  549. // 注意:不自动断开蓝牙连接,保持连接状态
  550. inputBarcodeRef.value?.show('', '请扫描波次/容器号', '')
  551. })
  552. }
  553. const reversePickingReset=()=>{
  554. orderMap.value.dataGroup=[]
  555. }
  556. const printerRef=ref(null)
  557. //设置打印机
  558. const setPrinter=()=>{
  559. printerRef.value?.show(warehouse)
  560. }
  561. const printer=ref(null)
  562. if(localStorage.getItem('check-print')){
  563. printer.value=JSON.parse(localStorage.getItem('check-print'))
  564. }
  565. const onPrint=(code)=>{
  566. printer.value=code
  567. localStorage.setItem('check-print',JSON.stringify(code))
  568. }
  569. const print=(templateCode,code)=>{
  570. if(!printer.value){
  571. scanError()
  572. showNotify({ type: 'warning', duration: 3000, message: '请先设置打印机' });
  573. return
  574. }
  575. const data = {warehouse,code,printServer: printer.value.server, printName:printer.value.printer,templateCode }
  576. showLoading()
  577. fluxPrint(data)
  578. .then(res => {
  579. if(res.code==200){
  580. scanSuccess()
  581. showNotify({ type: 'success', duration: 3000, message: '打印已发起,请检查打印情况' });
  582. }else {
  583. scanError()
  584. tips.value=res.message || '系统异常,请联系技术支持!'
  585. showNotify({ type: 'danger', duration: 3000, message: res.message || '系统异常,请联系技术支持!' });
  586. }
  587. })
  588. .catch(err => {
  589. scanError()
  590. tips.value=err.message || '系统异常,请联系技术支持!'
  591. showNotify({ type: 'danger', duration: 3000, message: err.message || '系统异常,请联系技术支持!' });
  592. }).finally(() => {
  593. closeLoading()
  594. })
  595. }
  596. const successNumber=ref(0)
  597. const errorNumber=ref(0)
  598. //结束复核
  599. const endCheck=()=>{
  600. if(!printer.value){
  601. scanError()
  602. showNotify({ type: 'warning', duration: 3000, message: '请先设置打印机' });
  603. return
  604. }
  605. const allCount = orderList.value.reduce((sum, item) => sum + Math.max(Number(item.qty), 0), 0);
  606. if(allCount>0){
  607. scanError()
  608. tips.value = '商品未扫描完成,请先扫描商品';
  609. showNotify({ type: 'warning', duration: 3000, message: '商品未扫描完成,请先扫描商品' });
  610. return
  611. }
  612. const lastNumber=Object.keys(orderMap.value.dataGroup).length
  613. if (Number(totalWeight.value)<=0 && lastNumber>0) {
  614. tips.value = '请输入重量';
  615. scanError()
  616. showNotify({ type: 'warning', duration: 3000, message: '请输入重量' });
  617. weightRef.value?.focus()
  618. return
  619. }
  620. showDialog({
  621. title: '温馨提示',
  622. message: '是否进行复核操作?',
  623. theme: 'round-button',
  624. }).then(() => {
  625. if (lastNumber > 0) {
  626. const dataGroup = orderMap.value.dataGroup
  627. for (const order of Object.values(dataGroup)) {
  628. for (const item of order) {
  629. if (item.qty !== 0 && item.status=='60') {
  630. item.quantity = item.qty
  631. item.qty = 0
  632. }
  633. }
  634. }
  635. }
  636. packingRequests(0,lastNumber)
  637. successNumber.value=0
  638. errorNumber.value=0
  639. })
  640. }
  641. //装箱
  642. const reversePickingRef=ref(null)
  643. const packingRequests = async (startIndex = 0, lastNumber) => {
  644. if(startIndex>=lastNumber){
  645. const cancelOrder= Object.keys(orderMap.value.cancelGroup).length
  646. const freezeOrder= Object.keys(orderMap.value.freezeGroup).length
  647. if(cancelOrder>0 || freezeOrder>0) {
  648. scanError()
  649. }else {
  650. scanSuccess()
  651. }
  652. reversePickingRef.value.show(successNumber.value,errorNumber.value,orderMap.value.cancelGroup,orderMap.value.freezeGroup)
  653. return
  654. }
  655. const key = Object.keys(orderMap.value.dataGroup)[startIndex];
  656. const list = orderMap.value.dataGroup[key] || [];
  657. const groupDetailList = list.map(items => {
  658. return {
  659. lotNum: items.lotNum,
  660. qty: items.quantity,
  661. };
  662. });
  663. const item = list[0] || {};
  664. try {
  665. const data = {
  666. warehouse: item.warehouseId,
  667. workStation: item.warehouseId,
  668. code: item.orderNo,
  669. totalGrossWeight:Number(totalWeight.value),
  670. groupDetailList,
  671. activityOrderFlag:true
  672. };
  673. showLoadingToast({
  674. duration: 0,
  675. forbidClick: true,
  676. message: `进度:${startIndex+1}/${lastNumber}`,
  677. });
  678. const res = await packingReview(data)
  679. // const res = await getPendingReviewTask(data)
  680. if (res) {
  681. if (res.data == '0000'){
  682. orderMap.value.cancelGroup[item.orderNo] = item.orderNo
  683. }else if(res.data == '1111'){
  684. orderMap.value.freezeGroup[item.orderNo] = item.orderNo
  685. }else {
  686. successNumber.value+=1
  687. if(isQualityCheck.value && startIndex==0){
  688. print('A3014_PACK_CARTON_QC',res.data)
  689. }
  690. }
  691. await packingRequests(startIndex + 1, lastNumber)
  692. }
  693. } catch (error) {
  694. errorNumber.value+=1
  695. tips.value=`错误信息: ${error.message} (订单号: ${item.orderNo || 'N/A'})`
  696. if(startIndex>0){
  697. reversePickingRef.value.show(successNumber.value,lastNumber-successNumber.value,orderMap.value.cancelGroup,orderMap.value.freezeGroup)
  698. }
  699. scanError()
  700. } finally {
  701. closeToast()
  702. }
  703. }
  704. //更多操作
  705. const orderListRef=ref(null)
  706. const onSelect=(item)=>{
  707. const handleGroup = (groupKey, emptyMessage) => {
  708. const order = orderMap.value[groupKey];
  709. if (Object.keys(order).length === 0) {
  710. showNotify({ message: emptyMessage, duration: 5000, type: 'danger' });
  711. return;
  712. }
  713. orderListRef.value?.show(item.value,order);
  714. };
  715. if (item.value == 'cancel') {
  716. handleGroup('cancelGroup', '暂无取消单');
  717. } else if (item.value == 'freeze') {
  718. handleGroup('freezeGroup', '暂无冻结单');
  719. }else if(item.value=='reset'){
  720. reset()
  721. }else if(item.value=='packing'){
  722. print('A3014_PACK_CARTON_PACKINGLIST',orderDetail.value.waveNo)
  723. }
  724. else if(item.value=='end'){
  725. endCheck()
  726. }
  727. }
  728. // 设置波次号
  729. const inputBarcodeRef = ref(null)
  730. const setBarcode = (code) => {
  731. const data = { warehouse, code, activityOrderFlag: true }
  732. showLoading()
  733. getPendingReviewTask(data).then(res => {
  734. if (res.data.details.length == 0) {
  735. scanError()
  736. inputBarcodeRef.value?.show('', '请扫描波次/容器号', '暂未查询到待复核数据,请切换波次/容器号')
  737. } else {
  738. if(res.data.waveType!=='*'){
  739. scanError()
  740. inputBarcodeRef.value?.show('', '请扫描波次/容器号', '仅支持活动单复核')
  741. return
  742. }
  743. scanSuccess()
  744. tips.value = '请扫描商品条码'
  745. waveNo.value = code
  746. orderDetail.value = res.data
  747. const allStatus= res.data.details.every(item => item.status == 60);
  748. if(!allStatus){
  749. inputBarcodeRef.value?.show('', '请扫描波次/容器号', `${code}:没有拣货完成请拣货`)
  750. return
  751. }
  752. orderMap.value=getDataList(res.data.details)
  753. if(orderMap.value.dataGroup && Object.keys(orderMap.value.dataGroup).length>0){
  754. dataList.value=orderMap.value.dataGroup[Object.keys(orderMap.value.dataGroup)[0]]
  755. isUniqueCode.value = dataList.value.some(item => item.uniqueRegExp || item.imeiRegExp );
  756. isQualityCheck.value = dataList.value.some(item => item.qualityCheck === true);
  757. }else {
  758. dataList.value=[]
  759. if(Object.keys(orderMap.value.cancelGroup).length>0){
  760. packingRequests(0,0)
  761. }
  762. }
  763. matchBarcodeList.value=[]
  764. scanBarcode.value=''
  765. totalWeight.value=''
  766. weightConfirmed.value = false // 切换波次时重置确认状态
  767. successNumber.value=0
  768. }
  769. }).catch(err => {
  770. scanError()
  771. inputBarcodeRef.value?.show('', '请扫描波次/容器号', err.message)
  772. }).finally(f=>{
  773. closeLoading()
  774. })
  775. }
  776. //格式化订单
  777. const getDataList = (data) => {
  778. const freezeList = [],cancelList = [],dataList = []
  779. const groupedData = {
  780. freezeGroup: {}, // 冻结订单
  781. cancelGroup: {}, //取消订单
  782. dataGroup: {} // 普通订单
  783. };
  784. const groupOrder = (order, group, groupKey, list) => {
  785. list.push(order)
  786. if (!group[groupKey]) {
  787. group[groupKey] = [] // 如果该订单号的组不存在,创建一个新数组
  788. }
  789. group[groupKey].push(order) // 将订单按订单号分组
  790. };
  791. data.forEach(curr => {
  792. curr.serialNoList = []
  793. curr.secondSerialNoList = []
  794. if (curr.universalBarcode) {
  795. curr.universalCode = '#@@@@@@#'
  796. }
  797. curr.quantity=0
  798. if (curr.releaseStatus === 'H') {
  799. groupOrder(curr, groupedData.freezeGroup, curr.orderNo, freezeList) // 处理冻结订单
  800. } else if (curr.erpCancelFlag === 'Y') {
  801. groupOrder(curr, groupedData.cancelGroup, curr.orderNo, cancelList) // 处理取消订单
  802. } else {
  803. groupOrder(curr, groupedData.dataGroup, curr.orderNo, dataList) // 处理普通订单
  804. }
  805. });
  806. return groupedData
  807. };
  808. const rowStyle=( row )=>{
  809. if(row.status!='60' ){
  810. return { background: '#b3b3b3'}
  811. }
  812. return ''
  813. }
  814. //切换波次
  815. const _setWaveNo = () => {
  816. back.value = false
  817. inputBarcodeRef.value?.show('', '请扫描波次/容器号', '')
  818. }
  819. // 数据刷新
  820. const loadData = () => {
  821. if (!waveNo.value) {
  822. inputBarcodeRef.value?.show('', '请扫描波次/容器号', '')
  823. return
  824. } else {
  825. setBarcode(waveNo.value)
  826. }
  827. }
  828. onUnmounted(() => {
  829. closeListener()
  830. // 清理蓝牙回调
  831. disconnectBluetooth()
  832. window.onScaleConnectionState = null
  833. window.onScaleWeight = null
  834. window.onScaleError = null
  835. })
  836. window.onRefresh = loadData
  837. </script>
  838. <style scoped lang="sass">
  839. .container
  840. background: #e9f4ff
  841. .activity
  842. .wave-title
  843. display: flex
  844. justify-content: space-between
  845. padding: 8px 10px
  846. .wave-tips
  847. color: #ed6a0c
  848. flex: 1
  849. .scan-barcode
  850. ::v-deep(.van-cell)
  851. padding: 0 15px
  852. height: 50px
  853. min-height: 50px
  854. display: flex
  855. align-items: center
  856. ::v-deep(.van-field__body)
  857. display: flex
  858. align-items: center
  859. height: 100%
  860. ::v-deep(.van-field__control)
  861. border-bottom: 2px solid #efefef
  862. font-size: 16px
  863. line-height: 46px
  864. ::v-deep(.van-field__label)
  865. width: unset
  866. font-size: 16px
  867. display: flex
  868. align-items: center
  869. .weight-input-wrapper
  870. display: flex
  871. align-items: center
  872. gap: 8px
  873. width: 100%
  874. ::v-deep(.van-field)
  875. flex: 1
  876. ::v-deep(.weight-confirmed)
  877. .van-field__control
  878. border-bottom: 2px solid #1ca600 !important
  879. color: #1ca600
  880. .weight-reset-btn
  881. flex-shrink: 0
  882. height: 36px
  883. padding: 0 16px
  884. .weight-confirm-btn
  885. flex-shrink: 0
  886. height: 36px
  887. padding: 0 16px
  888. margin-right: 15px
  889. .input-barcode
  890. ::v-deep(.van-field__control)
  891. border-bottom: 2px solid #0077ff
  892. line-height: 46px
  893. z-index: 2
  894. .success-input-barcode
  895. ::v-deep(.van-field__control)
  896. border-bottom: 2px solid #1ca600
  897. line-height: 46px
  898. z-index: 2
  899. .error-input-barcode
  900. ::v-deep(.van-field__control)
  901. border-bottom: 2px solid #ff0000
  902. line-height: 46px
  903. z-index: 2
  904. .order-detail
  905. margin-top: 2px
  906. background: #fff
  907. font-size: 14px
  908. .picking-no
  909. display: flex
  910. justify-content: space-between
  911. margin: 0 15px
  912. padding: 3px 0
  913. border-bottom: 1px solid #eaeaeb
  914. .picking-code
  915. flex: 1
  916. display: flex
  917. align-items: center
  918. color: #419bff
  919. .picking-container
  920. padding: 0 15px
  921. text-align: left
  922. border-bottom: 1px solid #eaeaeb
  923. .container-item
  924. line-height: 30px
  925. display: flex
  926. align-items: center
  927. .picking-order-count
  928. display: flex
  929. justify-content: space-between
  930. line-height: 30px
  931. .picking-button
  932. display: flex
  933. justify-content: space-evenly
  934. align-items: center
  935. .picking-button-item
  936. flex: 1
  937. color: #419bff
  938. font-weight: bold
  939. line-height: 35px
  940. border-right: 1px solid #eaeaeb
  941. box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1)
  942. .picking-button-item:last-child
  943. border-right: none
  944. .order-list-box
  945. background: #fff
  946. margin-top: 2px
  947. .order-list
  948. width: 100%
  949. overflow-y: auto
  950. max-height: 60vh
  951. .task-table, .task-table-bin, .task-table-box
  952. width: 100%
  953. table-layout: fixed
  954. border-collapse: collapse
  955. font-size: 15px
  956. .task-table th, .task-table-bin th, .task-table td, .task-table-bin td, .task-table-box th, .task-table-box td
  957. text-align: center
  958. border: 1px solid #ccc
  959. word-wrap: break-word
  960. word-break: break-all
  961. .task-table thead, .task-table-bin thead, .task-table-box thead
  962. background-color: #3f8dff
  963. position: sticky
  964. top: 0
  965. color: white
  966. font-size: 15px
  967. .task-table-bin thead
  968. background-color: #3f8dff
  969. .task-table-bin tbody
  970. background: #cde7ff
  971. .nav-bluetooth-scan
  972. display: flex
  973. align-items: center
  974. gap: 4px
  975. padding: 6px 12px
  976. background: rgba(255, 255, 255, 0.2)
  977. border: 1px solid rgba(255, 255, 255, 0.3)
  978. border-radius: 16px
  979. font-size: 13px
  980. color: #fff
  981. cursor: pointer
  982. transition: all 0.3s ease
  983. user-select: none
  984. white-space: nowrap
  985. &:active
  986. background: rgba(255, 255, 255, 0.3)
  987. transform: scale(0.95)
  988. .van-icon
  989. color: #4fc3f7
  990. .nav-bluetooth-connected
  991. display: flex
  992. flex-direction: column
  993. align-items: flex-end
  994. gap: 2px
  995. padding: 4px 10px
  996. background: rgba(76, 175, 80, 0.2)
  997. border: 1px solid rgba(76, 175, 80, 0.4)
  998. border-radius: 12px
  999. cursor: pointer
  1000. transition: all 0.3s ease
  1001. user-select: none
  1002. min-width: 80px
  1003. &:active
  1004. background: rgba(76, 175, 80, 0.3)
  1005. transform: scale(0.95)
  1006. .bluetooth-device-info
  1007. display: flex
  1008. align-items: center
  1009. gap: 4px
  1010. font-size: 12px
  1011. color: #fff
  1012. font-weight: 500
  1013. line-height: 1.2
  1014. .van-icon
  1015. color: #4caf50
  1016. flex-shrink: 0
  1017. .device-name
  1018. max-width: 100px
  1019. overflow: hidden
  1020. text-overflow: ellipsis
  1021. white-space: nowrap
  1022. .bluetooth-disconnect-text
  1023. font-size: 10px
  1024. color: rgba(255, 255, 255, 0.8)
  1025. line-height: 1.2
  1026. </style>