scannedMaterials.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  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" focus 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. </view>
  149. </template>
  150. </gui-page>
  151. </template>
  152. <script>
  153. import {
  154. onReachBottom
  155. } from '@dcloudio/uni-app'
  156. import {
  157. ref,
  158. onMounted,
  159. defineComponent,
  160. onBeforeMount,
  161. computed,
  162. watch
  163. } from 'vue'
  164. import {
  165. useSetWareHouseStore
  166. } from '@/stores/useSetWareHouseStore.js';
  167. export default defineComponent({
  168. setup(options) {
  169. const popup = ref()
  170. const queryParams = ref({
  171. pageSize: 20,
  172. pageNo: 1,
  173. masterId: options?.id ?? '',
  174. wmsProductionWorkOrderBomId: options?.id ?? ''
  175. })
  176. const errorTip = ref('')
  177. const errorTipMessage = ref('')
  178. const easyinput = ref('')
  179. const easyinputStore = ref('')
  180. const errorState = ref(0)
  181. const modalForm = ref()
  182. const parentRow = uni.getStorageSync('masterId') ?? {}
  183. const masterId = ref('')
  184. const signInput = ref()
  185. const signText = ref('')
  186. const isLightText = ref('')
  187. const isSubmitLight = ref('')
  188. const scanBatchNumber = ref('')
  189. const isBefore = ref(false)
  190. const tableData = ref([])
  191. const beforeTableData = ref([])
  192. const scanMaterialList = ref([])
  193. // 当前处理的数据行
  194. const fdIndex = ref(-1)
  195. // 当前扫描的物料
  196. const currentScanMaterial = ref([])
  197. // 前端临时缓存:已扫物料
  198. const localScannedList = ref([])
  199. // 控制保存按钮能否点击
  200. const saveDisabled = ref(false)
  201. // 控制提交按钮能否点击
  202. const submitDisabled = ref(false)
  203. const receiveList = ref([])
  204. // 库位相关变量
  205. const storeName = ref('') // 库位编码
  206. const erpStockName = ref('') // 仓库名称
  207. const wmsStoreName = ref('') // 货位名称
  208. onBeforeMount(() => {
  209. masterId.value = JSON.parse(parentRow)?.id
  210. })
  211. const search = function() {
  212. uni.$reqGet('getScannedInMatersDetails', { id: masterId.value })
  213. .then(({ code, data, msg }) => {
  214. if (code === 0) {
  215. // 将API返回的数据保存到receiveList
  216. receiveList.value = data;
  217. uni.setStorageSync('ids', JSON.stringify(data?.inRequestDetailPDAList?.[0] || {}))
  218. tableData.value = data?.inRequestDetailPDAList || []
  219. // 1. 先清空本地已扫列表,准备重新填充
  220. localScannedList.value = []
  221. // 2. 将后端返回的已扫物料数据塞进localScannedList
  222. tableData.value.forEach(item => {
  223. if (item.inRequestSubdetailList?.length) {
  224. localScannedList.value.push(...item.inRequestSubdetailList)
  225. }
  226. })
  227. // 3. 调用flushBeforeTableData(),以localScannedList为准重新生成beforeTableData
  228. flushBeforeTableData()
  229. } else {
  230. uni.showToast({
  231. title: msg,
  232. icon: 'none',
  233. duration: 2000
  234. })
  235. }
  236. })
  237. }
  238. onMounted(() => {
  239. search()
  240. })
  241. const goBack = function() {
  242. if (uni.getStorageSync('ids')) {
  243. uni.removeStorageSync('ids')
  244. }
  245. uni.$goBack('/pages/workbranch/warehouse/scanInOut/In/scanInPage')
  246. }
  247. const handleScanMaterial = function() {
  248. // #ifdef APP-PLUS
  249. const mpaasScanModule = uni.requireNativePlugin('Mpaas-Scan-Module')
  250. mpaasScanModule.mpaasScan({
  251. // 扫码识别类型,参数可多选,qrCode、barCode,不设置,默认识别所有
  252. 'scanType': ['qrCode', 'barCode'],
  253. // 是否隐藏相册,默认false不隐藏
  254. 'hideAlbum': false
  255. },
  256. (ret) => {
  257. if (ret.resp_code === 1000) {
  258. // 校验库位信息是否存在
  259. if (!storeName.value) {
  260. // #ifdef APP-PLUS
  261. plus.device.beep(2)
  262. // #endif
  263. errorTipMessage.value = '请先扫描库位信息'
  264. errorTip.value.open()
  265. errorState.value = 0
  266. return
  267. }
  268. uni.$reqGet('scanPrepareMaterial', {
  269. qrCode: ret.resp_result,
  270. locationCode: storeName.value // 传入库位编码
  271. })
  272. .then(async ({ code, data, msg }) => {
  273. if (code === 0) {
  274. scanBatchNumber.value = ret.resp_result
  275. // 更新仓库和货位名称
  276. erpStockName.value = data[0]?.erpStockName || ''
  277. wmsStoreName.value = data[0]?.wmsStoreName || ''
  278. if (Object.prototype.toString.call(data) === '[object Array]') {
  279. fdIndex.value = tableData.value.findIndex(item => item?.materialNo === data[0]?.materialNo)
  280. }
  281. if (fdIndex.value !== -1) {
  282. currentScanMaterial.value = data[0] ?? []
  283. // 校验批号是否已存在
  284. if (isBatchExist(currentScanMaterial.value.batchNumber)) {
  285. showBatchRepeatTip();
  286. return;
  287. }
  288. const row = tableData.value[fdIndex.value]
  289. if (row.nowDeliveredQty > row.completedQty) {
  290. /* ******** 前端暂存开始 ******** */
  291. // 1) 累加到“已备数”
  292. row.completedQty += currentScanMaterial.value.receiptQty || 1
  293. // 2) 扔进本地已扫池(用于已扫物料列表展示)
  294. localScannedList.value.push({
  295. ...currentScanMaterial.value,
  296. batchQty: currentScanMaterial.value.receiptQty || 1, // 本次扫描数量
  297. supplierName: currentScanMaterial.value.supplierName || ''
  298. })
  299. // 3) 刷新已扫物料列表
  300. flushBeforeTableData()
  301. // 4) 复位输入框,准备下一次扫码
  302. setInputFocus()
  303. /* ******** 前端暂存结束 ******** */
  304. } else {
  305. // #ifdef APP-PLUS
  306. plus.device.beep(2)
  307. // #endif
  308. errorTipMessage.value = '已备数量已满,无需再扫'
  309. errorTip.value.open()
  310. errorState.value = 0
  311. }
  312. } else {
  313. // #ifdef APP-PLUS
  314. plus.device.beep(2)
  315. // #endif
  316. errorTipMessage.value = '请扫描所需物料的物料条码'
  317. errorTip.value.open()
  318. errorState.value = 0
  319. }
  320. } else {
  321. // #ifdef APP-PLUS
  322. plus.device.beep(2)
  323. // #endif
  324. errorTipMessage.value = msg
  325. errorTip.value.open()
  326. errorState.value = 0
  327. }
  328. })
  329. .catch((err) => {
  330. // #ifdef APP-PLUS
  331. plus.device.beep(2)
  332. // #endif
  333. errorTipMessage.value = err.msg || '获取物料信息失败'
  334. errorTip.value.open()
  335. errorState.value = 0
  336. })
  337. }
  338. })
  339. // #endif
  340. }
  341. // 物料拆分
  342. const handleSplitMaterial = function() {
  343. modalForm.value.close()
  344. setInputFocus()
  345. }
  346. const handleKeydown = function(e) {
  347. // 校验库位信息是否存在
  348. if (!storeName.value) {
  349. // #ifdef APP-PLUS
  350. plus.device.beep(2)
  351. // #endif
  352. errorTipMessage.value = '请先扫描库位信息'
  353. errorTip.value.open()
  354. errorState.value = 0
  355. return
  356. }
  357. uni.$reqGet('scanPrepareMaterial', {
  358. qrCode: e,
  359. locationCode: storeName.value // 传入库位编码
  360. })
  361. .then(async({ code, data, msg }) => {
  362. if (code === 0) {
  363. scanBatchNumber.value = e
  364. // 更新仓库和货位名称
  365. erpStockName.value = data[0]?.erpStockName || ''
  366. wmsStoreName.value = data[0]?.wmsStoreName || ''
  367. if (Object.prototype.toString.call(data) === '[object Array]') {
  368. fdIndex.value = tableData.value.findIndex(item => item?.materialNo === data[0]?.materialNo)
  369. }
  370. if (fdIndex.value !== -1) {
  371. currentScanMaterial.value = data[0] ?? []
  372. // 校验批号是否已存在
  373. if (isBatchExist(currentScanMaterial.value.batchNumber)) {
  374. showBatchRepeatTip();
  375. return;
  376. }
  377. const row = tableData.value[fdIndex.value]
  378. if (row.nowDeliveredQty > row.completedQty) {
  379. /* ******** 前端暂存开始 ******** */
  380. // 1) 累加到“已备数”
  381. row.completedQty += currentScanMaterial.value.receiptQty || 1
  382. // 2) 扔进本地已扫池(用于已扫物料列表展示)
  383. localScannedList.value.push({
  384. ...currentScanMaterial.value,
  385. batchQty: currentScanMaterial.value.receiptQty || 1, // 本次扫描数量
  386. supplierName: currentScanMaterial.value.supplierName || ''
  387. })
  388. // 3) 刷新已扫物料列表
  389. flushBeforeTableData()
  390. // 4) 复位输入框,准备下一次扫码
  391. setInputFocus()
  392. /* ******** 前端暂存结束 ******** */
  393. } else {
  394. // #ifdef APP-PLUS
  395. plus.device.beep(2)
  396. // #endif
  397. errorTipMessage.value = '已备数量已满,无需再扫'
  398. errorTip.value.open()
  399. errorState.value = 0
  400. }
  401. } else {
  402. // #ifdef APP-PLUS
  403. plus.device.beep(2)
  404. // #endif
  405. errorTipMessage.value = '请扫描所需物料的物料条码'
  406. errorTip.value.open()
  407. errorState.value = 0
  408. }
  409. } else {
  410. // #ifdef APP-PLUS
  411. plus.device.beep(2)
  412. // #endif
  413. errorTipMessage.value = msg
  414. errorTip.value.open()
  415. errorState.value = 0
  416. }
  417. })
  418. .catch((err) => {
  419. // #ifdef APP-PLUS
  420. plus.device.beep(2)
  421. // #endif
  422. errorTipMessage.value = err.msg || '获取物料信息失败'
  423. errorTip.value.open()
  424. errorState.value = 0
  425. })
  426. }
  427. const handleToDetails = function(ret) {
  428. uni.navigateTo({
  429. url: '/pages/workbranch/warehouse/scanInOut/In/materialsDetail'
  430. })
  431. uni.setStorageSync('mixMaterialDetail', JSON.stringify(ret))
  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.$reqPost('deleteScanInMaterial', { 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. // 仅扫描本地缓存池,不再读 beforeTableData
  526. const isBatchExist = (batchNo) =>
  527. beforeTableData.value.some((it) => it.batchNumber === batchNo);
  528. const showBatchRepeatTip = () => {
  529. // #ifdef APP-PLUS
  530. plus.device.beep(2);
  531. // #endif
  532. errorTipMessage.value = '该批号已存在,请勿重复扫描';
  533. errorTip.value.open();
  534. errorState.value = 0;
  535. };
  536. // 禁用软键盘
  537. const handleInputFocus = function() {
  538. setTimeout(() => {
  539. uni.hideKeyboard()
  540. }, 100)
  541. }
  542. // 处理库位扫码
  543. const handleScanStore = function() {
  544. // #ifdef APP-PLUS
  545. const mpaasScanModule = uni.requireNativePlugin('Mpaas-Scan-Module')
  546. mpaasScanModule.mpaasScan({
  547. // 扫码识别类型,参数可多选,qrCode、barCode,不设置,默认识别所有
  548. 'scanType': ['qrCode', 'barCode'],
  549. // 是否隐藏相册,默认false不隐藏
  550. 'hideAlbum': false
  551. },
  552. (ret) => {
  553. if (ret.resp_code === 1000) {
  554. confirmStore(ret.resp_result)
  555. }
  556. })
  557. // #endif
  558. // #ifdef H5
  559. confirmStore('PC-1')
  560. // #endif
  561. }
  562. // 扫描货位输入框回车事件
  563. const confirmStore = function(e) {
  564. // 保持输入框里的原始数据不变
  565. storeName.value = e
  566. uni.$reqGet('getStockLocaltionByCode', {
  567. code: e
  568. })
  569. .then(({ code, data, msg }) => {
  570. if (code === 0) {
  571. // 验证是否获取到了货位和仓库信息
  572. if (!data || !data.erpStockName || !data.wmsStoreName) {
  573. // #ifdef APP-PLUS
  574. plus.device.beep(2)
  575. // #endif
  576. errorTipMessage.value = '请扫描正确的库位'
  577. errorTip.value.open()
  578. errorState.value = 0
  579. // 清空扫描框
  580. storeName.value = ''
  581. return
  582. }
  583. erpStockName.value = data.erpStockName // 仓库名称
  584. wmsStoreName.value = data.wmsStoreName // 货位名称
  585. } else {
  586. // #ifdef APP-PLUS
  587. plus.device.beep(2)
  588. // #endif
  589. errorTipMessage.value = '请扫描正确的库位'
  590. errorTip.value.open()
  591. errorState.value = 0
  592. // 清空扫描框
  593. storeName.value = ''
  594. }
  595. })
  596. }
  597. // 重置库位输入框
  598. const setStoreInputFocus = function() {
  599. storeName.value = ''
  600. easyinputStore.value.onBlur()
  601. easyinputStore.value.onFocus()
  602. }
  603. // 把 beforeTableData 追加到 tableData 对应物料的 inRequestSubdetailList
  604. const mergeBeforeIntoTable = () => {
  605. // 创建新数组存储合并结果
  606. const mergedTableData = JSON.parse(JSON.stringify(tableData.value))
  607. // 先建索引
  608. const map = {}
  609. mergedTableData.forEach(row => {
  610. if (!row.inRequestSubdetailList) row.inRequestSubdetailList = []
  611. map[row.materialNo] = row
  612. })
  613. // 只追加,不新增
  614. beforeTableData.value.forEach(item => {
  615. const target = map[item.materialNo]
  616. if (target) {
  617. target.inRequestSubdetailList.push({
  618. ...item
  619. }) // 整条记录丢进去
  620. }
  621. // 不存在就跳过
  622. })
  623. return mergedTableData
  624. }
  625. // 保存按钮点击事件
  626. const handleSave = async function() {
  627. if (saveDisabled.value) return
  628. saveDisabled.value = true
  629. try {
  630. // 保存逻辑实现
  631. isLightText.value = true
  632. // 先合并数据,获取合并后的新数组
  633. const mergedData = mergeBeforeIntoTable()
  634. // 调用保存API,使用合并后的新数组作为参数
  635. await uni.$reqPost('saveScannedInMaterials', {
  636. id: receiveList.value?.id,
  637. requestNo: receiveList.value?.requestNo,
  638. requestType: receiveList.value?.requestType,
  639. businessType: receiveList.value?.businessType,
  640. businessSubType: receiveList.value?.businessSubType,
  641. status: receiveList.value?.status,
  642. priority: receiveList.value?.priority,
  643. inRequestDetailPDAList: mergedData
  644. })
  645. .then(({ code, data, msg }) => {
  646. if (code === 0) {
  647. uni.showModal({
  648. title: '提示',
  649. content: '保存成功',
  650. showCancel: false
  651. })
  652. search();
  653. } else {
  654. // #ifdef APP-PLUS
  655. plus.device.beep(2)
  656. // #endif
  657. errorTipMessage.value = msg
  658. errorTip.value.open()
  659. errorState.value = 0
  660. }
  661. })
  662. } finally {
  663. saveDisabled.value = false
  664. }
  665. }
  666. // 提交按钮点击事件
  667. const handleSubmit = async function() {
  668. if (submitDisabled.value) return
  669. submitDisabled.value = true
  670. try {
  671. // 提交逻辑实现
  672. isSubmitLight.value = true
  673. // 先合并数据,获取合并后的新数组
  674. const mergedData = mergeBeforeIntoTable()
  675. // 调用提交API,使用合并后的新数组作为参数
  676. await uni.$reqPut('submitScannedInMaterials', {
  677. id: receiveList.value?.id,
  678. requestNo: receiveList.value?.requestNo,
  679. requestType: receiveList.value?.requestType,
  680. businessType: receiveList.value?.businessType,
  681. businessSubType: receiveList.value?.businessSubType,
  682. status: receiveList.value?.status,
  683. priority: receiveList.value?.priority,
  684. inRequestDetailPDAList: mergedData
  685. })
  686. .then(({ code, data, msg }) => {
  687. if (code === 0) {
  688. uni.showModal({
  689. title: '提示',
  690. content: '提交成功',
  691. showCancel: false
  692. })
  693. search();
  694. } else {
  695. // #ifdef APP-PLUS
  696. plus.device.beep(2)
  697. // #endif
  698. errorTipMessage.value = msg
  699. errorTip.value.open()
  700. errorState.value = 0
  701. }
  702. })
  703. } finally {
  704. submitDisabled.value = false
  705. }
  706. }
  707. // uniapp移动端触底事件
  708. onReachBottom(() => {
  709. queryParams.value.pageNo += 1
  710. uni.$reqGet('getPrepareMaterialList', queryParams.value)
  711. .then(({ data }) => {
  712. Array.prototype.push.call(scanMaterialList.value, ...data?.list ?? [])
  713. })
  714. })
  715. // 保存按钮文字样式
  716. const saveBtnTextStyle = computed(() => ({
  717. fontSize: '14px',
  718. fontWeight: 'bold',
  719. color: saveDisabled.value ? '#ccc' : (isLightText.value ? 'rgba(0,160,233,1)' : '')
  720. }))
  721. // 提交按钮文字样式
  722. const submitBtnTextStyle = computed(() => ({
  723. fontSize: '14px',
  724. fontWeight: 'bold',
  725. color: submitDisabled.value ? '#ccc' : (isSubmitLight.value ? 'rgba(0,160,233,1)' : '')
  726. }))
  727. // 移除status监听,提交按钮和保存按钮均始终可用
  728. // watch(() => receiveList.value?.status, (newStatus) => {
  729. // submitDisabled.value = newStatus !== 0
  730. // })
  731. return {
  732. goBack,
  733. popup,
  734. signText,
  735. isBefore,
  736. tableData,
  737. beforeTableData,
  738. signInput,
  739. modalForm,
  740. easyinput,
  741. easyinputStore,
  742. errorTip,
  743. errorTipMessage,
  744. handleInputFocus,
  745. isLightText,
  746. isSubmitLight,
  747. handleKeydown,
  748. scanBatchNumber,
  749. handleScanMaterial,
  750. scanMaterialList,
  751. handleSplitMaterial,
  752. handleToDetails,
  753. handleCloseErrorTipsModal,
  754. handleSave,
  755. handleSubmit,
  756. saveDisabled,
  757. submitDisabled,
  758. saveBtnTextStyle,
  759. submitBtnTextStyle,
  760. // 库位相关
  761. storeName,
  762. erpStockName,
  763. wmsStoreName,
  764. handleScanStore,
  765. confirmStore,
  766. // 左滑删除相关
  767. touchStart,
  768. touchMove,
  769. touchEnd,
  770. deleteItem
  771. }
  772. }
  773. })
  774. </script>
  775. <style lang="scss" scoped>
  776. /* 左滑删除样式 */
  777. .scroll-box{
  778. height:100%; /* 继承父级高度 */
  779. }
  780. .cell-row {
  781. display: flex;
  782. background-color: #f5f7fa;
  783. font-weight: bold;
  784. border-radius: 4px;
  785. margin-bottom: 5px;
  786. }
  787. .swipe-row{
  788. position:relative;
  789. width:100%;
  790. height:44px;
  791. overflow:hidden;
  792. border-bottom:1px solid #eee;
  793. }
  794. .content-area{
  795. position:absolute;
  796. left:0;
  797. top:0;
  798. right:0;
  799. bottom:0;
  800. z-index:2;
  801. background:#fff;
  802. display:flex;
  803. align-items:center;
  804. transition: transform .25s;
  805. }
  806. .cell{
  807. flex:1;
  808. text-align:center;
  809. font-size:14px;
  810. color:#333;
  811. }
  812. .btn-area{
  813. position:absolute;
  814. right:0;
  815. top:0;
  816. width:70px;
  817. height:100%;
  818. background:#e54d42;
  819. color:#fff;
  820. display:flex;
  821. align-items:center;
  822. justify-content:center;
  823. font-size:14px;
  824. z-index:1;
  825. }
  826. .gui-header-leader-btns {
  827. color: black;
  828. font-size: 24px !important;
  829. margin-left: 24rpx;
  830. }
  831. .list-content {
  832. margin-top: 80px;
  833. background-color: #edeeee;
  834. }
  835. .scan {
  836. margin-top: 10px;
  837. height: 55px;
  838. display: flex;
  839. justify-content: center;
  840. background-color: white;
  841. }
  842. .scan-card {
  843. display: flex;
  844. flex-direction: row;
  845. justify-content: space-between;
  846. align-items: center;
  847. width: 100%;
  848. padding-left: 10px;
  849. padding-right: 10px;
  850. }
  851. .store-info {
  852. margin-top: 10px;
  853. height: 140px;
  854. display: flex;
  855. justify-content: center;
  856. background-color: white;
  857. }
  858. .store-info-card {
  859. display: flex;
  860. flex-direction: column;
  861. .row-space-between {
  862. flex: 1;
  863. width: calc(100vw - 40px);
  864. display: flex;
  865. flex-direction: row;
  866. justify-content: space-between;
  867. align-items: center;
  868. padding-top: 12px;
  869. padding-bottom: 12px;
  870. }
  871. }
  872. .card-list-flexbox {
  873. display: flex;
  874. flex-direction: row;
  875. align-items: center;
  876. flex-wrap: wrap;
  877. margin: 3px 2px;
  878. .card-list-item {
  879. width: 750rpx;
  880. height: 40px;
  881. }
  882. }
  883. .card-list-item {
  884. margin: 2rpx 0;
  885. display: flex;
  886. flex-direction: row;
  887. align-items: center;
  888. justify-content: space-between;
  889. background-color: #fff;
  890. uni-text {
  891. font-size: 14px;
  892. height: 50rpx;
  893. text-align: left;
  894. padding: 0 12px;
  895. display: flex;
  896. flex-direction: row;
  897. align-items: center;
  898. }
  899. .text-1 {
  900. flex: 1;
  901. height: 40px;
  902. justify-content: flex-start;
  903. }
  904. .text-2 {
  905. flex: 3;
  906. height: 40px;
  907. justify-content: flex-end;
  908. margin-right: 4px;
  909. padding: 2px 6px;
  910. }
  911. }
  912. .card-list-flexbox:nth-of-type(2) {
  913. margin-top: 48px;
  914. }
  915. .fixedTop {
  916. bottom: 0 !important;
  917. top: 3.25rem !important;
  918. }
  919. .popup-content {
  920. height: 75vh;
  921. overflow-y: scroll;
  922. background-color: #edeeee;
  923. }
  924. .font-icons {
  925. width: 40px;
  926. font-size: 20px;
  927. }
  928. .scan {
  929. height: 45px;
  930. width: calc(100% - 48px);
  931. margin: 12px;
  932. padding: 0 12px;
  933. display: flex;
  934. justify-content: space-between;
  935. align-items: center;
  936. border-radius: 6px;
  937. background-color: white;
  938. .scan-card {
  939. width: 100%;
  940. display: grid;
  941. grid-template-rows: 1fr;
  942. grid-template-columns: 7fr 2fr;
  943. align-items: center;
  944. input {
  945. height: 35px;
  946. line-height: 35px;
  947. }
  948. text {
  949. width: 100%;
  950. text-align: right;
  951. }
  952. }
  953. }
  954. .custom-table {
  955. height: calc(100vh - 265px);
  956. min-height: 230px;
  957. margin: 5px 0;
  958. // min-height: 600px;
  959. overflow-y: scroll;
  960. }
  961. .custom-table-head .uni-th {
  962. color: #333;
  963. font-weight: bold;
  964. }
  965. .custom-table .uni-tr:nth-child(even) {
  966. background-color: #f5f7fa;
  967. }
  968. .custom-table .uni-tr:nth-child(odd) {
  969. background-color: #ffffff;
  970. }
  971. /* 仓库和货位信息展示样式 */
  972. .info-row {
  973. display: flex;
  974. align-items: center;
  975. padding: 10rpx 20rpx;
  976. background-color: #f0f2f5;
  977. border-radius: 8rpx;
  978. margin: 10rpx 20rpx;
  979. }
  980. .info-label {
  981. color: #666;
  982. font-size: 28rpx;
  983. margin-right: 8rpx;
  984. }
  985. .info-value {
  986. color: #333;
  987. font-size: 28rpx;
  988. margin-right: 20rpx;
  989. font-weight: 500;
  990. }
  991. .modal-btns {
  992. height: 100rpx;
  993. line-height: 100rpx;
  994. display: flex;
  995. justify-content: center;
  996. align-items: center;
  997. }
  998. .line {
  999. margin-top: 10rpx;
  1000. height: 80rpx;
  1001. width: 1rpx;
  1002. background-color: #dcdcdc;
  1003. }
  1004. .tabs {
  1005. width: 100%;
  1006. height: 45px;
  1007. display: flex;
  1008. align-items: flex-end;
  1009. padding: 0 2px;
  1010. background-color: white;
  1011. .tabs-list {
  1012. border-radius: 3px;
  1013. overflow: hidden;
  1014. }
  1015. .tabs-item {
  1016. display: inline-block;
  1017. width: 72px;
  1018. height: 30px;
  1019. line-height: 30px;
  1020. padding: 0 8px;
  1021. font-size: 14px;
  1022. font-weight: bold;
  1023. text-align: center;
  1024. color: black;
  1025. border-bottom: 1.5px dashed #00a0e9;
  1026. transition: all .5s ease-in-out;
  1027. }
  1028. .tabs-item-active {
  1029. position: relative;
  1030. display: inline-block;
  1031. width: 72px;
  1032. height: 30px;
  1033. line-height: 30px;
  1034. padding: 0 8px;
  1035. font-size: 14px;
  1036. font-weight: bold;
  1037. text-align: center;
  1038. color: white;
  1039. border-left: 1px solid #00a0e9;
  1040. border-top: 1px solid #00a0e9;
  1041. border-right: 1px solid #00a0e9;
  1042. border-bottom: 1.5px solid #00a0e9;
  1043. border-radius: 5px 5px 0 0;
  1044. animation: .3s linear show;
  1045. background-color: #00a0e9;
  1046. }
  1047. .tabs-item-active::before {
  1048. content: '';
  1049. position: absolute;
  1050. left: -10px;
  1051. bottom: 0;
  1052. width: 10px;
  1053. height: 10px;
  1054. background: radial-gradient(circle at 0% 25%, transparent 10px, #00a0e9 0)
  1055. }
  1056. .tabs-item-active::after {
  1057. content: '';
  1058. position: absolute;
  1059. right: -10px;
  1060. bottom: 0;
  1061. width: 10px;
  1062. height: 10px;
  1063. background: radial-gradient(circle at 100% 25%, transparent 10px, #00a0e9 0)
  1064. }
  1065. }
  1066. @keyframes show {
  1067. from {
  1068. transform: translateY(5%);
  1069. }
  1070. to {
  1071. transform: translateY(0%);
  1072. }
  1073. }
  1074. .sign-btn {
  1075. display: flex;
  1076. align-items: center;
  1077. justify-content: center;
  1078. margin: 0 8px;
  1079. border: 1px solid #999999;
  1080. background-color: white;
  1081. border-radius: 6px;
  1082. }
  1083. .sign-btn.disabled {
  1084. opacity: 0.5;
  1085. pointer-events: none;
  1086. }
  1087. </style>