@aliretail/react-materials-components
Version:
172 lines (151 loc) • 7.37 kB
JavaScript
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/extends";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
var _excluded = ["url", "appCode", "apiCode", "width", "topMessage", "primaryKey", "title", "showDeliveryStatus", "hidden", "mode", "columns", "selectEls", "value", "tablePageSizeList", "onChange"];
import * as React from 'react';
import * as PropTypes from 'prop-types';
import FilterSelectorDialog from "../../FilterSelectorDialog";
import { getTableColumnsList } from "../utils/getTableColumnsList";
export var InnerForm = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(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: _extends({}, (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 _extends({}, 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 _extends({}, customProps, {
disabled: !!(customProps !== null && customProps !== void 0 && customProps.disabled || props.isCheckAllDisabled)
});
}
})
};
return _this;
}
var _proto = InnerForm.prototype;
_proto.render = function render() {
var columnsConfig = 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 = _objectWithoutPropertiesLoose(_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.InnerForm, _extends({
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);
InnerForm.propTypes = {
appCode: PropTypes.string,
apiCode: PropTypes.string,
params: PropTypes.object,
propertyName: PropTypes.string,
title: PropTypes.string,
width: PropTypes.string,
propertySelect: PropTypes.string
};