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.

882 lines
36 KiB

2 years ago
2 years 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
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
​
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1 year ago
1 month ago
1 year ago
​
1 year ago
​
​
​
1 year ago
10 months ago
3 weeks ago
​
​
​
​
​
​
​
​
​
​
1 year ago
​
​
​
1 year ago
​
​
2 years ago
1 year 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
1 year ago
​
1 year ago
​
​
1 year ago
1 year ago
​
​
​
​
1 year ago
​
​
​
​
1 year ago
​
​
​
​
​
2 years ago
​
​
​
​
​
3 months ago
1 year ago
2 years ago
​
​
1 year ago
2 years ago
1 year ago
1 year ago
​
​
1 year ago
1 year ago
1 year ago
1 year ago
3 weeks ago
​
​
​
1 year ago
2 years ago
​
​
10 months ago
​
9 months ago
10 months ago
9 months ago
1 year ago
​
1 year ago
1 year ago
1 year ago
​
​
1 year ago
3 weeks ago
​
​
​
​
1 year ago
2 years ago
1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1 year ago
​
2 years ago
1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
1 year ago
​
​
​
​
1 year ago
1 year ago
1 year ago
1 year ago
​
​
3 months ago
1 year ago
3 months ago
​
​
3 months ago
​
​
​
1 year ago
​
​
​
​
​
​
​
1 year ago
​
​
​
​
​
1 year ago
​
1 year ago
​
​
​
1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1 year ago
​
​
10 months 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
​
​
​
1 year ago
1 year ago
​
​
1 year ago
​
​
1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1 year ago
​
​
​
​
​
​
​
​
​
1 year ago
​
10 months ago
1 year ago
​
​
1 year ago
​
​
​
​
​
​
​
​
​
​
​
10 months ago
​
1 year ago
10 months ago
​
9 months ago
10 months ago
​
1 year ago
​
​
​
​
​
​
​
10 months ago
9 months ago
​
1 year ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
1 year ago
​
​
​
1 year ago
10 months ago
9 months ago
1 year ago
​
​
​
​
​
1 year ago
1 year ago
​
​
2 years ago
​
​
​
​
​
​
​
​
​
3 weeks 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
​
​
​
​
​
​
1 year ago
1 year ago
​
​
​
​
​
​
​
​
​
1 year ago
​
​
3 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
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
​
3 weeks ago
​
​
​
​
​
​
4 weeks ago
1 year ago
​
​
​
​
1 year ago
1 year ago
1 year ago
1 year ago
​
​
1 year ago
​
1 year ago
​
​
​
4 weeks ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 weeks ago
1 year ago
​
​
​
4 weeks ago
​
​
​
​
​
2 years ago
​
3 weeks ago
1 year ago
1 year ago
2 years ago
​
​
1 year ago
​
​
2 years ago
​
​
​
​
​
​
​
1 year ago
1 year ago
1 year ago
​
1 year ago
1 year ago
2 years ago
1 year ago
​
2 years 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
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years 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="8"><el-form-item label="送货单信息">
  80. <el-input v-model="recvItem.deliveryNote" />
  81. </el-form-item></el-col>
  82. <el-col :span="10"><el-form-item label="失效日期">
  83. <el-date-picker v-model="recvItem.expiredDate" 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-date-picker v-model="recvItem.supplierManufactureDate" type="date" format="yyyy-MM-dd"
  92. value-format="yyyy-MM-dd" placeholder="请选择" style="width: 100%"
  93. inputmode="none"
  94. autocomplete="off"
  95. autocorrect="off"
  96. spellcheck="false" />
  97. </el-form-item></el-col>
  98. <el-col :span="12"><el-form-item label="供应商批次号">
  99. <el-input v-model="recvItem.supplierBatchNo" placeholder="请输入供应商批次号" />
  100. </el-form-item></el-col>
  101. <el-col :span="12"><el-form-item label="WDR">
  102. <el-input v-model="recvItem.wdr" placeholder="请输入WDR" />
  103. </el-form-item></el-col>
  104. <el-col :span="12"><el-form-item label="到达日期">
  105. <el-date-picker v-model="recvItem.arrivalDate" type="datetime" format="yyyy-MM-dd HH:mm:ss"
  106. value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择到达日期" style="width: 100%"
  107. inputmode="none"
  108. autocomplete="off"
  109. autocorrect="off"
  110. spellcheck="false" />
  111. </el-form-item></el-col>
  112. <el-col :span="12"><el-form-item label="库位">
  113. <el-autocomplete
  114. v-model.trim="recvItem.locationNo"
  115. :fetch-suggestions="querySearchLocation"
  116. placeholder="请输入库位"
  117. :trigger-on-focus="true"
  118. clearable
  119. style="width: 100%;"
  120. @select="handleLocationSelect"
  121. @blur="handleLocationBlur"
  122. />
  123. </el-form-item></el-col>
  124. <el-col :span="12"><el-form-item label="批号"><el-input v-model="recvItem.batchNo" placeholder="请输入批号" /></el-form-item></el-col>
  125. <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>
  126. <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>
  127. <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>
  128. </el-row>
  129. </el-form>
  130. </div>
  131. <!-- Step 3: 包装记录 -->
  132. <div v-if="processFlag === 3">
  133. <el-form label-position="top" class="form-section" style="margin: 5px;">
  134. <el-row :gutter="20">
  135. <el-col :span="12"><el-form-item label="商品编码"><el-input v-model="recvItem.partNo" disabled /></el-form-item></el-col>
  136. <el-col :span="12"><el-form-item label="待收数量"><el-input v-model="recvItem.qtyToReceive" disabled /></el-form-item></el-col>
  137. <el-col :span="24"><el-form-item label="商品名称"><el-input v-model="recvItem.description" disabled /></el-form-item></el-col>
  138. <!-- 自动计算开关 -->
  139. <el-col :span="24" style="margin-bottom: 10px;">
  140. <el-form-item>
  141. <el-switch
  142. v-model="autoCalculate"
  143. active-text="自动计算模式"
  144. inactive-text="手动输入模式"
  145. active-color="#17B3A3"
  146. style="display: block;"
  147. >
  148. </el-switch>
  149. <span v-if="autoCalculate" style="font-size: 13px; color: #17B3A3; margin-top: 5px; display: block; font-weight: bold;">
  150. 💡 输入单包装数量后按回车,将根据待收数量自动分配包装
  151. </span>
  152. <span v-else style="font-size: 12px; color: #999; margin-top: 5px; display: block;">
  153. 手动输入单包装数量和包装数,然后点击"创建"按钮
  154. </span>
  155. </el-form-item>
  156. </el-col>
  157. <el-col :span="8" style="margin-top: 5px"><el-form-item label="单包装数量">
  158. <el-input
  159. v-model="hanlingItem.perQty"
  160. type="number"
  161. :placeholder="autoCalculate ? '输入完按回车或失去焦点' : '请输入单包装数量'"
  162. @blur="autoCalculate && autoCreateHandlingUnits()"
  163. @keyup.enter.native="autoCalculate && autoCreateHandlingUnits()"
  164. />
  165. </el-form-item></el-col>
  166. <el-col :span="8" style="margin-top: 5px" v-if="!autoCalculate"><el-form-item label="包装数">
  167. <el-input v-model="hanlingItem.packageQty" type="number" placeholder="请输入包装数" />
  168. </el-form-item></el-col>
  169. <el-col :span="8" v-if="!autoCalculate" style="margin-top: 16px"><el-form-item>
  170. <el-button type="text" @click="createHandlingUnit" style="font-size: 16px">创建</el-button></el-form-item></el-col>
  171. <el-col :span="8" v-else style="margin-top: 16px"><el-form-item>
  172. <el-button type="text" style="font-size: 16px">确定</el-button></el-form-item></el-col>
  173. <el-table :data="handlingUnit" :row-style="{ height: '30px' }" style="width: 94%; margin-left: 10px;" highlight-current-row>
  174. <el-table-column prop="code" label="序号" />
  175. <el-table-column prop="packageQty" label="包装数" width="80" />
  176. <el-table-column prop="perQty" label="单包装数量" width="100" />
  177. <el-table-column label="操作" v-if="!autoCalculate">
  178. <template slot-scope="scope">
  179. <a @click="removeItem(scope.$index)">删除</a>
  180. </template>
  181. </el-table-column>
  182. </el-table>
  183. <el-col :span="24" v-if="autoCalculate && handlingUnit.length > 0" style="margin-top: 10px;">
  184. <span style="font-size: 12px; color: #999;">
  185. 💡 如需修改,请重新输入单包装数量
  186. </span>
  187. </el-col>
  188. <el-col :span="24"><el-form-item><span>合计</span><span style="margin-left: 38%">{{ totalQty }}</span></el-form-item></el-col>
  189. <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>
  190. <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>
  191. </el-row>
  192. </el-form>
  193. </div>
  194. </div>
  195. </div>
  196. </div>
  197. </template>
  198. <script>
  199. import { getPoList, receivePo, printLabel, getNextItemNo, validateLocationForReceiveCase, getPartAttributeInfo, getPartShelfLife } from "@/api/po/po.js";
  200. import { filterRowsByAuthorizedSubSite, getAuthorizedSubSiteCodeList } from "@/utils/subSiteAuth.js";
  201. export default {
  202. data() {
  203. return {
  204. processFlag: 1,
  205. scanCode: '',
  206. poList: [],
  207. recvItem: {},
  208. handlingUnit: [],
  209. hanlingItem: { code: '', qty: '', perQty: '', packageQty: '' },
  210. site:localStorage.getItem('site'),
  211. warehouseId:localStorage.getItem('selectedWarehouse'),
  212. fullscreenLoading: false, // 控制全屏loading
  213. loadingText: '加载中...', // 动态loading文本
  214. autoCalculate: true, // 自动计算包装数开关
  215. locationHistoryList: [],
  216. locationHistoryLimit: 20,
  217. // 上次参与计算的有效期和基准日。基准日没变时保留用户手改的失效日期。
  218. expiryBaseKey: ''
  219. };
  220. },
  221. computed: {
  222. totalQty() {
  223. // 使用整数运算避免浮点数精度问题
  224. const sumInCents = this.handlingUnit.reduce((sum, item) => {
  225. return sum + Math.round(Number(item.qty) * 10000);
  226. }, 0);
  227. const sum = sumInCents / 10000;
  228. this.recvItem.transQty = sum;
  229. return sum;
  230. },
  231. huKey() {
  232. return `hu_${this.recvItem.poNumber}_${this.recvItem.lineNo}`;
  233. },
  234. displayLineWdr() {
  235. return `${this.recvItem.lineNo || ''}/${this.recvItem.releaseNo}`;
  236. },
  237. locationHistoryKey() {
  238. // 按站点隔离,避免不同站点的库位混在同一份历史里。
  239. const site = this.site || 'defaultSite';
  240. return `recv_location_history_${site}`;
  241. }
  242. },
  243. watch: {
  244. // 监听自动计算开关变化
  245. autoCalculate(newVal, oldVal) {
  246. // 切换模式时清空输入框和HU列表
  247. this.hanlingItem.perQty = '';
  248. this.hanlingItem.packageQty = '';
  249. this.handlingUnit = [];
  250. localStorage.setItem(this.huKey, JSON.stringify(this.handlingUnit));
  251. if (newVal) {
  252. this.$message.success('已切换到自动创建HU模式');
  253. } else {
  254. this.$message.success('已切换到手动输入模式');
  255. }
  256. },
  257. // 基准日的日期变化后重算。只改到达时间不会覆盖已经手改的失效日期。
  258. 'recvItem.supplierManufactureDate'() {
  259. this.refreshExpiredDate();
  260. },
  261. 'recvItem.arrivalDate'() {
  262. this.refreshExpiredDate();
  263. }
  264. },
  265. methods: {
  266. // 计算“显示宽度”
  267. getTextWidth(text) {
  268. if (!text) return 0
  269. let len = 0
  270. for (let char of text) {
  271. // 中文、全角符号
  272. if (/[\u4e00-\u9fa5\u3000-\u303F\uFF00-\uFFEF]/.test(char)) {
  273. len += 2
  274. } else {
  275. len += 1
  276. }
  277. }
  278. return len
  279. },
  280. handleBack() {
  281. if (this.processFlag === 1) this.$router.back();
  282. else if (this.processFlag === 3) this.processFlag = 2;
  283. else this.processFlag = 1;
  284. },
  285. searchPoList() {
  286. if (!this.scanCode) return this.poList = [];
  287. // 开始搜索时显示loading
  288. this.loadingText = '搜索中...';
  289. this.fullscreenLoading = true;
  290. getPoList({ poNumber: this.scanCode,site: this.site+'%' }).then(({ data }) => {
  291. if (data.code === 0) {
  292. const sourceRows = data.rows || [];
  293. const authorizedSubSiteCodeList = getAuthorizedSubSiteCodeList(this.$store.state.user.subSiteCodeList);
  294. // 接口按site前缀查询会返回同前缀下的所有子site,这里按当前用户授权子site做二次过滤
  295. this.poList = filterRowsByAuthorizedSubSite(sourceRows, authorizedSubSiteCodeList, ['site']);
  296. if (this.poList.length === 0) {
  297. this.$message.warning('未找到匹配的采购订单或您没有权限查看');
  298. }
  299. } else {
  300. this.$message.error(data.msg || '操作失败');
  301. }
  302. // 搜索完成后让输入框失去焦点
  303. this.$nextTick(() => {
  304. if (this.$refs.scanCodeRef) {
  305. this.$refs.scanCodeRef.blur();
  306. }
  307. });
  308. }).catch(error => {
  309. console.error('搜索失败:', error);
  310. this.$message.error('搜索失败,请重试');
  311. }).finally(() => {
  312. // 搜索完成后关闭loading
  313. this.fullscreenLoading = false;
  314. });
  315. },
  316. async recvLine(row) {
  317. if (row.authorizationRequired=='TRUE') {
  318. return this.$message.warning("该采购订单需要审核,无法接收");
  319. }
  320. // ARRQA 是到货后转质检,和 INVDIR/QAINV/ARRINV 一样允许在 PDA 接收
  321. if (row.receiveCaseDB!='INVDIR' && row.receiveCaseDB!='QAINV' && row.receiveCaseDB!='ARRINV' && row.receiveCaseDB!='ARRQA') {
  322. return this.$message.warning("该采购订单行的收货方式为"+row.receiveCase+",无法接收");
  323. }
  324. if (row.poStatus === 'Stopped' || row.poStatus === 'Closed' || row.poStatus === 'Cancelled' || row.poStatus === 'Planned') {
  325. return this.$message.warning("该采购订单状态为"+row.poStatus+",无法接收");
  326. }
  327. if (row.status === 'Stopped' || row.status === 'Closed' || row.status === 'Cancelled') {
  328. return this.$message.warning("该采购订单行状态为"+row.status+",无法接收");
  329. }
  330. if (row.convFactor !== 1) {
  331. return this.$message.warning("采购计量单位和库存计量单位不一致,无法接收");
  332. }
  333. // 获取下一个itemNo
  334. let nextItemNo = 1;
  335. try {
  336. const { data } = await getNextItemNo({
  337. orderNo: row.orderNo,
  338. lineNo: row.lineNo,
  339. releaseNo: row.releaseNo || ''
  340. });
  341. if (data.code === 0) {
  342. nextItemNo = data.data;
  343. }
  344. } catch (error) {
  345. console.error('获取itemNo失败:', error);
  346. // 失败时使用默认值1
  347. }
  348. let site = this.site;
  349. let partNo = row.partNo;
  350. let height = '';
  351. let locationNo = '';
  352. try {
  353. const { data } = await getPartAttributeInfo({ site, partNo });
  354. if (data.code === 0) {
  355. height = data.data.height;
  356. if (data.partDefLoc && data.partDefLoc.length > 0) {
  357. locationNo = data.partDefLoc[0].warehouse==='INK'?data.partDefLoc[0].locationNo:'';
  358. }
  359. }
  360. } catch (error) {
  361. console.error('获取物料高度失败:', error);
  362. }
  363. this.recvItem = {
  364. ...row,
  365. poNo: row.orderNo || this.scanCode,
  366. dueinQty: row.qtyToReceive || row.invQtyToReceive,
  367. transQty: '',
  368. itemNo: nextItemNo,
  369. batchNo: row.orderNo+'-'+row.lineNo+'-'+row.releaseNo+'-'+nextItemNo,
  370. deliveryDate: row.plannedDeliveryDate || '',
  371. arrivalDate: this.getCurrentDate(),
  372. supplierManufactureDate: row.supplierManufactureDate || '',
  373. supplierBatchNo: row.supplierBatchNo || '',
  374. deliveryNote: row.deliveryNote || '',
  375. wdr:"*",
  376. height: height,
  377. locationNo: locationNo,
  378. durabilityDays: null,
  379. expiredDate: ''
  380. };
  381. // 换行后按新的基准日重算,不沿用上一行的手改结果
  382. this.expiryBaseKey = '';
  383. await this.loadShelfLifeAndExpiredDate(row.site, row.partNo);
  384. this.processFlag = 2;
  385. },
  386. async loadShelfLifeAndExpiredDate(site, partNo) {
  387. this.loadingText = '加载中...';
  388. this.fullscreenLoading = true;
  389. try {
  390. const { data } = await getPartShelfLife({ site, partNo });
  391. if (data.code === 0 && data.data) {
  392. this.recvItem.durabilityDays = data.data;
  393. this.refreshExpiredDate();
  394. } else {
  395. this.$message.warning(data.msg || '请联系工程维护产品有效期!');
  396. }
  397. } catch (error) {
  398. console.error('获取产品有效期失败:', error);
  399. this.$message.warning('获取产品有效期失败,请重试');
  400. } finally {
  401. this.fullscreenLoading = false;
  402. }
  403. },
  404. // 和后端原口径一致:有供应商生产日期就用它,否则用到达日期,再加有效期天数。
  405. // 只比较日期部分。到达时间变了但日期没变时,不覆盖用户手改的失效日期。
  406. refreshExpiredDate() {
  407. const item = this.recvItem;
  408. const days = Number(item && item.durabilityDays);
  409. if (!days) return;
  410. const supplierDate = (item.supplierManufactureDate || '').toString().trim();
  411. const arrivalDate = (item.arrivalDate || '').toString().trim();
  412. const baseDate = supplierDate || arrivalDate;
  413. const baseDay = baseDate ? baseDate.substring(0, 10) : '';
  414. const baseKey = `${days}|${baseDay}`;
  415. if (this.expiryBaseKey === baseKey) return;
  416. this.expiryBaseKey = baseKey;
  417. item.expiredDate = baseDate ? this.addDays(baseDate, days) : '';
  418. },
  419. addDays(dateText, days) {
  420. const matched = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(dateText).trim());
  421. if (!matched) return '';
  422. const date = new Date(Number(matched[1]), Number(matched[2]) - 1, Number(matched[3]));
  423. date.setDate(date.getDate() + Number(days));
  424. const month = String(date.getMonth() + 1).padStart(2, '0');
  425. const day = String(date.getDate()).padStart(2, '0');
  426. return `${date.getFullYear()}-${month}-${day}`;
  427. },
  428. isDateBeforeToday(dateText) {
  429. const day = (dateText || '').toString().trim().substring(0, 10);
  430. if (!/^\d{4}-\d{2}-\d{2}$/.test(day)) return true;
  431. const now = new Date();
  432. const today = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`;
  433. return day < today;
  434. },
  435. // 获取当前日期
  436. getCurrentDate() {
  437. const now = new Date();
  438. return now.getFullYear() + '-' +
  439. String(now.getMonth() + 1).padStart(2, '0') + '-' +
  440. String(now.getDate()).padStart(2, '0') + ' ' +
  441. String(now.getHours()).padStart(2, '0') + ':' +
  442. String(now.getMinutes()).padStart(2, '0') + ':' +
  443. String(now.getSeconds()).padStart(2, '0');
  444. },
  445. handlingUnitStep() {
  446. this.processFlag = 3;
  447. this.autoCalculate = false; // 默认使用手动输入模式
  448. const saved = localStorage.getItem(this.huKey);
  449. this.handlingUnit = saved ? JSON.parse(saved) : [];
  450. },
  451. /**
  452. * 自动创建HU列表(自动模式)
  453. */
  454. autoCreateHandlingUnits() {
  455. const perQty = this.hanlingItem.perQty;
  456. // 验证输入
  457. if (!perQty || isNaN(perQty) || parseFloat(perQty) <= 0) {
  458. this.$message.warning('请输入有效的单包装数量');
  459. return;
  460. }
  461. // 优先使用"此次接收数量",如果没有则使用"待收数量"
  462. let qtyToReceive = parseFloat(this.recvItem.transQty) || 0;
  463. if (qtyToReceive <= 0) {
  464. qtyToReceive = parseFloat(this.recvItem.qtyToReceive) || 0;
  465. }
  466. if (qtyToReceive <= 0) {
  467. this.$message.warning('待收数量为0,无法自动计算包装');
  468. this.hanlingItem.perQty = '';
  469. return;
  470. }
  471. const perQtyValue = parseFloat(perQty);
  472. // 计算需要多少个完整包装
  473. const packageQty = Math.floor(qtyToReceive / perQtyValue);
  474. // 计算余数(最后一个包装的数量)- 使用整数运算避免浮点数精度问题
  475. const remainderInCents = Math.round(qtyToReceive * 10000) - Math.round(perQtyValue * 10000) * packageQty;
  476. const remainder = remainderInCents / 10000;
  477. // 清空现有的HU列表
  478. this.handlingUnit = [];
  479. // 创建完整包装的HU
  480. if (packageQty > 0) {
  481. for (let i = 1; i <= packageQty; i++) {
  482. const qty = perQtyValue;
  483. const code = String(i);
  484. this.handlingUnit.push({
  485. code: code,
  486. perQty: perQtyValue,
  487. packageQty: 1,
  488. qty: qty
  489. });
  490. }
  491. }
  492. // 如果有余数,创建最后一个HU
  493. if (remainder > 0) {
  494. const code = String(this.handlingUnit.length + 1);
  495. this.handlingUnit.push({
  496. code: code,
  497. perQty: remainder,
  498. packageQty: 1,
  499. qty: remainder
  500. });
  501. }
  502. // 保存到localStorage
  503. localStorage.setItem(this.huKey, JSON.stringify(this.handlingUnit));
  504. // 清空输入框
  505. this.hanlingItem.perQty = '';
  506. this.hanlingItem.packageQty = '';
  507. this.$message.success(`自动创建了${this.handlingUnit.length}个HU,合计数量:${qtyToReceive}`);
  508. },
  509. /**
  510. * 手动创建HU(手动模式)
  511. */
  512. createHandlingUnit() {
  513. const { perQty, packageQty } = this.hanlingItem;
  514. if (!perQty || !packageQty || isNaN(perQty) || isNaN(packageQty)) {
  515. return this.$message.warning("请填写有效的包装信息");
  516. }
  517. // 使用整数运算避免浮点数精度问题
  518. const qty = Math.round(parseFloat(perQty) * 10000) * parseInt(packageQty) / 10000;
  519. const code = String(this.handlingUnit.length + 1);
  520. const newItem = { ...this.hanlingItem, qty, code };
  521. this.handlingUnit.push(newItem);
  522. localStorage.setItem(this.huKey, JSON.stringify(this.handlingUnit));
  523. // 创建HU后清空包装数和单包装数量
  524. this.hanlingItem.perQty = '';
  525. this.hanlingItem.packageQty = '';
  526. },
  527. removeItem(index) {
  528. this.handlingUnit.splice(index, 1);
  529. localStorage.setItem(this.huKey, JSON.stringify(this.handlingUnit));
  530. },
  531. // 清除所有handlingUnit缓存
  532. clearAllHandlingUnitCache() {
  533. this.hanlingItem = { code: '', qty: '', perQty: '', packageQty: '' };
  534. const keys = Object.keys(localStorage);
  535. keys.forEach(key => {
  536. if (key.startsWith('hu_')) {
  537. localStorage.removeItem(key);
  538. }
  539. });
  540. },
  541. loadLocationHistory() {
  542. const rawHistory = localStorage.getItem(this.locationHistoryKey);
  543. if (!rawHistory) {
  544. this.locationHistoryList = [];
  545. return;
  546. }
  547. try {
  548. const parsedHistory = JSON.parse(rawHistory);
  549. if (!Array.isArray(parsedHistory)) {
  550. this.locationHistoryList = [];
  551. return;
  552. }
  553. this.locationHistoryList = parsedHistory
  554. .map(item => (item || '').toString().trim())
  555. .filter((item, index, arr) => item && arr.indexOf(item) === index)
  556. .slice(0, this.locationHistoryLimit);
  557. } catch (error) {
  558. console.warn('解析库位历史缓存失败:', error);
  559. this.locationHistoryList = [];
  560. }
  561. },
  562. querySearchLocation(queryString, cb) {
  563. const normalizedKeyword = (queryString || '').trim().toLowerCase();
  564. const historyOptions = this.locationHistoryList.map(location => ({ value: location }));
  565. const result = normalizedKeyword
  566. ? historyOptions.filter(item => item.value.toLowerCase().includes(normalizedKeyword))
  567. : historyOptions;
  568. cb(result);
  569. },
  570. handleLocationSelect(selectedItem) {
  571. // 选中历史值后立即置顶,保证高频库位下次优先展示。
  572. this.saveLocationHistory(selectedItem && selectedItem.value);
  573. },
  574. handleLocationBlur() {
  575. // 失焦即缓存,覆盖“手输后直接切换焦点”的场景。
  576. this.saveLocationHistory(this.recvItem.locationNo);
  577. },
  578. saveLocationHistory(locationNo) {
  579. const normalizedLocation = (locationNo || '').trim();
  580. if (!normalizedLocation) return;
  581. const dedupedHistory = [normalizedLocation, ...this.locationHistoryList.filter(item => item !== normalizedLocation)]
  582. .slice(0, this.locationHistoryLimit);
  583. this.locationHistoryList = dedupedHistory;
  584. localStorage.setItem(this.locationHistoryKey, JSON.stringify(dedupedHistory));
  585. },
  586. // 校验库位
  587. async validateLocation() {
  588. if (!this.recvItem.locationNo || !this.recvItem.receiveCaseDB) {
  589. return;
  590. }
  591. try {
  592. const { data } = await validateLocationForReceiveCase({
  593. site: this.site,
  594. locationId: this.recvItem.locationNo,
  595. receiveCaseDB: this.recvItem.receiveCaseDB
  596. });
  597. if (data.code !== 0) {
  598. this.$message.error(data.msg || '库位校验失败');
  599. // 清空库位输入
  600. this.recvItem.locationNo = '';
  601. }
  602. } catch (error) {
  603. console.error('库位校验失败:', error);
  604. this.$message.error('库位校验失败,请重试');
  605. // 清空库位输入
  606. this.recvItem.locationNo = '';
  607. }
  608. },
  609. async receivePo() {
  610. const item = this.recvItem;
  611. if (item.transQty > item.qtyToReceive) {
  612. try {
  613. await this.$confirm(
  614. `本次入库数量(${item.transQty}) ,超过待收数量(${item.qtyToReceive}),是否继续?`,
  615. '数量超出提示',
  616. {
  617. confirmButtonText: '继续',
  618. cancelButtonText: '取消',
  619. type: 'warning'
  620. }
  621. );
  622. } catch (error) {
  623. // 用户取消
  624. return;
  625. }
  626. }
  627. if (this.fullscreenLoading) return; // 防止重复点
  628. this.loadingText = '提交中...';
  629. this.fullscreenLoading = true;
  630. if (!item.transQty || !item.locationNo || !item.batchNo) {
  631. this.fullscreenLoading = false;
  632. return this.$message.error("请填写完整信息");
  633. }
  634. if (!item.expiredDate) {
  635. this.fullscreenLoading = false;
  636. return this.$message.error("失效日期不能为空");
  637. }
  638. if (this.isDateBeforeToday(item.expiredDate)) {
  639. this.fullscreenLoading = false;
  640. return this.$message.error("失效日期早于当前日期,不能入库");
  641. }
  642. if(item.qtyToReceive>item.qtyToReceive){
  643. this.fullscreenLoading = false;
  644. return this.$message.error("接收数量不能大于待收数量");
  645. }
  646. // 提交前再次校验库位
  647. try {
  648. const { data: validationData } = await validateLocationForReceiveCase({
  649. site: this.site,
  650. locationId: item.locationNo,
  651. receiveCaseDB: item.receiveCaseDB
  652. });
  653. if (validationData.code !== 0) {
  654. this.fullscreenLoading = false;
  655. return this.$message.error(validationData.msg || '库位校验失败');
  656. }
  657. } catch (error) {
  658. console.error('库位校验失败:', error);
  659. this.fullscreenLoading = false;
  660. return this.$message.error('库位校验失败,请重试');
  661. }
  662. // 构建符合服务端TransDetailDto结构的数据
  663. const receiveData = {
  664. // 基本字段
  665. site: item.site,
  666. fuSite: localStorage.getItem('site'),
  667. warehouseId: this.warehouseId,
  668. partNo: item.partNo,
  669. partDesc: item.description,
  670. transQty: item.transQty,
  671. batchNo: item.batchNo,
  672. locationNo: item.locationNo,
  673. itemNo: item.itemNo,
  674. wdr: item.wdr || '*',
  675. deliveryDate: item.deliveryDate,
  676. arrivalDate: item.arrivalDate,
  677. expiredDate: item.expiredDate,
  678. supplierBatchNo: item.supplierBatchNo,
  679. deliveryNote: item.deliveryNote,
  680. samplePercent: item.samplePercent || 0,
  681. sampleQty: item.sampleQty || 0,
  682. qtyToReceive: item.qtyToReceive,
  683. engChgLevel: item.engChgLevel,
  684. // PO相关字段
  685. poNo: item.poNumber || item.poNo,
  686. orderNo: item.orderNo,
  687. lineNo: item.lineNo,
  688. releaseNo: item.releaseNo,
  689. receiptNo: item.receiptNo,
  690. orderRef1: item.orderNo,
  691. supplierNo: item.supplierNo,
  692. purchaseUOM: item.purchaseUOM,
  693. receiveCase: item.receiveCase,
  694. receiveCaseDB: item.receiveCaseDB,
  695. inventoryPartDB: item.inventoryPartDB,
  696. // 业务控制字段
  697. needHandlingUnit: item.needHandlingUnit ,
  698. needCheck: item.needCheck ,
  699. warehouseType: item.warehouseType ,
  700. // 日期字段
  701. supplierManufactureDate: item.supplierManufactureDate,
  702. height: item.height,
  703. // 处理单元列表
  704. handlingUnitList: this.handlingUnit.map(hu => ({
  705. perQty: hu.perQty,
  706. packageQty: hu.packageQty
  707. }))
  708. };
  709. receivePo(receiveData).then(({ data }) => {
  710. if (data.code === 0) {
  711. this.$message.success("操作成功");
  712. // 提交成功后再记一次,避免只填了默认库位、未失焦就保存时漏记。
  713. this.saveLocationHistory(item.locationNo);
  714. this.clearAllHandlingUnitCache();
  715. let printLabelType;
  716. if (item.partNo && item.partNo.startsWith("80")) {
  717. printLabelType = '库存成品标签';
  718. } else {
  719. printLabelType = 'BIL标签';
  720. }
  721. this.printViaServer(data.data, item.needCheck, printLabelType, receiveData.site); // 使用本次接收站点打印
  722. this.processFlag = 1;
  723. this.scanCode = '';
  724. this.poList = [];
  725. this.recvItem = {};
  726. this.handlingUnit = [];
  727. } else {
  728. this.$message.error(data.msg || '操作失败');
  729. }
  730. }).catch(error => {
  731. console.error('接收失败:', error);
  732. this.$message.error('网络错误,请重试');
  733. }).finally(() => {
  734. this.fullscreenLoading = false; // 结束后关闭loading
  735. });
  736. },
  737. /**
  738. * 通过服务器打印
  739. */
  740. async printViaServer(receiptNo, needCheck, printLabelType, site) {
  741. if (!site || !receiptNo) {
  742. this.$message.error('接收成功,但缺少接收站点或接收单号,无法打印标签')
  743. return
  744. }
  745. this.$emit('print-start')
  746. try {
  747. const printRequest = {
  748. reportId: this.reportId,
  749. zplCode: this.zplCode,
  750. paperSize: this.paperSize,
  751. orientation: this.orientation,
  752. dpi: this.dpi,
  753. userId: localStorage.getItem('userName'),
  754. username: localStorage.getItem('userName'),
  755. site: localStorage.getItem('site'),
  756. subSite: site,
  757. receiptNo: receiptNo,
  758. needCheck:needCheck,
  759. labelType:printLabelType
  760. }
  761. const { data } = await printLabel(printRequest)
  762. if (data.code === 200) {
  763. this.$message.success(`打印任务已发送!`)
  764. } else {
  765. this.$message.error(data.msg || '接收成功,但标签打印失败,请补打标签')
  766. }
  767. } catch (error) {
  768. console.error('服务器打印失败:', error)
  769. this.$message.error(`打印失败: ${error.message || error}`)
  770. }
  771. },
  772. },
  773. mounted() {
  774. this.loadLocationHistory();
  775. this.$nextTick(() => this.$refs.scanCodeRef.focus());
  776. },
  777. };
  778. </script>
  779. <style scoped>
  780. .mt10 {
  781. margin-top: 10px;
  782. }
  783. .scan-box input {
  784. width: 100%;
  785. padding: 12px;
  786. font-size: 16px;
  787. }
  788. .item-list {
  789. flex: 1;
  790. overflow-y: auto;
  791. margin: 10px 0;
  792. border: 1px solid rgba(200, 200, 200, 0.8);
  793. }
  794. .item-list span {
  795. color: #000;
  796. font-size: 15px;
  797. }
  798. .bottom-line-row {
  799. border-bottom: 1px solid rgba(200, 200, 200, 0.8);
  800. }
  801. .recvButton {
  802. font-size: 16px;
  803. border-radius: 3px;
  804. color: #17b3a3;
  805. }
  806. .item-list .el-row {
  807. cursor: pointer;
  808. transition: background 0.3s;
  809. }
  810. .item-list .el-row:hover {
  811. background: #f5f7fa;
  812. }
  813. .disabled-button {
  814. color: #ccc !important;
  815. cursor: not-allowed !important;
  816. }
  817. .form-section >>> .el-date-editor.el-input {
  818. width: 100%;
  819. }
  820. .form-section >>> .el-date-editor .el-input__inner {
  821. padding-left: 8px;
  822. padding-right: 26px;
  823. }
  824. .status-bar {
  825. display: flex;
  826. justify-content: space-between;
  827. align-items: center;
  828. background: #17b3a3;
  829. color: white;
  830. }
  831. /* 自定义loading样式 */
  832. .pda-container >>> .el-loading-mask {
  833. background-color: rgba(255, 255, 255, 0.3) !important;
  834. }
  835. .pda-container >>> .el-loading-spinner {
  836. margin-top: -25px;
  837. }
  838. .pda-container >>> .el-loading-spinner .circular {
  839. width: 35px;
  840. height: 35px;
  841. }
  842. .pda-container >>> .el-loading-text {
  843. color: #17b3a3 !important;
  844. font-size: 14px;
  845. font-weight: 500;
  846. margin-top: 10px;
  847. }
  848. </style>