react-form-ui-y
Version:
356 lines (292 loc) • 13.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _reactRedux = require('react-redux');
var _reactUtilsY = require('react-utils-y');
var _themeY = require('theme-y');
var _index = require('../../actions/index');
var _organizationTreeStyle = require('./organizationTreeStyle');
var _subpage = require('./subpage');
var _publicField = require('../publicField');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
// import {Theme} from '../../../theme/index';
var propTypes = {
designationTheme: _propTypes2.default.string,
formType: _propTypes2.default.string,
inputName: _propTypes2.default.string.isRequired,
formText: _propTypes2.default.string,
disabled: _propTypes2.default.bool,
required: _propTypes2.default.bool,
hintText: _propTypes2.default.string,
textWidth: _propTypes2.default.string,
valueWidth: _propTypes2.default.string,
changeValue: _propTypes2.default.func,
errorText: _propTypes2.default.string,
dataType: _propTypes2.default.string,
// remarks 无规则 自定义传参
// regex:PropTypes.number,//正则 input特有
regexText: _propTypes2.default.string //input特有
};
var removeByValue = function removeByValue(arr, val) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] == val) {
arr.splice(i, 1);
break;
}
}
};
var OrganizationTreeField = function (_Theme) {
_inherits(OrganizationTreeField, _Theme);
function OrganizationTreeField(props) {
_classCallCheck(this, OrganizationTreeField);
var _this2 = _possibleConstructorReturn(this, (OrganizationTreeField.__proto__ || Object.getPrototypeOf(OrganizationTreeField)).call(this, props));
_this2.initScrollList = function () {
_this2.setState({ shouldUpdateList: false });
};
_this2.initScrollChoose = function () {
_this2.setState({ shouldUpdateChoose: false });
};
_this2.initScroll = function () {
_this2.setState({ shouldUpdate: false });
};
_this2.handleShow = function (menuObj) {
var idText = _this2.props.idText || "orgId";
var showData = _this2.state.showData.concat();
if (showData.in_array(menuObj[idText])) {
removeByValue(showData, menuObj[idText]);
} else {
showData.push(menuObj[idText]);
}
_this2.setState({
showData: showData,
shouldUpdateList: true
});
};
_this2.handleMove = function (menuObj) {
_this2.setState({
moveItem: menuObj[_this2.props.idText || "orgId"]
});
};
_this2.handleLeave = function () {
_this2.setState({
moveItem: ""
});
};
_this2.deleteChoose = function (menuObj) {
var idText = _this2.props.idText || "orgId";
var chooseArr = _this2.state.chooseArr.concat();
var chooseData = Object.assign({}, _this2.state.chooseData);
removeByValue(chooseArr, menuObj[idText]);
delete chooseData[menuObj[idText]];
_this2.setState({
chooseArr: chooseArr, chooseData: chooseData,
shouldUpdateChoose: true
});
};
_this2.handleCheck = function (menuObj) {
var idText = _this2.props.idText || "orgId";
var chooseArr = _this2.state.chooseArr.concat();
var chooseData = Object.assign({}, _this2.state.chooseData);
if (chooseArr.in_array(menuObj[idText])) {
removeByValue(chooseArr, menuObj[idText]);
delete chooseData[menuObj[idText]];
} else {
chooseArr.push(menuObj[idText]);
chooseData[menuObj[idText]] = menuObj;
}
_this2.setState({
chooseArr: chooseArr, chooseData: chooseData,
shouldUpdateChoose: true
});
};
_this2.showTree = function (e) {
if (_this2.props.disabled) return false;
_this2.setState({
openTree: true
});
(0, _publicField.setLocationFn)(_this2, e);
};
_this2.handleTreeCloseSelect = function () {};
_this2.handleTreeSubmit = function () {
var _this = _this2;
var chooseData = _this.state.chooseData;
var idText = _this.props.idText || "orgId";
var nameText = _this.props.nameText || "nameText";
var choId = [],
choText = [],
choData = [],
choChlId = [],
choChlText = [],
choChlData = [];
var loopTree = function loopTree(data) {
if (data instanceof Array) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = data[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var o = _step.value;
loopTree(o);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
} else {
if (!choChlId.in_array(data[idText])) {
choChlId.push(data[idText]);
choChlText.push(data[nameText]);
choChlData.push(data);
}
if (data.subList && data.subList.length) {
loopTree(data.subList);
}
}
};
for (var o in chooseData) {
loopTree(chooseData[o]);
if (!choId.in_array(chooseData[o][idText])) {
choId.push(chooseData[o][idText]);
choText.push(chooseData[o][nameText]);
choData.push(chooseData[o]);
}
}
// let data = {
// choId, choText, choData, choChlId, choChlText, choChlData,
// };
_this2.setState({
openTree: false,
initFocusState: 1
});
var obj = [{
type: "organization", //type 类型
name: _this2.props.inputName, //name input名称
text: choText.join(), //选中的text集合
value: choId, //选中的ID集合
obj: {
choId: choId, choText: choText, choData: choData, choChlId: choChlId, choChlText: choChlText, choChlData: choChlData
},
remarks: _this2.props.remarks, //备注
other: {
required: _this2.props.required
}
}];
_this2.props.setFormData(obj, _this2.props.dataType);
};
_this2.handleTreeClose = function () {
_this2.setState({ openTree: false, initFocusState: 1 });
};
var _state = {
focusState: false, //处理点击的样式
initFocusState: 0, //是否触发过 0 未触发 1 已经触发
errorState: false, //是否显示报错提示框, true 显示报错 false 不显示
loading: false,
showData: [],
chooseArr: [],
chooseData: {},
shouldUpdateChoose: true, //选择展示区滚动条
shouldUpdateList: true, //列表滚动条true
selLocationH: "bottom", // selLocation:"bottom" // top bottom
selLocationW: "right" // left right
};
_this2.state = _reactUtilsY._Object.merge(_this2.state || {}, _state);
return _this2;
}
//列表滚动条
//选择展示区滚动条
// componentWillReceiveProps(nextProps) {
// if (nextProps && !nextProps.dataObj[nextProps.inputName]) {
// this.setState({
// showData: [],
// chooseArr: [],
// chooseData: {},
// })
// }
// }
//年份的下拉滚动条
//点击树复选框
//下拉点击旁边关闭下拉 设置date值
//数据提交
//返回
_createClass(OrganizationTreeField, [{
key: 'componentWillMount',
value: function componentWillMount() {
var props = this.props;
var flag = "set";
try {
//已经存在数据 就不 重新赋值
flag = props.formData[props.dataType || "default"][props.inputName] ? "none" : "set";
} catch (ex) {
flag = "set";
} finally {
if (props.inputName && flag == "set") {
var obj = [{
type: "organization", //type 类型
name: this.props.inputName, //name input名称
text: "", //text input值
value: "",
obj: [],
remarks: this.props.remarks, //备注
other: {
required: this.props.required
}
}];
props.setFormData(obj, props.dataType);
}
}
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.props.delFormData(this.props.inputName || "", this.props.dataType);
}
}, {
key: 'render',
value: function render() {
return (0, _publicField.renderBox)(this, _organizationTreeStyle.treeSty, _subpage.formTypeDom, _subpage.verifyFn);
}
}]);
return OrganizationTreeField;
}(_themeY.Theme);
OrganizationTreeField.propTypes = propTypes;
var mapStateToProps = function mapStateToProps(state) {
return {
formData: state.formData,
subVerifyRes: state.subVerifyRes,
theme: state.theme
};
};
var mapDispatchToProps = function mapDispatchToProps(dispatch) {
return {
setFormData: function setFormData(data, dataType) {
return dispatch((0, _index.setFormData)(data, dataType));
},
delFormData: function delFormData(inputName, dataType) {
return dispatch((0, _index.delFormData)(inputName, dataType));
}
};
};
exports.default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(OrganizationTreeField);
//# sourceMappingURL=organizationTreeField.js.map