UNPKG

ming-demo3

Version:
271 lines (233 loc) 8.43 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _react = _interopRequireDefault(require("react")); var _baseui = require("@mdf/baseui"); var _row = _interopRequireDefault(require("./row")); var _col = _interopRequireDefault(require("./col")); var _label = _interopRequireDefault(require("./label")); var _env = _interopRequireDefault(require("@mdf/metaui-web/lib/helpers/env")); var LabelSwitchControl = function (_React$Component) { (0, _inherits2["default"])(LabelSwitchControl, _React$Component); function LabelSwitchControl(props) { var _this; (0, _classCallCheck2["default"])(this, LabelSwitchControl); _this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(LabelSwitchControl).call(this, props)); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "doConfirm", function () { var _assertThisInitialize = (0, _assertThisInitialized2["default"])(_this), value = _assertThisInitialize.value; var _this$props = _this.props, viewModel = _this$props.viewModel, model = _this$props.model; var _this$state = _this.state, readOnly = _this$state.readOnly, config = _this$state.config; var YAction = config.YAction, NAction = config.NAction; var trueValue = _this._getTrueValue(value); var currentAction = value ? YAction : NAction; var acParams = { params: { index: _this.index, cItemName: currentAction } }; if (currentAction) { if (viewModel) { viewModel.biz["do"](currentAction, viewModel, acParams); } else { if (model) { model.getParent().biz["do"](currentAction, model.getParent(), acParams); } } } else { if (_this.props.model) { _this.props.model.setValue(trueValue, true); } else { if (_this.props.onChange) _this.props.onChange(trueValue); } } }); var cStyle = props.cStyle; var _config = {}; if (cStyle) { try { _config = JSON.parse(cStyle); } catch (e) { _config = {}; } } _this.state = { value: props.value, checkedChildren: props.checkedChildren || '√', unCheckedChildren: props.unCheckedChildren || 'X', defaultChecked: false, size: 'default', disabled: props.disabled || false, visible: !props.bHidden, readOnly: props.readOnly || false, style: {}, config: _config }; _this.getControl = _this.getControl.bind((0, _assertThisInitialized2["default"])(_this)); return _this; } (0, _createClass2["default"])(LabelSwitchControl, [{ key: "componentDidMount", value: function componentDidMount() { var _this2 = this; if (this.props.model) this.props.model.addListener(this); var pageModel = this.props.pageModel; if (pageModel) { pageModel.on('modeChange', function (mode) { _this2.setState({ disabled: mode !== _env["default"].VOUCHER_STATE_BROWSE }); }); } } }, { key: "componentWillUnmount", value: function componentWillUnmount() { if (this.props.model) this.props.model.removeListener(this); } }, { key: "componentDidUpdate", value: function componentDidUpdate() { if (this.props.model) this.props.model.addListener(this); } }, { key: "componentWillReceiveProps", value: function componentWillReceiveProps(nextProps) { if (this.props.model) return; if (nextProps.index >= 0 && nextProps.index !== this.index) { this.index = nextProps.index; } if (nextProps.value != 'undefined' & nextProps.value != undefined) { this.setState({ readOnly: nextProps.readOnly, disabled: nextProps.disabled, value: nextProps.value }); } else { this.setState({ readOnly: nextProps.readOnly }); } } }, { key: "setDisabled", value: function setDisabled(value) { var pageModel = this.props.pageModel; var _pageModel$getParams = pageModel.getParams(), metaType = _pageModel$getParams.metaType; this.setState({ disabled: metaType === 'treevoucher' ? !value : value }); } }, { key: "onChange", value: function onChange(value) { this.value = value; } }, { key: "baseControl", value: function baseControl() { var _this3 = this; var _this$state2 = this.state, value = _this$state2.value, config = _this$state2.config, disabled = _this$state2.disabled; var checked = value, title = "确认要停用吗?"; if ('N' in config) { if (value == config.N) checked = false; } if ('Y' in config) { if (value == config.Y) checked = true; } if (!checked) title = "确认要启用吗?"; return disabled ? _react["default"].createElement(_baseui.Switch, { checked: checked, onChange: function onChange(value) { return _this3.onChange(value); }, size: this.state.size, style: this.state.style, disabled: disabled, checkedChildren: this.state.checkedChildren, unCheckedChildren: this.state.unCheckedChildren }) : _react["default"].createElement(_baseui.Popconfirm, { overlayClassName: 'switch-popconform ncc-popconfirm', trigger: "click", placement: "top", title: title, okText: "\u786E\u5B9A", cancelText: "\u53D6\u6D88", btnReverse: true, onConfirm: this.doConfirm }, _react["default"].createElement("span", null, _react["default"].createElement(_baseui.Switch, { checked: checked, onChange: function onChange(value) { return _this3.onChange(value); }, size: this.state.size, style: this.state.style, disabled: disabled, checkedChildren: this.state.checkedChildren, unCheckedChildren: this.state.unCheckedChildren }))); } }, { key: "_getTrueValue", value: function _getTrueValue(value) { var trueValue = value; var config = this.state.config; if (value) { if ('Y' in config) trueValue = config.Y; } else { if ('N' in config) trueValue = config.N; } return trueValue; } }, { key: "getControl", value: function getControl() { var cShowCaption = this.props.cShowCaption; var title = !this.state.readOnly && this.state.bIsNull === false && cShowCaption ? _react["default"].createElement("label", null, _react["default"].createElement(Icon, { type: "star" }), cShowCaption) : _react["default"].createElement("label", null, cShowCaption); var control = cShowCaption ? _react["default"].createElement(_label["default"], { control: this.baseControl(), title: title }) : this.baseControl(); return control; } }, { key: "render", value: function render() { var control = this.getControl(); var style = this.state.visible ? { display: 'block' } : { display: "none" }; return _react["default"].createElement("div", { style: style }, control); } }]); return LabelSwitchControl; }(_react["default"].Component); exports["default"] = LabelSwitchControl; //# sourceMappingURL=labelswitch.js.map