scannedMaterials.vue 31 KB

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