UNPKG

11.4 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports["default"] = void 0;
7
8var _react = _interopRequireDefault(require("react"));
9
10var _propTypes = _interopRequireDefault(require("prop-types"));
11
12var _reactLifecyclesCompat = require("react-lifecycles-compat");
13
14var _TabsComponents = _interopRequireDefault(require("./components/TabsComponents"));
15
16function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
18function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
20function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
21
22function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
23
24function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
25
26function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
27
28function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
29
30function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
31
32function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
33
34var Formulas =
35/*#__PURE__*/
36function (_React$Component) {
37 _inherits(Formulas, _React$Component);
38
39 function Formulas(props) {
40 var _this;
41
42 _classCallCheck(this, Formulas);
43
44 _this = _possibleConstructorReturn(this, _getPrototypeOf(Formulas).call(this, props));
45 _this.onChange = _this.onChange.bind(_assertThisInitialized(_this));
46 _this.onClick = _this.onClick.bind(_assertThisInitialized(_this));
47 _this.onCancel = _this.onCancel.bind(_assertThisInitialized(_this));
48 _this.onSubmit = _this.onSubmit.bind(_assertThisInitialized(_this));
49 _this.onValidate = _this.onValidate.bind(_assertThisInitialized(_this));
50 _this.onValueSelected = _this.onValueSelected.bind(_assertThisInitialized(_this));
51 _this.onClear = _this.onClear.bind(_assertThisInitialized(_this));
52 _this.onInsertValue = _this.onInsertValue.bind(_assertThisInitialized(_this));
53 _this.onDesc = _this.onDesc.bind(_assertThisInitialized(_this));
54 _this.state = {
55 value: _this.props.textareaValue,
56 tabs: _this.props.tabs,
57 tabsJSON: JSON.stringify(_this.props.tabs),
58 activeKey: _this.props.activeKey,
59 DocumentTreeData: _this.props.DocumentTreeData,
60 DocumentTreeDataJSON: JSON.stringify(_this.props.DocumentTreeData),
61 textDescription: '' // this.yyFormulasTextareaRef = React.createRef()
62
63 };
64 return _this;
65 }
66
67 _createClass(Formulas, [{
68 key: "componentWillReceiveProps",
69 value: function componentWillReceiveProps(nextProps) {
70 if (nextProps.textareaValue != this.state.value) {
71 this.setState({
72 value: nextProps.textareaValue
73 });
74 }
75
76 if (JSON.stringify(nextProps.tabs) != this.state.tabsJSON) {
77 this.setState({
78 tabs: nextProps.tabs,
79 tabsJSON: JSON.stringify(nextProps.tabs)
80 });
81 }
82
83 if (nextProps.activeKey != this.state.activeKey) {
84 var activeKey = nextProps.activeKey;
85 this.setState({
86 activeKey: activeKey
87 });
88 }
89
90 if (JSON.stringify(nextProps.DocumentTreeData) != this.state.DocumentTreeData) {
91 this.setState({
92 DocumentTreeData: nextProps.DocumentTreeData,
93 DocumentTreeDataJSON: JSON.stringify(nextProps.DocumentTreeData)
94 });
95 }
96 }
97 }, {
98 key: "onChange",
99 value: function onChange(event) {
100 var _this2 = this;
101
102 var value = event.target.value;
103 this.setState({
104 value: value
105 }, function () {
106 _this2.props.onChange(value);
107 });
108 }
109 }, {
110 key: "onClick",
111 value: function onClick(item) {
112 if (this[item.event]) {
113 this[item.event]();
114 } else if (this.props[item.event]) {
115 this.props[item.event](this.state.value);
116 }
117 }
118 }, {
119 key: "onCancel",
120 value: function onCancel() {
121 this.props.onCancel(this.state.value);
122 }
123 }, {
124 key: "onSubmit",
125 value: function onSubmit() {
126 this.props.onSubmit(this.state.value);
127 }
128 }, {
129 key: "onValidate",
130 value: function onValidate() {
131 this.props.onValidate(this.state.value);
132 }
133 }, {
134 key: "onValueSelected",
135 value: function onValueSelected() {
136 // this.yyFormulasTextareaRef.current.select()
137 this.yyFormulasTextareaRef.select();
138 }
139 }, {
140 key: "onClear",
141 value: function onClear() {
142 var _this3 = this;
143
144 this.setState({
145 value: ''
146 }, function () {
147 _this3.props.onChange('');
148 });
149 }
150 }, {
151 key: "onInsertValue",
152 value: function onInsertValue(val) {
153 var _this4 = this;
154
155 console.log([this, this.yyFormulasTextareaRef]);
156 var yyFormulasTextareaRef = this.yyFormulasTextareaRef; // this.yyFormulasTextareaRef.current
157
158 if (document.selection) {
159 var sel = document.selection.createRange();
160 sel.text = val;
161 } else if (typeof yyFormulasTextareaRef.selectionStart === 'number' && typeof yyFormulasTextareaRef.selectionEnd === 'number') {
162 var startPos = yyFormulasTextareaRef.selectionStart;
163 var endPos = yyFormulasTextareaRef.selectionEnd;
164 var tmpStr = this.state.value;
165 var value = tmpStr.substring(0, startPos) + val + tmpStr.substring(endPos, tmpStr.length);
166 this.setState({
167 value: value
168 }, function () {
169 yyFormulasTextareaRef.selectionStart = _this4.state.value.length;
170 yyFormulasTextareaRef.selectionEnd = _this4.state.value.length;
171 });
172 } else {
173 this.setState({
174 value: val
175 }, function () {
176 yyFormulasTextareaRef.selectionStart = _this4.state.value.length;
177 yyFormulasTextareaRef.selectionEnd = _this4.state.value.length;
178 });
179 }
180 }
181 }, {
182 key: "onDesc",
183 value: function onDesc(key) {
184 var textDescription = key ? key.toUpperCase() + ':' + this.props.Description['' + key.toUpperCase()] : '';
185 this.setState({
186 textDescription: textDescription
187 });
188 }
189 }, {
190 key: "render",
191 value: function render() {
192 var _this5 = this;
193
194 var _this$props = this.props,
195 prefixCls = _this$props.prefixCls,
196 textareaPlaceholder = _this$props.textareaPlaceholder,
197 buttonList = _this$props.buttonList,
198 tabsPrefixCls = _this$props.tabsPrefixCls,
199 ReferDataUrl = _this$props.ReferDataUrl,
200 fixedData = _this$props.fixedData,
201 SubjectData = _this$props.SubjectData;
202 return _react["default"].createElement("div", {
203 className: prefixCls
204 }, _react["default"].createElement("div", {
205 className: "row"
206 }, _react["default"].createElement("div", {
207 className: prefixCls + '-textarea-warp col-xs-10 col-md-10 col-sm-10'
208 }, _react["default"].createElement("textarea", {
209 className: prefixCls + '-textarea form-control',
210 onChange: this.onChange,
211 placeholder: textareaPlaceholder,
212 ref: function ref(_ref) {
213 return _this5.yyFormulasTextareaRef = _ref;
214 },
215 value: this.state.value
216 })), _react["default"].createElement("div", {
217 className: prefixCls + '-button-warp col-xs-2 col-md-2 col-sm-2'
218 }, buttonList.map(function (item, index) {
219 return _react["default"].createElement("button", {
220 key: index,
221 className: prefixCls + '-button ' + item.className,
222 onClick: _this5.onClick.bind(_this5, item)
223 }, item.name);
224 }))), _react["default"].createElement("div", {
225 className: "row"
226 }, _react["default"].createElement(_TabsComponents["default"], {
227 prefixCls: tabsPrefixCls,
228 tabs: this.state.tabs,
229 activeKey: this.state.activeKey,
230 DocumentTreeData: this.state.DocumentTreeData,
231 onInsertValue: this.onInsertValue,
232 ReferDataUrl: ReferDataUrl,
233 fixedData: fixedData,
234 SubjectData: SubjectData,
235 onDesc: this.onDesc
236 })), _react["default"].createElement("p", {
237 className: "formulas-desc"
238 }, this.state.textDescription));
239 }
240 }]);
241
242 return Formulas;
243}(_react["default"].Component);
244
245var noop = function noop() {
246 return null;
247};
248
249Formulas.propTypes = {
250 prefixCls: _propTypes["default"].string,
251 textareaPlaceholder: _propTypes["default"].string,
252 textareaValue: _propTypes["default"].string,
253 buttonList: _propTypes["default"].array,
254 onCancel: _propTypes["default"].func,
255 onChange: _propTypes["default"].func,
256 onSubmit: _propTypes["default"].func,
257 onValidate: _propTypes["default"].func,
258 tabsPrefixCls: _propTypes["default"].string,
259 tabs: _propTypes["default"].array,
260 activeKey: _propTypes["default"].string,
261 //PropTypes.oneOfType([PropTypes.string,PropTypes.number]),
262 DocumentTreeData: _propTypes["default"].array,
263 ReferDataUrl: _propTypes["default"].string,
264 fixedData: _propTypes["default"].object,
265 Description: _propTypes["default"].object
266};
267Formulas.defaultProps = {
268 prefixCls: 'yy-formulas',
269 textareaPlaceholder: '请输入...',
270 textareaValue: '',
271 buttonList: [{
272 name: '确定',
273 className: 'btn btn-default',
274 event: 'onSubmit'
275 }, {
276 name: '取消',
277 className: 'btn btn-default',
278 event: 'onCancel'
279 }, {
280 name: '验证',
281 className: 'btn btn-default',
282 event: 'onValidate'
283 }, {
284 name: '全选',
285 className: 'btn btn-default',
286 event: 'onValueSelected'
287 }, {
288 name: '清空',
289 className: 'btn btn-default',
290 event: 'onClear'
291 }],
292 onCancel: noop,
293 onChange: noop,
294 onSubmit: noop,
295 onValidate: noop,
296 tabsPrefixCls: 'rc-tabs',
297 tabs: [{
298 id: 10,
299 name: '单据字段',
300 type: 'sys',
301 component: 'Document',
302 disabled: false
303 }, {
304 id: 11,
305 name: '固定值',
306 type: 'sys',
307 component: 'Fixed',
308 disabled: false
309 }, {
310 id: 12,
311 name: '科目转换',
312 type: 'sys',
313 component: 'Subject',
314 disabled: false
315 }],
316 activeKey: '10',
317 DocumentTreeData: [],
318 ReferDataUrl: '',
319 fixedData: {},
320 Description: {}
321};
322(0, _reactLifecyclesCompat.polyfill)(Formulas);
323var _default = Formulas;
324exports["default"] = _default;
\No newline at end of file