|
|
@@ -1,6 +1,7 @@
|
|
|
import { Fields, ICurrent_RPT, IDataObj, IGroupField, IParam } from "../index";
|
|
|
import { IParams } from "../interface/basic";
|
|
|
import { IDataObjProps } from '../interface/enum';
|
|
|
+import ReportDate from '../public/ReportDate'
|
|
|
|
|
|
let FData: Record<string, IGroupField> = {};
|
|
|
let PData: Record<string, IParam> = {};
|
|
|
@@ -66,6 +67,7 @@ const P = (fieldID: number) => {
|
|
|
const fieldID = field.replace('ID_', '');
|
|
|
if (fieldID === fieldID) {
|
|
|
PData[fieldID] = rpt.params[field]
|
|
|
+ DData[fieldID] = rpt.params[field].Default_Value;
|
|
|
return rpt.params[field];
|
|
|
}
|
|
|
}
|
|
|
@@ -87,8 +89,7 @@ const D = (fieldID: number, valIndex?: number, newValue?: any) => {
|
|
|
console.log(`指标id:${fieldID},${valIndex}>${DData[fieldID].length},请检查`)
|
|
|
return '';
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
console.log(`无ID为${fieldID}的指标,请检查`)
|
|
|
return '';
|
|
|
}
|
|
|
@@ -97,7 +98,7 @@ const D = (fieldID: number, valIndex?: number, newValue?: any) => {
|
|
|
if (DData[fieldID]) {
|
|
|
return DData[fieldID];
|
|
|
} else {
|
|
|
- F(fieldID);
|
|
|
+ if (!F(fieldID)) P(fieldID);
|
|
|
if (DData[fieldID]) {
|
|
|
return DData[fieldID];
|
|
|
} else {
|
|
|
@@ -110,9 +111,9 @@ const D = (fieldID: number, valIndex?: number, newValue?: any) => {
|
|
|
|
|
|
//获取相应指标的数据长度
|
|
|
const L = (arg: any) => {
|
|
|
- if(arg in IDataObjProps){
|
|
|
+ if (arg in IDataObjProps) {
|
|
|
return orgData[arg][0].length;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
if (DData[arg]) {
|
|
|
return DData[arg].length;
|
|
|
} else {
|
|
|
@@ -187,7 +188,7 @@ const setFieldDefaultValue = (fieldID: number, newValue: any) => {
|
|
|
//该函数为共用方法,参数有两套组合:
|
|
|
// (指标id,更改后的数组)
|
|
|
// (指标id,需要更改的index,.需要更改的值)
|
|
|
-const setData = (fieldID: number, arg1: number[] | number, arg2?: number | string) => {
|
|
|
+const setData = (fieldID: number, arg1: number[] | string[] | number | string, arg2?: number | string) => {
|
|
|
const field = F(fieldID)
|
|
|
if (field) {
|
|
|
if (arg1 instanceof Array) {
|
|
|
@@ -198,50 +199,110 @@ const setData = (fieldID: number, arg1: number[] | number, arg2?: number | strin
|
|
|
console.log(`无ID为${fieldID}的指标,请检查`)
|
|
|
}
|
|
|
} else {
|
|
|
- if (DData[fieldID]) {
|
|
|
- if (arg1 <= DData[fieldID].length) {
|
|
|
- DData[fieldID][arg1] = arg2;
|
|
|
- setFieldValue(field, arg1, arg2);
|
|
|
+ if (typeof (arg1) === 'number') {
|
|
|
+ if (DData[fieldID]) {
|
|
|
+ if (arg1 <= DData[fieldID].length) {
|
|
|
+ DData[fieldID][arg1] = arg2;
|
|
|
+ setFieldValue(field, arg1, arg2);
|
|
|
+ } else {
|
|
|
+ console.log(`指标id:${fieldID},数据长度为${DData[fieldID].length},第二参数为${arg1},请检查`)
|
|
|
+ }
|
|
|
} else {
|
|
|
- console.log(`指标id:${fieldID},数据长度为${DData[fieldID].length},第二参数为${arg1},请检查`)
|
|
|
+ console.log(`无ID为${fieldID}的指标,请检查`)
|
|
|
}
|
|
|
- } else {
|
|
|
- console.log(`无ID为${fieldID}的指标,请检查`)
|
|
|
}
|
|
|
}
|
|
|
} else if (P(fieldID)) {
|
|
|
setFieldDefaultValue(fieldID, arg1);
|
|
|
+ DData[fieldID] = arg1;
|
|
|
}
|
|
|
}
|
|
|
//把数组每个元素都转换成数字
|
|
|
-const getNumberArray=(data:string[]|undefined[]|[]|number[])=>{
|
|
|
- const rst:number[]=[];
|
|
|
- for(const item of data){
|
|
|
- if(isNaN(Number(item))){
|
|
|
+const getNumberArray = (data: string[] | undefined[] | [] | number[]) => {
|
|
|
+ const rst: number[] = [];
|
|
|
+ for (const item of data) {
|
|
|
+ if (isNaN(Number(item))) {
|
|
|
rst.push(0);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
rst.push(Number(item));
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
return rst;
|
|
|
}
|
|
|
|
|
|
|
|
|
const removeFieldValue = (fieldID: number, valIdx: number) => {
|
|
|
- if (!DData[fieldID]) {
|
|
|
- F(fieldID);
|
|
|
+ const fField: (IGroupField) = <IGroupField>F(fieldID);
|
|
|
+ if (fField) {
|
|
|
+ DData[fieldID].splice(valIdx, 1);
|
|
|
+ setFieldValue(fField, valIdx, DData[fieldID])
|
|
|
+ } else {
|
|
|
+ console.log(`指标${fieldID}的数据不支持removeFieldValue操作`);
|
|
|
}
|
|
|
- DData[fieldID].splice(valIdx, 1);
|
|
|
}
|
|
|
|
|
|
const insertFieldValue = (fieldID: number, valIdx: number, newValue: number) => {
|
|
|
- if (!DData[fieldID]) {
|
|
|
- F(fieldID);
|
|
|
+ let field = <IGroupField>F(fieldID);
|
|
|
+ if (field) {
|
|
|
+ DData[fieldID].splice(valIdx, 0, newValue);
|
|
|
+ setFieldValue(field, valIdx, DData[fieldID])
|
|
|
+ } else {
|
|
|
+ console.log(`指标${fieldID}的数据不支持insertFieldValue操作`);
|
|
|
}
|
|
|
- DData[fieldID].splice(valIdx, 0, newValue);
|
|
|
}
|
|
|
|
|
|
+//设置精度
|
|
|
+const copyPrecision = (targetFieldID: number, orgFieldID: number) => {
|
|
|
+ // const targetField = <IGroupField>F(targetFieldID);
|
|
|
+ // const orgField = <IGroupField>F(orgFieldID);
|
|
|
+ // if (targetField && orgField) {
|
|
|
+ // Object.assign(targetField.Precision, orgField.Precision);
|
|
|
+ // } else {
|
|
|
+ // console.log(`指标${targetFieldID}和${orgFieldID}的数据不支持setPrecision操作`);
|
|
|
+ // }
|
|
|
+ copyProperty(targetFieldID, orgFieldID,'Precision');
|
|
|
+}
|
|
|
+
|
|
|
+const copyFixedPrecisionNum = (targetFieldID: number, orgFieldID: number) => {
|
|
|
+ // const targetField = <IGroupField>F(targetFieldID);
|
|
|
+ // const orgField = <IGroupField>F(orgFieldID);
|
|
|
+ // if (targetField && orgField) {
|
|
|
+ // if (orgField.fixedPrecisionNum) {
|
|
|
+ // if (!targetField.fixedPrecisionNum) {
|
|
|
+ // targetField.fixedPrecisionNum = 0;
|
|
|
+ // }
|
|
|
+ // Object.assign(targetField.fixedPrecisionNum, orgField.fixedPrecisionNum);
|
|
|
+ // }else{
|
|
|
+ // console.log(`指标${orgFieldID}不存在${fixedPrecisionNum}属性`);
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // console.log(`指标${targetFieldID}和${orgFieldID}的数据不支持setPrecision操作`);
|
|
|
+ // }
|
|
|
+ copyProperty(targetFieldID, orgFieldID,'fixedPrecisionNum');
|
|
|
+}
|
|
|
+
|
|
|
+//复制属性
|
|
|
+const copyProperty = (targetFieldID: number, orgFieldID: number, property: string) => {
|
|
|
+ const targetField = <IGroupField>F(targetFieldID);
|
|
|
+ const orgField = <IGroupField>F(orgFieldID);
|
|
|
+ if (targetField && orgField) {
|
|
|
+ if(orgField[property]){
|
|
|
+ if(!targetField[property]){
|
|
|
+ targetField[property]={};
|
|
|
+ }
|
|
|
+ Object.assign(targetField[property], orgField[property]);
|
|
|
+ }else{
|
|
|
+ console.log(`指标${orgFieldID}不存在${property}属性`);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.log(`指标${targetFieldID}和${orgFieldID}的数据不支持copyProperty操作`);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const setDate = (fieldID: number, format: string) => {
|
|
|
+ const date = new ReportDate();
|
|
|
+ setData(fieldID, date.Format(format));
|
|
|
+}
|
|
|
export default {
|
|
|
setupData,
|
|
|
P,
|
|
|
@@ -253,10 +314,14 @@ export default {
|
|
|
setFieldValue,
|
|
|
setFieldValueArray,
|
|
|
removeFieldValue,
|
|
|
- insertFieldValue,
|
|
|
- setData,
|
|
|
+ insertFieldValue,
|
|
|
+ setData,
|
|
|
resetData,
|
|
|
- getNumberArray
|
|
|
+ getNumberArray,
|
|
|
+ copyPrecision,
|
|
|
+ copyFixedPrecisionNum,
|
|
|
+ copyProperty,
|
|
|
+ setDate
|
|
|
}
|
|
|
|
|
|
|