@aliretail/react-materials-components
Version:
195 lines (172 loc) • 8.21 kB
JavaScript
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _Button from "@alifd/next/es/button";
import _extends from "@babel/runtime/helpers/extends";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
var _excluded = ["url", "appCode", "apiCode", "width", "height", "topMessage", "primaryKey", "title", "showDeliveryStatus", "hidden", "mode", "columns", "selectEls", "value", "children", "onChange", "tablePageSizeList"];
// 添加购物车商品弹窗
import * as React from 'react';
import * as PropTypes from 'prop-types';
import FilterSelectorDialog from "../../FilterSelectorDialog";
import { getTableColumnsList } from "../utils/getTableColumnsList";
import { InnerForm } from "../InnerForm/index";
export var CommoditySelector = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(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: _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 = CommoditySelector.prototype;
_proto.render = function render() {
var childrenConfig = /*#__PURE__*/React.createElement(_Button, {
className: "btn",
type: "secondary"
}, this.props.title);
var columnsConfig = 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 = _objectWithoutPropertiesLoose(_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, _extends({
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);
CommoditySelector.InnerForm = InnerForm;
CommoditySelector.propTypes = {
title: PropTypes.string,
width: PropTypes.number
};
CommoditySelector.defaultProps = {
title: '添加商品',
width: 600
};