scannedMaterials.vue 39 KB

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