UNPKG

@aliretail/react-materials-components

Version:
215 lines (178 loc) 9.88 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.CommoditySelector = void 0; var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")); var _button = _interopRequireDefault(require("@alifd/next/lib/button")); var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); var React = _interopRequireWildcard(require("react")); var PropTypes = _interopRequireWildcard(require("prop-types")); var _FilterSelectorDialog = _interopRequireDefault(require("../../FilterSelectorDialog")); var _getTableColumnsList = require("../utils/getTableColumnsList"); var _index = require("../InnerForm/index"); var _excluded = ["url", "appCode", "apiCode", "width", "height", "topMessage", "primaryKey", "title", "showDeliveryStatus", "hidden", "mode", "columns", "selectEls", "value", "children", "onChange", "tablePageSizeList"]; function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } var CommoditySelector = /*#__PURE__*/function (_React$Component) { (0, _inheritsLoose2["default"])(CommoditySelector, _React$Component); function CommoditySelector(props) { var _props$rowSelection, _props$value; var _this; _this = _React$Component.call(this, props) || this; _this.handleChange = function (data, btnId) { var _this$props = _this.props, onSubmit = _this$props.onSubmit, mode = _this$props.mode; if (!onSubmit) return; if (mode === 'single') { if (btnId && btnId.length) { onSubmit(btnId[0]); } else { onSubmit(''); } } else { onSubmit(data, btnId); } }; _this.handleRequestParams = function (filterData) { var _this$props2 = _this.props, selectEls = _this$props2.selectEls, params = _this$props2.params, propertyName = _this$props2.propertyName, propertySelect = _this$props2.propertySelect; var filterDataConfig = filterData && Object.entries(filterData)[0]; var dealParams = {}; if (filterDataConfig) { selectEls.forEach(function (it) { if (filterDataConfig[0] === it.value) { dealParams[propertyName] = filterDataConfig[1]; dealParams[propertySelect] = filterDataConfig[0]; } }); } _this.setState({ dealParams: Object.assign(params, dealParams) }); }; _this.handleSelected = function (valueList, keyList) { _this.props.onChange(valueList, keyList); }; _this.state = { dealParams: props.params, rowSelection: (0, _extends2["default"])({}, (props === null || props === void 0 ? void 0 : props.rowSelection) || {}, { selectedRowKeys: [].concat((props === null || props === void 0 ? void 0 : (_props$rowSelection = props.rowSelection) === null || _props$rowSelection === void 0 ? void 0 : _props$rowSelection.selectedRowKeys) || [], ((_props$value = props.value) === null || _props$value === void 0 ? void 0 : _props$value.map(function (e) { return e.id; })) || []), getProps: function getProps(record, index) { var _props$rowSelection2; var isDisabled = false; if (props.checkedDisabled) { var _record$item, _props$value2; if ((record === null || record === void 0 ? void 0 : (_record$item = record.item) === null || _record$item === void 0 ? void 0 : _record$item.quantity) === 0 || (_props$value2 = props.value) !== null && _props$value2 !== void 0 && _props$value2.find(function (e) { return e.id === (record === null || record === void 0 ? void 0 : record.id); })) { isDisabled = true; } } var customProps = (props === null || props === void 0 ? void 0 : (_props$rowSelection2 = props.rowSelection) === null || _props$rowSelection2 === void 0 ? void 0 : _props$rowSelection2.getProps(record, index)) || {}; return (0, _extends2["default"])({}, customProps, { disabled: isDisabled || customProps.disabled }); }, titleProps: function titleProps() { var _props$rowSelection3, _props$rowSelection4; var customProps = (props === null || props === void 0 ? void 0 : (_props$rowSelection3 = props.rowSelection) === null || _props$rowSelection3 === void 0 ? void 0 : _props$rowSelection3.titleProps) && (props === null || props === void 0 ? void 0 : (_props$rowSelection4 = props.rowSelection) === null || _props$rowSelection4 === void 0 ? void 0 : _props$rowSelection4.titleProps()) || {}; return (0, _extends2["default"])({}, customProps, { disabled: !!(customProps !== null && customProps !== void 0 && customProps.disabled || props.isCheckAllDisabled) }); } }) }; return _this; } // 选择数据 var _proto = CommoditySelector.prototype; _proto.render = function render() { var childrenConfig = /*#__PURE__*/React.createElement(_button["default"], { className: "btn", type: "secondary" }, this.props.title); var columnsConfig = (0, _getTableColumnsList.getTableColumnsList)(this.props); var _this$props3 = this.props, url = _this$props3.url, _this$props3$appCode = _this$props3.appCode, appCode = _this$props3$appCode === void 0 ? '' : _this$props3$appCode, _this$props3$apiCode = _this$props3.apiCode, apiCode = _this$props3$apiCode === void 0 ? '' : _this$props3$apiCode, _this$props3$width = _this$props3.width, width = _this$props3$width === void 0 ? 600 : _this$props3$width, height = _this$props3.height, topMessage = _this$props3.topMessage, _this$props3$primaryK = _this$props3.primaryKey, primaryKey = _this$props3$primaryK === void 0 ? 'code' : _this$props3$primaryK, _this$props3$title = _this$props3.title, title = _this$props3$title === void 0 ? '添加商品' : _this$props3$title, showDeliveryStatus = _this$props3.showDeliveryStatus, hidden = _this$props3.hidden, _this$props3$mode = _this$props3.mode, mode = _this$props3$mode === void 0 ? 'multiple' : _this$props3$mode, _this$props3$columns = _this$props3.columns, columns = _this$props3$columns === void 0 ? columnsConfig : _this$props3$columns, _this$props3$selectEl = _this$props3.selectEls, selectEls = _this$props3$selectEl === void 0 ? [] : _this$props3$selectEl, _this$props3$value = _this$props3.value, value = _this$props3$value === void 0 ? [] : _this$props3$value, _this$props3$children = _this$props3.children, children = _this$props3$children === void 0 ? childrenConfig : _this$props3$children, onChange = _this$props3.onChange, _this$props3$tablePag = _this$props3.tablePageSizeList, tablePageSizeList = _this$props3$tablePag === void 0 ? [20, 50, 100] : _this$props3$tablePag, othersConfig = (0, _objectWithoutPropertiesLoose2["default"])(_this$props3, _excluded); var _this$state = this.state, dealParams = _this$state.dealParams, rowSelection = _this$state.rowSelection; var getFilterConfigList = function getFilterConfigList() { var filterList = []; selectEls.forEach(function (it) { filterList.push({ code: it.value, codeName: it.label, inputPlaceholder: "\u8BF7\u8F93\u5165" + it.label }); }); return filterList; }; return /*#__PURE__*/React.createElement(_FilterSelectorDialog["default"], (0, _extends2["default"])({ dialogWidth: width, url: url, apiCode: apiCode, appCode: appCode, columns: columns, title: title, hasTableBorder: false, mode: mode, primaryKey: primaryKey, selectedRowList: value, filterConfigList: !hidden ? getFilterConfigList() : [], topMessage: topMessage, onSelected: this.handleSelected, onChange: this.handleChange, handleRequestParams: this.handleRequestParams, tablePageSizeList: tablePageSizeList }, othersConfig, { requestExtraParams: dealParams, rowSelection: rowSelection }), children); }; return CommoditySelector; }(React.Component); exports.CommoditySelector = CommoditySelector; CommoditySelector.InnerForm = _index.InnerForm; CommoditySelector.propTypes = { title: PropTypes.string, width: PropTypes.number }; CommoditySelector.defaultProps = { title: '添加商品', width: 600 };