Explorar o código

feat(wise-cost-util): 获取标准清单编号共用方法

zhangweicheng %!s(int64=3) %!d(string=hai) anos
pai
achega
ea7f9cac25
Modificáronse 2 ficheiros con 38 adicións e 1 borrados
  1. 1 1
      wise-cost-util/package.json
  2. 37 0
      wise-cost-util/src/bill.ts

+ 1 - 1
wise-cost-util/package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "@sc/wise-cost-util",
   "name": "@sc/wise-cost-util",
-  "version": "1.1.4",
+  "version": "1.1.5",
   "description": "wise-cost项目前后端业务通用工具包",
   "description": "wise-cost项目前后端业务通用工具包",
   "main": "./dist/index.cjs.js",
   "main": "./dist/index.cjs.js",
   "module": "./dist/index.esm.js",
   "module": "./dist/index.esm.js",

+ 37 - 0
wise-cost-util/src/bill.ts

@@ -88,3 +88,40 @@ export const getItemCharacters = (stdBill: IStdBill, itemCharacterMap: IItemChar
 
 
   return characters;
   return characters;
 };
 };
+
+// 对于含有中文的清单编号,分离出中文和数字
+export const separateBillCode = (code: string) => {
+  const result = code.match(/^([\u4e00-\u9fa5]+)(\d+)/);
+  if (result && result.length === 3) {
+    const pre = result[1];
+    const subCode = result[2];
+    return { pre, code: subCode };
+  }
+  return { pre: '', code };
+};
+
+/**
+ *
+ * @param sourceCode 清单ID
+ *
+ * 返回: isStd是否来自标准清单  code:标准清单编号
+ */
+export const matchAndGetStdBillCode = (sourceCode: string) => {
+  const { pre, code } = separateBillCode(sourceCode);
+  if (code.length === 12) {
+    return { isStd: true, code: pre + code.substring(0, 9) };
+  }
+  if (code.length === 9) {
+    return { isStd: true, code: pre + code };
+  }
+  return { isStd: false, code: sourceCode };
+};
+
+// 取标准清单编号
+export const getStdBillCode = (sourceCode: string) => {
+  const { isStd, code } = matchAndGetStdBillCode(sourceCode);
+  if (isStd) {
+    return code;
+  }
+  return '';
+};