scannedMaterials.vue 38 KB

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