@bchr/bchr-front-lib 0.3.102 → 0.3.103

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +1,48 @@
1
1
  "use strict";
2
2
 
3
- window.AppFormulaFunctions = {};
4
-
5
- window.AppFormulaFunctions.currentMonthStartDay = function (date) {
6
- var currentDate = new Date(date),
7
- currentYear = currentDate.getFullYear(),
8
- currentMouth = currentDate.getMonth() + 1;
9
- return currentYear + "-" + currentMouth + "-1";
10
- };
11
-
12
- window.AppFormulaFunctions.nextMonthStartDay = function (date) {
13
- var currentDate = new Date(date),
14
- currentYear = currentDate.getFullYear(),
15
- currentMouth = currentDate.getMonth() + 1;
16
- return new Date(currentYear, currentMouth, 1);
17
- };
18
-
19
- window.AppFormulaFunctions.currentDateToDeadline = function (date, during) {
20
- debugger;
21
- var changeDate = new Date(new Date(date).getTime() + during * 24 * 60 * 60 * 1000);
22
- var changeYear = changeDate.getFullYear(),
23
- changeMouth = changeDate.getMonth() + 1,
24
- changeDay = changeDate.getDay();
25
- return changeYear + '-' + changeMouth + '-' + changeDay;
3
+ var _moment = _interopRequireDefault(require("moment"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
6
+
7
+ window.AppFormulaFunctions = {
8
+ currentMonthStartDay: function currentMonthStartDay(dateStr) {
9
+ if (dateStr) {
10
+ var baseDate = (0, _moment["default"])(dateStr, "YYYY-MM-DD");
11
+ return baseDate.date(1).format("YYYY-MM-DD");
12
+ }
13
+
14
+ return null;
15
+ },
16
+ nextMonthStartDay: function nextMonthStartDay(dateStr) {
17
+ if (dateStr) {
18
+ var baseDate = (0, _moment["default"])(dateStr, "YYYY-MM-DD");
19
+ return baseDate.add(1, 'months').date(1).format("YYYY-MM-DD");
20
+ }
21
+
22
+ return null;
23
+ },
24
+ datePlusDays: function datePlusDays(dateStr, during_days) {
25
+ if (dateStr && during_days) {
26
+ var baseDate = (0, _moment["default"])(dateStr, "YYYY-MM-DD");
27
+ return baseDate.add(during_days, 'days').format("YYYY-MM-DD");
28
+ }
29
+
30
+ return null;
31
+ },
32
+ datePlusMonths: function datePlusMonths(dateStr, during_months) {
33
+ if (dateStr && during_months) {
34
+ var baseDate = (0, _moment["default"])(dateStr, "YYYY-MM-DD");
35
+ return baseDate.add(during_months, 'months').format("YYYY-MM-DD");
36
+ }
37
+
38
+ return null;
39
+ },
40
+ datePlusYears: function datePlusYears(dateStr, during_years) {
41
+ if (dateStr && during_years) {
42
+ var baseDate = (0, _moment["default"])(dateStr, "YYYY-MM-DD");
43
+ return baseDate.add(during_years, 'years').format("YYYY-MM-DD");
44
+ }
45
+
46
+ return null;
47
+ }
26
48
  };
@@ -21,6 +21,8 @@ var _HttpService = _interopRequireDefault(require("../../../../services/HttpServ
21
21
 
22
22
  var _InputPassword = _interopRequireDefault(require("../InputPassword"));
23
23
 
24
+ require("../../../AppFormulaFunctions");
25
+
24
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
25
27
 
26
28
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
@@ -57,6 +59,12 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
57
59
 
58
60
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
59
61
 
62
+ var FormulasValueType = {
63
+ Disabled: "disabled",
64
+ Enabled: "enabled",
65
+ Function: "AppFormulaFunctions"
66
+ };
67
+
60
68
  var FormForModify = /*#__PURE__*/function (_React$Component) {
61
69
  _inherits(FormForModify, _React$Component);
62
70
 
@@ -137,9 +145,8 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
137
145
  }));
138
146
  });
139
147
 
140
- _defineProperty(_assertThisInitialized(_this2), "buildFormItems", function (editFormulasState) {
148
+ _defineProperty(_assertThisInitialized(_this2), "buildFormItems", function () {
141
149
  var _this2$props2 = _this2.props,
142
- data = _this2$props2.data,
143
150
  info_set_fields = _this2$props2.info_set_fields,
144
151
  ext_form_items = _this2$props2.ext_form_items;
145
152
 
@@ -147,120 +154,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
147
154
  return;
148
155
  }
149
156
 
150
- var setFieldsValue = _this2.ref.current.setFieldsValue;
151
-
152
157
  if (info_set_fields && info_set_fields.length > 0) {
153
- info_set_fields.forEach(function (formItem) {
154
- formItem.initialValue = null;
155
-
156
- _this2.preParseFormItemExtConfig(formItem);
157
-
158
- if (editFormulasState && editFormulasState.length) {
159
- formItem.b_disabled = formItem.b_readonly;
160
-
161
- var _loop = function _loop(i, len) {
162
- var editFormulaStateItemCode = editFormulasState[i].editFormulasStateCode;
163
- var editFormulaStateItem = editFormulasState[i].editFormulaItem;
164
-
165
- if (editFormulaStateItem) {
166
- editFormulaStateItem.otherFormItemResponses.forEach(function (item) {
167
- if (formItem.code === item.formItemCode) {
168
- if (item.formItemValue === 'disabled') {
169
- formItem.b_disabled = true;
170
- } else if (item.formItemValue === 'enabled') {
171
- formItem.b_disabled = false;
172
- } else if (item.formItemValue.indexOf('exp') !== -1) {
173
- var expValue = '';
174
-
175
- if (isNaN(data[formItem.code])) {
176
- expValue = item.formItemValue.split('exp(')[1].split(')')[0].replace('#value#', data[formItem.code]);
177
- } else {
178
- expValue = String(item.formItemValue.split('exp(')[1].split(')')[0].replace('#value#', Number(data[formItem.code])));
179
- }
180
-
181
- formItem.initialValue = eval(expValue);
182
- } else if (item.formItemValue.indexOf('AppFormulaFunctions') !== -1) {
183
- var formulaValue = '';
184
-
185
- if (item.formItemValue.indexOf('currentDateToDeadline') !== -1) {
186
- formulaValue = eval(item.formItemValue.replace('#value#', "data[editFormulaStateItemCode], 300"));
187
- } else {
188
- formulaValue = eval(item.formItemValue.replace('#value#', data[editFormulaStateItemCode]));
189
- }
190
-
191
- if (formItem.ui_render_type === _consts.UI_RENDER_TYPE.DATE || formItem.ui_render_type === _consts.UI_RENDER_TYPE.DATE_MONTH || formItem.ui_render_type === _consts.UI_RENDER_TYPE.DATE_YEAR || formItem.ui_render_type === _consts.UI_RENDER_TYPE.DATE_TIME) {
192
- formulaValue = (0, _moment["default"])(formulaValue);
193
- }
194
-
195
- formItem.initialValue = formulaValue;
196
- } else {
197
- formItem.initialValue = item.formItemValue || data[formItem.display_code];
198
- }
199
-
200
- if (formItem.initialValue || data[formItem.code]) {
201
- if (formItem.code.indexOf('date') !== -1) {
202
- setFieldsValue(_defineProperty({}, formItem.code, (0, _moment["default"])(formItem.initialValue || data[formItem.code])));
203
-
204
- if (formItem.code.endsWith("_date")) {
205
- data[formItem.code] = (0, _moment["default"])(formItem.initialValue || data[formItem.code]).valueOf();
206
- } else if (formItem.code.indexOf('_date$') !== -1) {
207
- data[formItem.code] = (0, _moment["default"])(formItem.initialValue || data[formItem.code]).format("YYYY-MM-DD");
208
- }
209
- } else {
210
- setFieldsValue(_defineProperty({}, formItem.code, formItem.initialValue || data[formItem.code]));
211
- data[formItem.code] = formItem.initialValue || data[formItem.code];
212
- }
213
- }
214
- }
215
- });
216
- }
217
- };
218
-
219
- for (var i = 0, len = editFormulasState.length; i < len; i++) {
220
- _loop(i, len);
221
- }
222
- } else {
223
- if (formItem.editFormulaConfigs) {
224
- for (var _i = 0, _len = formItem.editFormulaConfigs.length; _i < _len; _i++) {
225
- var editFormulaConfig = formItem.editFormulaConfigs[_i];
226
- var initialValue = formItem.ui_render_type === 'switch' ? (data[formItem.code] && data[formItem.code].toString() || '').toLowerCase() !== 'true' : data[formItem.code];
227
- var formulaValueOf = formItem.ui_render_type === 'switch' ? (editFormulaConfig.onValueOf || '').toLowerCase() !== 'true' : editFormulaConfig.onValueOf;
228
-
229
- if (formulaValueOf === initialValue) {
230
- var currentOtherFormItemResponses = editFormulaConfig.otherFormItemResponses;
231
- currentOtherFormItemResponses.forEach(function (item) {
232
- info_set_fields.forEach(function (formItemInner) {
233
- if (formItemInner.code === item.formItemCode) {
234
- if (item.formItemValue === 'disabled') {
235
- formItemInner.b_disabled = true;
236
- } else if (item.formItemValue === 'enabled') {
237
- formItemInner.b_disabled = false;
238
- } else {
239
- formItemInner.initialValue = item.formItemValue || data[formItemInner.display_code];
240
- }
241
-
242
- if (formItemInner.initialValue || data[formItemInner.code]) {
243
- if (formItemInner.code.indexOf('date') !== -1) {
244
- setFieldsValue(_defineProperty({}, formItemInner.code, (0, _moment["default"])(formItemInner.initialValue || data[formItemInner.code])));
245
-
246
- if (formItemInner.code.endsWith("_date")) {
247
- data[formItemInner.code] = (0, _moment["default"])(formItemInner.initialValue || data[formItemInner.code]).valueOf();
248
- } else if (formItemInner.code.indexOf('_date$') !== -1) {
249
- data[formItemInner.code] = (0, _moment["default"])(formItem.initialValue || data[formItemInner.code]).format("YYYY-MM-DD");
250
- }
251
- } else {
252
- setFieldsValue(_defineProperty({}, formItemInner.code, formItemInner.initialValue || data[formItemInner.code]));
253
- data[formItemInner.code] = formItemInner.initialValue || data[formItemInner.code];
254
- }
255
- }
256
- }
257
- });
258
- });
259
- }
260
- }
261
- }
262
- }
263
- });
264
158
  var groupNames = info_set_fields.map(function (item) {
265
159
  return item.belong_form_group;
266
160
  }).filter(function (item, index, arr) {
@@ -340,8 +234,8 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
340
234
 
341
235
  var editFormulaConfigs = [];
342
236
 
343
- for (var _i2 = 0, _len2 = pureFormulaTextItems.length; _i2 < _len2; _i2++) {
344
- var formulaTextItem = pureFormulaTextItems[_i2];
237
+ for (var _i = 0, _len = pureFormulaTextItems.length; _i < _len; _i++) {
238
+ var formulaTextItem = pureFormulaTextItems[_i];
345
239
  var formulaChildTextItems = formulaTextItem.split("=>");
346
240
 
347
241
  if (formulaChildTextItems.length !== 2) {
@@ -799,9 +693,131 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
799
693
  return dict.title;
800
694
  });
801
695
 
696
+ _defineProperty(_assertThisInitialized(_this2), "formItemOnChangeForFormula", function (config, value) {
697
+ var formItemFormulaConfigs = config.editFormulaConfigs;
698
+
699
+ if (formItemFormulaConfigs && formItemFormulaConfigs.length > 0) {
700
+ var fieldCodeKeyMap = _this2.state.fieldCodeKeyMap;
701
+ var _this2$props4 = _this2.props,
702
+ data = _this2$props4.data,
703
+ def_docs = _this2$props4.def_docs;
704
+ var setFieldsValue = _this2.ref.current.setFieldsValue; // value exists
705
+
706
+ var editFormulaItem = config.editFormulaConfigs.find(function (editFormulaItem) {
707
+ return editFormulaItem.onValueOf === value.toString() || editFormulaItem.onValueOf === "value";
708
+ });
709
+
710
+ if (editFormulaItem) {
711
+ var otherFormItemResponses = editFormulaItem.otherFormItemResponses;
712
+
713
+ var _loop = function _loop(i, len) {
714
+ var otherFormItem = otherFormItemResponses[i];
715
+
716
+ if (!otherFormItem) {
717
+ return "continue";
718
+ }
719
+
720
+ var formItemCode = otherFormItem.formItemCode,
721
+ formItemValue = otherFormItem.formItemValue;
722
+ var otherFormItemConfig = fieldCodeKeyMap[formItemCode];
723
+
724
+ if (!otherFormItemConfig) {
725
+ return "continue";
726
+ }
727
+
728
+ if (!formItemValue) {
729
+ return "continue";
730
+ }
731
+
732
+ var code = otherFormItemConfig.code,
733
+ display_code = otherFormItemConfig.display_code,
734
+ ref_pk = otherFormItemConfig.ref_pk,
735
+ ui_render_type = otherFormItemConfig.ui_render_type;
736
+
737
+ if (FormulasValueType.Disabled == formItemValue) {
738
+ data[code] = null;
739
+ setFieldsValue(_defineProperty({}, code, null));
740
+
741
+ if (display_code) {
742
+ data[display_code] = null;
743
+ setFieldsValue(_defineProperty({}, display_code, null));
744
+ }
745
+
746
+ otherFormItemConfig.b_disabled = true;
747
+ otherFormItemConfig.b_readonly = true;
748
+ } else if (FormulasValueType.Enabled == formItemValue) {
749
+ otherFormItemConfig.b_disabled = false;
750
+ otherFormItemConfig.b_readonly = true;
751
+ } else if (formItemValue.startsWith(FormulasValueType.Function)) {
752
+ var formulaFunctionValue;
753
+
754
+ if (formItemValue.search("#value#") !== -1) {
755
+ formulaFunctionValue = eval(formItemValue.replace('#value#', "value").replace("@", ","));
756
+ } else {
757
+ var formItemValueList = formItemValue.split("#");
758
+
759
+ if (!formItemValueList || formItemValueList.length != 3) {
760
+ console.log("formula error, detail info: formItemCode=" + formItemValue + ", formItemValue=" + formItemValue);
761
+ return "continue";
762
+ }
763
+
764
+ var realFormulaValue = formItemValueList[0] + "data[formItemValueList[1]]" + formItemValueList[2];
765
+ formulaFunctionValue = eval(realFormulaValue.replace("@", ","));
766
+ }
767
+
768
+ if (!formulaFunctionValue) {
769
+ console.log("formula function return null, detail info: formItemCode=" + formItemValue + ", formItemValue=" + formItemValue);
770
+ return "continue";
771
+ }
772
+
773
+ data[code] = formulaFunctionValue;
774
+ var otherFormItemValue;
775
+
776
+ if (_consts.UI_RENDER_TYPE.DATE == ui_render_type) {
777
+ otherFormItemValue = (0, _moment["default"])(formulaFunctionValue, "YYYY-MM-DD");
778
+ } else {
779
+ otherFormItemValue = formulaFunctionValue;
780
+ }
781
+
782
+ setFieldsValue(_defineProperty({}, code, otherFormItemValue));
783
+ } else {
784
+ data[code] = formItemValue;
785
+ setFieldsValue(_defineProperty({}, code, formItemValue));
786
+
787
+ if (display_code && display_code.trim().length > 0) {
788
+ var dictList = def_docs["def_" + ref_pk];
789
+
790
+ if (dictList && dictList.length > 0) {
791
+ var filteredDict = dictList.find(function (item) {
792
+ return item.pk.toString() == formItemValue;
793
+ });
794
+
795
+ if (filteredDict) {
796
+ var ref_title = filteredDict.title;
797
+ data[display_code] = ref_title;
798
+ setFieldsValue(_defineProperty({}, display_code, ref_title));
799
+ }
800
+ }
801
+ }
802
+ }
803
+ };
804
+
805
+ for (var i = 0, len = otherFormItemResponses.length; i < len; i++) {
806
+ var _ret = _loop(i, len);
807
+
808
+ if (_ret === "continue") continue;
809
+ }
810
+ }
811
+
812
+ _this2.setState({
813
+ fieldCodeKeyMap: fieldCodeKeyMap
814
+ });
815
+ }
816
+ });
817
+
802
818
  _this2.ref = _this2.props.formref || /*#__PURE__*/_react["default"].createRef();
803
819
  _this2.state = {
804
- editFormulasState: []
820
+ fieldCodeKeyMap: {}
805
821
  };
806
822
  return _this2;
807
823
  }
@@ -809,32 +825,32 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
809
825
  _createClass(FormForModify, [{
810
826
  key: "componentDidMount",
811
827
  value: function componentDidMount() {
812
- var _this3 = this;
813
-
814
828
  var _this$props = this.props,
815
829
  data = _this$props.data,
816
830
  info_set_fields = _this$props.info_set_fields;
817
- var editFormulasState = this.state.editFormulasState;
818
- info_set_fields.forEach(function (formItem) {
819
- _this3.preParseFormItemExtConfig(formItem);
820
-
821
- if (formItem.editFormulaConfigs) {
822
- for (var i = 0, len = formItem.editFormulaConfigs.length; i < len; i++) {
823
- var editFormulaConfig = formItem.editFormulaConfigs[i];
824
- var initialValue = formItem.ui_render_type === 'switch' ? (data[formItem.code] && data[formItem.code].toString() || '').toLowerCase() !== 'true' : data[formItem.code];
825
- var formulaValueOf = formItem.ui_render_type === 'switch' ? (editFormulaConfig.onValueOf || '').toLowerCase() !== 'true' : editFormulaConfig.onValueOf;
826
-
827
- if (formulaValueOf === initialValue) {
828
- editFormulasState.push({
829
- editFormulasStateCode: formItem.code,
830
- editFormulaItem: editFormulaConfig
831
- });
832
- }
833
- }
831
+ var fieldCodeKeyMap = this.state.fieldCodeKeyMap;
832
+
833
+ for (var i = 0, len = info_set_fields.length; i < len; i++) {
834
+ var formItem = info_set_fields[i];
835
+ this.preParseFormItemExtConfig(formItem);
836
+ var code = formItem.code,
837
+ ui_render_type = formItem.ui_render_type;
838
+ var fieldCodeValue = data[code];
839
+
840
+ if (_consts.UI_RENDER_TYPE.SWITCH == ui_render_type) {
841
+ fieldCodeValue = (fieldCodeValue + '' || '').toLowerCase() === 'true' || (fieldCodeValue + '' || '').toLowerCase() === '1' ? "true" : "false";
834
842
  }
835
- });
843
+
844
+ if (fieldCodeValue) {
845
+ this.formItemOnChangeForFormula(formItem, fieldCodeValue);
846
+ }
847
+
848
+ formItem.b_disabled = formItem.b_readonly;
849
+ fieldCodeKeyMap[formItem.code] = formItem;
850
+ }
851
+
836
852
  this.setState({
837
- editFormulasState: editFormulasState
853
+ fieldCodeKeyMap: fieldCodeKeyMap
838
854
  });
839
855
  }
840
856
  }, {
@@ -942,82 +958,14 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
942
958
  }, {
943
959
  key: "datePickerOnChange",
944
960
  value: function datePickerOnChange(config, callback, formData, dateFormat, date, dateString) {
945
- var _this4 = this;
946
-
947
- if (config.editFormulaConfigs && config.editFormulaConfigs.length) {
948
- var code = config.code;
949
- var editFormulasState = this.state.editFormulasState;
950
- var _this$ref$current = this.ref.current,
951
- setFieldsValue = _this$ref$current.setFieldsValue,
952
- resetFields = _this$ref$current.resetFields;
953
-
954
- if (dateString) {
955
- var editFormulaItem = config.editFormulaConfigs[0];
956
-
957
- if (editFormulaItem) {
958
- if (dateString) {
959
- editFormulaItem.otherFormItemResponses.forEach(function (item) {
960
- if (item.formItemValue === 'disabled') {
961
- resetFields([item.formItemCode]);
962
- setFieldsValue(_defineProperty({}, item.formItemCode, null));
963
-
964
- if (item.formItemCode.endsWith('_pk') && _this4.props.data["".concat(item.formItemCode.split('_pk')[0], "_ext_name")]) {
965
- _this4.props.data["".concat(item.formItemCode.split('_pk')[0], "_ext_name")] = null;
966
- } else if (item.formItemCode.indexOf('_pk$') !== -1 && _this4.props.data["".concat(item.formItemCode.split('_pk$')[0], "_ext_name$").concat(item.formItemCode.split('_pk$')[1])]) {
967
- _this4.props.data["".concat(item.formItemCode.split('_pk$')[0], "_ext_name$").concat(item.formItemCode.split('_pk$')[1])] = null;
968
- }
969
-
970
- _this4.props.data[item.formItemCode] = null;
971
- }
972
- });
973
- }
974
-
975
- if (editFormulasState.filter(function (item) {
976
- return item.editFormulasStateCode === code;
977
- }).length) {
978
- editFormulasState.forEach(function (item) {
979
- if (item.editFormulasStateCode === code) {
980
- item.editFormulaItem = editFormulaItem;
981
- }
982
- });
983
- } else {
984
- editFormulasState.push({
985
- editFormulasStateCode: code,
986
- editFormulaItem: editFormulaItem
987
- });
988
- }
989
- } else {
990
- if (editFormulasState.filter(function (item) {
991
- return item.editFormulasStateCode === code;
992
- }).length) {
993
- editFormulasState.forEach(function (item) {
994
- if (item.editFormulasStateCode === code) {
995
- item.editFormulaItem = null;
996
- }
997
- });
998
- }
999
- }
1000
- } else {
1001
- if (editFormulasState.filter(function (item) {
1002
- return item.editFormulasStateCode === code;
1003
- }).length) {
1004
- editFormulasState.forEach(function (item) {
1005
- if (item.editFormulasStateCode === code) {
1006
- item.editFormulaItem = null;
1007
- }
1008
- });
1009
- }
1010
- }
1011
-
1012
- this.setState({
1013
- editFormulasState: editFormulasState
1014
- });
1015
- }
1016
-
1017
961
  if (dateFormat != null) {
1018
962
  formData[config.code] = date.format(dateFormat);
1019
963
  }
1020
964
 
965
+ if (dateString) {
966
+ this.formItemOnChangeForFormula(config, dateString);
967
+ }
968
+
1021
969
  if (callback && typeof callback === "function") {
1022
970
  callback(date, dateString);
1023
971
  }
@@ -1047,8 +995,6 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
1047
995
  }, {
1048
996
  key: "selectOnChange",
1049
997
  value: function selectOnChange(config, callback, value, option) {
1050
- var _this5 = this;
1051
-
1052
998
  var display_code = config.display_code,
1053
999
  code = config.code;
1054
1000
 
@@ -1092,75 +1038,8 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
1092
1038
  this.props.data[display_code] = display_value;
1093
1039
  }
1094
1040
 
1095
- if (config.editFormulaConfigs && config.editFormulaConfigs.length) {
1096
- var editFormulasState = this.state.editFormulasState;
1097
- var _this$ref$current2 = this.ref.current,
1098
- setFieldsValue = _this$ref$current2.setFieldsValue,
1099
- resetFields = _this$ref$current2.resetFields;
1100
-
1101
- if (value) {
1102
- var editFormulaItem = config.editFormulaConfigs.filter(function (editFormulaItem) {
1103
- return editFormulaItem.onValueOf === value.toString();
1104
- })[0];
1105
-
1106
- if (editFormulaItem) {
1107
- if (value) {
1108
- editFormulaItem.otherFormItemResponses.forEach(function (item) {
1109
- if (item.formItemValue === 'disabled') {
1110
- resetFields([item.formItemCode]);
1111
- setFieldsValue(_defineProperty({}, item.formItemCode, null));
1112
-
1113
- if (item.formItemCode.endsWith('_pk') && _this5.props.data["".concat(item.formItemCode.split('_pk')[0], "_ext_name")]) {
1114
- _this5.props.data["".concat(item.formItemCode.split('_pk')[0], "_ext_name")] = null;
1115
- } else if (item.formItemCode.indexOf('_pk$') !== -1 && _this5.props.data["".concat(item.formItemCode.split('_pk$')[0], "_ext_name$").concat(item.formItemCode.split('_pk$')[1])]) {
1116
- _this5.props.data["".concat(item.formItemCode.split('_pk$')[0], "_ext_name$").concat(item.formItemCode.split('_pk$')[1])] = null;
1117
- }
1118
-
1119
- _this5.props.data[item.formItemCode] = null;
1120
- }
1121
- });
1122
- }
1123
-
1124
- if (editFormulasState.filter(function (item) {
1125
- return item.editFormulasStateCode === code;
1126
- }).length) {
1127
- editFormulasState.forEach(function (item) {
1128
- if (item.editFormulasStateCode === code) {
1129
- item.editFormulaItem = editFormulaItem;
1130
- }
1131
- });
1132
- } else {
1133
- editFormulasState.push({
1134
- editFormulasStateCode: code,
1135
- editFormulaItem: editFormulaItem
1136
- });
1137
- }
1138
- } else {
1139
- if (editFormulasState.filter(function (item) {
1140
- return item.editFormulasStateCode === code;
1141
- }).length) {
1142
- editFormulasState.forEach(function (item) {
1143
- if (item.editFormulasStateCode === code) {
1144
- item.editFormulaItem = null;
1145
- }
1146
- });
1147
- }
1148
- }
1149
- } else {
1150
- if (editFormulasState.filter(function (item) {
1151
- return item.editFormulasStateCode === code;
1152
- }).length) {
1153
- editFormulasState.forEach(function (item) {
1154
- if (item.editFormulasStateCode === code) {
1155
- item.editFormulaItem = null;
1156
- }
1157
- });
1158
- }
1159
- }
1160
-
1161
- this.setState({
1162
- editFormulasState: editFormulasState
1163
- });
1041
+ if (value) {
1042
+ this.formItemOnChangeForFormula(config, value);
1164
1043
  }
1165
1044
 
1166
1045
  if (callback && typeof callback === "function") {
@@ -1192,7 +1071,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
1192
1071
  }, {
1193
1072
  key: "buildTreeNode",
1194
1073
  value: function buildTreeNode(defNodes) {
1195
- var _this6 = this;
1074
+ var _this3 = this;
1196
1075
 
1197
1076
  if (!defNodes || defNodes.length === 0) {
1198
1077
  return null;
@@ -1213,7 +1092,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
1213
1092
  ext_attr_value: ext_attr_value,
1214
1093
  selectable: item.selectable,
1215
1094
  prop: ext_attr_value
1216
- }, _this6.buildTreeNode(item.children));
1095
+ }, _this3.buildTreeNode(item.children));
1217
1096
  });
1218
1097
  }
1219
1098
  }, {
@@ -1270,59 +1149,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
1270
1149
  }, {
1271
1150
  key: "switchOnChange",
1272
1151
  value: function switchOnChange(config, callback, checked, event) {
1273
- var _this7 = this;
1274
-
1275
- if (config.editFormulaConfigs && config.editFormulaConfigs.length) {
1276
- var code = config.code;
1277
- var editFormulasState = this.state.editFormulasState;
1278
- var _this$ref$current3 = this.ref.current,
1279
- setFieldsValue = _this$ref$current3.setFieldsValue,
1280
- resetFields = _this$ref$current3.resetFields;
1281
- var editFormulaItem = config.editFormulaConfigs.filter(function (editFormulaItem) {
1282
- return editFormulaItem.onValueOf === checked.toString();
1283
- })[0];
1284
-
1285
- if (editFormulaItem) {
1286
- if (!checked) {
1287
- editFormulaItem.otherFormItemResponses.forEach(function (item) {
1288
- resetFields([item.formItemCode]);
1289
- setFieldsValue(_defineProperty({}, item.formItemCode, null));
1290
-
1291
- if (item.formItemCode.endsWith('_pk') && _this7.props.data["".concat(item.formItemCode.split('_pk')[0], "_ext_name")]) {
1292
- _this7.props.data["".concat(item.formItemCode.split('_pk')[0], "_ext_name")] = null;
1293
- } else if (item.formItemCode.indexOf('_pk$') !== -1 && _this7.props.data["".concat(item.formItemCode.split('_pk$')[0], "_ext_name$").concat(item.formItemCode.split('_pk$')[1])]) {
1294
- _this7.props.data["".concat(item.formItemCode.split('_pk$')[0], "_ext_name$").concat(item.formItemCode.split('_pk$')[1])] = null;
1295
- }
1296
-
1297
- _this7.props.data[item.formItemCode] = null;
1298
- });
1299
- }
1300
-
1301
- if (editFormulasState.filter(function (item) {
1302
- return item.editFormulasStateCode === code;
1303
- }).length) {
1304
- editFormulasState.forEach(function (item) {
1305
- if (item.editFormulasStateCode === code) {
1306
- item.editFormulaItem = editFormulaItem;
1307
- }
1308
- });
1309
- } else {
1310
- editFormulasState.push({
1311
- editFormulasStateCode: code,
1312
- editFormulaItem: editFormulaItem
1313
- });
1314
- }
1315
- } else {
1316
- editFormulasState.push({
1317
- editFormulasStateCode: code,
1318
- editFormulaItem: null
1319
- });
1320
- }
1321
-
1322
- this.setState({
1323
- editFormulasState: editFormulasState
1324
- });
1325
- }
1152
+ this.formItemOnChangeForFormula(config, checked);
1326
1153
 
1327
1154
  if (callback && typeof callback === "function") {
1328
1155
  callback(checked, event);
@@ -1420,7 +1247,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
1420
1247
  key: "render",
1421
1248
  value: function render() {
1422
1249
  var props = this.props;
1423
- var editFormulasState = this.state.editFormulasState;
1250
+ var fieldCodeKeyMap = this.state.fieldCodeKeyMap;
1424
1251
  return /*#__PURE__*/_react["default"].createElement(_antd.ConfigProvider, {
1425
1252
  locale: _zh_CN["default"]
1426
1253
  }, /*#__PURE__*/_react["default"].createElement(_antd.Form, _extends({}, props, {
@@ -1428,7 +1255,7 @@ var FormForModify = /*#__PURE__*/function (_React$Component) {
1428
1255
  ref: this.ref,
1429
1256
  scrollToFirstError: true,
1430
1257
  onValuesChange: this.onValuesChange.bind(this)
1431
- }), this.buildFormItems(editFormulasState), this.buildExtFormItems()));
1258
+ }), this.buildFormItems(fieldCodeKeyMap), this.buildExtFormItems()));
1432
1259
  }
1433
1260
  }]);
1434
1261
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bchr/bchr-front-lib",
3
- "version": "0.3.102",
3
+ "version": "0.3.103",
4
4
  "description": "bchr front lib",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,24 +1,48 @@
1
- window.AppFormulaFunctions = {};
2
-
3
- window.AppFormulaFunctions.currentMonthStartDay = function (date) {
4
- var currentDate = new Date(date),
5
- currentYear = currentDate.getFullYear(),
6
- currentMouth = currentDate.getMonth() + 1;
7
- return currentYear + "-" + currentMouth + "-1"
8
- }
9
-
10
- window.AppFormulaFunctions.nextMonthStartDay = function (date) {
11
- var currentDate = new Date(date),
12
- currentYear = currentDate.getFullYear(),
13
- currentMouth = currentDate.getMonth() + 1;
14
- return new Date(currentYear, currentMouth, 1)
15
- }
16
-
17
- window.AppFormulaFunctions.currentDateToDeadline = function (date, during) {
18
- debugger
19
- var changeDate = new Date(new Date(date).getTime() + during * 24 * 60 * 60 * 1000);
20
- var changeYear = changeDate.getFullYear(),
21
- changeMouth = changeDate.getMonth() + 1,
22
- changeDay = changeDate.getDay();
23
- return changeYear + '-' + changeMouth + '-' + changeDay;
24
- }
1
+ import moment from "moment";
2
+
3
+ window.AppFormulaFunctions = {
4
+ currentMonthStartDay : function (dateStr) {
5
+ if (dateStr) {
6
+ let baseDate = moment(dateStr, "YYYY-MM-DD");
7
+ return baseDate.date(1).format("YYYY-MM-DD");
8
+ }
9
+
10
+ return null;
11
+ },
12
+
13
+ nextMonthStartDay : function (dateStr) {
14
+ if (dateStr) {
15
+ let baseDate = moment(dateStr, "YYYY-MM-DD");
16
+ return baseDate.add(1,'months').date(1).format("YYYY-MM-DD");
17
+ }
18
+
19
+ return null;
20
+ },
21
+
22
+ datePlusDays : function (dateStr, during_days) {
23
+ if (dateStr && during_days) {
24
+ let baseDate = moment(dateStr, "YYYY-MM-DD");
25
+ return baseDate.add(during_days, 'days').format("YYYY-MM-DD")
26
+ }
27
+
28
+ return null;
29
+ },
30
+
31
+ datePlusMonths : function (dateStr, during_months) {
32
+ if (dateStr && during_months) {
33
+ let baseDate = moment(dateStr, "YYYY-MM-DD");
34
+ return baseDate.add(during_months, 'months').format("YYYY-MM-DD")
35
+ }
36
+
37
+ return null;
38
+ },
39
+
40
+ datePlusYears : function (dateStr, during_years) {
41
+ if (dateStr && during_years) {
42
+ let baseDate = moment(dateStr, "YYYY-MM-DD");
43
+ return baseDate.add(during_years, 'years').format("YYYY-MM-DD")
44
+ }
45
+
46
+ return null;
47
+ }
48
+ };
@@ -22,6 +22,13 @@ import {UI_RENDER_TYPE} from "../consts";
22
22
  import zhCN from "antd/es/locale/zh_CN";
23
23
  import HttpService from "../../../../services/HttpService";
24
24
  import InputPassword from "../InputPassword";
25
+ import '../../../AppFormulaFunctions'
26
+
27
+ const FormulasValueType = {
28
+ Disabled : "disabled",
29
+ Enabled : "enabled",
30
+ Function : "AppFormulaFunctions",
31
+ }
25
32
 
26
33
  class FormForModify extends React.Component{
27
34
  constructor(props) {
@@ -30,28 +37,37 @@ class FormForModify extends React.Component{
30
37
  this.ref = this.props.formref || React.createRef();
31
38
 
32
39
  this.state = {
33
- editFormulasState: []
40
+ fieldCodeKeyMap: {},
34
41
  }
35
42
  }
36
43
 
37
44
  componentDidMount() {
38
45
  let {data, info_set_fields} = this.props;
39
- let {editFormulasState} = this.state;
40
- info_set_fields.forEach(formItem => {
46
+ let {fieldCodeKeyMap} = this.state;
47
+
48
+ for (let i = 0, len = info_set_fields.length; i < len; i++) {
49
+ let formItem = info_set_fields[i];
50
+
41
51
  this.preParseFormItemExtConfig(formItem);
42
- if (formItem.editFormulaConfigs) {
43
- for (let i = 0, len = formItem.editFormulaConfigs.length; i < len; i++) {
44
- let editFormulaConfig = formItem.editFormulaConfigs[i];
45
- let initialValue = formItem.ui_render_type === 'switch' ? ((data[formItem.code] && data[formItem.code].toString()) || '').toLowerCase() !== 'true' : data[formItem.code];
46
- let formulaValueOf = formItem.ui_render_type === 'switch' ? (editFormulaConfig.onValueOf || '').toLowerCase() !== 'true' : editFormulaConfig.onValueOf;
47
-
48
- if (formulaValueOf === initialValue) {
49
- editFormulasState.push({editFormulasStateCode: formItem.code, editFormulaItem: editFormulaConfig})
50
- }
51
- }
52
+
53
+ let {code, ui_render_type} = formItem;
54
+ let fieldCodeValue = data[code];
55
+
56
+ if (UI_RENDER_TYPE.SWITCH == ui_render_type) {
57
+ fieldCodeValue = (((fieldCodeValue + '' || '').toLowerCase() === 'true' || (fieldCodeValue + '' || '').toLowerCase() === '1') ? "true" : "false");
58
+ }
59
+
60
+ if (fieldCodeValue) {
61
+ this.formItemOnChangeForFormula(formItem, fieldCodeValue);
52
62
  }
63
+
64
+ formItem.b_disabled = formItem.b_readonly;
65
+ fieldCodeKeyMap[formItem.code] = formItem;
66
+ }
67
+
68
+ this.setState({
69
+ fieldCodeKeyMap,
53
70
  })
54
- this.setState({editFormulasState})
55
71
  }
56
72
 
57
73
  buildExtFormItems = () => {
@@ -129,114 +145,13 @@ class FormForModify extends React.Component{
129
145
  )
130
146
  }
131
147
 
132
- buildFormItems = (editFormulasState) => {
133
- let {data, info_set_fields, ext_form_items} = this.props;
148
+ buildFormItems = () => {
149
+ let {info_set_fields, ext_form_items} = this.props;
134
150
  if (this.ref.current == null) {
135
151
  return;
136
152
  }
137
153
 
138
- let {setFieldsValue} = this.ref.current;
139
154
  if (info_set_fields && info_set_fields.length > 0) {
140
- info_set_fields.forEach(formItem => {
141
- formItem.initialValue = null;
142
-
143
- this.preParseFormItemExtConfig(formItem);
144
-
145
- if (editFormulasState && editFormulasState.length) {
146
- formItem.b_disabled = formItem.b_readonly;
147
- for (let i = 0, len = editFormulasState.length; i < len; i++) {
148
- let editFormulaStateItemCode = editFormulasState[i].editFormulasStateCode;
149
- let editFormulaStateItem = editFormulasState[i].editFormulaItem;
150
- if (editFormulaStateItem) {
151
- editFormulaStateItem.otherFormItemResponses.forEach(item => {
152
- if (formItem.code === item.formItemCode) {
153
- if (item.formItemValue === 'disabled') {
154
- formItem.b_disabled = true;
155
- } else if (item.formItemValue === 'enabled') {
156
- formItem.b_disabled = false;
157
- } else if (item.formItemValue.indexOf('exp') !== -1) {
158
- let expValue = '';
159
- if (isNaN(data[formItem.code])) {
160
- expValue = item.formItemValue.split('exp(')[1].split(')')[0].replace('#value#', data[formItem.code]);
161
- } else {
162
- expValue = String(item.formItemValue.split('exp(')[1].split(')')[0].replace('#value#', Number(data[formItem.code])));
163
- }
164
- formItem.initialValue = eval(expValue);
165
- } else if (item.formItemValue.indexOf('AppFormulaFunctions') !== -1) {
166
- let formulaValue = '';
167
- if (item.formItemValue.indexOf('currentDateToDeadline') !== -1) {
168
- formulaValue = eval(item.formItemValue.replace('#value#', `data[editFormulaStateItemCode], 300`))
169
- } else {
170
- formulaValue = eval(item.formItemValue.replace('#value#', data[editFormulaStateItemCode]))
171
- }
172
- if (formItem.ui_render_type === UI_RENDER_TYPE.DATE || formItem.ui_render_type === UI_RENDER_TYPE.DATE_MONTH || formItem.ui_render_type === UI_RENDER_TYPE.DATE_YEAR || formItem.ui_render_type === UI_RENDER_TYPE.DATE_TIME) {
173
- formulaValue = moment(formulaValue);
174
- }
175
- formItem.initialValue = formulaValue;
176
- } else {
177
- formItem.initialValue = item.formItemValue || data[formItem.display_code];
178
- }
179
- if (formItem.initialValue || data[formItem.code]) {
180
- if (formItem.code.indexOf('date') !== -1) {
181
- setFieldsValue({[formItem.code]: moment(formItem.initialValue || data[formItem.code])});
182
- if (formItem.code.endsWith("_date")) {
183
- data[formItem.code] = moment(formItem.initialValue || data[formItem.code]).valueOf();
184
- } else if (formItem.code.indexOf('_date$') !== -1) {
185
- data[formItem.code] = moment(formItem.initialValue || data[formItem.code]).format("YYYY-MM-DD");
186
- }
187
- } else {
188
- setFieldsValue({[formItem.code]: formItem.initialValue || data[formItem.code]});
189
- data[formItem.code] = formItem.initialValue || data[formItem.code];
190
- }
191
- }
192
- }
193
- })
194
- }
195
- }
196
-
197
- } else {
198
- if (formItem.editFormulaConfigs) {
199
- for (let i = 0, len = formItem.editFormulaConfigs.length; i < len; i++) {
200
- let editFormulaConfig = formItem.editFormulaConfigs[i];
201
- let initialValue = formItem.ui_render_type === 'switch' ? ((data[formItem.code] && data[formItem.code].toString()) || '').toLowerCase() !== 'true' : data[formItem.code];
202
- let formulaValueOf = formItem.ui_render_type === 'switch' ? (editFormulaConfig.onValueOf || '').toLowerCase() !== 'true' : editFormulaConfig.onValueOf;
203
-
204
- if (formulaValueOf === initialValue) {
205
- let currentOtherFormItemResponses = editFormulaConfig.otherFormItemResponses;
206
- currentOtherFormItemResponses.forEach(item => {
207
- info_set_fields.forEach(formItemInner => {
208
- if (formItemInner.code === item.formItemCode) {
209
- if (item.formItemValue === 'disabled') {
210
- formItemInner.b_disabled = true;
211
- } else if (item.formItemValue === 'enabled') {
212
- formItemInner.b_disabled = false;
213
- } else {
214
- formItemInner.initialValue = item.formItemValue || data[formItemInner.display_code];
215
- }
216
- if (formItemInner.initialValue || data[formItemInner.code]) {
217
- if (formItemInner.code.indexOf('date') !== -1) {
218
- setFieldsValue({[formItemInner.code]: moment(formItemInner.initialValue || data[formItemInner.code])})
219
- if (formItemInner.code.endsWith("_date")) {
220
- data[formItemInner.code] = moment(formItemInner.initialValue || data[formItemInner.code]).valueOf();
221
- } else if (formItemInner.code.indexOf('_date$') !== -1) {
222
- data[formItemInner.code] = moment(formItem.initialValue || data[formItemInner.code]).format("YYYY-MM-DD");
223
- }
224
- } else {
225
- setFieldsValue({[formItemInner.code]: formItemInner.initialValue || data[formItemInner.code]});
226
- data[formItemInner.code] = formItemInner.initialValue || data[formItemInner.code];
227
- }
228
- }
229
- }
230
- })
231
- })
232
- }
233
-
234
- }
235
-
236
- }
237
-
238
- }
239
- })
240
155
 
241
156
  let groupNames = info_set_fields.map(item => item.belong_form_group).filter((item, index, arr) => item && item.trim().length > 0 && arr.indexOf(item) === index);
242
157
 
@@ -943,61 +858,14 @@ class FormForModify extends React.Component{
943
858
  }
944
859
 
945
860
  datePickerOnChange(config, callback, formData, dateFormat, date, dateString) {
946
- if (config.editFormulaConfigs && config.editFormulaConfigs.length) {
947
- let {code} = config;
948
- let {editFormulasState} = this.state;
949
- let {setFieldsValue, resetFields} = this.ref.current;
950
- if (dateString) {
951
- let editFormulaItem = config.editFormulaConfigs[0];
952
- if (editFormulaItem) {
953
- if (dateString) {
954
- editFormulaItem.otherFormItemResponses.forEach(item => {
955
- if (item.formItemValue === 'disabled') {
956
- resetFields([item.formItemCode]);
957
- setFieldsValue({[item.formItemCode]: null});
958
- if (item.formItemCode.endsWith('_pk') && this.props.data[`${item.formItemCode.split('_pk')[0]}_ext_name`]) {
959
- this.props.data[`${item.formItemCode.split('_pk')[0]}_ext_name`] = null;
960
- } else if (item.formItemCode.indexOf('_pk$') !== -1 && this.props.data[`${item.formItemCode.split('_pk$')[0]}_ext_name$${item.formItemCode.split('_pk$')[1]}`]) {
961
- this.props.data[`${item.formItemCode.split('_pk$')[0]}_ext_name$${item.formItemCode.split('_pk$')[1]}`] = null;
962
- }
963
- this.props.data[item.formItemCode] = null;
964
- }
965
- })
966
- }
967
- if (editFormulasState.filter(item => item.editFormulasStateCode === code).length) {
968
- editFormulasState.forEach(item => {
969
- if (item.editFormulasStateCode === code) {
970
- item.editFormulaItem = editFormulaItem;
971
- }
972
- })
973
- } else {
974
- editFormulasState.push({editFormulasStateCode: code, editFormulaItem});
975
- }
976
- } else {
977
- if (editFormulasState.filter(item => item.editFormulasStateCode === code).length) {
978
- editFormulasState.forEach(item => {
979
- if (item.editFormulasStateCode === code) {
980
- item.editFormulaItem = null;
981
- }
982
- })
983
- }
984
- }
985
- } else {
986
- if (editFormulasState.filter(item => item.editFormulasStateCode === code).length) {
987
- editFormulasState.forEach(item => {
988
- if (item.editFormulasStateCode === code) {
989
- item.editFormulaItem = null;
990
- }
991
- })
992
- }
993
- }
994
- this.setState({editFormulasState})
995
- }
996
-
997
861
  if (dateFormat != null) {
998
862
  formData[config.code] = date.format(dateFormat);
999
863
  }
1000
864
 
865
+ if (dateString) {
866
+ this.formItemOnChangeForFormula(config, dateString);
867
+ }
868
+
1001
869
  if (callback && typeof callback === "function") {
1002
870
  callback(date, dateString);
1003
871
  }
@@ -1070,56 +938,8 @@ class FormForModify extends React.Component{
1070
938
  this.props.data[display_code] = display_value;
1071
939
  }
1072
940
 
1073
- if (config.editFormulaConfigs && config.editFormulaConfigs.length) {
1074
- let {editFormulasState} = this.state;
1075
- let {setFieldsValue, resetFields} = this.ref.current;
1076
-
1077
- if (value) {
1078
- let editFormulaItem = config.editFormulaConfigs.filter(editFormulaItem => editFormulaItem.onValueOf === value.toString())[0];
1079
- if (editFormulaItem) {
1080
- if (value) {
1081
- editFormulaItem.otherFormItemResponses.forEach(item => {
1082
- if (item.formItemValue === 'disabled') {
1083
- resetFields([item.formItemCode]);
1084
- setFieldsValue({[item.formItemCode]: null});
1085
- if (item.formItemCode.endsWith('_pk') && this.props.data[`${item.formItemCode.split('_pk')[0]}_ext_name`]) {
1086
- this.props.data[`${item.formItemCode.split('_pk')[0]}_ext_name`] = null;
1087
- } else if (item.formItemCode.indexOf('_pk$') !== -1 && this.props.data[`${item.formItemCode.split('_pk$')[0]}_ext_name$${item.formItemCode.split('_pk$')[1]}`]) {
1088
- this.props.data[`${item.formItemCode.split('_pk$')[0]}_ext_name$${item.formItemCode.split('_pk$')[1]}`] = null;
1089
- }
1090
- this.props.data[item.formItemCode] = null;
1091
- }
1092
- })
1093
- }
1094
- if (editFormulasState.filter(item => item.editFormulasStateCode === code).length) {
1095
- editFormulasState.forEach(item => {
1096
- if (item.editFormulasStateCode === code) {
1097
- item.editFormulaItem = editFormulaItem;
1098
- }
1099
- })
1100
- } else {
1101
- editFormulasState.push({editFormulasStateCode: code, editFormulaItem});
1102
- }
1103
- } else {
1104
- if (editFormulasState.filter(item => item.editFormulasStateCode === code).length) {
1105
- editFormulasState.forEach(item => {
1106
- if (item.editFormulasStateCode === code) {
1107
- item.editFormulaItem = null;
1108
- }
1109
- })
1110
- }
1111
- }
1112
- } else {
1113
- if (editFormulasState.filter(item => item.editFormulasStateCode === code).length) {
1114
- editFormulasState.forEach(item => {
1115
- if (item.editFormulasStateCode === code) {
1116
- item.editFormulaItem = null;
1117
- }
1118
- })
1119
- }
1120
- }
1121
-
1122
- this.setState({editFormulasState})
941
+ if (value) {
942
+ this.formItemOnChangeForFormula(config, value)
1123
943
  }
1124
944
 
1125
945
  if (callback && typeof callback === "function") {
@@ -1217,39 +1037,106 @@ class FormForModify extends React.Component{
1217
1037
  }
1218
1038
  }
1219
1039
 
1220
- switchOnChange(config, callback, checked, event) {
1221
- if (config.editFormulaConfigs && config.editFormulaConfigs.length) {
1222
- let {code} = config;
1223
- let {editFormulasState} = this.state;
1224
- let {setFieldsValue, resetFields} = this.ref.current;
1225
- let editFormulaItem = config.editFormulaConfigs.filter(editFormulaItem => editFormulaItem.onValueOf === checked.toString())[0];
1040
+ formItemOnChangeForFormula = (config, value) => {
1041
+ let formItemFormulaConfigs = config.editFormulaConfigs;
1042
+ if (formItemFormulaConfigs && formItemFormulaConfigs.length > 0) {
1043
+ let {fieldCodeKeyMap} = this.state;
1044
+ let {data, def_docs} = this.props;
1045
+ let {setFieldsValue} = this.ref.current;
1046
+ // value exists
1047
+ let editFormulaItem = config.editFormulaConfigs.find(editFormulaItem => editFormulaItem.onValueOf === value.toString() || editFormulaItem.onValueOf === "value");
1048
+
1226
1049
  if (editFormulaItem) {
1227
- if (!checked) {
1228
- editFormulaItem.otherFormItemResponses.forEach(item => {
1229
- resetFields([item.formItemCode]);
1230
- setFieldsValue({[item.formItemCode]: null});
1231
- if (item.formItemCode.endsWith('_pk') && this.props.data[`${item.formItemCode.split('_pk')[0]}_ext_name`]) {
1232
- this.props.data[`${item.formItemCode.split('_pk')[0]}_ext_name`] = null;
1233
- } else if (item.formItemCode.indexOf('_pk$') !== -1 && this.props.data[`${item.formItemCode.split('_pk$')[0]}_ext_name$${item.formItemCode.split('_pk$')[1]}`]) {
1234
- this.props.data[`${item.formItemCode.split('_pk$')[0]}_ext_name$${item.formItemCode.split('_pk$')[1]}`] = null;
1050
+ let otherFormItemResponses = editFormulaItem.otherFormItemResponses;
1051
+
1052
+ for (let i = 0, len = otherFormItemResponses.length; i < len; i++) {
1053
+ let otherFormItem = otherFormItemResponses[i];
1054
+ if (!otherFormItem) {
1055
+ continue;
1056
+ }
1057
+
1058
+ let {formItemCode, formItemValue} = otherFormItem;
1059
+ let otherFormItemConfig = fieldCodeKeyMap[formItemCode];
1060
+ if (!otherFormItemConfig) {
1061
+ continue;
1062
+ }
1063
+
1064
+ if (!formItemValue) {
1065
+ continue;
1066
+ }
1067
+
1068
+ let {code, display_code, ref_pk, ui_render_type} = otherFormItemConfig;
1069
+ if (FormulasValueType.Disabled == formItemValue) {
1070
+ data[code] = null;
1071
+ setFieldsValue({[code]: null});
1072
+
1073
+ if (display_code) {
1074
+ data[display_code] = null;
1075
+ setFieldsValue({[display_code]: null});
1235
1076
  }
1236
- this.props.data[item.formItemCode] = null;
1237
- })
1238
- }
1239
- if (editFormulasState.filter(item => item.editFormulasStateCode === code).length) {
1240
- editFormulasState.forEach(item => {
1241
- if (item.editFormulasStateCode === code) {
1242
- item.editFormulaItem = editFormulaItem;
1077
+
1078
+ otherFormItemConfig.b_disabled = true;
1079
+ otherFormItemConfig.b_readonly = true;
1080
+ } else if (FormulasValueType.Enabled == formItemValue) {
1081
+
1082
+ otherFormItemConfig.b_disabled = false;
1083
+ otherFormItemConfig.b_readonly = true;
1084
+ } else if (formItemValue.startsWith(FormulasValueType.Function)) {
1085
+ let formulaFunctionValue;
1086
+ if (formItemValue.search("#value#") !== -1) {
1087
+ formulaFunctionValue = eval(formItemValue.replace('#value#', `value`).replace("@", ","));
1088
+ } else {
1089
+ let formItemValueList = formItemValue.split("#");
1090
+ if (!formItemValueList || formItemValueList.length != 3) {
1091
+ console.log("formula error, detail info: formItemCode=" + formItemValue + ", formItemValue=" + formItemValue);
1092
+ continue;
1093
+ }
1094
+
1095
+ let realFormulaValue = formItemValueList[0] + `data[formItemValueList[1]]` + formItemValueList[2];
1096
+
1097
+ formulaFunctionValue = eval(realFormulaValue.replace("@", ","));
1243
1098
  }
1244
- })
1245
- } else {
1246
- editFormulasState.push({editFormulasStateCode: code, editFormulaItem});
1099
+
1100
+ if (!formulaFunctionValue) {
1101
+ console.log("formula function return null, detail info: formItemCode=" + formItemValue + ", formItemValue=" + formItemValue);
1102
+ continue;
1103
+ }
1104
+
1105
+ data[code] = formulaFunctionValue;
1106
+
1107
+ let otherFormItemValue;
1108
+ if (UI_RENDER_TYPE.DATE == ui_render_type) {
1109
+ otherFormItemValue = moment(formulaFunctionValue, "YYYY-MM-DD");
1110
+ } else {
1111
+ otherFormItemValue = formulaFunctionValue;
1112
+ }
1113
+ setFieldsValue({[code]: otherFormItemValue});
1114
+ } else {
1115
+ data[code] = formItemValue;
1116
+ setFieldsValue({[code]: formItemValue});
1117
+
1118
+ if (display_code && display_code.trim().length > 0) {
1119
+ let dictList = def_docs["def_" + ref_pk];
1120
+ if (dictList && dictList.length > 0) {
1121
+ let filteredDict = dictList.find(item => item.pk.toString() == formItemValue);
1122
+ if (filteredDict) {
1123
+ let ref_title = filteredDict.title;
1124
+
1125
+ data[display_code] = ref_title;
1126
+ setFieldsValue({[display_code]: ref_title});
1127
+ }
1128
+ }
1129
+ }
1130
+ }
1247
1131
  }
1248
- } else {
1249
- editFormulasState.push({editFormulasStateCode: code, editFormulaItem: null});
1250
1132
  }
1251
- this.setState({editFormulasState})
1133
+
1134
+ this.setState({fieldCodeKeyMap})
1252
1135
  }
1136
+ }
1137
+
1138
+ switchOnChange(config, callback, checked, event) {
1139
+ this.formItemOnChangeForFormula(config, checked);
1253
1140
 
1254
1141
  if (callback && typeof callback === "function") {
1255
1142
  callback(checked, event);
@@ -1312,7 +1199,7 @@ class FormForModify extends React.Component{
1312
1199
 
1313
1200
  render() {
1314
1201
  let {props} = this;
1315
- let {editFormulasState} = this.state;
1202
+ let {fieldCodeKeyMap} = this.state;
1316
1203
  return (
1317
1204
  <ConfigProvider locale={zhCN}>
1318
1205
  <Form
@@ -1322,7 +1209,7 @@ class FormForModify extends React.Component{
1322
1209
  scrollToFirstError
1323
1210
  onValuesChange={this.onValuesChange.bind(this)}
1324
1211
  >
1325
- {this.buildFormItems(editFormulasState)}
1212
+ {this.buildFormItems(fieldCodeKeyMap)}
1326
1213
  {this.buildExtFormItems()}
1327
1214
  </Form>
1328
1215
  </ConfigProvider>