Commit 2e2af2c947f7e4b04383fffb4646f7dd00f89718
1 parent
2637c528
修改一堆问题,太多了
Showing
2 changed files
with
143 additions
and
77 deletions
Antis.Erp.Plat/antis-ncc-admin/src/views/wtXsckd/Form.vue
| ... | ... | @@ -290,7 +290,7 @@ |
| 290 | 290 | <el-table-column prop="selectedSerialNumbers" label="选择序列号" width="170" align="center"> |
| 291 | 291 | <template slot-scope="scope"> |
| 292 | 292 | <serial-number-summary |
| 293 | - v-if="needsSerialNumber(scope.row)" | |
| 293 | + v-if="shouldShowSerialNumberSelector(scope.row)" | |
| 294 | 294 | :serial-numbers="scope.row.selectedSerialNumbers" |
| 295 | 295 | :quantity="scope.row.sl" |
| 296 | 296 | :disabled="!scope.row.spbh" |
| ... | ... | @@ -824,13 +824,48 @@ |
| 824 | 824 | this.dataForm.ydje = retailAmount.toFixed(2) |
| 825 | 825 | this.dataForm.ysje = (retailAmount - skje).toFixed(2) |
| 826 | 826 | }, |
| 827 | + normalizeSpxlhType(val) { | |
| 828 | + if (val == null || val === '' || String(val) === 'null' || String(val) === 'undefined') return '' | |
| 829 | + return String(val) | |
| 830 | + }, | |
| 831 | + // 解析明细行序列号类型:档案/明细优先;已绑序列号且档案未维护时按入0出1推断 | |
| 832 | + resolveRowSpxlhType(row, allowInfer = true) { | |
| 833 | + if (!row || !row.spbh) return '' | |
| 834 | + const key = String(row.spbh) | |
| 835 | + const cached = this.productCache.get(key) | |
| 836 | + const fromCache = cached && cached.spxlhType ? String(cached.spxlhType).trim() : '' | |
| 837 | + if (fromCache) return fromCache | |
| 838 | + const fromRow = this.normalizeSpxlhType(row.spxlhType) | |
| 839 | + if (fromRow) return fromRow | |
| 840 | + if (allowInfer && Array.isArray(row.selectedSerialNumbers) && row.selectedSerialNumbers.length > 0) { | |
| 841 | + return '2' | |
| 842 | + } | |
| 843 | + return '' | |
| 844 | + }, | |
| 845 | + hasSelectedSerialNumbers(row) { | |
| 846 | + return Array.isArray(row.selectedSerialNumbers) && row.selectedSerialNumbers.length > 0 | |
| 847 | + }, | |
| 848 | + ensureRowSerialNumberDisplayState(row) { | |
| 849 | + if (!row) return | |
| 850 | + if (!Array.isArray(row.selectedSerialNumbers)) { | |
| 851 | + this.$set(row, 'selectedSerialNumbers', []) | |
| 852 | + } | |
| 853 | + const type = this.resolveRowSpxlhType(row) | |
| 854 | + if (type && row.spbh) { | |
| 855 | + this.setProductSerialNumberType(row.spbh, type) | |
| 856 | + } | |
| 857 | + }, | |
| 827 | 858 | // 获取商品信息(只通过API获取序列号类型) |
| 828 | - async getProductInfo(productId) { | |
| 859 | + async getProductInfo(productId, mxRow) { | |
| 829 | 860 | const key = String(productId); |
| 830 | 861 | // 如果缓存中已有该商品信息,直接返回 |
| 831 | 862 | if (this.productCache.has(key)) { |
| 832 | - console.log('[getProductInfo] 命中缓存:', key, this.productCache.get(key)); | |
| 833 | - return this.productCache.get(key); | |
| 863 | + const cached = this.productCache.get(key); | |
| 864 | + if (mxRow && mxRow.spxlhType && !cached.spxlhType) { | |
| 865 | + cached.spxlhType = this.normalizeSpxlhType(mxRow.spxlhType); | |
| 866 | + } | |
| 867 | + console.log('[getProductInfo] 命中缓存:', key, cached); | |
| 868 | + return cached; | |
| 834 | 869 | } |
| 835 | 870 | |
| 836 | 871 | try { |
| ... | ... | @@ -845,7 +880,13 @@ |
| 845 | 880 | // 正确处理API返回结构 |
| 846 | 881 | if (response.code === 200 && response.data) { |
| 847 | 882 | const product = response.data; |
| 848 | - product.spxlhType = String(product.spxlhType); | |
| 883 | + const rawType = (product.spxlhType != null) | |
| 884 | + ? product.spxlhType | |
| 885 | + : (mxRow && mxRow.spxlhType); | |
| 886 | + product.spxlhType = this.normalizeSpxlhType(rawType); | |
| 887 | + if (!product.spxlhType && mxRow && this.hasSelectedSerialNumbers(mxRow)) { | |
| 888 | + product.spxlhType = '2'; | |
| 889 | + } | |
| 849 | 890 | this.productCache.set(key, product); |
| 850 | 891 | console.log('[getProductInfo] 商品信息已缓存:', key, product); |
| 851 | 892 | return product; |
| ... | ... | @@ -1165,6 +1206,9 @@ |
| 1165 | 1206 | if (!item.hasOwnProperty('productQuery')) { |
| 1166 | 1207 | _this.$set(item, 'productQuery', ''); |
| 1167 | 1208 | } |
| 1209 | + if (!Array.isArray(item.selectedSerialNumbers)) { | |
| 1210 | + _this.$set(item, 'selectedSerialNumbers', []); | |
| 1211 | + } | |
| 1168 | 1212 | }); |
| 1169 | 1213 | } |
| 1170 | 1214 | // 旧单无 ydje 时用 收款+优惠 反推原价,保证收款金额不被算错 |
| ... | ... | @@ -1550,39 +1594,48 @@ |
| 1550 | 1594 | if (!parts.length) return '' |
| 1551 | 1595 | return `机身码未入库,已核销在库占位串码:${parts.join('、')}` |
| 1552 | 1596 | }, |
| 1553 | - // 更新序列号状态 | |
| 1597 | + // 更新序列号状态(按明细行分别传 productCode,多商品出库单不可共用同一商品编号) | |
| 1554 | 1598 | async updateSerialNumberStatus(documentId, isDraft = false) { |
| 1555 | - // 收集所有选择的序列号 | |
| 1556 | - const allSerialNumbers = [] | |
| 1557 | - this.dataForm.wtXsckdMxList.forEach(row => { | |
| 1558 | - if (row.selectedSerialNumbers && row.selectedSerialNumbers.length > 0) { | |
| 1559 | - allSerialNumbers.push(...row.selectedSerialNumbers) | |
| 1560 | - } | |
| 1561 | - }) | |
| 1599 | + const mxRows = (this.dataForm.wtXsckdMxList || []).filter( | |
| 1600 | + row => row.spbh && Array.isArray(row.selectedSerialNumbers) && row.selectedSerialNumbers.length > 0 | |
| 1601 | + ) | |
| 1602 | + if (!mxRows.length) return | |
| 1562 | 1603 | |
| 1563 | - if (allSerialNumbers.length === 0) return | |
| 1604 | + for (const row of mxRows) { | |
| 1605 | + const allSerialNumbers = [...new Set( | |
| 1606 | + row.selectedSerialNumbers.map(s => String(s || '').trim()).filter(Boolean) | |
| 1607 | + )] | |
| 1608 | + if (!allSerialNumbers.length) continue | |
| 1564 | 1609 | |
| 1565 | - const response = await request({ | |
| 1566 | - url: '/api/Extend/WtXsckd/UpdateSerialNumberStatus', | |
| 1567 | - method: 'post', | |
| 1568 | - data: allSerialNumbers, | |
| 1569 | - params: { | |
| 1570 | - outDocumentId: documentId, | |
| 1571 | - outDocumentType: '销售出库单', | |
| 1572 | - outWarehouse: this.dataForm.cjck, | |
| 1573 | - isDraft: isDraft | |
| 1610 | + const productCode = String(row.spbh || '').trim() | |
| 1611 | + if (!productCode) { | |
| 1612 | + throw new Error('出库扫码须指定商品编号 productCode') | |
| 1613 | + } | |
| 1614 | + | |
| 1615 | + const response = await request({ | |
| 1616 | + url: '/api/Extend/WtXsckd/UpdateSerialNumberStatus', | |
| 1617 | + method: 'post', | |
| 1618 | + data: allSerialNumbers, | |
| 1619 | + params: { | |
| 1620 | + outDocumentId: documentId, | |
| 1621 | + outDocumentType: this.dataForm.djlx || '销售出库单', | |
| 1622 | + outWarehouse: row.ckck || this.dataForm.cjck, | |
| 1623 | + isDraft: isDraft, | |
| 1624 | + productCode: productCode, | |
| 1625 | + productName: row.spmc || '' | |
| 1626 | + } | |
| 1627 | + }) | |
| 1628 | + const payload = (response && response.data) || response || {} | |
| 1629 | + if (payload.success === false) { | |
| 1630 | + const errMsg = payload.message || payload.msg || response.msg || '序列号状态更新失败' | |
| 1631 | + throw new Error(errMsg) | |
| 1632 | + } | |
| 1633 | + const replacedMsg = this.formatReplacedPlaceholdersMsg( | |
| 1634 | + payload.replacedPlaceholders || payload.ReplacedPlaceholders | |
| 1635 | + ) | |
| 1636 | + if (replacedMsg) { | |
| 1637 | + this.$message.warning(replacedMsg) | |
| 1574 | 1638 | } |
| 1575 | - }) | |
| 1576 | - const payload = (response && response.data) || response || {} | |
| 1577 | - if (payload.success === false) { | |
| 1578 | - const errMsg = payload.message || payload.msg || response.msg || '序列号状态更新失败' | |
| 1579 | - throw new Error(errMsg) | |
| 1580 | - } | |
| 1581 | - const replacedMsg = this.formatReplacedPlaceholdersMsg( | |
| 1582 | - payload.replacedPlaceholders || payload.ReplacedPlaceholders | |
| 1583 | - ) | |
| 1584 | - if (replacedMsg) { | |
| 1585 | - this.$message.warning(replacedMsg) | |
| 1586 | 1639 | } |
| 1587 | 1640 | }, |
| 1588 | 1641 | addHandleWtXsckdMxEntityList() { |
| ... | ... | @@ -1883,14 +1936,26 @@ |
| 1883 | 1936 | const row = this.dataForm.wtXsckdMxList[i]; |
| 1884 | 1937 | |
| 1885 | 1938 | if (row.spbh) { |
| 1886 | - if (row.selectedSerialNumbers && row.selectedSerialNumbers.length > 0) { | |
| 1939 | + this.ensureRowSerialNumberDisplayState(row) | |
| 1940 | + | |
| 1941 | + if (this.hasSelectedSerialNumbers(row)) { | |
| 1887 | 1942 | console.log(`第${i + 1}行商品恢复序列号:`, row.selectedSerialNumbers); |
| 1888 | - } else { | |
| 1889 | - row.selectedSerialNumbers = []; | |
| 1943 | + } | |
| 1944 | + | |
| 1945 | + // 优先使用单据明细自带的序列号类型(反审后编辑时 API 可能返回 null) | |
| 1946 | + if (row.spxlhType) { | |
| 1947 | + this.setProductSerialNumberType(row.spbh, this.normalizeSpxlhType(row.spxlhType)); | |
| 1948 | + } else if (this.hasSelectedSerialNumbers(row)) { | |
| 1949 | + this.setProductSerialNumberType(row.spbh, '2'); | |
| 1890 | 1950 | } |
| 1891 | 1951 | |
| 1892 | 1952 | // 加载商品序列号类型信息 |
| 1893 | - this.getProductInfo(row.spbh).then(() => { | |
| 1953 | + this.getProductInfo(row.spbh, row).then(() => { | |
| 1954 | + this.ensureRowSerialNumberDisplayState(row) | |
| 1955 | + this.$set(row, 'spxlhLoaded', true); | |
| 1956 | + this.$forceUpdate(); | |
| 1957 | + }).catch(() => { | |
| 1958 | + this.ensureRowSerialNumberDisplayState(row) | |
| 1894 | 1959 | this.$set(row, 'spxlhLoaded', true); |
| 1895 | 1960 | this.$forceUpdate(); |
| 1896 | 1961 | }); |
| ... | ... | @@ -1899,59 +1964,48 @@ |
| 1899 | 1964 | } |
| 1900 | 1965 | }, |
| 1901 | 1966 | |
| 1967 | + // 判断该行是否展示序列号选择(入1出1/入0出1,或本单已绑序列号) | |
| 1968 | + shouldShowSerialNumberSelector(row) { | |
| 1969 | + return this.needsSerialNumber(row) || this.hasSelectedSerialNumbers(row) | |
| 1970 | + }, | |
| 1902 | 1971 | // 判断该行商品是否需要序列号(入1出1 或 入0出1) |
| 1903 | 1972 | needsSerialNumber(row) { |
| 1904 | 1973 | if (!row.spbh || !row.spxlhLoaded) return false; |
| 1905 | - const key = String(row.spbh); | |
| 1906 | - const product = this.productCache.get(key); | |
| 1907 | - if (product && product.spxlhType) { | |
| 1908 | - return product.spxlhType === '1' || product.spxlhType === '2'; | |
| 1909 | - } | |
| 1910 | - return false; | |
| 1974 | + const spxlhType = this.resolveRowSpxlhType(row); | |
| 1975 | + return spxlhType === '1' || spxlhType === '2'; | |
| 1911 | 1976 | }, |
| 1912 | 1977 | // 获取序列号类型显示文本 |
| 1913 | 1978 | getSerialNumberTypeText(row) { |
| 1914 | 1979 | if (!row.spbh) return '未选择'; |
| 1915 | 1980 | if (!row.spxlhLoaded) return '加载中...'; |
| 1916 | - const key = String(row.spbh); | |
| 1917 | - const product = this.productCache.get(key); | |
| 1918 | - if (product && product.spxlhType) { | |
| 1919 | - const spxlhType = product.spxlhType; | |
| 1920 | - if (spxlhType === '1') return '入1出1'; | |
| 1921 | - if (spxlhType === '2') return '入0出1'; | |
| 1922 | - if (spxlhType === '3') return '入0出0'; | |
| 1923 | - return spxlhType; | |
| 1924 | - } | |
| 1925 | - return '未知'; | |
| 1981 | + const spxlhType = this.resolveRowSpxlhType(row); | |
| 1982 | + if (spxlhType === '1') return '入1出1'; | |
| 1983 | + if (spxlhType === '2') return '入0出1'; | |
| 1984 | + if (spxlhType === '3') return '入0出0'; | |
| 1985 | + if (spxlhType) return spxlhType; | |
| 1986 | + return '入0出0'; | |
| 1926 | 1987 | }, |
| 1927 | 1988 | |
| 1928 | 1989 | // 获取序列号类型标签颜色 |
| 1929 | 1990 | getSerialNumberTypeTagType(row) { |
| 1930 | 1991 | if (!row.spbh) return 'info'; |
| 1931 | 1992 | if (!row.spxlhLoaded) return 'info'; |
| 1932 | - const key = String(row.spbh); | |
| 1933 | - const product = this.productCache.get(key); | |
| 1934 | - if (product && product.spxlhType) { | |
| 1935 | - const spxlhType = product.spxlhType; | |
| 1936 | - if (spxlhType === '1' || spxlhType === '2') return 'warning'; // 需要序列号 - 橙色警告 | |
| 1937 | - if (spxlhType === '3') return 'success'; // 不需要序列号 - 绿色 | |
| 1938 | - } | |
| 1939 | - return 'info'; // 未知 - 蓝色 | |
| 1993 | + const spxlhType = this.resolveRowSpxlhType(row); | |
| 1994 | + if (spxlhType === '1' || spxlhType === '2') return 'warning'; // 需要序列号 - 橙色警告 | |
| 1995 | + if (spxlhType === '3') return 'success'; // 不需要序列号 - 绿色 | |
| 1996 | + return 'success'; | |
| 1940 | 1997 | }, |
| 1941 | 1998 | |
| 1942 | 1999 | // 获取序列号类型描述 |
| 1943 | 2000 | getSerialNumberTypeDescription(row) { |
| 1944 | 2001 | if (!row.spbh) return '请先选择商品'; |
| 1945 | 2002 | if (!row.spxlhLoaded) return '加载中...'; |
| 1946 | - const key = String(row.spbh); | |
| 1947 | - const product = this.productCache.get(key); | |
| 1948 | - if (product && product.spxlhType) { | |
| 1949 | - const spxlhType = product.spxlhType; | |
| 1950 | - if (spxlhType === '1') return '入库和出库都需要序列号'; | |
| 1951 | - if (spxlhType === '2') return '入库不需要,出库需要序列号'; | |
| 1952 | - if (spxlhType === '3') return '入库和出库都不需要序列号'; | |
| 1953 | - } | |
| 1954 | - return '序列号类型信息未知'; | |
| 2003 | + const spxlhType = this.resolveRowSpxlhType(row); | |
| 2004 | + if (spxlhType === '1') return '入库和出库都需要序列号'; | |
| 2005 | + if (spxlhType === '2') return '入库不需要,出库需要序列号'; | |
| 2006 | + if (spxlhType === '3') return '入库和出库都不需要序列号'; | |
| 2007 | + if (this.hasSelectedSerialNumbers(row)) return '本单已绑定序列号(商品档案未维护序列号类型)'; | |
| 2008 | + return '商品档案未维护序列号类型,默认按入0出0处理'; | |
| 1955 | 2009 | }, |
| 1956 | 2010 | |
| 1957 | 2011 | // 刷新序列号类型信息 | ... | ... |
Antis.Erp.Plat/netcore/src/Modularity/Extend/NCC.Extend/WtXsckdService.cs
| ... | ... | @@ -12682,7 +12682,8 @@ LIMIT {offset}, {pageSize}"; |
| 12682 | 12682 | /// 预售/草稿预留:序列号须已在库,禁止扫码新建虚增。 |
| 12683 | 12683 | /// </summary> |
| 12684 | 12684 | private async Task ValidatePresaleReserveSerialsAsync( |
| 12685 | - IList<string> serialNumbers, string productCode, string outWarehouse) | |
| 12685 | + IList<string> serialNumbers, string productCode, string outWarehouse, | |
| 12686 | + string currentOutDocumentId = null) | |
| 12686 | 12687 | { |
| 12687 | 12688 | if (serialNumbers == null || serialNumbers.Count == 0) return; |
| 12688 | 12689 | |
| ... | ... | @@ -12716,9 +12717,19 @@ LIMIT {offset}, {pageSize}"; |
| 12716 | 12717 | if (row.Status == 2) |
| 12717 | 12718 | throw NCCException.Bah($"序列号「{sn}」已报废,不可预留"); |
| 12718 | 12719 | |
| 12719 | - if (row.Status == 1 || !string.IsNullOrWhiteSpace(row.OutDjbh)) | |
| 12720 | + if (row.Status == 1) | |
| 12720 | 12721 | throw NCCException.Bah($"序列号「{sn}」已出库占用,不可预留"); |
| 12721 | 12722 | |
| 12723 | + if (!string.IsNullOrWhiteSpace(row.OutDjbh)) | |
| 12724 | + { | |
| 12725 | + var reservedForCurrentDoc = !string.IsNullOrWhiteSpace(currentOutDocumentId) | |
| 12726 | + && string.Equals(row.OutDjbh.Trim(), currentOutDocumentId.Trim(), StringComparison.OrdinalIgnoreCase) | |
| 12727 | + && (row.Status == 0 || row.Status == 3); | |
| 12728 | + if (!reservedForCurrentDoc) | |
| 12729 | + throw NCCException.Bah($"序列号「{sn}」已出库占用,不可预留"); | |
| 12730 | + continue; | |
| 12731 | + } | |
| 12732 | + | |
| 12722 | 12733 | if ((row.Status != 0 && row.Status != 3) |
| 12723 | 12734 | || !whSet.Contains((row.InWarehouse ?? string.Empty).Trim())) |
| 12724 | 12735 | throw NCCException.Bah($"序列号「{sn}」不在当前出库仓库在库可选范围,不可预留"); |
| ... | ... | @@ -12935,7 +12946,7 @@ LIMIT {offset}, {pageSize}"; |
| 12935 | 12946 | |
| 12936 | 12947 | if (isPresaleReserve) |
| 12937 | 12948 | { |
| 12938 | - await ValidatePresaleReserveSerialsAsync(serialNumbers, productCode, outWarehouse); | |
| 12949 | + await ValidatePresaleReserveSerialsAsync(serialNumbers, productCode, outWarehouse, outDocumentId); | |
| 12939 | 12950 | await _db.Updateable<WtSerialNumberEntity>() |
| 12940 | 12951 | .SetColumns(it => new WtSerialNumberEntity |
| 12941 | 12952 | { |
| ... | ... | @@ -14221,7 +14232,7 @@ LIMIT {offset}, {pageSize}"; |
| 14221 | 14232 | .ToList(); |
| 14222 | 14233 | if (toBind.Count == 0) continue; |
| 14223 | 14234 | |
| 14224 | - await ValidatePresaleReserveSerialsAsync(toBind, inputMx.spbh.Trim(), outStoreOrCk); | |
| 14235 | + await ValidatePresaleReserveSerialsAsync(toBind, inputMx.spbh.Trim(), outStoreOrCk, documentId); | |
| 14225 | 14236 | |
| 14226 | 14237 | var bound = await _db.Updateable<WtSerialNumberEntity>() |
| 14227 | 14238 | .SetColumns(it => new WtSerialNumberEntity |
| ... | ... | @@ -17261,7 +17272,8 @@ LIMIT {offset}, {pageSize}"; |
| 17261 | 17272 | } |
| 17262 | 17273 | |
| 17263 | 17274 | /// <summary> |
| 17264 | - /// 删除出库单前:将 <c>out_djbh</c> 指向本单的序列号恢复为在库,并清空出库字段(与建单出库对称)。 | |
| 17275 | + /// 删除/反审出库单前:将 <c>out_djbh</c> 指向本单的序列号恢复为在库,并清空出库字段(与建单出库对称)。 | |
| 17276 | + /// 含 status=0 草稿预留,避免反审后编辑保存时误判「已出库占用」。 | |
| 17265 | 17277 | /// </summary> |
| 17266 | 17278 | private async Task RevertSerialNumbersForDeletedOutboundAsync(string documentId) |
| 17267 | 17279 | { |
| ... | ... | @@ -17276,7 +17288,7 @@ LIMIT {offset}, {pageSize}"; |
| 17276 | 17288 | OutTime = null, |
| 17277 | 17289 | OutOperator = "" |
| 17278 | 17290 | }) |
| 17279 | - .Where(it => it.OutDjbh == documentId && it.Status == 1) | |
| 17291 | + .Where(it => it.OutDjbh == documentId && it.Status != 2) | |
| 17280 | 17292 | .ExecuteCommandAsync(); |
| 17281 | 17293 | } |
| 17282 | 17294 | ... | ... |