You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

718 lines
28 KiB

1 year ago
1 year ago
11 months ago
11 months ago
1 year ago
11 months ago
1 year ago
10 months ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
12 months ago
1 year ago
12 months ago
1 year ago
12 months ago
1 year ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
12 months ago
1 year ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
1 year ago
9 months ago
11 months ago
12 months ago
9 months ago
12 months ago
8 months ago
12 months ago
11 months ago
11 months ago
12 months ago
7 months ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
11 months ago
11 months ago
7 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
10 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
12 months ago
12 months ago
11 months ago
11 months ago
1 year ago
1 year ago
7 months ago
6 months ago
7 months ago
6 months ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
12 months ago
1 year ago
1 year ago
1 year ago
11 months ago
11 months ago
3 days ago
12 months ago
4 days ago
12 months ago
11 months ago
1 year ago
11 months ago
11 months ago
12 months ago
11 months ago
12 months ago
11 months ago
10 months ago
7 months ago
10 months ago
7 months ago
10 months ago
1 year ago
11 months ago
12 months ago
11 months ago
12 months ago
11 months ago
10 months ago
7 months ago
1 year ago
1 year ago
12 months ago
1 year ago
7 months ago
1 year ago
11 months ago
7 months ago
11 months ago
7 months ago
6 months ago
7 months ago
11 months ago
7 months ago
6 months ago
11 months ago
1 year ago
1 year ago
7 months ago
6 months ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
11 months ago
12 months ago
1 year ago
12 months ago
1 year ago
1 year ago
10 months ago
1 year ago
11 months ago
11 months ago
11 months ago
1 year ago
3 days ago
12 months ago
1 year ago
12 months ago
1 year ago
12 months ago
11 months ago
11 months ago
9 months ago
1 year ago
12 months ago
1 year ago
12 months ago
12 months ago
12 months ago
1 year ago
12 months ago
1 year ago
11 months ago
1 year ago
11 months ago
11 months ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
12 months ago
1 year ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
1 year ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
1 year ago
11 months ago
1 year ago
  1. <template>
  2. <div>
  3. <div class="pda-container" v-loading.fullscreen.lock="fullscreenLoading"
  4. element-loading-background="rgba(255, 255, 255, 0.3)"
  5. element-loading-spinner="el-icon-loading"
  6. :element-loading-text="loadingText">
  7. <div class="status-bar">
  8. <div class="goBack" @click="handleBack"><i class="el-icon-arrow-left"></i>上一页</div>
  9. <div class="goBack">登记到达</div>
  10. <div class="network" style="color: #fff" @click="$router.push({ path: '/' })">🏠首页</div>
  11. </div>
  12. <div style="overflow-y: auto">
  13. <!-- Step 1: 扫描 -->
  14. <div v-if="processFlag === 1">
  15. <div class="scan-box" style="margin: 2px;">
  16. <el-input clearable v-model="scanCode" placeholder="扫描PO条码或输入PO号"
  17. @keyup.enter.native="searchPoList" ref="scanCodeRef" />
  18. </div>
  19. <div class="item-list" v-if="poList.length > 0" style="margin: 2px;">
  20. <el-form label-position="top" style="margin: 3px;">
  21. <el-row :gutter="5"
  22. v-for="(poDetail, index) in poList" :key="index" :class="index < poList.length - 1 ? 'bottom-line-row' : ''">
  23. <el-col :span="8">
  24. <el-form-item label="商品编码"><span>{{ poDetail.partNo }}</span></el-form-item>
  25. </el-col>
  26. <el-col :span="8">
  27. <el-form-item label="行号/下达号"><span>{{ poDetail.lineNo }}/{{ poDetail.releaseNo }}</span></el-form-item>
  28. </el-col>
  29. <el-col :span="8">
  30. <el-form-item label="">
  31. <el-button type="text" class="recvButton" @click="recvLine(poDetail)"
  32. style="margin-top: 10px;margin-left: 20px" size="small">接收</el-button>
  33. </el-form-item>
  34. </el-col>
  35. <el-col :span="24">
  36. <el-form-item label="商品描述"><span>{{ poDetail.description }}</span></el-form-item>
  37. </el-col>
  38. <el-col :span="6" :class="{ mt10: getTextWidth(poDetail.description) > 34 }">
  39. <el-form-item label="订单数量"><span>{{ poDetail.purchaseQty }}</span></el-form-item>
  40. </el-col>
  41. <el-col :span="6" :class="{ mt10: getTextWidth(poDetail.description) > 34 }">
  42. <el-form-item label="待收数量"><span>{{ poDetail.qtyToReceive }}</span></el-form-item>
  43. </el-col>
  44. <el-col :span="6" :class="{ mt10: getTextWidth(poDetail.description) > 34 }">
  45. <el-form-item label="计划数量"><span>{{ poDetail.invQtyToReceive }}</span></el-form-item>
  46. </el-col>
  47. <el-col :span="6" :class="{ mt10: getTextWidth(poDetail.description) > 34 }">
  48. <el-form-item style="margin-left: 20px" label="单位"><span>{{ poDetail.purchaseUOM }}</span></el-form-item>
  49. </el-col>
  50. </el-row>
  51. </el-form>
  52. </div>
  53. </div>
  54. <!-- Step 2: 收货明细 -->
  55. <div v-if="processFlag === 2">
  56. <el-form label-position="top" class="form-section" style="margin: 5px;">
  57. <el-row :gutter="20">
  58. <el-col :span="12"><el-form-item label="PO号码"><el-input v-model="recvItem.orderNo" disabled /></el-form-item></el-col>
  59. <el-col :span="12"><el-form-item label="行号/下达号"><el-input v-model="displayLineWdr" disabled /></el-form-item></el-col>
  60. <el-col :span="12"><el-form-item label="商品编码"><el-input v-model="recvItem.partNo" disabled /></el-form-item></el-col>
  61. <el-col :span="12"><el-form-item label="计量单位"><el-input v-model="recvItem.purchaseUOM" disabled /></el-form-item></el-col>
  62. <el-col :span="24"><el-form-item label="商品名称"><el-input v-model="recvItem.description" disabled /></el-form-item></el-col>
  63. <el-col :span="12"><el-form-item label="订单数量"><el-input v-model="recvItem.purchaseQty" disabled /></el-form-item></el-col>
  64. <el-col :span="12"><el-form-item label="待收数量"><el-input v-model="recvItem.qtyToReceive" disabled /></el-form-item></el-col>
  65. <el-col :span="12">
  66. <el-form-item label="此次接收数量">
  67. <el-input v-model="recvItem.transQty" />
  68. </el-form-item>
  69. </el-col>
  70. <el-col :span="12">
  71. <el-form-item label=" ">
  72. <el-button type="text" @click.stop="handlingUnitStep"
  73. style="font-size: 16px;margin-top: -5px" size="small">包装记录</el-button>
  74. </el-form-item>
  75. </el-col>
  76. <el-col :span="6"> <el-form-item label="高度(mm)">
  77. <el-input v-model="recvItem.height" />
  78. </el-form-item></el-col>
  79. <el-col :span="18"><el-form-item label="送货单信息">
  80. <el-input v-model="recvItem.deliveryNote" />
  81. </el-form-item></el-col>
  82. <el-col :span="12"><el-form-item label="供应商生产日期">
  83. <el-date-picker v-model="recvItem.supplierManufactureDate" type="date" format="yyyy-MM-dd"
  84. value-format="yyyy-MM-dd" placeholder="请选择" style="width: 100%"
  85. inputmode="none"
  86. autocomplete="off"
  87. autocorrect="off"
  88. spellcheck="false" />
  89. </el-form-item></el-col>
  90. <el-col :span="12"><el-form-item label="供应商批次号">
  91. <el-input v-model="recvItem.supplierBatchNo" placeholder="请输入供应商批次号" />
  92. </el-form-item></el-col>
  93. <el-col :span="12"><el-form-item label="WDR">
  94. <el-input v-model="recvItem.wdr" disabled placeholder="请输入WDR" />
  95. </el-form-item></el-col>
  96. <el-col :span="12"><el-form-item label="到达日期">
  97. <el-date-picker v-model="recvItem.arrivalDate" type="datetime" format="yyyy-MM-dd HH:mm:ss"
  98. value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择到达日期" style="width: 100%"
  99. inputmode="none"
  100. autocomplete="off"
  101. autocorrect="off"
  102. spellcheck="false" />
  103. </el-form-item></el-col>
  104. <el-col :span="12"><el-form-item label="库位">
  105. <el-input v-model="recvItem.locationNo" placeholder="请输入库位" /></el-form-item></el-col>
  106. <el-col :span="12"><el-form-item label="批号"><el-input v-model="recvItem.batchNo" placeholder="请输入批号" /></el-form-item></el-col>
  107. <el-col :span="8" style="margin-top: 10px"><el-form-item><el-button type="text" style="font-size: 16px;margin-left: 30px" @click="processFlag = 1">回退</el-button></el-form-item></el-col>
  108. <el-col :span="8" style="margin-top: 10px"><el-form-item><el-button type="text" style="font-size: 16px;margin-left: 20px" @click="receivePo">保存</el-button></el-form-item></el-col>
  109. <el-col :span="8" style="margin-top: 10px"><el-form-item><el-button type="text" style="font-size: 16px;margin-left: 10px" @click="$router.push('/')">退出</el-button></el-form-item></el-col>
  110. </el-row>
  111. </el-form>
  112. </div>
  113. <!-- Step 3: 包装记录 -->
  114. <div v-if="processFlag === 3">
  115. <el-form label-position="top" class="form-section" style="margin: 5px;">
  116. <el-row :gutter="20">
  117. <el-col :span="12"><el-form-item label="商品编码"><el-input v-model="recvItem.partNo" disabled /></el-form-item></el-col>
  118. <el-col :span="12"><el-form-item label="待收数量"><el-input v-model="recvItem.qtyToReceive" disabled /></el-form-item></el-col>
  119. <el-col :span="24"><el-form-item label="商品名称"><el-input v-model="recvItem.description" disabled /></el-form-item></el-col>
  120. <!-- 自动计算开关 -->
  121. <el-col :span="24" style="margin-bottom: 10px;">
  122. <el-form-item>
  123. <el-switch
  124. v-model="autoCalculate"
  125. active-text="自动计算模式"
  126. inactive-text="手动输入模式"
  127. active-color="#17B3A3"
  128. style="display: block;"
  129. >
  130. </el-switch>
  131. <span v-if="autoCalculate" style="font-size: 13px; color: #17B3A3; margin-top: 5px; display: block; font-weight: bold;">
  132. 💡 输入单包装数量后按回车将根据待收数量自动分配包装
  133. </span>
  134. <span v-else style="font-size: 12px; color: #999; margin-top: 5px; display: block;">
  135. 手动输入单包装数量和包装数然后点击"创建"按钮
  136. </span>
  137. </el-form-item>
  138. </el-col>
  139. <el-col :span="8" style="margin-top: 5px"><el-form-item label="单包装数量">
  140. <el-input
  141. v-model="hanlingItem.perQty"
  142. type="number"
  143. :placeholder="autoCalculate ? '输入完按回车或失去焦点' : '请输入单包装数量'"
  144. @blur="autoCalculate && autoCreateHandlingUnits()"
  145. @keyup.enter.native="autoCalculate && autoCreateHandlingUnits()"
  146. />
  147. </el-form-item></el-col>
  148. <el-col :span="8" style="margin-top: 5px" v-if="!autoCalculate"><el-form-item label="包装数">
  149. <el-input v-model="hanlingItem.packageQty" type="number" placeholder="请输入包装数" />
  150. </el-form-item></el-col>
  151. <el-col :span="8" v-if="!autoCalculate" style="margin-top: 16px"><el-form-item>
  152. <el-button type="text" @click="createHandlingUnit" style="font-size: 16px">创建</el-button></el-form-item></el-col>
  153. <el-col :span="8" v-else style="margin-top: 16px"><el-form-item>
  154. <el-button type="text" style="font-size: 16px">确定</el-button></el-form-item></el-col>
  155. <el-table :data="handlingUnit" :row-style="{ height: '30px' }" style="width: 94%; margin-left: 10px;" highlight-current-row>
  156. <el-table-column prop="code" label="序号" />
  157. <el-table-column prop="packageQty" label="包装数" width="80" />
  158. <el-table-column prop="perQty" label="单包装数量" width="100" />
  159. <el-table-column label="操作" v-if="!autoCalculate">
  160. <template slot-scope="scope">
  161. <a @click="removeItem(scope.$index)">删除</a>
  162. </template>
  163. </el-table-column>
  164. </el-table>
  165. <el-col :span="24" v-if="autoCalculate && handlingUnit.length > 0" style="margin-top: 10px;">
  166. <span style="font-size: 12px; color: #999;">
  167. 💡 如需修改请重新输入单包装数量
  168. </span>
  169. </el-col>
  170. <el-col :span="24"><el-form-item><span>合计</span><span style="margin-left: 38%">{{ totalQty }}</span></el-form-item></el-col>
  171. <el-col :span="12"><el-form-item><el-button type="text" @click="processFlag = 2" style="font-size: 18px;margin-left: 60px">回退</el-button></el-form-item></el-col>
  172. <el-col :span="12"><el-form-item><el-button type="text" @click="processFlag = 2" style="font-size: 18px;">确定</el-button></el-form-item></el-col>
  173. </el-row>
  174. </el-form>
  175. </div>
  176. </div>
  177. </div>
  178. </div>
  179. </template>
  180. <script>
  181. import { getPoList, receivePo, printLabel, getNextItemNo, validateLocationForReceiveCase,getPartAttributeInfo } from "@/api/po/po.js";
  182. export default {
  183. data() {
  184. return {
  185. processFlag: 1,
  186. scanCode: '',
  187. poList: [],
  188. recvItem: {},
  189. handlingUnit: [],
  190. hanlingItem: { code: '', qty: '', perQty: '', packageQty: '' },
  191. site:localStorage.getItem('site'),
  192. warehouseId:localStorage.getItem('selectedWarehouse'),
  193. fullscreenLoading: false, // 控制全屏loading
  194. loadingText: '加载中...', // 动态loading文本
  195. autoCalculate: true // 自动计算包装数开关
  196. };
  197. },
  198. computed: {
  199. totalQty() {
  200. // 使用整数运算避免浮点数精度问题
  201. const sumInCents = this.handlingUnit.reduce((sum, item) => {
  202. return sum + Math.round(Number(item.qty) * 10000);
  203. }, 0);
  204. const sum = sumInCents / 10000;
  205. this.recvItem.transQty = sum;
  206. return sum;
  207. },
  208. huKey() {
  209. return `hu_${this.recvItem.poNumber}_${this.recvItem.lineNo}`;
  210. },
  211. displayLineWdr() {
  212. return `${this.recvItem.lineNo || ''}/${this.recvItem.releaseNo}`;
  213. }
  214. },
  215. watch: {
  216. // 监听自动计算开关变化
  217. autoCalculate(newVal, oldVal) {
  218. // 切换模式时清空输入框和HU列表
  219. this.hanlingItem.perQty = '';
  220. this.hanlingItem.packageQty = '';
  221. this.handlingUnit = [];
  222. localStorage.setItem(this.huKey, JSON.stringify(this.handlingUnit));
  223. if (newVal) {
  224. this.$message.success('已切换到自动创建HU模式');
  225. } else {
  226. this.$message.success('已切换到手动输入模式');
  227. }
  228. }
  229. },
  230. methods: {
  231. // 计算“显示宽度”
  232. getTextWidth(text) {
  233. if (!text) return 0
  234. let len = 0
  235. for (let char of text) {
  236. // 中文、全角符号
  237. if (/[\u4e00-\u9fa5\u3000-\u303F\uFF00-\uFFEF]/.test(char)) {
  238. len += 2
  239. } else {
  240. len += 1
  241. }
  242. }
  243. return len
  244. },
  245. handleBack() {
  246. if (this.processFlag === 1) this.$router.back();
  247. else if (this.processFlag === 3) this.processFlag = 2;
  248. else this.processFlag = 1;
  249. },
  250. searchPoList() {
  251. if (!this.scanCode) return this.poList = [];
  252. // 开始搜索时显示loading
  253. this.loadingText = '搜索中...';
  254. this.fullscreenLoading = true;
  255. getPoList({ poNumber: this.scanCode,site: this.site+'%' }).then(({ data }) => {
  256. if (data.code === 0) {
  257. /*let subSiteCodeList = localStorage.getItem('userSubSiteCodeList') ;
  258. let subSiteCodeList2 = this.$store.state.user.subSiteCodeList;*/
  259. this.poList = data.rows
  260. } else {
  261. this.$message.error(data.msg || '操作失败');
  262. }
  263. // 搜索完成后让输入框失去焦点
  264. this.$nextTick(() => {
  265. if (this.$refs.scanCodeRef) {
  266. this.$refs.scanCodeRef.blur();
  267. }
  268. });
  269. }).catch(error => {
  270. console.error('搜索失败:', error);
  271. this.$message.error('搜索失败,请重试');
  272. }).finally(() => {
  273. // 搜索完成后关闭loading
  274. this.fullscreenLoading = false;
  275. });
  276. },
  277. async recvLine(row) {
  278. if (row.authorizationRequired=='TRUE') {
  279. return this.$message.warning("该采购订单需要审核,无法接收");
  280. }
  281. if (row.receiveCaseDB!='INVDIR' && row.receiveCaseDB!='QAINV' && row.receiveCaseDB!='ARRINV') {
  282. return this.$message.warning("该采购订单行的收货方式为"+row.receiveCase+",无法接收");
  283. }
  284. if (row.poStatus === 'Stopped' || row.poStatus === 'Closed' || row.poStatus === 'Cancelled' || row.poStatus === 'Planned') {
  285. return this.$message.warning("该采购订单状态为"+row.poStatus+",无法接收");
  286. }
  287. if (row.status === 'Stopped' || row.status === 'Closed' || row.status === 'Cancelled') {
  288. return this.$message.warning("该采购订单行状态为"+row.status+",无法接收");
  289. }
  290. if (row.convFactor !== 1) {
  291. return this.$message.warning("采购计量单位和库存计量单位不一致,无法接收");
  292. }
  293. // 获取下一个itemNo
  294. let nextItemNo = 1;
  295. try {
  296. const { data } = await getNextItemNo({
  297. orderNo: row.orderNo,
  298. lineNo: row.lineNo,
  299. releaseNo: row.releaseNo || ''
  300. });
  301. if (data.code === 0) {
  302. nextItemNo = data.data;
  303. }
  304. } catch (error) {
  305. console.error('获取itemNo失败:', error);
  306. // 失败时使用默认值1
  307. }
  308. let site = this.site;
  309. let partNo = row.partNo;
  310. let height = '';
  311. let locationNo = '';
  312. try {
  313. const { data } = await getPartAttributeInfo({ site, partNo });
  314. if (data.code === 0) {
  315. height = data.data.height;
  316. if (data.partDefLoc && data.partDefLoc.length > 0) {
  317. locationNo = data.partDefLoc[0].warehouse==='INK'?data.partDefLoc[0].locationNo:'';
  318. }
  319. }
  320. } catch (error) {
  321. console.error('获取物料高度失败:', error);
  322. }
  323. this.recvItem = {
  324. ...row,
  325. poNo: row.orderNo || this.scanCode,
  326. dueinQty: row.qtyToReceive || row.invQtyToReceive,
  327. transQty: '',
  328. itemNo: nextItemNo,
  329. batchNo: row.orderNo+'-'+row.lineNo+'-'+row.releaseNo+'-'+nextItemNo,
  330. deliveryDate: row.plannedDeliveryDate || '',
  331. arrivalDate: this.getCurrentDate(),
  332. supplierManufactureDate: row.supplierManufactureDate || '',
  333. supplierBatchNo: row.supplierBatchNo || '',
  334. deliveryNote: row.deliveryNote || '',
  335. wdr:"*",
  336. height: height,
  337. locationNo: locationNo
  338. };
  339. this.processFlag = 2;
  340. },
  341. // 获取当前日期
  342. getCurrentDate() {
  343. const now = new Date();
  344. return now.getFullYear() + '-' +
  345. String(now.getMonth() + 1).padStart(2, '0') + '-' +
  346. String(now.getDate()).padStart(2, '0') + ' ' +
  347. String(now.getHours()).padStart(2, '0') + ':' +
  348. String(now.getMinutes()).padStart(2, '0') + ':' +
  349. String(now.getSeconds()).padStart(2, '0');
  350. },
  351. handlingUnitStep() {
  352. this.processFlag = 3;
  353. this.autoCalculate = false; // 默认使用手动输入模式
  354. const saved = localStorage.getItem(this.huKey);
  355. this.handlingUnit = saved ? JSON.parse(saved) : [];
  356. },
  357. /**
  358. * 自动创建HU列表自动模式
  359. */
  360. autoCreateHandlingUnits() {
  361. const perQty = this.hanlingItem.perQty;
  362. // 验证输入
  363. if (!perQty || isNaN(perQty) || parseFloat(perQty) <= 0) {
  364. this.$message.warning('请输入有效的单包装数量');
  365. return;
  366. }
  367. // 优先使用"此次接收数量",如果没有则使用"待收数量"
  368. let qtyToReceive = parseFloat(this.recvItem.transQty) || 0;
  369. if (qtyToReceive <= 0) {
  370. qtyToReceive = parseFloat(this.recvItem.qtyToReceive) || 0;
  371. }
  372. if (qtyToReceive <= 0) {
  373. this.$message.warning('待收数量为0,无法自动计算包装');
  374. this.hanlingItem.perQty = '';
  375. return;
  376. }
  377. const perQtyValue = parseFloat(perQty);
  378. // 计算需要多少个完整包装
  379. const packageQty = Math.floor(qtyToReceive / perQtyValue);
  380. // 计算余数(最后一个包装的数量)- 使用整数运算避免浮点数精度问题
  381. const remainderInCents = Math.round(qtyToReceive * 10000) - Math.round(perQtyValue * 10000) * packageQty;
  382. const remainder = remainderInCents / 10000;
  383. // 清空现有的HU列表
  384. this.handlingUnit = [];
  385. // 创建完整包装的HU
  386. if (packageQty > 0) {
  387. for (let i = 1; i <= packageQty; i++) {
  388. const qty = perQtyValue;
  389. const code = String(i);
  390. this.handlingUnit.push({
  391. code: code,
  392. perQty: perQtyValue,
  393. packageQty: 1,
  394. qty: qty
  395. });
  396. }
  397. }
  398. // 如果有余数,创建最后一个HU
  399. if (remainder > 0) {
  400. const code = String(this.handlingUnit.length + 1);
  401. this.handlingUnit.push({
  402. code: code,
  403. perQty: remainder,
  404. packageQty: 1,
  405. qty: remainder
  406. });
  407. }
  408. // 保存到localStorage
  409. localStorage.setItem(this.huKey, JSON.stringify(this.handlingUnit));
  410. // 清空输入框
  411. this.hanlingItem.perQty = '';
  412. this.hanlingItem.packageQty = '';
  413. this.$message.success(`自动创建了${this.handlingUnit.length}个HU,合计数量:${qtyToReceive}`);
  414. },
  415. /**
  416. * 手动创建HU手动模式
  417. */
  418. createHandlingUnit() {
  419. const { perQty, packageQty } = this.hanlingItem;
  420. if (!perQty || !packageQty || isNaN(perQty) || isNaN(packageQty)) {
  421. return this.$message.warning("请填写有效的包装信息");
  422. }
  423. // 使用整数运算避免浮点数精度问题
  424. const qty = Math.round(parseFloat(perQty) * 10000) * parseInt(packageQty) / 10000;
  425. const code = String(this.handlingUnit.length + 1);
  426. const newItem = { ...this.hanlingItem, qty, code };
  427. this.handlingUnit.push(newItem);
  428. localStorage.setItem(this.huKey, JSON.stringify(this.handlingUnit));
  429. // 创建HU后清空包装数和单包装数量
  430. this.hanlingItem.perQty = '';
  431. this.hanlingItem.packageQty = '';
  432. },
  433. removeItem(index) {
  434. this.handlingUnit.splice(index, 1);
  435. localStorage.setItem(this.huKey, JSON.stringify(this.handlingUnit));
  436. },
  437. // 清除所有handlingUnit缓存
  438. clearAllHandlingUnitCache() {
  439. this.hanlingItem = { code: '', qty: '', perQty: '', packageQty: '' };
  440. const keys = Object.keys(localStorage);
  441. keys.forEach(key => {
  442. if (key.startsWith('hu_')) {
  443. localStorage.removeItem(key);
  444. }
  445. });
  446. },
  447. // 校验库位
  448. async validateLocation() {
  449. if (!this.recvItem.locationNo || !this.recvItem.receiveCaseDB) {
  450. return;
  451. }
  452. try {
  453. const { data } = await validateLocationForReceiveCase({
  454. site: this.site,
  455. locationId: this.recvItem.locationNo,
  456. receiveCaseDB: this.recvItem.receiveCaseDB
  457. });
  458. if (data.code !== 0) {
  459. this.$message.error(data.msg || '库位校验失败');
  460. // 清空库位输入
  461. this.recvItem.locationNo = '';
  462. }
  463. } catch (error) {
  464. console.error('库位校验失败:', error);
  465. this.$message.error('库位校验失败,请重试');
  466. // 清空库位输入
  467. this.recvItem.locationNo = '';
  468. }
  469. },
  470. async receivePo() {
  471. const item = this.recvItem;
  472. if (item.transQty > item.qtyToReceive) {
  473. try {
  474. await this.$confirm(
  475. `本次入库数量(${item.transQty}) ,超过待收数量(${item.qtyToReceive}),是否继续?`,
  476. '数量超出提示',
  477. {
  478. confirmButtonText: '继续',
  479. cancelButtonText: '取消',
  480. type: 'warning'
  481. }
  482. );
  483. } catch (error) {
  484. // 用户取消
  485. return;
  486. }
  487. }
  488. if (this.fullscreenLoading) return; // 防止重复点
  489. this.loadingText = '提交中...';
  490. this.fullscreenLoading = true;
  491. if (!item.transQty || !item.locationNo || !item.batchNo) {
  492. this.fullscreenLoading = false;
  493. return this.$message.error("请填写完整信息");
  494. }
  495. if(item.qtyToReceive>item.qtyToReceive){
  496. this.fullscreenLoading = false;
  497. return this.$message.error("接收数量不能大于待收数量");
  498. }
  499. // 提交前再次校验库位
  500. try {
  501. const { data: validationData } = await validateLocationForReceiveCase({
  502. site: this.site,
  503. locationId: item.locationNo,
  504. receiveCaseDB: item.receiveCaseDB
  505. });
  506. if (validationData.code !== 0) {
  507. this.fullscreenLoading = false;
  508. return this.$message.error(validationData.msg || '库位校验失败');
  509. }
  510. } catch (error) {
  511. console.error('库位校验失败:', error);
  512. this.fullscreenLoading = false;
  513. return this.$message.error('库位校验失败,请重试');
  514. }
  515. // 构建符合服务端TransDetailDto结构的数据
  516. const receiveData = {
  517. // 基本字段
  518. site: item.contract,
  519. warehouseId: this.warehouseId,
  520. partNo: item.partNo,
  521. partDesc: item.description,
  522. transQty: item.transQty,
  523. batchNo: item.batchNo,
  524. locationNo: item.locationNo,
  525. itemNo: item.itemNo,
  526. wdr: item.wdr || '*',
  527. deliveryDate: item.deliveryDate,
  528. arrivalDate: item.arrivalDate,
  529. supplierBatchNo: item.supplierBatchNo,
  530. deliveryNote: item.deliveryNote,
  531. samplePercent: item.samplePercent || 0,
  532. sampleQty: item.sampleQty || 0,
  533. qtyToReceive: item.qtyToReceive,
  534. engChgLevel: item.engChgLevel,
  535. // PO相关字段
  536. poNo: item.poNumber || item.poNo,
  537. orderNo: item.orderNo,
  538. lineNo: item.lineNo,
  539. releaseNo: item.releaseNo,
  540. receiptNo: item.receiptNo,
  541. orderRef1: item.orderNo,
  542. supplierNo: item.supplierNo,
  543. purchaseUOM: item.purchaseUOM,
  544. receiveCase: item.receiveCase,
  545. receiveCaseDB: item.receiveCaseDB,
  546. inventoryPartDB: item.inventoryPartDB,
  547. // 业务控制字段
  548. needHandlingUnit: item.needHandlingUnit ,
  549. needCheck: item.needCheck ,
  550. warehouseType: item.warehouseType ,
  551. // 日期字段
  552. supplierManufactureDate: item.supplierManufactureDate,
  553. height: item.height,
  554. // 处理单元列表
  555. handlingUnitList: this.handlingUnit.map(hu => ({
  556. perQty: hu.perQty,
  557. packageQty: hu.packageQty
  558. }))
  559. };
  560. receivePo(receiveData).then(({ data }) => {
  561. if (data.code === 0) {
  562. this.$message.success("操作成功");
  563. this.clearAllHandlingUnitCache();
  564. let printLabelType;
  565. if (item.partNo && item.partNo.startsWith("80")) {
  566. printLabelType = '库存成品标签';
  567. } else {
  568. printLabelType = 'BIL标签';
  569. }
  570. this.printViaServer(data.data,item.needCheck,printLabelType); // 调用打印
  571. this.processFlag = 1;
  572. this.scanCode = '';
  573. this.poList = [];
  574. this.recvItem = {};
  575. this.handlingUnit = [];
  576. } else {
  577. this.$message.error(data.msg || '操作失败');
  578. }
  579. }).catch(error => {
  580. console.error('接收失败:', error);
  581. this.$message.error('网络错误,请重试');
  582. }).finally(() => {
  583. this.fullscreenLoading = false; // 结束后关闭loading
  584. });
  585. },
  586. /**
  587. * 通过服务器打印
  588. */
  589. async printViaServer(receiptNo,needCheck,printLabelType) {
  590. this.$emit('print-start')
  591. try {
  592. const printRequest = {
  593. reportId: this.reportId,
  594. zplCode: this.zplCode,
  595. paperSize: this.paperSize,
  596. orientation: this.orientation,
  597. dpi: this.dpi,
  598. userId: localStorage.getItem('userName'),
  599. username: localStorage.getItem('userName'),
  600. site: localStorage.getItem('site'),
  601. receiptNo: receiptNo,
  602. needCheck:needCheck,
  603. labelType:printLabelType
  604. }
  605. const { data } = await printLabel(printRequest)
  606. if (data.code === 200) {
  607. this.$message.success(`打印任务已发送!`)
  608. }
  609. } catch (error) {
  610. console.error('服务器打印失败:', error)
  611. this.$message.error(`打印失败: ${error.message || error}`)
  612. }
  613. },
  614. },
  615. mounted() {
  616. this.$nextTick(() => this.$refs.scanCodeRef.focus());
  617. },
  618. };
  619. </script>
  620. <style scoped>
  621. .mt10 {
  622. margin-top: 10px;
  623. }
  624. .scan-box input {
  625. width: 100%;
  626. padding: 12px;
  627. font-size: 16px;
  628. }
  629. .item-list {
  630. flex: 1;
  631. overflow-y: auto;
  632. margin: 10px 0;
  633. border: 1px solid rgba(200, 200, 200, 0.8);
  634. }
  635. .item-list span {
  636. color: #000;
  637. font-size: 15px;
  638. }
  639. .bottom-line-row {
  640. border-bottom: 1px solid rgba(200, 200, 200, 0.8);
  641. }
  642. .recvButton {
  643. font-size: 16px;
  644. border-radius: 3px;
  645. color: #17b3a3;
  646. }
  647. .item-list .el-row {
  648. cursor: pointer;
  649. transition: background 0.3s;
  650. }
  651. .item-list .el-row:hover {
  652. background: #f5f7fa;
  653. }
  654. .disabled-button {
  655. color: #ccc !important;
  656. cursor: not-allowed !important;
  657. }
  658. .form-section >>> .el-col {
  659. margin-bottom: 2px;
  660. }
  661. .status-bar {
  662. display: flex;
  663. justify-content: space-between;
  664. align-items: center;
  665. background: #17b3a3;
  666. color: white;
  667. }
  668. /* 自定义loading样式 */
  669. .pda-container >>> .el-loading-mask {
  670. background-color: rgba(255, 255, 255, 0.3) !important;
  671. }
  672. .pda-container >>> .el-loading-spinner {
  673. margin-top: -25px;
  674. }
  675. .pda-container >>> .el-loading-spinner .circular {
  676. width: 35px;
  677. height: 35px;
  678. }
  679. .pda-container >>> .el-loading-text {
  680. color: #17b3a3 !important;
  681. font-size: 14px;
  682. font-weight: 500;
  683. margin-top: 10px;
  684. }
  685. </style>