scannedMaterials.vue 36 KB

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