UNPKG

@aliretail/react-materials-components

Version:
191 lines (158 loc) 9.01 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.InnerForm = void 0; var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose")); 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 _excluded = ["url", "appCode", "apiCode", "width", "topMessage", "primaryKey", "title", "showDeliveryStatus", "hidden", "mode", "columns", "selectEls", "value", "tablePageSizeList", "onChange"]; 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 InnerForm = /*#__PURE__*/function (_React$Component) { (0, _inheritsLoose2["default"])(InnerForm, _React$Component); function InnerForm(props) { var _props$rowSelection, _props$value; var _this; _this = _React$Component.call(this, props) || this; _this.onChange = function (value) { _this.props.onChange(value); }; _this.handleRequestParams = function (filterData) { var _this$props = _this.props, selectEls = _this$props.selectEls, params = _this$props.params, propertyName = _this$props.propertyName, propertySelect = _this$props.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 = InnerForm.prototype; _proto.render = function render() { var columnsConfig = (0, _getTableColumnsList.getTableColumnsList)(this.props); var _this$props2 = this.props, url = _this$props2.url, _this$props2$appCode = _this$props2.appCode, appCode = _this$props2$appCode === void 0 ? '' : _this$props2$appCode, _this$props2$apiCode = _this$props2.apiCode, apiCode = _this$props2$apiCode === void 0 ? '' : _this$props2$apiCode, width = _this$props2.width, topMessage = _this$props2.topMessage, _this$props2$primaryK = _this$props2.primaryKey, primaryKey = _this$props2$primaryK === void 0 ? 'id' : _this$props2$primaryK, _this$props2$title = _this$props2.title, title = _this$props2$title === void 0 ? '添加商品' : _this$props2$title, showDeliveryStatus = _this$props2.showDeliveryStatus, hidden = _this$props2.hidden, _this$props2$mode = _this$props2.mode, mode = _this$props2$mode === void 0 ? 'multiple' : _this$props2$mode, _this$props2$columns = _this$props2.columns, columns = _this$props2$columns === void 0 ? columnsConfig : _this$props2$columns, _this$props2$selectEl = _this$props2.selectEls, selectEls = _this$props2$selectEl === void 0 ? [] : _this$props2$selectEl, _this$props2$value = _this$props2.value, value = _this$props2$value === void 0 ? [] : _this$props2$value, _this$props2$tablePag = _this$props2.tablePageSizeList, tablePageSizeList = _this$props2$tablePag === void 0 ? [20, 50, 100] : _this$props2$tablePag, onChange = _this$props2.onChange, othersConfig = (0, _objectWithoutPropertiesLoose2["default"])(_this$props2, _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"].InnerForm, (0, _extends2["default"])({ dialogWidth: width, url: url, apiCode: apiCode, appCode: appCode, requestExtraParams: dealParams, columns: columns, title: title, hasTableBorder: false // 表格不带边框 , mode: mode, primaryKey: primaryKey, selectedRowList: value // 按钮选中回显 , filterConfigList: !hidden ? getFilterConfigList() : [] // 下拉框data , onSelected: this.handleSelected // 返回选中的item数组和id数组 , topMessage: topMessage, handleRequestParams: this.handleRequestParams, tablePageSizeList: tablePageSizeList, rowSelection: rowSelection }, othersConfig)); }; return InnerForm; }(React.Component); exports.InnerForm = InnerForm; InnerForm.propTypes = { appCode: PropTypes.string, apiCode: PropTypes.string, params: PropTypes.object, propertyName: PropTypes.string, title: PropTypes.string, width: PropTypes.string, propertySelect: PropTypes.string };