scanTieInputs.vue 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004
  1. <template>
  2. <gui-page
  3. :custom-header="true"
  4. :header-class="['gui-theme-background-color']"
  5. >
  6. <template #gHeader>
  7. <view
  8. style="height: 44px"
  9. class="gui-flex gui-nowrap gui-rows gui-align-items-center"
  10. >
  11. <!-- 使用组件实现返回按钮及返回首页按钮 -->
  12. <text
  13. style="font-size: 44rpx"
  14. class="gui-header-leader-btns gui-color-white font-icons"
  15. @tap="goBack"
  16. >&#xe6c5;</text
  17. >
  18. <!-- 导航文本此处也可以是其他自定义内容 -->
  19. <text
  20. class="gui-h4 gui-blod gui-flex1 gui-text-center gui-ellipsis gui-color-white gui-primary-text"
  21. >扫描出库明细</text
  22. >
  23. <!-- 此处加一个右侧展位元素与左侧同宽,实现标题居中 -->
  24. <!-- 实际宽度请根据自己情况设置 -->
  25. <view style="width: 40px" />
  26. <!-- 如果右侧有其他内容可以利用条件编译和定位来实现-->
  27. </view>
  28. </template>
  29. <template #gBody>
  30. <view class="list-content">
  31. <view class="scan">
  32. <view class="scan-card" style="margin-top: 8px">
  33. <uni-easyinput
  34. ref="tmInput"
  35. v-model="tmId"
  36. :input-border="false"
  37. :clearable="false"
  38. type="text"
  39. placeholder="请扫描或输入贴纸ID"
  40. @confirm="handleTmConfirm"
  41. />
  42. <text class="font-icons" @click="setTmOnly">&#xe6b7;</text>
  43. </view>
  44. </view>
  45. <view class="scan">
  46. <view class="scan-card" style="margin-top: 8px">
  47. <uni-easyinput
  48. ref="partInput"
  49. v-model="tmMaterialNo"
  50. :input-border="false"
  51. :clearable="false"
  52. type="text"
  53. placeholder="请输入料号"
  54. @confirm="handlePartKeydown"
  55. />
  56. <text class="font-icons" @click="handleQueryPart">&#xe6b7;</text>
  57. </view>
  58. </view>
  59. <view class="scan">
  60. <view class="scan-card">
  61. <!-- 禁用软键盘 -->
  62. <!-- <uni-easyinput ref="easyinput" v-model="scanBatchNumber" :input-border="false"
  63. :clearable="false" type="text" focus @focus="handleInputFocus" placeholder="请扫描物料二维码"
  64. @confirm="handleKeydown" /> -->
  65. <!-- 不禁用软键盘 -->
  66. <uni-easyinput
  67. ref="easyinput"
  68. v-model="scanBatchNumber"
  69. :input-border="false"
  70. :clearable="false"
  71. type="text"
  72. placeholder="请扫描物料二维码"
  73. @confirm="handleKeydown"
  74. />
  75. <text class="font-icons" @click="handleScanMaterial">&#xe6b7;</text>
  76. </view>
  77. </view>
  78. <view class="tabs">
  79. <div class="tabs-list">
  80. <text
  81. :class="!isBefore ? 'tabs-item-active' : 'tabs-item'"
  82. @click="isBefore = false"
  83. >物料需求</text
  84. >
  85. <text
  86. :class="isBefore ? 'tabs-item-active' : 'tabs-item'"
  87. @click="isBefore = true"
  88. >已扫物料</text
  89. >
  90. </div>
  91. </view>
  92. <view v-if="!isBefore" class="custom-table">
  93. <uni-table border stripe empty-text="暂无更多数据">
  94. <!-- 表头行 -->
  95. <uni-tr class="custom-table-head">
  96. <uni-th align="center" width="180px" class="break-col"
  97. >可出库位(数量)</uni-th
  98. >
  99. <uni-th align="center" width="180px">物料</uni-th>
  100. <uni-th align="center" width="120px">应备数</uni-th>
  101. <uni-th align="center" width="120px">已备数</uni-th>
  102. </uni-tr>
  103. <!-- 表格数据行 -->
  104. <!-- 可点击行,方法存在 -->
  105. <uni-tr
  106. v-for="(item, key) in tableData"
  107. :key="key"
  108. @click="handleToDetails(item)"
  109. >
  110. <!-- 不可点击行 -->
  111. <!-- <uni-tr v-for="(item, key) in tableData" :key="key"> -->
  112. <uni-td align="center" class="break-cell">{{
  113. item.ableStockLocation
  114. }}</uni-td>
  115. <uni-td align="center"
  116. >{{ item.materialNo }}({{ item.materialName }})</uni-td
  117. >
  118. <uni-td align="center">{{ item.nowDeliveredQty }}</uni-td>
  119. <uni-td align="center" style="color: orange; font-weight: bold">{{
  120. item.completedQty
  121. }}</uni-td>
  122. </uni-tr>
  123. </uni-table>
  124. </view>
  125. <view v-else class="custom-table">
  126. <scroll-view scroll-y class="scroll-box" style="height: 300px">
  127. <view class="cell-row">
  128. <view class="cell1">物料</view>
  129. <view class="cell2">数量</view>
  130. <view class="cell3">批号</view>
  131. </view>
  132. <view
  133. v-for="(item, idx) in beforeTableData"
  134. :key="item.uniqueId"
  135. class="swipe-row"
  136. :data-index="idx"
  137. @touchstart="touchStart"
  138. @touchmove="touchMove"
  139. @touchend="touchEnd"
  140. >
  141. <view
  142. class="content-area"
  143. :style="`transform: translateX(${item.slideX}px)`"
  144. >
  145. <view class="cell1"
  146. >{{ item.materialNo }}({{ item.materialName }})</view
  147. >
  148. <view class="cell2">{{ item.batchQty }}</view>
  149. <view class="cell3">{{ item.batchNumber }}</view>
  150. </view>
  151. <view class="btn-area" @click="deleteItem(idx)">删除</view>
  152. </view>
  153. </scroll-view>
  154. </view>
  155. <view
  156. class="card-list-item"
  157. style="
  158. margin: 12px 0;
  159. display: grid;
  160. grid-template-columns: 1fr 1fr;
  161. grid-template-rows: 1fr;
  162. gap: 10px;
  163. "
  164. >
  165. <view
  166. class="sign-btn"
  167. :class="{ disabled: saveDisabled }"
  168. @click="handleSave"
  169. >
  170. <text :style="saveBtnTextStyle">保存</text>
  171. </view>
  172. <view
  173. class="sign-btn"
  174. :class="{ disabled: submitDisabled }"
  175. @click="handleSubmit"
  176. >
  177. <text :style="submitBtnTextStyle">提交</text>
  178. </view>
  179. <view style="width: 0px">
  180. <!-- <uni-easyinput ref="signInput" v-model="signText" @focus="handleInputFocus"
  181. :input-border="false" :clearable="false" type="text" @confirm="handleComplete" /> -->
  182. <uni-easyinput
  183. ref="signInput"
  184. v-model="signText"
  185. :input-border="false"
  186. :clearable="false"
  187. type="text"
  188. @confirm="handleComplete"
  189. />
  190. </view>
  191. </view>
  192. <gui-modal
  193. ref="modalForm"
  194. :custom-class="[
  195. 'gui-bg-white',
  196. 'gui-dark-bg-level-3',
  197. 'gui-border-radius',
  198. ]"
  199. title="提示"
  200. >
  201. <template #content>
  202. <view class="gui-padding gui-bg-gray gui-dark-bg-level-2">
  203. <text
  204. class="gui-block gui-text-center gui-text gui-color-gray"
  205. style="line-height: 100rpx; padding: 10rpx"
  206. >备料超出,是否拆分?</text
  207. >
  208. </view>
  209. </template>
  210. <!-- 利用 flex 布局 可以放置多个自定义按钮哦 -->
  211. <template #btns>
  212. <view class="gui-flex gui-row gui-space-between operation-flex">
  213. <view
  214. hover-class="gui-tap"
  215. class="modal-btns gui-flex1"
  216. @tap="modalForm.close()"
  217. >
  218. <text class="modal-btns gui-color-gray">取消</text>
  219. </view>
  220. <view class="line" />
  221. <view
  222. hover-class="gui-tap"
  223. class="modal-btns gui-flex1"
  224. @tap="handleSplitMaterial"
  225. >
  226. <text class="modal-btns gui-primary-color">确认</text>
  227. </view>
  228. </view>
  229. </template>
  230. </gui-modal>
  231. <uni-popup ref="errorTip" type="dialog">
  232. <uni-popup-dialog
  233. type="error"
  234. cancel-text="关闭"
  235. confirm-text="确认"
  236. title="提示"
  237. :content="errorTipMessage"
  238. @confirm="handleCloseErrorTipsModal"
  239. @close="handleCloseErrorTipsModal"
  240. />
  241. </uni-popup>
  242. <!-- FIFO 二次确认弹窗 -->
  243. <uni-popup ref="fifoPopup" type="dialog">
  244. <uni-popup-dialog
  245. title="FIFO 提示"
  246. :content="fifoMsg"
  247. confirm-text="继续"
  248. cancel-text="取消"
  249. @confirm="fifoContinue"
  250. @close="fifoCancel"
  251. />
  252. </uni-popup>
  253. <!-- 条码是否在库校验弹窗 -->
  254. <uni-popup ref="inStockCheckPopup" type="dialog">
  255. <view class="instock-dialog">
  256. <view class="instock-title"
  257. >当前箱码未录入系统,请确认数量并录入</view
  258. >
  259. <view class="instock-row">
  260. <text class="instock-label">生产日期</text>
  261. <view class="instock-datetime">
  262. <uni-datetime-picker
  263. v-model="inStockCheckProduceDate"
  264. type="date"
  265. placeholder="请选择生产日期"
  266. />
  267. </view>
  268. </view>
  269. <view class="instock-row">
  270. <text class="instock-label">数量</text>
  271. <input
  272. v-model="inStockCheckQty"
  273. class="instock-input"
  274. type="number"
  275. placeholder="请输入数量"
  276. />
  277. </view>
  278. <view class="instock-row">
  279. <text class="instock-label">库位</text>
  280. <input
  281. v-model="inStockCheckStore"
  282. class="instock-input"
  283. placeholder="请扫描/输入库位"
  284. @confirm="confirmInStockStore"
  285. />
  286. <text
  287. class="instock-scan-icon font-icons"
  288. @click="scanInStockStore"
  289. >&#xe6b7;</text
  290. >
  291. </view>
  292. <view
  293. v-if="inStockCheckErpStockName || inStockCheckWmsStoreName"
  294. class="instock-store-info"
  295. >
  296. <text>仓库: {{ inStockCheckErpStockName }}</text>
  297. <text>货位: {{ inStockCheckWmsStoreName }}</text>
  298. </view>
  299. <view class="instock-btns">
  300. <view
  301. class="instock-btn instock-btn-cancel"
  302. @click="cancelInStockCheck"
  303. >取消</view
  304. >
  305. <view
  306. class="instock-btn instock-btn-confirm"
  307. @click="confirmInStockCheck"
  308. >确认</view
  309. >
  310. </view>
  311. </view>
  312. </uni-popup>
  313. </view>
  314. </template>
  315. </gui-page>
  316. </template>
  317. <script>
  318. import { onReachBottom, onShow } from "@dcloudio/uni-app";
  319. import {
  320. ref,
  321. onMounted,
  322. defineComponent,
  323. onBeforeMount,
  324. computed,
  325. watch,
  326. nextTick,
  327. } from "vue";
  328. export default defineComponent({
  329. setup(options) {
  330. const popup = ref();
  331. const queryParams = ref({
  332. pageSize: 20,
  333. pageNo: 1,
  334. masterId: options?.id ?? "",
  335. wmsProductionWorkOrderBomId: options?.id ?? "",
  336. });
  337. const errorTip = ref("");
  338. const errorTipMessage = ref("");
  339. const easyinput = ref("");
  340. const partInput = ref(null); // ref 指向料号输入框
  341. const tmMaterialNo = ref(""); // 料号
  342. const tmId = ref(""); // 贴纸ID
  343. const tmInput = ref(null); // ref 指向贴纸ID输入框
  344. const scanTie = ref(0); // 控制贴纸和料号扫描框显示
  345. const errorState = ref(0);
  346. const modalForm = ref();
  347. const parentRow = uni.getStorageSync("masterId") ?? {};
  348. const masterId = ref("");
  349. const businessType = ref("");
  350. // const saveId = ref('')
  351. const signInput = ref();
  352. const signText = ref("");
  353. const isLightText = ref("");
  354. const isSubmitLight = ref("");
  355. const scanBatchNumber = ref("");
  356. const isBefore = ref(false);
  357. const tableData = ref([]);
  358. const beforeTableData = ref([]);
  359. const scanMaterialList = ref([]);
  360. const receiveList = ref([]);
  361. const currentWarehouseId = ref("");
  362. const currentWarehouseName = ref("");
  363. // 当前处理的数据行
  364. const fdIndex = ref(-1);
  365. // 当前扫描的物料
  366. const currentScanMaterial = ref([]);
  367. // 前端临时缓存:已扫物料
  368. const localScannedList = ref([]);
  369. // 控制保存按钮能否点击
  370. const saveDisabled = ref(false);
  371. // 控制提交按钮能否点击
  372. const submitDisabled = ref(false);
  373. /* -------------------- 下面 4 行是新增变量 -------------------- */
  374. const fifoPopup = ref(null); // 弹窗实例
  375. const fifoMsg = ref(""); // 提示语
  376. let fifoQrCode = ""; // 缓存本次二维码
  377. const fifoGo = ref(false); // 用户是否点了“继续”
  378. // 存储fifo_check_order_type字典数据
  379. const fifoCheckOrderTypeDict = ref([]);
  380. // 标记businessType是否在fifo_check_order_type字典内
  381. const isBusinessTypeInFifoDict = ref(false);
  382. /* -------------------- 条码是否在库校验相关 -------------------- */
  383. const inStockCheckPopup = ref(null); // 弹窗实例
  384. const inStockCheckQty = ref(""); // 数量输入
  385. const inStockCheckProduceDate = ref(""); // 生产日期输入
  386. const inStockCheckStore = ref(""); // 库位输入
  387. const inStockCheckErpStockName = ref(""); // 弹窗内仓库名称
  388. const inStockCheckWmsStoreName = ref(""); // 弹窗内货位名称
  389. const wmsStockId = ref(""); // 仓库id
  390. const wmsStoreAreaId = ref(""); // 区域id
  391. const wmsStoreLocationId = ref(""); // 货位id
  392. let instockQrCode = ""; // 缓存待入库的二维码
  393. const instockGo = ref(false); // 自动入库成功后一次性放行
  394. onBeforeMount(() => {
  395. initMasterData();
  396. // 获取fifo_check_order_type字典数据
  397. getFifoCheckOrderTypeDict();
  398. });
  399. // 获取fifo_check_order_type字典数据
  400. const getFifoCheckOrderTypeDict = function () {
  401. uni
  402. .$reqGet("getDictDataPage", {
  403. dictType: "fifo_check_order_type",
  404. })
  405. .then(({ code, data, msg }) => {
  406. if (code === 0) {
  407. fifoCheckOrderTypeDict.value = data?.list || [];
  408. console.log(
  409. "fifo_check_order_type字典数据:",
  410. fifoCheckOrderTypeDict.value,
  411. );
  412. console.log(
  413. "fifo_check_order_type字典数据长度:",
  414. fifoCheckOrderTypeDict.value.length,
  415. );
  416. // 判断businessType是否在字典内
  417. checkBusinessTypeInFifoDict();
  418. } else {
  419. console.error("获取fifo_check_order_type字典失败:", msg);
  420. }
  421. })
  422. .catch((error) => {
  423. console.error("获取fifo_check_order_type字典异常:", error);
  424. });
  425. };
  426. // 判断businessType是否在fifo_check_order_type字典内
  427. const checkBusinessTypeInFifoDict = function () {
  428. // 使用some方法检查businessType是否存在于字典数据中
  429. isBusinessTypeInFifoDict.value = fifoCheckOrderTypeDict.value.some(
  430. (item) =>
  431. String(item?.value).trim() === String(businessType.value).trim(),
  432. );
  433. console.log(
  434. "businessType是否在fifo_check_order_type字典内:",
  435. isBusinessTypeInFifoDict.value,
  436. );
  437. };
  438. const search = function () {
  439. uni
  440. .$reqGet("getScannedOutMatersDetails", { id: masterId.value })
  441. .then(({ code, data, msg }) => {
  442. if (code === 0) {
  443. uni.setStorageSync(
  444. "ids",
  445. JSON.stringify(data?.inoutRequestDetailPDARespVOList?.[0] || {}),
  446. );
  447. // saveId.value = data?.id
  448. receiveList.value = data;
  449. scanTie.value = data?.scanTie;
  450. currentWarehouseId.value = data?.warehouseId;
  451. currentWarehouseName.value = data?.warehouseName;
  452. tableData.value = data?.inoutRequestDetailPDARespVOList || [];
  453. console.log("获取到的scanTie:", scanTie.value);
  454. // 1. 先清空本地已扫列表,准备重新填充
  455. localScannedList.value = [];
  456. // 2. 将后端返回的已扫物料数据塞进localScannedList
  457. tableData.value.forEach((item) => {
  458. if (item.inoutRequestSubdetailList?.length) {
  459. localScannedList.value.push(...item.inoutRequestSubdetailList);
  460. }
  461. });
  462. // 3. 调用flushBeforeTableData(),以localScannedList为准重新生成beforeTableData
  463. flushBeforeTableData();
  464. // // 新增:根据 scanTie 决定首次焦点
  465. // nextTick(() => {
  466. // if (Number(scanTie.value) === 1) {
  467. // // 先让贴纸 ID 框聚焦
  468. // tmInput.value.onBlur()
  469. // tmInput.value.onFocus()
  470. // } else {
  471. // setInputFocus()
  472. // }
  473. // })
  474. } else {
  475. uni.showToast({
  476. title: msg,
  477. icon: "none",
  478. duration: 2000,
  479. });
  480. }
  481. });
  482. };
  483. onMounted(() => {
  484. search();
  485. // 首次进入页面:贴纸ID输入框自动获取焦点
  486. nextTick(() => {
  487. tmInput.value?.onBlur();
  488. tmInput.value?.onFocus();
  489. });
  490. });
  491. const initMasterData = () => {
  492. const parsedData = JSON.parse(parentRow);
  493. masterId.value = parsedData?.id;
  494. businessType.value = parsedData?.businessType || "0";
  495. console.log("获取到的businessType:", businessType.value);
  496. if (businessType.value == "5") {
  497. submitDisabled.value = true;
  498. }
  499. };
  500. onShow(() => {
  501. initMasterData();
  502. if (masterId.value) {
  503. // 检查是否需要刷新(从详情页返回时)
  504. const needRefresh = uni.getStorageSync("needRefreshScanOut");
  505. if (needRefresh === "true") {
  506. search();
  507. uni.removeStorageSync("needRefreshScanOut");
  508. }
  509. }
  510. });
  511. const goBack = function () {
  512. if (uni.getStorageSync("masterId")) {
  513. uni.removeStorageSync("masterId");
  514. }
  515. if (uni.getStorageSync("ids")) {
  516. uni.removeStorageSync("ids");
  517. }
  518. uni.$goBack("/pages/workbranch/warehouse/scanInOut/Out/scanOutPage");
  519. };
  520. const handleScanMaterial = async function () {
  521. // #ifdef APP-PLUS
  522. /* 0. 基本校验 */
  523. // if (businessType.value == '5') {
  524. // if (!tmId.value.trim()) {
  525. // uni.showToast({
  526. // title: '请先扫描贴纸ID',
  527. // icon: 'none',
  528. // duration: 2000
  529. // });
  530. // nextTick(() => tmInput.value?.onFocus());
  531. // return;
  532. // }
  533. // if (!tmMaterialNo.value.trim()) {
  534. // uni.showToast({
  535. // title: '请先扫描料号',
  536. // icon: 'none',
  537. // duration: 2000
  538. // });
  539. // nextTick(() => partInput.value?.onFocus());
  540. // return;
  541. // }
  542. // }
  543. /* 1. 先调摄像头 */
  544. const mpaasScanModule = { mpaasScan: uni.$scanByCameraCompat };
  545. const ret = await new Promise((resolve) =>
  546. mpaasScanModule.mpaasScan(
  547. { scanType: ["qrCode", "barCode"], hideAlbum: false },
  548. resolve,
  549. ),
  550. );
  551. if (ret.resp_code !== 1000) return;
  552. const qrCode = ret.resp_result;
  553. /* 1.5 条码是否在库校验 */
  554. const instockOk = await checkInstock(qrCode);
  555. if (!instockOk) return;
  556. /* 2. FIFO 校验 */
  557. const ok = await checkFifo(qrCode);
  558. if (!ok && !fifoGo.value) {
  559. // 新增:清空二维码框并重新聚焦
  560. resetAllInputs(); // 如果你只想清二维码,也可以只写 scanBatchNumber.value = ''
  561. nextTick(() => easyinput.value.onFocus());
  562. return;
  563. }
  564. /* 3. 业务接口 */
  565. uni
  566. .$reqGet("scanPrepareMaterial", {
  567. qrCode,
  568. requestNo: receiveList.value.requestNo,
  569. businessType: receiveList.value.businessType,
  570. tmMaterialNo: tmMaterialNo.value.trim(),
  571. tmId: tmId.value.trim(),
  572. })
  573. .then(({ code, data, msg }) => {
  574. fifoGo.value = false;
  575. if (code !== 0) {
  576. // #ifdef APP-PLUS
  577. plus.device.beep(2);
  578. // #endif
  579. resetAllInputs(); // ← 新增
  580. errorTipMessage.value = msg;
  581. errorTip.value.open();
  582. errorState.value = 0;
  583. /* 补焦点 */
  584. // nextTick(() => {
  585. // Number(scanTie.value) === 1 ? tmInput.value.onFocus() : easyinput.value.onFocus()
  586. // });
  587. nextTick(() => {
  588. easyinput.value.onFocus(); // ← 固定回到二维码框
  589. });
  590. return;
  591. }
  592. /* ---------- 新增仓库ID校验 ---------- */
  593. if (!validateWarehouseId(data)) {
  594. return; // 仓库ID不一致,终止后续逻辑
  595. }
  596. /* ------------------------------------ */
  597. /* ---------- 新增批号重复校验 ---------- */
  598. const cur = Array.isArray(data) ? data[0] : data;
  599. if (cur && isBatchExist(cur.batchNumber)) {
  600. showBatchRepeatTip();
  601. return; // 直接终止
  602. }
  603. /* ------------------------------------ */
  604. scanBatchNumber.value = qrCode;
  605. // === 新增:将 tmMaterialNo 和 tmId 插入返回数据 ===
  606. if (Object.prototype.toString.call(data) === "[object Array]") {
  607. data.forEach((item) => {
  608. item.tmMaterialNo = tmMaterialNo.value.trim();
  609. item.tmId = tmId.value.trim();
  610. });
  611. } else if (data && typeof data === "object") {
  612. data.tmMaterialNo = tmMaterialNo.value.trim();
  613. data.tmId = tmId.value.trim();
  614. }
  615. // ============================================
  616. // 以下保持你原有逻辑不变
  617. if (Object.prototype.toString.call(data) === "[object Array]") {
  618. fdIndex.value = tableData.value.findIndex(
  619. (item) => item?.materialNo === data[0]?.materialNo,
  620. );
  621. }
  622. if (fdIndex.value === -1) {
  623. // #ifdef APP-PLUS
  624. plus.device.beep(2);
  625. // #endif
  626. errorTipMessage.value = "请扫描所需物料的物料条码";
  627. errorTip.value.open();
  628. errorState.value = 0;
  629. return;
  630. }
  631. currentScanMaterial.value = data[0] ?? [];
  632. const row = tableData.value[fdIndex.value];
  633. if (row.nowDeliveredQty > row.completedQty) {
  634. /* ===== 前端暂存逻辑 ===== */
  635. row.completedQty += currentScanMaterial.value.receiptQty || 1;
  636. localScannedList.value.push({
  637. ...currentScanMaterial.value,
  638. batchQty: currentScanMaterial.value.receiptQty || 1,
  639. supplierName: currentScanMaterial.value.supplierName || "",
  640. });
  641. flushBeforeTableData();
  642. /* 唯一成功出口:全部清空 */
  643. resetAllInputs();
  644. /* 再决定下一个焦点 */
  645. nextTick(() => {
  646. Number(scanTie.value) === 1
  647. ? tmInput.value.onFocus() // 贴纸模式→回到贴纸框
  648. : easyinput.value.onFocus(); // 原模式→回到二维码框
  649. });
  650. } else {
  651. // #ifdef APP-PLUS
  652. plus.device.beep(2);
  653. // #endif
  654. errorTipMessage.value = "已备数量已满,无需再扫";
  655. errorTip.value.open();
  656. errorState.value = 0;
  657. }
  658. })
  659. .catch(() => {
  660. // 异常也要复位
  661. fifoGo.value = false;
  662. });
  663. // #endif
  664. };
  665. const handleToNavigate = function () {
  666. uni.navigateTo({
  667. url: "/pages/workbranch/warehouse/production/materialIssuance",
  668. });
  669. };
  670. const handleComplete = function (e) {
  671. // #ifdef APP-PLUS
  672. // 扫描员工工号
  673. uni
  674. .$reqPost("scanPrepareMaterialSign", {
  675. encodedEmployeeId: e,
  676. id: masterId.value,
  677. })
  678. .then(({ code, data, msg }) => {
  679. if (code === 0) {
  680. uni.showToast({
  681. title: "扫码成功",
  682. icon: "none",
  683. duration: 2000,
  684. });
  685. setTimeout(() => {
  686. goBack();
  687. }, 500);
  688. } else {
  689. // #ifdef APP-PLUS
  690. plus.device.beep(2);
  691. // #endif
  692. errorTipMessage.value = msg;
  693. errorTip.value.open();
  694. errorState.value = -1;
  695. }
  696. isLightText.value = false;
  697. signText.value = "";
  698. });
  699. // #endif
  700. };
  701. // 物料拆分
  702. const handleSplitMaterial = function () {
  703. uni
  704. .$reqPost("prepareSplit", {
  705. prepareId: masterId.value,
  706. id: scanBatchNumber.value,
  707. inQty: currentScanMaterial.value?.receiptQty,
  708. splitQty:
  709. tableData.value[fdIndex.value].completedQty -
  710. currentScanMaterial.value?.receiptQty,
  711. })
  712. .then((res) => {
  713. search();
  714. modalForm.value.close();
  715. if (res.code === 0) {
  716. // 调取打印机拆分物料后打印标签
  717. uni.showToast({
  718. title: "拆分完毕",
  719. icon: "none",
  720. duration: 2000,
  721. });
  722. } else {
  723. // #ifdef APP-PLUS
  724. plus.device.beep(2);
  725. // #endif
  726. errorTipMessage.value = res.msg;
  727. errorTip.value.open();
  728. errorState.value = 0;
  729. }
  730. });
  731. };
  732. const handleKeydown = async function (e) {
  733. const qrCode = e;
  734. // if (businessType.value == '5') {
  735. // if (!tmId.value.trim()) {
  736. // uni.showToast({
  737. // title: '请先扫描贴纸ID',
  738. // icon: 'none',
  739. // duration: 2000
  740. // });
  741. // nextTick(() => tmInput.value?.onFocus());
  742. // return;
  743. // }
  744. // if (!tmMaterialNo.value.trim()) {
  745. // uni.showToast({
  746. // title: '请先扫描料号',
  747. // icon: 'none',
  748. // duration: 2000
  749. // });
  750. // nextTick(() => partInput.value?.onFocus());
  751. // return;
  752. // }
  753. // }
  754. /* 条码是否在库校验 */
  755. const instockOk = await checkInstock(qrCode);
  756. if (!instockOk) return;
  757. /* ===== 新增 FIFO 校验 ===== */
  758. const ok = await checkFifo(qrCode);
  759. if (!ok && !fifoGo.value) {
  760. resetAllInputs();
  761. nextTick(() => easyinput.value.onFocus());
  762. return;
  763. }
  764. /* ========================= */
  765. uni
  766. .$reqGet("scanPrepareMaterial", {
  767. qrCode,
  768. requestNo: receiveList.value.requestNo,
  769. businessType: receiveList.value.businessType,
  770. tmMaterialNo: tmMaterialNo.value.trim(),
  771. tmId: tmId.value.trim(),
  772. })
  773. .then(async ({ code, data, msg }) => {
  774. scanBatchNumber.value = qrCode;
  775. // === 新增:将 tmMaterialNo 和 tmId 插入返回数据 ===
  776. if (Object.prototype.toString.call(data) === "[object Array]") {
  777. data.forEach((item) => {
  778. item.tmMaterialNo = tmMaterialNo.value.trim();
  779. item.tmId = tmId.value.trim();
  780. });
  781. } else if (data && typeof data === "object") {
  782. data.tmMaterialNo = tmMaterialNo.value.trim();
  783. data.tmId = tmId.value.trim();
  784. }
  785. // ============================================
  786. fifoGo.value = false;
  787. if (code !== 0) {
  788. // #ifdef APP-PLUS
  789. plus.device.beep(2);
  790. // #endif
  791. /* 1. 全部输入框清空(含二维码) */
  792. resetAllInputs();
  793. errorTipMessage.value = msg;
  794. errorTip.value.open();
  795. errorState.value = 0;
  796. /* 2. 焦点回到正确的输入框 */
  797. // nextTick(() => {
  798. // Number(scanTie.value) === 1 ? tmInput.value.onFocus() : easyinput.value.onFocus()
  799. // });
  800. nextTick(() => {
  801. easyinput.value.onFocus(); // ← 固定回到二维码框
  802. });
  803. return;
  804. }
  805. /* ---------- 新增仓库ID校验 ---------- */
  806. if (!validateWarehouseId(data)) {
  807. return; // 仓库ID不一致,终止后续逻辑
  808. }
  809. /* ------------------------------------ */
  810. /* ---------- 新增批号重复校验 ---------- */
  811. const cur = Array.isArray(data) ? data[0] : data;
  812. if (cur && isBatchExist(cur.batchNumber)) {
  813. showBatchRepeatTip();
  814. return; // 直接终止
  815. }
  816. /* ------------------------------------ */
  817. if (Object.prototype.toString.call(data) === "[object Array]") {
  818. fdIndex.value = tableData.value.findIndex(
  819. (item) => item?.materialNo === data[0]?.materialNo,
  820. );
  821. }
  822. if (fdIndex.value === -1) {
  823. // #ifdef APP-PLUS
  824. plus.device.beep(2);
  825. // #endif
  826. errorTipMessage.value = "请扫描所需物料的物料条码";
  827. errorTip.value.open();
  828. errorState.value = 0;
  829. return;
  830. }
  831. currentScanMaterial.value = data[0] ?? [];
  832. const row = tableData.value[fdIndex.value];
  833. if (row.nowDeliveredQty > row.completedQty) {
  834. /* ===== 前端暂存逻辑 ===== */
  835. row.completedQty += currentScanMaterial.value.receiptQty || 1;
  836. localScannedList.value.push({
  837. ...currentScanMaterial.value,
  838. batchQty: currentScanMaterial.value.receiptQty || 1,
  839. supplierName: currentScanMaterial.value.supplierName || "",
  840. });
  841. flushBeforeTableData();
  842. resetAllInputs();
  843. setInputFocus();
  844. } else {
  845. // #ifdef APP-PLUS
  846. plus.device.beep(2);
  847. // #endif
  848. errorTipMessage.value = "已备数量已满,无需再扫";
  849. errorTip.value.open();
  850. errorState.value = 0;
  851. }
  852. })
  853. .catch(() => {
  854. // 异常也要复位
  855. fifoGo.value = false;
  856. });
  857. };
  858. const handleToDetails = function (ret) {
  859. // 设置刷新标记,从详情页返回时需要刷新
  860. uni.setStorageSync("needRefreshScanOut", "true");
  861. uni.navigateTo({
  862. url: "/pages/workbranch/warehouse/scanInOut/Out/scanTieInputs/scanTieInputsDetail.vue",
  863. });
  864. uni.setStorageSync("mixMaterialDetail", JSON.stringify(ret));
  865. };
  866. // 设置高亮
  867. const handleBtnLight = function () {
  868. // #ifdef APP-PLUS
  869. signInput.value.onBlur();
  870. isLightText.value = true;
  871. signInput.value.onFocus();
  872. // #endif
  873. };
  874. // const setInputFocus = function() {
  875. // if (Number(scanTie.value) === 1) {
  876. // // 闭环:回到贴纸 ID
  877. // nextTick(() => {
  878. // tmInput.value.onBlur()
  879. // tmInput.value.onFocus()
  880. // })
  881. // } else {
  882. // // 原逻辑:继续在二维码框循环
  883. // easyinput.value.onBlur()
  884. // easyinput.value.onFocus()
  885. // }
  886. // }
  887. const setInputFocus = function () {
  888. // 统一回到物料二维码输入框
  889. nextTick(() => {
  890. easyinput.value?.onBlur();
  891. easyinput.value?.onFocus();
  892. });
  893. };
  894. /* 统一出口:清空所有输入框 */
  895. const resetAllInputs = () => {
  896. scanBatchNumber.value = "";
  897. tmMaterialNo.value = "";
  898. tmId.value = "";
  899. };
  900. /* ===== 2. 键盘回车 ===== */
  901. const handlePartKeydown = async (e) => {
  902. const desc = tmMaterialNo.value.trim();
  903. if (!desc) return;
  904. await queryPart(desc);
  905. };
  906. /* ===== 3. 右侧图标点击 ===== */
  907. // 将 handleQueryPart 改为扫码方法
  908. const handleQueryPart = async () => {
  909. // #ifdef APP-PLUS
  910. const mpaasScanModule = { mpaasScan: uni.$scanByCameraCompat };
  911. const ret = await new Promise((resolve) =>
  912. mpaasScanModule.mpaasScan(
  913. { scanType: ["qrCode", "barCode"], hideAlbum: false },
  914. resolve,
  915. ),
  916. );
  917. if (ret.resp_code !== 1000) return;
  918. tmMaterialNo.value = ret.resp_result; // 回填扫码结果
  919. // 扫码成功后自动跳转到二维码输入框
  920. if (Number(scanTie.value) === 1) {
  921. nextTick(() => {
  922. easyinput.value.onBlur();
  923. easyinput.value.onFocus();
  924. });
  925. } else {
  926. nextTick(() => easyinput.value.onFocus());
  927. }
  928. // #endif
  929. };
  930. /* ===== 4. 真正查料号 ===== */
  931. /* ===== 料号框:只保存,不调接口 ===== */
  932. const queryPart = (desc) => {
  933. tmMaterialNo.value = desc.trim(); // 保存料号
  934. // 回车后跳回贴纸ID输入框,形成循环
  935. nextTick(() => {
  936. tmInput.value?.onBlur();
  937. tmInput.value?.onFocus();
  938. });
  939. };
  940. /* ===== 5. 料号框重新聚焦 ===== */
  941. const setPartFocus = () => {
  942. if (Number(scanTie.value) === 1) {
  943. nextTick(() => {
  944. easyinput.value.onBlur();
  945. easyinput.value.onFocus();
  946. });
  947. } else {
  948. // 非贴纸模式保持原逻辑(仅保存)
  949. partInput.value.onBlur();
  950. partInput.value.onFocus();
  951. }
  952. };
  953. /* ===== 2. 仅保存贴纸ID,不请求 ===== */
  954. const setTmOnly = async () => {
  955. // #ifdef APP-PLUS
  956. const mpaasScanModule = { mpaasScan: uni.$scanByCameraCompat };
  957. const ret = await new Promise((resolve) =>
  958. mpaasScanModule.mpaasScan(
  959. { scanType: ["qrCode", "barCode"], hideAlbum: false },
  960. resolve,
  961. ),
  962. );
  963. if (ret.resp_code !== 1000) return;
  964. tmId.value = ret.resp_result; // 回填扫码结果
  965. // 扫码成功后自动跳转到料号输入框(贴纸模式下)
  966. if (Number(scanTie.value) === 1) {
  967. nextTick(() => {
  968. partInput.value.onBlur();
  969. partInput.value.onFocus();
  970. });
  971. }
  972. // #endif
  973. };
  974. // 相同物料+相同批号才合并数量,否则新增一行
  975. const flushBeforeTableData = function () {
  976. const map = new Map();
  977. localScannedList.value.forEach((it) => {
  978. // 用“物料编码+批号”当唯一键
  979. const key = `${it.materialNo}__${it.batchNumber}`;
  980. if (map.has(key)) {
  981. map.get(key).batchQty += it.batchQty; // 同批号累加
  982. } else {
  983. map.set(key, { ...it }); // 新批号新开一行
  984. }
  985. });
  986. // 为每个项目添加唯一ID和滑动属性
  987. beforeTableData.value = Array.from(map.values()).map((v, i) => ({
  988. ...v,
  989. uniqueId: `${v.materialNo}_${v.batchNumber}_${i}`,
  990. slideX: 0,
  991. }));
  992. };
  993. /* ========= 左滑删除 ========= */
  994. const touchStart = (e) => {
  995. const idx = e.currentTarget.dataset.index;
  996. beforeTableData.value.forEach((v, i) => {
  997. if (i !== idx) v.slideX = 0; // 其余归位
  998. });
  999. beforeTableData.value[idx].startX = e.touches[0].pageX;
  1000. beforeTableData.value[idx].slideX =
  1001. beforeTableData.value[idx].slideX || 0;
  1002. };
  1003. const touchMove = (e) => {
  1004. const idx = e.currentTarget.dataset.index;
  1005. const row = beforeTableData.value[idx];
  1006. const delta = e.touches[0].pageX - row.startX;
  1007. if (delta < 0) {
  1008. // 只允许左滑
  1009. row.slideX = Math.max(delta, -70); // 70 = 按钮宽度
  1010. } else {
  1011. row.slideX = Math.min(delta, 0);
  1012. }
  1013. };
  1014. const touchEnd = (e) => {
  1015. const idx = e.currentTarget.dataset.index;
  1016. const row = beforeTableData.value[idx];
  1017. row.slideX = row.slideX <= -35 ? -70 : 0; // 过半则露出,否则收回
  1018. };
  1019. /**
  1020. * 删除一条已扫物料
  1021. * @param {number} idx 在 beforeTableData 中的下标
  1022. */
  1023. const deleteItem = async (idx) => {
  1024. const target = beforeTableData.value[idx];
  1025. /* 1. 有 id 就先调接口删后端 */
  1026. if (target.id) {
  1027. try {
  1028. const { code, msg } = await uni.$reqDelete("deleteScanOutMaterial", {
  1029. id: target.id,
  1030. });
  1031. if (code !== 0) {
  1032. // 接口明确返回失败,提示用户并终止后续逻辑
  1033. errorTipMessage.value = msg || "后端删除失败";
  1034. errorTip.value.open();
  1035. return;
  1036. }
  1037. } catch (err) {
  1038. // 网络或其它异常
  1039. errorTipMessage.value = err.errMsg || "网络异常,删除失败";
  1040. errorTip.value.open();
  1041. return;
  1042. }
  1043. }
  1044. /* 2. 无论有没有 id、接口成不成功,只要走到这里就删本地 */
  1045. // 2.1 从 localScannedList 里删掉对应项(同物料+同批号)
  1046. const key = `${target.materialNo}__${target.batchNumber}`;
  1047. const listIdx = localScannedList.value.findIndex(
  1048. (v) => `${v.materialNo}__${v.batchNumber}` === key,
  1049. );
  1050. if (listIdx > -1) localScannedList.value.splice(listIdx, 1);
  1051. // 2.2 重新合并生成 beforeTableData
  1052. flushBeforeTableData();
  1053. // 2.3 把对应物料的“已备数”回退
  1054. const row = tableData.value.find(
  1055. (r) => r.materialNo === target.materialNo,
  1056. );
  1057. if (row) row.completedQty -= target.batchQty;
  1058. };
  1059. // 关闭错误信息弹窗
  1060. const handleCloseErrorTipsModal = async function () {
  1061. errorTip.value.close();
  1062. if (errorState.value === 0) {
  1063. await setInputFocus();
  1064. }
  1065. };
  1066. /* ===================== 公共校验函数 ===================== */
  1067. // 仓库ID校验函数
  1068. const validateWarehouseId = (scanData) => {
  1069. // businessType 为 '1' 时跳过仓库ID校验
  1070. if (businessType.value == "1") {
  1071. return true;
  1072. }
  1073. const cur = Array.isArray(scanData) ? scanData[0] : scanData;
  1074. if (
  1075. cur &&
  1076. cur.warehouseId &&
  1077. currentWarehouseId.value &&
  1078. cur.warehouseId !== currentWarehouseId.value
  1079. ) {
  1080. // #ifdef APP-PLUS
  1081. plus.device.beep(2);
  1082. // #endif
  1083. errorTipMessage.value = `物料仓库(${cur.erpStockName})与当前仓库(${currentWarehouseName.value})不一致`;
  1084. errorTip.value.open();
  1085. errorState.value = 0;
  1086. return false;
  1087. }
  1088. return true;
  1089. };
  1090. // 仅扫描本地缓存池,不再读 beforeTableData
  1091. const isBatchExist = (batchNo) =>
  1092. beforeTableData.value.some((it) => it.batchNumber === batchNo);
  1093. const showBatchRepeatTip = () => {
  1094. // #ifdef APP-PLUS
  1095. plus.device.beep(2);
  1096. // #endif
  1097. errorTipMessage.value = "该批号已存在,请勿重复扫描";
  1098. errorTip.value.open();
  1099. errorState.value = 0;
  1100. };
  1101. // 禁用软键盘
  1102. const handleInputFocus = function () {
  1103. setTimeout(() => {
  1104. uni.hideKeyboard();
  1105. }, 100);
  1106. };
  1107. // 把 beforeTableData 追加到 tableData 对应物料的 inoutRequestSubdetailList
  1108. const mergeBeforeIntoTable = () => {
  1109. // 创建新数组存储合并结果
  1110. const mergedTableData = JSON.parse(JSON.stringify(tableData.value));
  1111. // 先建索引
  1112. const map = {};
  1113. mergedTableData.forEach((row) => {
  1114. if (!row.inoutRequestSubdetailList) row.inoutRequestSubdetailList = [];
  1115. map[row.materialNo] = row;
  1116. });
  1117. // 只追加,不新增
  1118. beforeTableData.value.forEach((item) => {
  1119. const target = map[item.materialNo];
  1120. if (target) {
  1121. target.inoutRequestSubdetailList.push({ ...item }); // 整条记录丢进去
  1122. }
  1123. // 不存在就跳过
  1124. });
  1125. return mergedTableData;
  1126. };
  1127. // 保存按钮点击事件
  1128. const handleSave = async function () {
  1129. if (saveDisabled.value) return;
  1130. saveDisabled.value = true;
  1131. try {
  1132. // 保存逻辑实现
  1133. isLightText.value = true;
  1134. // 先合并数据,获取合并后的新数组
  1135. const mergedData = mergeBeforeIntoTable();
  1136. // 调用保存API,使用合并后的新数组作为参数
  1137. await uni
  1138. .$reqPost("saveScannedOutMaterials", {
  1139. id: receiveList.value?.id,
  1140. requestNo: receiveList.value?.requestNo,
  1141. requestType: receiveList.value?.requestType,
  1142. businessType: receiveList.value?.businessType,
  1143. businessSubType: receiveList.value?.businessSubType,
  1144. status: receiveList.value?.status,
  1145. priority: receiveList.value?.priority,
  1146. inoutRequestDetailPDASaveReqVOList: mergedData,
  1147. })
  1148. .then(({ code, data, msg }) => {
  1149. if (code === 0) {
  1150. uni.showModal({
  1151. title: "提示",
  1152. content: "保存成功",
  1153. showCancel: false,
  1154. });
  1155. search();
  1156. } else {
  1157. // #ifdef APP-PLUS
  1158. plus.device.beep(2);
  1159. // #endif
  1160. errorTipMessage.value = msg;
  1161. errorTip.value.open();
  1162. errorState.value = 0;
  1163. }
  1164. });
  1165. } finally {
  1166. saveDisabled.value = false;
  1167. }
  1168. };
  1169. // 提交按钮点击事件
  1170. const handleSubmit = async function () {
  1171. if (submitDisabled.value) return;
  1172. submitDisabled.value = true;
  1173. try {
  1174. // 提交逻辑实现
  1175. isSubmitLight.value = true;
  1176. // 先合并数据,获取合并后的新数组
  1177. const mergedData = mergeBeforeIntoTable();
  1178. // 调用提交API,使用合并后的新数组作为参数
  1179. await uni
  1180. .$reqPut("submitScannedOutMaterials", {
  1181. id: receiveList.value?.id,
  1182. requestNo: receiveList.value?.requestNo,
  1183. requestType: receiveList.value?.requestType,
  1184. businessType: receiveList.value?.businessType,
  1185. businessSubType: receiveList.value?.businessSubType,
  1186. status: receiveList.value?.status,
  1187. priority: receiveList.value?.priority,
  1188. inoutRequestDetailPDASaveReqVOList: mergedData,
  1189. })
  1190. .then(({ code, data, msg }) => {
  1191. if (code === 0) {
  1192. uni.showModal({
  1193. title: "提示",
  1194. content: "提交成功",
  1195. showCancel: false,
  1196. });
  1197. search();
  1198. // 保存成功后可以跳转到其他页面或执行其他操作
  1199. // goBack()
  1200. } else {
  1201. // #ifdef APP-PLUS
  1202. plus.device.beep(2);
  1203. // #endif
  1204. errorTipMessage.value = msg;
  1205. errorTip.value.open();
  1206. errorState.value = 0;
  1207. }
  1208. });
  1209. } finally {
  1210. submitDisabled.value = false;
  1211. }
  1212. };
  1213. // uniapp移动端触底事件
  1214. onReachBottom(() => {
  1215. queryParams.value.pageNo += 1;
  1216. uni
  1217. .$reqGet("getPrepareMaterialList", queryParams.value)
  1218. .then(({ data }) => {
  1219. Array.prototype.push.call(
  1220. scanMaterialList.value,
  1221. ...(data?.list ?? []),
  1222. );
  1223. });
  1224. });
  1225. // 保存按钮文字样式
  1226. const saveBtnTextStyle = computed(() => ({
  1227. fontSize: "14px",
  1228. fontWeight: "bold",
  1229. color: saveDisabled.value
  1230. ? "#ccc"
  1231. : isLightText.value
  1232. ? "rgba(0,160,233,1)"
  1233. : "",
  1234. }));
  1235. // 提交按钮文字样式
  1236. const submitBtnTextStyle = computed(() => ({
  1237. fontSize: "14px",
  1238. fontWeight: "bold",
  1239. color: submitDisabled.value
  1240. ? "#ccc"
  1241. : isSubmitLight.value
  1242. ? "rgba(0,160,233,1)"
  1243. : "",
  1244. }));
  1245. // 移除status监听,提交按钮和保存按钮均始终可用
  1246. // watch(() => receiveList.value?.status, (newStatus) => {
  1247. // submitDisabled.value = newStatus !== 0
  1248. // })
  1249. /* -------------------- 新增 3 个方法 -------------------- */
  1250. // 真正继续扫码(关闭弹窗并置标志)
  1251. const fifoContinue = () => {
  1252. fifoPopup.value.close();
  1253. fifoGo.value = true;
  1254. // 用下一个 tick 把老流程续起来
  1255. nextTick(() => {
  1256. if (fifoQrCode) handleKeydown(fifoQrCode);
  1257. });
  1258. };
  1259. const fifoCancel = () => {
  1260. fifoPopup.value.close();
  1261. }; // 什么都不做
  1262. // 统一 FIFO 校验入口
  1263. const checkFifo = (qrCode) => {
  1264. // 用户已点“继续”,直接放行
  1265. if (fifoGo.value) return Promise.resolve(true);
  1266. if (!isBusinessTypeInFifoDict.value) return Promise.resolve(true);
  1267. return uni
  1268. .$reqPost("fifoCheck", {
  1269. qrCode,
  1270. requestNo: receiveList.value.requestNo,
  1271. businessType: receiveList.value.businessType,
  1272. })
  1273. .then(({ code, data, msg }) => {
  1274. if (code !== 0) {
  1275. errorTipMessage.value = msg || "FIFO 校验异常";
  1276. errorTip.value.open();
  1277. return false;
  1278. }
  1279. if (data === null) return true;
  1280. fifoMsg.value = `当前条码(${qrCode})不是库存中生产日期最早的物料条码(${data}),是否继续发料?`;
  1281. fifoQrCode = qrCode;
  1282. fifoPopup.value.open();
  1283. return false;
  1284. });
  1285. };
  1286. // ========== 条码是否在库校验 ==========
  1287. const checkInstock = function (qrCode) {
  1288. // 自动入库成功后的一次性放行
  1289. if (instockGo.value) {
  1290. instockGo.value = false;
  1291. return Promise.resolve(true);
  1292. }
  1293. return uni
  1294. .$reqPost("inStockCheck", { qrCode })
  1295. .then(({ code, data, msg }) => {
  1296. if (code !== 0) {
  1297. // #ifdef APP-PLUS
  1298. plus.device.beep(2);
  1299. // #endif
  1300. errorTipMessage.value = msg || "条码是否在库检查异常";
  1301. errorTip.value.open();
  1302. errorState.value = 0;
  1303. resetAllInputs();
  1304. nextTick(() => easyinput.value?.onFocus());
  1305. return false;
  1306. }
  1307. // 在库:直接放行
  1308. if (Number(data?.instockFlag) === 1) return true;
  1309. // 不在库:弹窗确认数量 + 库位
  1310. instockQrCode = qrCode;
  1311. const defaultQty = Number(data?.qrCodeQty);
  1312. inStockCheckQty.value = Number.isFinite(defaultQty)
  1313. ? String(defaultQty)
  1314. : "";
  1315. inStockCheckProduceDate.value = data?.produceDate || "";
  1316. inStockCheckStore.value = "";
  1317. inStockCheckErpStockName.value = "";
  1318. inStockCheckWmsStoreName.value = "";
  1319. wmsStockId.value = "";
  1320. wmsStoreAreaId.value = "";
  1321. wmsStoreLocationId.value = "";
  1322. nextTick(() => inStockCheckPopup.value?.open());
  1323. return false;
  1324. });
  1325. };
  1326. // 弹窗内库位扫码
  1327. const scanInStockStore = function () {
  1328. // #ifdef APP-PLUS
  1329. const mpaasScanModule = { mpaasScan: uni.$scanByCameraCompat };
  1330. mpaasScanModule.mpaasScan(
  1331. {
  1332. scanType: ["qrCode", "barCode"],
  1333. hideAlbum: false,
  1334. },
  1335. (ret) => {
  1336. if (ret.resp_code === 1000) {
  1337. confirmInStockStore(ret.resp_result);
  1338. }
  1339. },
  1340. );
  1341. // #endif
  1342. };
  1343. // 弹窗内库位输入回车事件
  1344. const confirmInStockStore = function (e) {
  1345. // @confirm 传入的是事件对象,扫码图标传入的是字符串,这里统一取码
  1346. const code =
  1347. typeof e === "string" ? e : (e && e.detail && e.detail.value) || "";
  1348. inStockCheckStore.value = code;
  1349. if (!code) return;
  1350. uni
  1351. .$reqGet("getStockLocaltionByCode", { code })
  1352. .then(({ code, data, msg }) => {
  1353. if (
  1354. code === 0 &&
  1355. data &&
  1356. data.erpStockId &&
  1357. data.wmsStoreAreaId &&
  1358. data.wmsStoreId
  1359. ) {
  1360. wmsStockId.value = data.erpStockId; // 仓库id
  1361. wmsStoreAreaId.value = data.wmsStoreAreaId; // 区域id
  1362. wmsStoreLocationId.value = data.wmsStoreId; // 货位id
  1363. inStockCheckErpStockName.value = data.erpStockName || "";
  1364. inStockCheckWmsStoreName.value = data.wmsStoreName || "";
  1365. } else {
  1366. // #ifdef APP-PLUS
  1367. plus.device.beep(2);
  1368. // #endif
  1369. inStockCheckStore.value = "";
  1370. wmsStockId.value = "";
  1371. wmsStoreAreaId.value = "";
  1372. wmsStoreLocationId.value = "";
  1373. uni.showToast({ title: "请扫描正确的库位", icon: "none" });
  1374. }
  1375. });
  1376. };
  1377. // 弹窗确认:数量 > 0 且库位已正确返回,再调自动入库
  1378. const confirmInStockCheck = function () {
  1379. const qty = Number(inStockCheckQty.value);
  1380. if (!Number.isFinite(qty) || qty <= 0) {
  1381. uni.showToast({ title: "请输入大于0的数量", icon: "none" });
  1382. return;
  1383. }
  1384. const produceDate = (inStockCheckProduceDate.value || "").trim();
  1385. if (!produceDate) {
  1386. uni.showToast({ title: "请输入生产日期", icon: "none" });
  1387. return;
  1388. }
  1389. if (!/^\d{4}-\d{2}-\d{2}$/.test(produceDate)) {
  1390. uni.showToast({ title: "生产日期格式应为 2026-10-15", icon: "none" });
  1391. return;
  1392. }
  1393. if (!wmsStockId.value) {
  1394. uni.showToast({ title: "当前库位信息无仓库id数据", icon: "none" });
  1395. return;
  1396. }
  1397. if (!wmsStoreAreaId.value) {
  1398. uni.showToast({ title: "当前库位信息无区域id数据", icon: "none" });
  1399. return;
  1400. }
  1401. if (!wmsStoreLocationId.value) {
  1402. uni.showToast({ title: "当前库位信息无货位id数据", icon: "none" });
  1403. return;
  1404. }
  1405. inStockCheckPopup.value?.close();
  1406. uni
  1407. .$reqPost("autoInStock", {
  1408. qrCode: instockQrCode,
  1409. qrCodeQty: qty,
  1410. produceDate: produceDate,
  1411. wmsStockId: wmsStockId.value,
  1412. wmsStoreAreaId: wmsStoreAreaId.value,
  1413. wmsStoreLocationId: wmsStoreLocationId.value,
  1414. })
  1415. .then(({ code, data, msg }) => {
  1416. if (code !== 0) {
  1417. // #ifdef APP-PLUS
  1418. plus.device.beep(2);
  1419. // #endif
  1420. errorTipMessage.value = msg || "自动入库失败";
  1421. errorTip.value.open();
  1422. errorState.value = 0;
  1423. instockGo.value = false;
  1424. resetAllInputs();
  1425. nextTick(() => easyinput.value?.onFocus());
  1426. return;
  1427. }
  1428. // 自动入库成功:放行并继续原业务接口
  1429. instockGo.value = true;
  1430. nextTick(() => {
  1431. if (instockQrCode) handleKeydown(instockQrCode);
  1432. });
  1433. });
  1434. };
  1435. // 弹窗取消
  1436. const cancelInStockCheck = function () {
  1437. inStockCheckPopup.value?.close();
  1438. instockGo.value = false;
  1439. instockQrCode = "";
  1440. scanBatchNumber.value = "";
  1441. nextTick(() => easyinput.value?.onFocus());
  1442. };
  1443. // 回车触发 - 只跳转,不打开摄像头
  1444. const handleTmConfirm = () => {
  1445. if (!tmId.value.trim()) {
  1446. // 如果值为空,可能是误触发,聚焦到料号框
  1447. nextTick(() => partInput.value?.onFocus());
  1448. return;
  1449. }
  1450. // 有值的话,直接跳转到料号框
  1451. nextTick(() => {
  1452. partInput.value?.onBlur();
  1453. partInput.value?.onFocus();
  1454. });
  1455. };
  1456. return {
  1457. goBack,
  1458. popup,
  1459. signText,
  1460. isBefore,
  1461. tableData,
  1462. beforeTableData,
  1463. signInput,
  1464. modalForm,
  1465. easyinput,
  1466. handleTmConfirm,
  1467. errorTip,
  1468. errorTipMessage,
  1469. handleInputFocus,
  1470. isLightText,
  1471. isSubmitLight,
  1472. handleBtnLight,
  1473. handleKeydown,
  1474. scanBatchNumber,
  1475. handleScanMaterial,
  1476. handleToNavigate,
  1477. saveDisabled,
  1478. submitDisabled,
  1479. saveBtnTextStyle,
  1480. submitBtnTextStyle,
  1481. scanMaterialList,
  1482. handleComplete,
  1483. handleSplitMaterial,
  1484. handleToDetails,
  1485. handleCloseErrorTipsModal,
  1486. handleSubmit,
  1487. handleSave,
  1488. // 左滑删除相关
  1489. touchStart,
  1490. touchMove,
  1491. touchEnd,
  1492. deleteItem,
  1493. scanTie,
  1494. // 料号输入相关
  1495. tmMaterialNo,
  1496. partInput,
  1497. handlePartKeydown,
  1498. handleQueryPart,
  1499. // 贴纸ID输入相关
  1500. tmId,
  1501. tmInput,
  1502. setTmOnly,
  1503. // FIFO相关
  1504. fifoPopup,
  1505. fifoMsg,
  1506. fifoContinue,
  1507. fifoCancel,
  1508. // 条码是否在库校验相关
  1509. inStockCheckPopup,
  1510. inStockCheckQty,
  1511. inStockCheckProduceDate,
  1512. inStockCheckStore,
  1513. inStockCheckErpStockName,
  1514. inStockCheckWmsStoreName,
  1515. confirmInStockCheck,
  1516. cancelInStockCheck,
  1517. confirmInStockStore,
  1518. scanInStockStore,
  1519. };
  1520. },
  1521. });
  1522. </script>
  1523. <style lang="scss" scoped>
  1524. .gui-header-leader-btns {
  1525. color: black;
  1526. font-size: 24px !important;
  1527. margin-left: 24rpx;
  1528. }
  1529. .list-content {
  1530. margin-top: 80px;
  1531. background-color: #edeeee;
  1532. }
  1533. .card-list-flexbox {
  1534. display: flex;
  1535. flex-direction: row;
  1536. align-items: center;
  1537. flex-wrap: wrap;
  1538. margin: 3px 2px;
  1539. .card-list-item {
  1540. width: 750rpx;
  1541. height: 40px;
  1542. margin: 2rpx 0;
  1543. display: flex;
  1544. flex-direction: row;
  1545. align-items: center;
  1546. justify-content: space-between;
  1547. background-color: #fff;
  1548. uni-text {
  1549. font-size: 14px;
  1550. height: 50rpx;
  1551. text-align: left;
  1552. padding: 0 12px;
  1553. display: flex;
  1554. flex-direction: row;
  1555. align-items: center;
  1556. }
  1557. .text-1 {
  1558. flex: 1;
  1559. height: 40px;
  1560. justify-content: flex-start;
  1561. }
  1562. .text-2 {
  1563. flex: 3;
  1564. height: 40px;
  1565. justify-content: flex-end;
  1566. margin-right: 4px;
  1567. padding: 2px 6px;
  1568. }
  1569. }
  1570. }
  1571. .card-list-flexbox:nth-of-type(2) {
  1572. margin-top: 48px;
  1573. }
  1574. .fixedTop {
  1575. bottom: 0 !important;
  1576. top: 3.25rem !important;
  1577. }
  1578. .popup-content {
  1579. height: 75vh;
  1580. overflow-y: scroll;
  1581. background-color: #edeeee;
  1582. }
  1583. .font-icons {
  1584. width: 40px;
  1585. font-size: 20px;
  1586. }
  1587. .scan {
  1588. height: 45px;
  1589. width: calc(100% - 48px);
  1590. margin: 12px;
  1591. padding: 0 12px;
  1592. display: flex;
  1593. justify-content: space-between;
  1594. align-items: center;
  1595. border-radius: 6px;
  1596. background-color: white;
  1597. .scan-card {
  1598. width: 100%;
  1599. display: grid;
  1600. grid-template-rows: 1fr;
  1601. grid-template-columns: 7fr 2fr;
  1602. align-items: center;
  1603. input {
  1604. height: 35px;
  1605. line-height: 35px;
  1606. }
  1607. text {
  1608. width: 100%;
  1609. text-align: right;
  1610. }
  1611. }
  1612. }
  1613. .custom-table {
  1614. height: calc(100vh - 265px);
  1615. min-height: 230px;
  1616. margin: 5px 0;
  1617. // min-height: 600px;
  1618. overflow-y: scroll;
  1619. }
  1620. .modal-btns {
  1621. height: 100rpx;
  1622. line-height: 100rpx;
  1623. display: flex;
  1624. justify-content: center;
  1625. align-items: center;
  1626. }
  1627. .line {
  1628. margin-top: 10rpx;
  1629. height: 80rpx;
  1630. width: 1rpx;
  1631. background-color: #dcdcdc;
  1632. }
  1633. .tabs {
  1634. width: 100%;
  1635. height: 45px;
  1636. display: flex;
  1637. align-items: flex-end;
  1638. padding: 0 2px;
  1639. background-color: white;
  1640. .tabs-list {
  1641. border-radius: 3px;
  1642. overflow: hidden;
  1643. }
  1644. .tabs-item {
  1645. display: inline-block;
  1646. width: 72px;
  1647. height: 30px;
  1648. line-height: 30px;
  1649. padding: 0 8px;
  1650. font-size: 14px;
  1651. font-weight: bold;
  1652. text-align: center;
  1653. color: black;
  1654. border-bottom: 1.5px dashed #00a0e9;
  1655. transition: all 0.5s ease-in-out;
  1656. }
  1657. .tabs-item-active {
  1658. position: relative;
  1659. display: inline-block;
  1660. width: 72px;
  1661. height: 30px;
  1662. line-height: 30px;
  1663. padding: 0 8px;
  1664. font-size: 14px;
  1665. font-weight: bold;
  1666. text-align: center;
  1667. color: white;
  1668. border-left: 1px solid #00a0e9;
  1669. border-top: 1px solid #00a0e9;
  1670. border-right: 1px solid #00a0e9;
  1671. border-bottom: 1.5px solid #00a0e9;
  1672. border-radius: 5px 5px 0 0;
  1673. animation: 0.3s linear show;
  1674. background-color: #00a0e9;
  1675. }
  1676. .tabs-item-active::before {
  1677. content: "";
  1678. position: absolute;
  1679. left: -10px;
  1680. bottom: 0;
  1681. width: 10px;
  1682. height: 10px;
  1683. background: radial-gradient(circle at 0% 25%, transparent 10px, #00a0e9 0);
  1684. }
  1685. .tabs-item-active::after {
  1686. content: "";
  1687. position: absolute;
  1688. right: -10px;
  1689. bottom: 0;
  1690. width: 10px;
  1691. height: 10px;
  1692. background: radial-gradient(
  1693. circle at 100% 25%,
  1694. transparent 10px,
  1695. #00a0e9 0
  1696. );
  1697. }
  1698. }
  1699. @keyframes show {
  1700. from {
  1701. transform: translateY(5%);
  1702. }
  1703. to {
  1704. transform: translateY(0%);
  1705. }
  1706. }
  1707. .sign-btn {
  1708. display: flex;
  1709. align-items: center;
  1710. justify-content: center;
  1711. margin: 0 8px;
  1712. border: 1px solid #999999;
  1713. background-color: white;
  1714. border-radius: 6px;
  1715. }
  1716. .sign-btn.disabled {
  1717. border-color: #ccc;
  1718. background-color: #f5f5f5;
  1719. pointer-events: none;
  1720. }
  1721. /* 左滑删除样式 */
  1722. .scroll-box {
  1723. height: 100%; /* 继承父级高度 */
  1724. }
  1725. .cell-row {
  1726. display: flex;
  1727. background-color: #f5f7fa;
  1728. font-weight: bold;
  1729. border-radius: 4px;
  1730. margin-bottom: 5px;
  1731. }
  1732. .swipe-row {
  1733. position: relative;
  1734. width: 100%;
  1735. height: 44px;
  1736. overflow: hidden;
  1737. border-bottom: 1px solid #eee;
  1738. margin-bottom: 5px;
  1739. border-radius: 4px;
  1740. }
  1741. .content-area {
  1742. position: absolute;
  1743. left: 0;
  1744. top: 0;
  1745. right: 0;
  1746. bottom: 0;
  1747. z-index: 2;
  1748. background: #fff;
  1749. display: flex;
  1750. align-items: center;
  1751. transition: transform 0.25s;
  1752. border-radius: 4px;
  1753. }
  1754. .cell1 {
  1755. flex: 2;
  1756. text-align: center;
  1757. font-size: 14px;
  1758. color: #333;
  1759. height: 44px;
  1760. line-height: 44px;
  1761. }
  1762. .cell2 {
  1763. flex: 1;
  1764. text-align: center;
  1765. font-size: 14px;
  1766. color: #333;
  1767. height: 44px;
  1768. line-height: 44px;
  1769. }
  1770. .cell3 {
  1771. flex: 2;
  1772. text-align: center;
  1773. font-size: 14px;
  1774. color: #333;
  1775. height: 44px;
  1776. line-height: 44px;
  1777. }
  1778. .btn-area {
  1779. position: absolute;
  1780. right: 0;
  1781. top: 0;
  1782. width: 70px;
  1783. height: 100%;
  1784. background: #e54d42;
  1785. color: #fff;
  1786. display: flex;
  1787. align-items: center;
  1788. justify-content: center;
  1789. font-size: 14px;
  1790. z-index: 1;
  1791. border-radius: 4px;
  1792. }
  1793. // /* 表头也允许换行,保证与列宽对齐 */
  1794. // ::v-deep .break-col {
  1795. // white-space: normal !important;
  1796. // word-break: break-all !important;
  1797. // line-height: 1.2;
  1798. // }
  1799. // /* 单元格超长自动分段 */
  1800. // ::v-deep .break-cell {
  1801. // white-space: normal !important;
  1802. // word-break: break-all !important;
  1803. // line-height: 1.2;
  1804. // padding: 4px 2px; /* 上下留一点空隙,视觉更舒服 */
  1805. // }
  1806. /* 条码是否在库校验弹窗样式 */
  1807. .instock-dialog {
  1808. width: 600rpx;
  1809. background-color: #fff;
  1810. border-radius: 12rpx;
  1811. padding: 40rpx 32rpx;
  1812. box-sizing: border-box;
  1813. }
  1814. .instock-title {
  1815. font-size: 32rpx;
  1816. font-weight: bold;
  1817. color: #333;
  1818. text-align: center;
  1819. margin-bottom: 32rpx;
  1820. line-height: 1.4;
  1821. }
  1822. .instock-row {
  1823. display: flex;
  1824. align-items: center;
  1825. margin-bottom: 24rpx;
  1826. }
  1827. .instock-label {
  1828. width: 90rpx;
  1829. font-size: 28rpx;
  1830. color: #333;
  1831. }
  1832. .instock-input {
  1833. flex: 1;
  1834. height: 64rpx;
  1835. line-height: 64rpx;
  1836. border: 1rpx solid #dcdfe6;
  1837. border-radius: 8rpx;
  1838. padding: 0 16rpx;
  1839. font-size: 28rpx;
  1840. background-color: #fff;
  1841. }
  1842. .instock-datetime {
  1843. flex: 1;
  1844. }
  1845. .instock-scan-icon {
  1846. margin-left: 16rpx;
  1847. font-size: 36rpx;
  1848. color: #00a0e9;
  1849. }
  1850. .instock-store-info {
  1851. display: flex;
  1852. gap: 24rpx;
  1853. margin-bottom: 24rpx;
  1854. font-size: 24rpx;
  1855. color: #666;
  1856. }
  1857. .instock-btns {
  1858. display: flex;
  1859. justify-content: space-between;
  1860. margin-top: 16rpx;
  1861. }
  1862. .instock-btn {
  1863. flex: 1;
  1864. height: 72rpx;
  1865. line-height: 72rpx;
  1866. text-align: center;
  1867. border-radius: 8rpx;
  1868. font-size: 28rpx;
  1869. }
  1870. .instock-btn-cancel {
  1871. background-color: #f5f5f5;
  1872. color: #666;
  1873. margin-right: 16rpx;
  1874. }
  1875. .instock-btn-confirm {
  1876. background-color: #00a0e9;
  1877. color: #fff;
  1878. }
  1879. </style>