scannedMaterials.vue 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324
  1. <template>
  2. <gui-page :custom-header="true" :header-class="['gui-theme-background-color']">
  3. <template #gHeader>
  4. <view style="height:44px;" class="gui-flex gui-nowrap gui-rows gui-align-items-center">
  5. <!-- 使用组件实现返回按钮及返回首页按钮 -->
  6. <text style="font-size:44rpx;" class="gui-header-leader-btns gui-color-white font-icons"
  7. @tap="goBack">&#xe6c5;</text>
  8. <!-- 导航文本此处也可以是其他自定义内容 -->
  9. <text
  10. class="gui-h4 gui-blod gui-flex1 gui-text-center gui-ellipsis gui-color-white gui-primary-text">扫描入库明细</text>
  11. <!-- 此处加一个右侧展位元素与左侧同宽,实现标题居中 -->
  12. <!-- 实际宽度请根据自己情况设置 -->
  13. <view style="width:40px;" />
  14. <!-- 如果右侧有其他内容可以利用条件编译和定位来实现-->
  15. </view>
  16. </template>
  17. <template #gBody>
  18. <view class="list-content">
  19. <!-- 库位扫描输入框 -->
  20. <view class="scan">
  21. <view class="scan-card">
  22. <!-- 禁用软键盘 -->
  23. <!-- <uni-easyinput ref="easyinputStore" v-model="storeName" :input-border="false"
  24. :clearable="false" type="text" focus @focus="handleInputFocus" placeholder="请扫描库位信息"
  25. @confirm="confirmStore" /> -->
  26. <!-- 不禁用软键盘 -->
  27. <uni-easyinput ref="easyinputStore" v-model="storeName" :input-border="false"
  28. :clearable="false" type="text" focus placeholder="请扫描库位信息"
  29. @confirm="confirmStore" />
  30. <text class="font-icons" @click="handleScanStore">&#xe6b7;</text>
  31. </view>
  32. </view>
  33. <!-- 物料扫描输入框 -->
  34. <view class="scan">
  35. <view class="scan-card">
  36. <!-- 禁用软键盘 -->
  37. <!-- <uni-easyinput ref="easyinput" v-model="scanBatchNumber" :input-border="false"
  38. :clearable="false" type="text" focus @focus="handleInputFocus" placeholder="请扫描物料二维码"
  39. @confirm="handleKeydown" /> -->
  40. <!-- 不禁用软键盘 -->
  41. <uni-easyinput ref="easyinput" v-model="scanBatchNumber" :input-border="false"
  42. :clearable="false" type="text" placeholder="请扫描物料二维码"
  43. @confirm="handleKeydown" />
  44. <text class="font-icons" @click="handleScanMaterial">
  45. &#xe6b7;
  46. </text>
  47. </view>
  48. </view>
  49. <!-- 仓库和货位信息展示 -->
  50. <view class="info-row">
  51. <text class="info-label">仓库:</text>
  52. <text class="info-value">{{ erpStockName }}</text>
  53. <text class="info-label">货位:</text>
  54. <text class="info-value">{{ wmsStoreName }}</text>
  55. </view>
  56. <view class="tabs">
  57. <div class="tabs-list">
  58. <text :class="!isBefore?'tabs-item-active':'tabs-item'" @click="isBefore = false">物料需求</text>
  59. <text :class="isBefore?'tabs-item-active':'tabs-item'" @click="isBefore = true">已扫物料</text>
  60. </div>
  61. </view>
  62. <view v-if="!isBefore" class="custom-table">
  63. <uni-table border stripe empty-text="暂无更多数据">
  64. <!-- 表头行 -->
  65. <uni-tr class="custom-table-head">
  66. <uni-th align="center" width="180px" class="break-col">推荐库位(数量)</uni-th>
  67. <uni-th align="center" width="180px">物料</uni-th>
  68. <uni-th align="center" width="120px">应备数</uni-th>
  69. <uni-th align="center" width="120px">已备数</uni-th>
  70. </uni-tr>
  71. <!-- 表格数据行 -->
  72. <!-- 可点击 -->
  73. <uni-tr v-for="(item, key) in tableData" :key="key" @click="handleToDetails(item)">
  74. <!-- 不可点击行 -->
  75. <!-- <uni-tr v-for="(item, key) in tableData" :key="key"> -->
  76. <uni-td align="center" class="break-cell">{{ item.recommendStockLocation }}</uni-td>
  77. <uni-td align="center">{{ item.materialNo }}({{ item.materialName }})</uni-td>
  78. <uni-td align="center">{{ item.nowDeliveredQty }}</uni-td>
  79. <uni-td align="center"
  80. style="color: orange;font-weight: bold;">{{ item.completedQty }}</uni-td>
  81. </uni-tr>
  82. </uni-table>
  83. </view>
  84. <!-- 已扫物料 -->
  85. <view v-else class="custom-table">
  86. <scroll-view scroll-y class="scroll-box" style="height: 300px;">
  87. <view class="cell-row">
  88. <view class="cell">物料</view>
  89. <view class="cell">数量</view>
  90. <view class="cell">批号</view>
  91. </view>
  92. <view
  93. v-for="(item, idx) in beforeTableData"
  94. :key="item.uniqueId || idx"
  95. class="swipe-row"
  96. :data-index="idx"
  97. @touchstart="touchStart"
  98. @touchmove="touchMove"
  99. @touchend="touchEnd"
  100. >
  101. <!-- 内容区 -->
  102. <view
  103. class="content-area"
  104. :style="{ transform: `translateX(${item.slideX || 0}px)` }"
  105. >
  106. <view class="cell">{{ item.materialNo }}({{ item.materialName }})</view>
  107. <view class="cell">{{ item.batchQty }}</view>
  108. <view class="cell">{{ item.batchNumber }}</view>
  109. </view>
  110. <!-- 按钮区 -->
  111. <view class="btn-area" @tap.stop="deleteItem(idx)">删除</view>
  112. </view>
  113. </scroll-view>
  114. </view>
  115. <view class="card-list-item"
  116. style="margin: 12px 0;display: grid;grid-template-columns: 1fr 1fr;grid-template-rows: 1fr;gap: 10px;">
  117. <view class="sign-btn" :class="{ disabled: saveDisabled }" @click="handleSave">
  118. <text :style="saveBtnTextStyle">保存</text>
  119. </view>
  120. <view class="sign-btn" :class="{ disabled: submitDisabled }" @click="handleSubmit">
  121. <text :style="submitBtnTextStyle">提交</text>
  122. </view>
  123. </view>
  124. <gui-modal ref="modalForm" :custom-class="['gui-bg-white', 'gui-dark-bg-level-3', 'gui-border-radius']"
  125. title="提示">
  126. <template #content>
  127. <view class="gui-padding gui-bg-gray gui-dark-bg-level-2">
  128. <text class="gui-block gui-text-center gui-text gui-color-gray"
  129. style="line-height:100rpx; padding:10rpx;">备料超出,是否拆分?</text>
  130. </view>
  131. </template>
  132. <!-- 利用 flex 布局 可以放置多个自定义按钮哦 -->
  133. <template #btns>
  134. <view class="gui-flex gui-row gui-space-between operation-flex">
  135. <view hover-class="gui-tap" class="modal-btns gui-flex1" @tap="modalForm.close()">
  136. <text class="modal-btns gui-color-gray">取消</text>
  137. </view>
  138. <view class="line" />
  139. <view hover-class="gui-tap" class="modal-btns gui-flex1" @tap="handleSplitMaterial">
  140. <text class="modal-btns gui-primary-color">确认</text>
  141. </view>
  142. </view>
  143. </template>
  144. </gui-modal>
  145. <uni-popup ref="errorTip" type="dialog">
  146. <uni-popup-dialog type="error" cancel-text="关闭" confirm-text="确认" title="提示"
  147. :content="errorTipMessage" @confirm="handleCloseErrorTipsModal"
  148. @close="handleCloseErrorTipsModal" />
  149. </uni-popup>
  150. <!-- FIFO 二次确认弹窗 -->
  151. <uni-popup ref="fifoPopup" type="dialog">
  152. <uni-popup-dialog
  153. title="FIFO 提示"
  154. :content="fifoMsg"
  155. confirm-text="继续"
  156. cancel-text="取消"
  157. @confirm="fifoContinue"
  158. @close="fifoCancel" />
  159. </uni-popup>
  160. </view>
  161. </template>
  162. </gui-page>
  163. </template>
  164. <script>
  165. import {
  166. onReachBottom
  167. } from '@dcloudio/uni-app'
  168. import {
  169. ref,
  170. onMounted,
  171. defineComponent,
  172. onBeforeMount,
  173. computed,
  174. watch,
  175. nextTick
  176. } from 'vue'
  177. import {
  178. useSetWareHouseStore
  179. } from '@/stores/useSetWareHouseStore.js';
  180. export default defineComponent({
  181. setup(options) {
  182. const popup = ref()
  183. const queryParams = ref({
  184. pageSize: 20,
  185. pageNo: 1,
  186. masterId: options?.id ?? '',
  187. wmsProductionWorkOrderBomId: options?.id ?? ''
  188. })
  189. const errorTip = ref('')
  190. const errorTipMessage = ref('')
  191. const easyinput = ref('')
  192. const easyinputStore = ref('')
  193. const errorState = ref(0)
  194. const modalForm = ref()
  195. const parentRow = uni.getStorageSync('masterId') ?? {}
  196. const masterId = ref('')
  197. const businessType = ref('')
  198. const signInput = ref()
  199. const signText = ref('')
  200. const isLightText = ref('')
  201. const isSubmitLight = ref('')
  202. const scanBatchNumber = ref('')
  203. const isBefore = ref(false)
  204. const tableData = ref([])
  205. const beforeTableData = ref([])
  206. const scanMaterialList = ref([])
  207. // 当前处理的数据行
  208. const fdIndex = ref(-1)
  209. // 当前扫描的物料
  210. const currentScanMaterial = ref([])
  211. // 前端临时缓存:已扫物料
  212. const localScannedList = ref([])
  213. // 控制保存按钮能否点击
  214. const saveDisabled = ref(false)
  215. // 控制提交按钮能否点击
  216. const submitDisabled = ref(false)
  217. const receiveList = ref([])
  218. /* -------------------- FIFO相关变量 -------------------- */
  219. const fifoPopup = ref(null) // 弹窗实例
  220. const fifoMsg = ref('') // 提示语
  221. let fifoQrCode = '' // 缓存本次二维码
  222. const fifoGo = ref(false) // 用户是否点了“继续”
  223. // 存储fifo_check_order_type字典数据
  224. const fifoCheckOrderTypeDict = ref([])
  225. // 标记businessType是否在fifo_check_order_type字典内
  226. const isBusinessTypeInFifoDict = ref(false)
  227. /* -------------------- FIFO校验核心方法 -------------------- */
  228. // 真正继续扫码(关闭弹窗并置标志)
  229. const fifoContinue = () => {
  230. fifoPopup.value.close()
  231. fifoGo.value = true
  232. nextTick(() => {
  233. if (fifoQrCode) handleKeydown(fifoQrCode) // 或 handleScanMaterial 里的 ret.resp_result
  234. })
  235. }
  236. const fifoCancel = () => { fifoPopup.value.close() } // 什么都不做
  237. // 统一 FIFO 校验入口
  238. const checkFifo = (qrCode) => {
  239. if (fifoGo.value) return Promise.resolve(true) // 关键:放行
  240. if (!isBusinessTypeInFifoDict.value) return Promise.resolve(true)
  241. return uni.$reqPost('fifoCheck', { qrCode,
  242. requestNo: receiveList.value.requestNo,
  243. businessType: receiveList.value.businessType,
  244. }).then(({ code, data, msg }) => {
  245. if (code !== 0) {
  246. errorTipMessage.value = msg || 'FIFO 校验异常'
  247. errorTip.value.open()
  248. return false
  249. }
  250. if (data === null) return true
  251. fifoMsg.value = `当前条码(${qrCode})不是库存中生产日期最早的物料条码(${data}),是否继续入库?`
  252. fifoQrCode = qrCode
  253. fifoPopup.value.open()
  254. return false
  255. })
  256. }
  257. // 库位相关变量
  258. const storeName = ref('') // 库位编码
  259. const erpStockName = ref('') // 仓库名称
  260. const wmsStoreName = ref('') // 货位名称
  261. onBeforeMount(() => {
  262. const parsedData = JSON.parse(parentRow)
  263. masterId.value = parsedData?.id
  264. businessType.value = parsedData?.businessType || '0'
  265. console.log('获取到的businessType:', businessType.value)
  266. // 获取fifo_check_order_type字典数据
  267. getFifoCheckOrderTypeDict()
  268. })
  269. // 获取fifo_check_order_type字典数据
  270. const getFifoCheckOrderTypeDict = function() {
  271. uni.$reqGet('getDictDataPage', {
  272. dictType: 'fifo_check_order_type'
  273. })
  274. .then(({ code, data, msg }) => {
  275. if (code === 0) {
  276. fifoCheckOrderTypeDict.value = data?.list || []
  277. console.log('fifo_check_order_type字典数据:', fifoCheckOrderTypeDict.value)
  278. console.log('fifo_check_order_type字典数据长度:', fifoCheckOrderTypeDict.value.length)
  279. // 判断businessType是否在字典内
  280. checkBusinessTypeInFifoDict()
  281. } else {
  282. console.error('获取fifo_check_order_type字典失败:', msg)
  283. }
  284. })
  285. .catch(error => {
  286. console.error('获取fifo_check_order_type字典异常:', error)
  287. })
  288. }
  289. // 判断businessType是否在fifo_check_order_type字典内
  290. const checkBusinessTypeInFifoDict = function() {
  291. // 使用some方法检查businessType是否存在于字典数据中
  292. isBusinessTypeInFifoDict.value = fifoCheckOrderTypeDict.value.some(item =>
  293. String(item?.value).trim() === String(businessType.value).trim()
  294. )
  295. console.log('businessType是否在fifo_check_order_type字典内:', isBusinessTypeInFifoDict.value)
  296. }
  297. const search = function() {
  298. uni.$reqGet('getScannedInMatersDetails', { id: masterId.value })
  299. .then(({ code, data, msg }) => {
  300. if (code === 0) {
  301. // 将API返回的数据保存到receiveList
  302. receiveList.value = data;
  303. uni.setStorageSync('ids', JSON.stringify(data?.inRequestDetailPDAList?.[0] || {}))
  304. tableData.value = data?.inRequestDetailPDAList || []
  305. // 1. 先清空本地已扫列表,准备重新填充
  306. localScannedList.value = []
  307. // 2. 将后端返回的已扫物料数据塞进localScannedList
  308. tableData.value.forEach(item => {
  309. if (item.inRequestSubdetailList?.length) {
  310. localScannedList.value.push(...item.inRequestSubdetailList)
  311. }
  312. })
  313. // 3. 调用flushBeforeTableData(),以localScannedList为准重新生成beforeTableData
  314. flushBeforeTableData()
  315. } else {
  316. uni.showToast({
  317. title: msg,
  318. icon: 'none',
  319. duration: 2000
  320. })
  321. }
  322. })
  323. }
  324. onMounted(() => {
  325. search()
  326. })
  327. const goBack = function() {
  328. if (uni.getStorageSync('masterId')) {
  329. uni.removeStorageSync('masterId')
  330. }
  331. if (uni.getStorageSync('ids')) {
  332. uni.removeStorageSync('ids')
  333. }
  334. uni.$goBack('/pages/workbranch/warehouse/scanInOut/In/scanInPage')
  335. }
  336. const handleScanMaterial = async function () {
  337. // #ifdef APP-PLUS
  338. // 0. 基本校验
  339. if (!storeName.value) {
  340. plus.device.beep(2)
  341. errorTipMessage.value = '请先扫描库位信息'
  342. errorTip.value.open()
  343. return
  344. }
  345. // 1. 先扫码
  346. const mpaasScanModule = uni.requireNativePlugin('Mpaas-Scan-Module')
  347. const ret = await new Promise(resolve =>
  348. mpaasScanModule.mpaasScan(
  349. { scanType: ['qrCode', 'barCode'], hideAlbum: false },
  350. resolve
  351. )
  352. )
  353. if (ret.resp_code !== 1000) return // 用户取消
  354. const qrCode = ret.resp_result
  355. // 2. FIFO 校验(暂时注释)
  356. // const pass = await checkFifo(qrCode)
  357. // if (!pass) return // 用户点了“取消”
  358. const pass = true // FIFO校验直接放行
  359. // 3. 业务接口
  360. uni.$reqGet('scanPrepareMaterial', {
  361. qrCode: qrCode,
  362. locationCode: storeName.value // 传入库位编码
  363. })
  364. .then(async ({ code, data, msg }) => {
  365. if (code === 0) {
  366. scanBatchNumber.value = qrCode
  367. // 更新仓库和货位名称(直接覆盖)
  368. erpStockName.value = data[0]?.erpStockName || ''
  369. wmsStoreName.value = data[0]?.wmsStoreName || ''
  370. // 更新仓库和货位名称(非空才覆盖,保留原有值)
  371. // erpStockName.value = data[0]?.erpStockName || erpStockName.value
  372. // wmsStoreName.value = data[0]?.wmsStoreName || wmsStoreName.value
  373. if (Object.prototype.toString.call(data) === '[object Array]') {
  374. fdIndex.value = tableData.value.findIndex(item => item?.materialNo === data[0]?.materialNo)
  375. }
  376. if (fdIndex.value !== -1) {
  377. currentScanMaterial.value = data[0] ?? []
  378. // 校验批号是否已存在
  379. if (isBatchExist(currentScanMaterial.value.batchNumber)) {
  380. showBatchRepeatTip();
  381. return;
  382. }
  383. const row = tableData.value[fdIndex.value]
  384. if (row.nowDeliveredQty > row.completedQty) {
  385. /* ******** 前端暂存开始 ******** */
  386. // 1) 累加到“已备数”
  387. row.completedQty += currentScanMaterial.value.receiptQty || 1
  388. // 2) 扔进本地已扫池(用于已扫物料列表展示)
  389. localScannedList.value.push({
  390. ...currentScanMaterial.value,
  391. batchQty: currentScanMaterial.value.receiptQty || 1, // 本次扫描数量
  392. supplierName: currentScanMaterial.value.supplierName || ''
  393. })
  394. // 3) 刷新已扫物料列表
  395. flushBeforeTableData()
  396. // 4) 复位输入框,准备下一次扫码
  397. setInputFocus()
  398. /* ******** 前端暂存结束 ******** */
  399. } else {
  400. // #ifdef APP-PLUS
  401. plus.device.beep(2)
  402. // #endif
  403. errorTipMessage.value = '已备数量已满,无需再扫'
  404. errorTip.value.open()
  405. errorState.value = 0
  406. }
  407. } else {
  408. // #ifdef APP-PLUS
  409. plus.device.beep(2)
  410. // #endif
  411. errorTipMessage.value = '请扫描所需物料的物料条码'
  412. errorTip.value.open()
  413. errorState.value = 0
  414. }
  415. } else {
  416. // #ifdef APP-PLUS
  417. plus.device.beep(2)
  418. // #endif
  419. errorTipMessage.value = msg
  420. errorTip.value.open()
  421. errorState.value = 0
  422. }
  423. })
  424. .catch((err) => {
  425. // #ifdef APP-PLUS
  426. plus.device.beep(2)
  427. // #endif
  428. errorTipMessage.value = err.msg || '获取物料信息失败'
  429. errorTip.value.open()
  430. errorState.value = 0
  431. }).finally(() => {
  432. fifoGo.value = false // ★★★ 复位:一次放行即失效 ★★★
  433. })
  434. // #endif
  435. }
  436. // 物料拆分
  437. const handleSplitMaterial = function() {
  438. modalForm.value.close()
  439. setInputFocus()
  440. }
  441. const handleKeydown = async function(e) {
  442. // 校验库位信息是否存在
  443. if (!storeName.value) {
  444. // #ifdef APP-PLUS
  445. plus.device.beep(2)
  446. // #endif
  447. errorTipMessage.value = '请先扫描库位信息'
  448. errorTip.value.open()
  449. errorState.value = 0
  450. return
  451. }
  452. // FIFO 校验(暂时关闭)
  453. // const pass = await checkFifo(e)
  454. // if (!pass && !fifoGo.value) return
  455. const pass = true // FIFO校验直接放行
  456. uni.$reqGet('scanPrepareMaterial', {
  457. qrCode: e,
  458. locationCode: storeName.value // 传入库位编码
  459. })
  460. .then(async({ code, data, msg }) => {
  461. fifoGo.value = false
  462. if (code === 0) {
  463. scanBatchNumber.value = e
  464. // 更新仓库和货位名称(直接覆盖)
  465. erpStockName.value = data[0]?.erpStockName || ''
  466. wmsStoreName.value = data[0]?.wmsStoreName || ''
  467. // 更新仓库和货位名称(非空才覆盖,保留原有值)
  468. // erpStockName.value = data[0]?.erpStockName || erpStockName.value
  469. // wmsStoreName.value = data[0]?.wmsStoreName || wmsStoreName.value
  470. if (Object.prototype.toString.call(data) === '[object Array]') {
  471. fdIndex.value = tableData.value.findIndex(item => item?.materialNo === data[0]?.materialNo)
  472. }
  473. if (fdIndex.value !== -1) {
  474. currentScanMaterial.value = data[0] ?? []
  475. // 校验批号是否已存在
  476. if (isBatchExist(currentScanMaterial.value.batchNumber)) {
  477. showBatchRepeatTip();
  478. return;
  479. }
  480. const row = tableData.value[fdIndex.value]
  481. if (row.nowDeliveredQty > row.completedQty) {
  482. /* ******** 前端暂存开始 ******** */
  483. // 1) 累加到“已备数”
  484. row.completedQty += currentScanMaterial.value.receiptQty || 1
  485. // 2) 扔进本地已扫池(用于已扫物料列表展示)
  486. localScannedList.value.push({
  487. ...currentScanMaterial.value,
  488. batchQty: currentScanMaterial.value.receiptQty || 1, // 本次扫描数量
  489. supplierName: currentScanMaterial.value.supplierName || ''
  490. })
  491. // 3) 刷新已扫物料列表
  492. flushBeforeTableData()
  493. // 4) 复位输入框,准备下一次扫码
  494. setInputFocus()
  495. /* ******** 前端暂存结束 ******** */
  496. } else {
  497. // #ifdef APP-PLUS
  498. plus.device.beep(2)
  499. // #endif
  500. errorTipMessage.value = '已备数量已满,无需再扫'
  501. errorTip.value.open()
  502. errorState.value = 0
  503. }
  504. } else {
  505. // #ifdef APP-PLUS
  506. plus.device.beep(2)
  507. // #endif
  508. errorTipMessage.value = '请扫描所需物料的物料条码'
  509. errorTip.value.open()
  510. errorState.value = 0
  511. }
  512. } else {
  513. // #ifdef APP-PLUS
  514. plus.device.beep(2)
  515. // #endif
  516. errorTipMessage.value = msg
  517. errorTip.value.open()
  518. errorState.value = 0
  519. }
  520. })
  521. .catch((err) => {
  522. // #ifdef APP-PLUS
  523. plus.device.beep(2)
  524. // #endif
  525. errorTipMessage.value = err.msg || '获取物料信息失败'
  526. errorTip.value.open()
  527. errorState.value = 0
  528. }).finally(() => {
  529. fifoGo.value = false // ★★★ 复位:一次放行即失效 ★★★
  530. })
  531. }
  532. const handleToDetails = function(ret) {
  533. uni.navigateTo({
  534. url: '/pages/workbranch/warehouse/scanInOut/In/materialsDetail'
  535. })
  536. uni.setStorageSync('mixMaterialDetail', JSON.stringify(ret))
  537. }
  538. const setInputFocus = function() {
  539. scanBatchNumber.value = ''
  540. easyinput.value.onBlur()
  541. easyinput.value.onFocus()
  542. }
  543. // 相同物料+相同批号才合并数量,否则新增一行
  544. const flushBeforeTableData = function() {
  545. const map = new Map()
  546. localScannedList.value.forEach(it => {
  547. // 用“物料编码+批号”当唯一键
  548. const key = `${it.materialNo}__${it.batchNumber}`
  549. if (map.has(key)) {
  550. map.get(key).batchQty += it.batchQty // 同批号累加
  551. } else {
  552. map.set(key, { ...it })// 新批号新开一行
  553. }
  554. })
  555. // 为每个项目添加唯一ID和滑动属性
  556. beforeTableData.value = Array.from(map.values()).map((v, i) => ({
  557. ...v,
  558. uniqueId: `${v.materialNo}_${v.batchNumber}_${i}`,
  559. slideX: 0
  560. }))
  561. }
  562. /* ========= 左滑删除 ========= */
  563. const touchStart = (e) => {
  564. const idx = e.currentTarget.dataset.index
  565. beforeTableData.value.forEach((v, i) => {
  566. if (i !== idx) v.slideX = 0 // 其余归位
  567. })
  568. beforeTableData.value[idx].startX = e.touches[0].pageX
  569. beforeTableData.value[idx].slideX = beforeTableData.value[idx].slideX || 0
  570. }
  571. const touchMove = (e) => {
  572. const idx = e.currentTarget.dataset.index
  573. const row = beforeTableData.value[idx]
  574. const delta = e.touches[0].pageX - row.startX
  575. if (delta < 0) { // 只允许左滑
  576. row.slideX = Math.max(delta, -70) // 70 = 按钮宽度
  577. } else {
  578. row.slideX = Math.min(delta, 0)
  579. }
  580. }
  581. const touchEnd = (e) => {
  582. const idx = e.currentTarget.dataset.index
  583. const row = beforeTableData.value[idx]
  584. row.slideX = row.slideX <= -35 ? -70 : 0 // 过半则露出,否则收回
  585. }
  586. /**
  587. * 删除一条已扫物料
  588. * @param {number} idx 在 beforeTableData 中的下标
  589. */
  590. const deleteItem = async (idx) => {
  591. const target = beforeTableData.value[idx];
  592. /* 1. 有 id 就先调接口删后端 */
  593. if (target.id) {
  594. try {
  595. const { code, msg } = await uni.$reqPost('deleteScanInMaterial', { id: target.id });
  596. if (code !== 0) {
  597. // 接口明确返回失败,提示用户并终止后续逻辑
  598. errorTipMessage.value = msg || '后端删除失败';
  599. errorTip.value.open();
  600. return;
  601. }
  602. } catch (err) {
  603. // 网络或其它异常
  604. errorTipMessage.value = err.errMsg || '网络异常,删除失败';
  605. errorTip.value.open();
  606. return;
  607. }
  608. }
  609. /* 2. 无论有没有 id、接口成不成功,只要走到这里就删本地 */
  610. // 2.1 从 localScannedList 里删掉对应项(同物料+同批号)
  611. const key = `${target.materialNo}__${target.batchNumber}`;
  612. const listIdx = localScannedList.value.findIndex(
  613. v => `${v.materialNo}__${v.batchNumber}` === key
  614. );
  615. if (listIdx > -1) localScannedList.value.splice(listIdx, 1);
  616. // 2.2 重新合并生成 beforeTableData
  617. flushBeforeTableData();
  618. // 2.3 把对应物料的“已备数”回退
  619. const row = tableData.value.find(r => r.materialNo === target.materialNo);
  620. if (row) row.completedQty -= target.batchQty;
  621. };
  622. // 关闭错误信息弹窗
  623. const handleCloseErrorTipsModal = async function() {
  624. errorTip.value.close()
  625. if (errorState.value === 0) {
  626. await setInputFocus()
  627. }
  628. }
  629. /* ===================== 公共校验函数 ===================== */
  630. // 仅扫描本地缓存池,不再读 beforeTableData
  631. const isBatchExist = (batchNo) =>
  632. beforeTableData.value.some((it) => it.batchNumber === batchNo);
  633. const showBatchRepeatTip = () => {
  634. // #ifdef APP-PLUS
  635. plus.device.beep(2);
  636. // #endif
  637. errorTipMessage.value = '该批号已存在,请勿重复扫描';
  638. errorTip.value.open();
  639. errorState.value = 0;
  640. };
  641. // 禁用软键盘
  642. const handleInputFocus = function() {
  643. setTimeout(() => {
  644. uni.hideKeyboard()
  645. }, 100)
  646. }
  647. // 处理库位扫码
  648. const handleScanStore = function() {
  649. // #ifdef APP-PLUS
  650. const mpaasScanModule = uni.requireNativePlugin('Mpaas-Scan-Module')
  651. mpaasScanModule.mpaasScan({
  652. // 扫码识别类型,参数可多选,qrCode、barCode,不设置,默认识别所有
  653. 'scanType': ['qrCode', 'barCode'],
  654. // 是否隐藏相册,默认false不隐藏
  655. 'hideAlbum': false
  656. },
  657. (ret) => {
  658. if (ret.resp_code === 1000) {
  659. confirmStore(ret.resp_result)
  660. }
  661. })
  662. // #endif
  663. // #ifdef H5
  664. confirmStore('PC-1')
  665. // #endif
  666. }
  667. // 扫描货位输入框回车事件
  668. const confirmStore = function(e) {
  669. // 保持输入框里的原始数据不变
  670. storeName.value = e
  671. uni.$reqGet('getStockLocaltionByCode', {
  672. code: e
  673. })
  674. .then(({ code, data, msg }) => {
  675. if (code === 0) {
  676. // 验证是否获取到了货位和仓库信息
  677. if (!data || !data.erpStockName || !data.wmsStoreName) {
  678. // #ifdef APP-PLUS
  679. plus.device.beep(2)
  680. // #endif
  681. errorTipMessage.value = '请扫描正确的库位'
  682. errorTip.value.open()
  683. errorState.value = 0
  684. // 清空扫描框
  685. storeName.value = ''
  686. return
  687. }
  688. erpStockName.value = data.erpStockName // 仓库名称
  689. wmsStoreName.value = data.wmsStoreName // 货位名称
  690. // 关键:让物料输入框获得焦点
  691. nextTick(() => {
  692. easyinput.value.onFocus()
  693. })
  694. } else {
  695. // #ifdef APP-PLUS
  696. plus.device.beep(2)
  697. // #endif
  698. errorTipMessage.value = '请扫描正确的库位'
  699. errorTip.value.open()
  700. errorState.value = 0
  701. // 清空扫描框
  702. storeName.value = ''
  703. }
  704. })
  705. }
  706. // 重置库位输入框
  707. const setStoreInputFocus = function() {
  708. storeName.value = ''
  709. easyinputStore.value.onBlur()
  710. easyinputStore.value.onFocus()
  711. }
  712. // 把 beforeTableData 追加到 tableData 对应物料的 inRequestSubdetailList
  713. const mergeBeforeIntoTable = () => {
  714. // 创建新数组存储合并结果
  715. const mergedTableData = JSON.parse(JSON.stringify(tableData.value))
  716. // 先建索引
  717. const map = {}
  718. mergedTableData.forEach(row => {
  719. if (!row.inRequestSubdetailList) row.inRequestSubdetailList = []
  720. map[row.materialNo] = row
  721. })
  722. // 只追加,不新增
  723. beforeTableData.value.forEach(item => {
  724. const target = map[item.materialNo]
  725. if (target) {
  726. target.inRequestSubdetailList.push({
  727. ...item
  728. }) // 整条记录丢进去
  729. }
  730. // 不存在就跳过
  731. })
  732. return mergedTableData
  733. }
  734. // 保存按钮点击事件
  735. const handleSave = async function() {
  736. if (saveDisabled.value) return
  737. saveDisabled.value = true
  738. try {
  739. // 保存逻辑实现
  740. isLightText.value = true
  741. // 先合并数据,获取合并后的新数组
  742. const mergedData = mergeBeforeIntoTable()
  743. // 调用保存API,使用合并后的新数组作为参数
  744. await uni.$reqPost('saveScannedInMaterials', {
  745. id: receiveList.value?.id,
  746. requestNo: receiveList.value?.requestNo,
  747. requestType: receiveList.value?.requestType,
  748. businessType: receiveList.value?.businessType,
  749. businessSubType: receiveList.value?.businessSubType,
  750. status: receiveList.value?.status,
  751. priority: receiveList.value?.priority,
  752. inRequestDetailPDAList: mergedData
  753. })
  754. .then(({ code, data, msg }) => {
  755. if (code === 0) {
  756. uni.showModal({
  757. title: '提示',
  758. content: '保存成功',
  759. showCancel: false
  760. })
  761. search();
  762. } else {
  763. // #ifdef APP-PLUS
  764. plus.device.beep(2)
  765. // #endif
  766. errorTipMessage.value = msg
  767. errorTip.value.open()
  768. errorState.value = 0
  769. }
  770. })
  771. } finally {
  772. saveDisabled.value = false
  773. }
  774. }
  775. // 提交按钮点击事件
  776. const handleSubmit = async function() {
  777. if (submitDisabled.value) return
  778. submitDisabled.value = true
  779. try {
  780. // 提交逻辑实现
  781. isSubmitLight.value = true
  782. // 先合并数据,获取合并后的新数组
  783. const mergedData = mergeBeforeIntoTable()
  784. // 调用提交API,使用合并后的新数组作为参数
  785. await uni.$reqPut('submitScannedInMaterials', {
  786. id: receiveList.value?.id,
  787. requestNo: receiveList.value?.requestNo,
  788. requestType: receiveList.value?.requestType,
  789. businessType: receiveList.value?.businessType,
  790. businessSubType: receiveList.value?.businessSubType,
  791. status: receiveList.value?.status,
  792. priority: receiveList.value?.priority,
  793. inRequestDetailPDAList: mergedData
  794. })
  795. .then(({ code, data, msg }) => {
  796. if (code === 0) {
  797. uni.showModal({
  798. title: '提示',
  799. content: '提交成功',
  800. showCancel: false
  801. })
  802. search();
  803. } else {
  804. // #ifdef APP-PLUS
  805. plus.device.beep(2)
  806. // #endif
  807. errorTipMessage.value = msg
  808. errorTip.value.open()
  809. errorState.value = 0
  810. }
  811. })
  812. } finally {
  813. submitDisabled.value = false
  814. }
  815. }
  816. // uniapp移动端触底事件
  817. onReachBottom(() => {
  818. queryParams.value.pageNo += 1
  819. uni.$reqGet('getPrepareMaterialList', queryParams.value)
  820. .then(({ data }) => {
  821. Array.prototype.push.call(scanMaterialList.value, ...data?.list ?? [])
  822. })
  823. })
  824. // 保存按钮文字样式
  825. const saveBtnTextStyle = computed(() => ({
  826. fontSize: '14px',
  827. fontWeight: 'bold',
  828. color: saveDisabled.value ? '#ccc' : (isLightText.value ? 'rgba(0,160,233,1)' : '')
  829. }))
  830. // 提交按钮文字样式
  831. const submitBtnTextStyle = computed(() => ({
  832. fontSize: '14px',
  833. fontWeight: 'bold',
  834. color: submitDisabled.value ? '#ccc' : (isSubmitLight.value ? 'rgba(0,160,233,1)' : '')
  835. }))
  836. // 移除status监听,提交按钮和保存按钮均始终可用
  837. // watch(() => receiveList.value?.status, (newStatus) => {
  838. // submitDisabled.value = newStatus !== 0
  839. // })
  840. return {
  841. goBack,
  842. popup,
  843. signText,
  844. isBefore,
  845. tableData,
  846. beforeTableData,
  847. signInput,
  848. modalForm,
  849. easyinput,
  850. easyinputStore,
  851. errorTip,
  852. errorTipMessage,
  853. handleInputFocus,
  854. isLightText,
  855. isSubmitLight,
  856. handleKeydown,
  857. scanBatchNumber,
  858. handleScanMaterial,
  859. scanMaterialList,
  860. handleSplitMaterial,
  861. handleToDetails,
  862. handleCloseErrorTipsModal,
  863. handleSave,
  864. handleSubmit,
  865. saveDisabled,
  866. submitDisabled,
  867. saveBtnTextStyle,
  868. submitBtnTextStyle,
  869. // 库位相关
  870. storeName,
  871. erpStockName,
  872. wmsStoreName,
  873. handleScanStore,
  874. confirmStore,
  875. // 左滑删除相关
  876. touchStart,
  877. touchMove,
  878. touchEnd,
  879. deleteItem,
  880. // FIFO相关
  881. fifoPopup,
  882. fifoMsg,
  883. fifoContinue,
  884. fifoCancel
  885. }
  886. }
  887. })
  888. </script>
  889. <style lang="scss" scoped>
  890. /* 左滑删除样式 */
  891. .scroll-box{
  892. height:100%; /* 继承父级高度 */
  893. }
  894. .cell-row {
  895. display: flex;
  896. background-color: #f5f7fa;
  897. font-weight: bold;
  898. border-radius: 4px;
  899. margin-bottom: 5px;
  900. }
  901. .swipe-row{
  902. position:relative;
  903. width:100%;
  904. height:44px;
  905. overflow:hidden;
  906. border-bottom:1px solid #eee;
  907. }
  908. .content-area{
  909. position:absolute;
  910. left:0;
  911. top:0;
  912. right:0;
  913. bottom:0;
  914. z-index:2;
  915. background:#fff;
  916. display:flex;
  917. align-items:center;
  918. transition: transform .25s;
  919. }
  920. .cell{
  921. flex:1;
  922. text-align:center;
  923. font-size:14px;
  924. color:#333;
  925. }
  926. .btn-area{
  927. position:absolute;
  928. right:0;
  929. top:0;
  930. width:70px;
  931. height:100%;
  932. background:#e54d42;
  933. color:#fff;
  934. display:flex;
  935. align-items:center;
  936. justify-content:center;
  937. font-size:14px;
  938. z-index:1;
  939. }
  940. .gui-header-leader-btns {
  941. color: black;
  942. font-size: 24px !important;
  943. margin-left: 24rpx;
  944. }
  945. .list-content {
  946. margin-top: 80px;
  947. background-color: #edeeee;
  948. }
  949. .scan {
  950. margin-top: 10px;
  951. height: 55px;
  952. display: flex;
  953. justify-content: center;
  954. background-color: white;
  955. }
  956. .scan-card {
  957. display: flex;
  958. flex-direction: row;
  959. justify-content: space-between;
  960. align-items: center;
  961. width: 100%;
  962. padding-left: 10px;
  963. padding-right: 10px;
  964. }
  965. .store-info {
  966. margin-top: 10px;
  967. height: 140px;
  968. display: flex;
  969. justify-content: center;
  970. background-color: white;
  971. }
  972. .store-info-card {
  973. display: flex;
  974. flex-direction: column;
  975. .row-space-between {
  976. flex: 1;
  977. width: calc(100vw - 40px);
  978. display: flex;
  979. flex-direction: row;
  980. justify-content: space-between;
  981. align-items: center;
  982. padding-top: 12px;
  983. padding-bottom: 12px;
  984. }
  985. }
  986. .card-list-flexbox {
  987. display: flex;
  988. flex-direction: row;
  989. align-items: center;
  990. flex-wrap: wrap;
  991. margin: 3px 2px;
  992. .card-list-item {
  993. width: 750rpx;
  994. height: 40px;
  995. }
  996. }
  997. .card-list-item {
  998. margin: 2rpx 0;
  999. display: flex;
  1000. flex-direction: row;
  1001. align-items: center;
  1002. justify-content: space-between;
  1003. background-color: #fff;
  1004. uni-text {
  1005. font-size: 14px;
  1006. height: 50rpx;
  1007. text-align: left;
  1008. padding: 0 12px;
  1009. display: flex;
  1010. flex-direction: row;
  1011. align-items: center;
  1012. }
  1013. .text-1 {
  1014. flex: 1;
  1015. height: 40px;
  1016. justify-content: flex-start;
  1017. }
  1018. .text-2 {
  1019. flex: 3;
  1020. height: 40px;
  1021. justify-content: flex-end;
  1022. margin-right: 4px;
  1023. padding: 2px 6px;
  1024. }
  1025. }
  1026. .card-list-flexbox:nth-of-type(2) {
  1027. margin-top: 48px;
  1028. }
  1029. .fixedTop {
  1030. bottom: 0 !important;
  1031. top: 3.25rem !important;
  1032. }
  1033. .popup-content {
  1034. height: 75vh;
  1035. overflow-y: scroll;
  1036. background-color: #edeeee;
  1037. }
  1038. .font-icons {
  1039. width: 40px;
  1040. font-size: 20px;
  1041. }
  1042. .scan {
  1043. height: 45px;
  1044. width: calc(100% - 48px);
  1045. margin: 12px;
  1046. padding: 0 12px;
  1047. display: flex;
  1048. justify-content: space-between;
  1049. align-items: center;
  1050. border-radius: 6px;
  1051. background-color: white;
  1052. .scan-card {
  1053. width: 100%;
  1054. display: grid;
  1055. grid-template-rows: 1fr;
  1056. grid-template-columns: 7fr 2fr;
  1057. align-items: center;
  1058. input {
  1059. height: 35px;
  1060. line-height: 35px;
  1061. }
  1062. text {
  1063. width: 100%;
  1064. text-align: right;
  1065. }
  1066. }
  1067. }
  1068. .custom-table {
  1069. height: calc(100vh - 265px);
  1070. min-height: 230px;
  1071. margin: 5px 0;
  1072. // min-height: 600px;
  1073. overflow-y: scroll;
  1074. }
  1075. .custom-table-head .uni-th {
  1076. color: #333;
  1077. font-weight: bold;
  1078. }
  1079. .custom-table .uni-tr:nth-child(even) {
  1080. background-color: #f5f7fa;
  1081. }
  1082. .custom-table .uni-tr:nth-child(odd) {
  1083. background-color: #ffffff;
  1084. }
  1085. /* 仓库和货位信息展示样式 */
  1086. .info-row {
  1087. display: flex;
  1088. align-items: center;
  1089. padding: 10rpx 20rpx;
  1090. background-color: #f0f2f5;
  1091. border-radius: 8rpx;
  1092. margin: 10rpx 20rpx;
  1093. }
  1094. .info-label {
  1095. color: #666;
  1096. font-size: 28rpx;
  1097. margin-right: 8rpx;
  1098. }
  1099. .info-value {
  1100. color: #333;
  1101. font-size: 28rpx;
  1102. margin-right: 20rpx;
  1103. font-weight: 500;
  1104. }
  1105. .modal-btns {
  1106. height: 100rpx;
  1107. line-height: 100rpx;
  1108. display: flex;
  1109. justify-content: center;
  1110. align-items: center;
  1111. }
  1112. .line {
  1113. margin-top: 10rpx;
  1114. height: 80rpx;
  1115. width: 1rpx;
  1116. background-color: #dcdcdc;
  1117. }
  1118. .tabs {
  1119. width: 100%;
  1120. height: 45px;
  1121. display: flex;
  1122. align-items: flex-end;
  1123. padding: 0 2px;
  1124. background-color: white;
  1125. .tabs-list {
  1126. border-radius: 3px;
  1127. overflow: hidden;
  1128. }
  1129. .tabs-item {
  1130. display: inline-block;
  1131. width: 72px;
  1132. height: 30px;
  1133. line-height: 30px;
  1134. padding: 0 8px;
  1135. font-size: 14px;
  1136. font-weight: bold;
  1137. text-align: center;
  1138. color: black;
  1139. border-bottom: 1.5px dashed #00a0e9;
  1140. transition: all .5s ease-in-out;
  1141. }
  1142. .tabs-item-active {
  1143. position: relative;
  1144. display: inline-block;
  1145. width: 72px;
  1146. height: 30px;
  1147. line-height: 30px;
  1148. padding: 0 8px;
  1149. font-size: 14px;
  1150. font-weight: bold;
  1151. text-align: center;
  1152. color: white;
  1153. border-left: 1px solid #00a0e9;
  1154. border-top: 1px solid #00a0e9;
  1155. border-right: 1px solid #00a0e9;
  1156. border-bottom: 1.5px solid #00a0e9;
  1157. border-radius: 5px 5px 0 0;
  1158. animation: .3s linear show;
  1159. background-color: #00a0e9;
  1160. }
  1161. .tabs-item-active::before {
  1162. content: '';
  1163. position: absolute;
  1164. left: -10px;
  1165. bottom: 0;
  1166. width: 10px;
  1167. height: 10px;
  1168. background: radial-gradient(circle at 0% 25%, transparent 10px, #00a0e9 0)
  1169. }
  1170. .tabs-item-active::after {
  1171. content: '';
  1172. position: absolute;
  1173. right: -10px;
  1174. bottom: 0;
  1175. width: 10px;
  1176. height: 10px;
  1177. background: radial-gradient(circle at 100% 25%, transparent 10px, #00a0e9 0)
  1178. }
  1179. }
  1180. @keyframes show {
  1181. from {
  1182. transform: translateY(5%);
  1183. }
  1184. to {
  1185. transform: translateY(0%);
  1186. }
  1187. }
  1188. .sign-btn {
  1189. display: flex;
  1190. align-items: center;
  1191. justify-content: center;
  1192. margin: 0 8px;
  1193. border: 1px solid #999999;
  1194. background-color: white;
  1195. border-radius: 6px;
  1196. }
  1197. .sign-btn.disabled {
  1198. opacity: 0.5;
  1199. pointer-events: none;
  1200. }
  1201. // /* 表头也允许换行,保证与列宽对齐 */
  1202. // ::v-deep .break-col {
  1203. // white-space: normal !important;
  1204. // word-break: break-all !important;
  1205. // line-height: 1.2;
  1206. // }
  1207. // /* 单元格超长自动分段 */
  1208. // ::v-deep .break-cell {
  1209. // white-space: normal !important;
  1210. // word-break: break-all !important;
  1211. // line-height: 1.2;
  1212. // padding: 4px 2px; /* 上下留一点空隙,视觉更舒服 */
  1213. // }
  1214. </style>