UNPKG

@aliretail/react-materials-components

Version:
296 lines (262 loc) 9.67 kB
import _Select from "@alifd/next/es/select"; import _Field from "@alifd/next/es/field"; import _Dialog from "@alifd/next/es/dialog"; import _Message from "@alifd/next/es/message"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; /** * 当前先不管数据调用,该组件只接受数据,不调用接口处理数据 */ import * as React from 'react'; import * as PropTypes from 'prop-types'; import { fieldKey, getData, getFiledkeys, getValues, getValidataKeys, getErrInfo, deleteTable, getValueByName } from "./config/data-adaptor"; import StoreTable from "./components/StoreTable"; // const { Option } = Select; var SupplyRelationshipRatio = /*#__PURE__*/function (_React$Component) { _inheritsLoose(SupplyRelationshipRatio, _React$Component); // 即便 ts 声明了 SupplyRelationshipRatioProps,这里还是要提供 IPropsTypes,用于 react 报错提示 function SupplyRelationshipRatio(props) { var _values; var _this; _this = _React$Component.call(this, props) || this; _this.state = { warehouseSearchRes: [], isWareHouseSearch: false }; _this.warehouseChange = function (id) { var onWarehouseChange = _this.props.onWarehouseChange; // 重置table信息 var reset = _this.fields.reset; reset(fieldKey); onWarehouseChange(id); // 这个不做修改数据 // onChange([]); }; _this.onWarehouseSearch = function (val) { var warehouseList = _this.props.warehouseList; var list = getValueByName(warehouseList, val); _this.setState({ warehouseSearchRes: list, isWareHouseSearch: true }); }; _this.onChange = function (id, list, totalProportion) { var _this$props = _this.props, value = _this$props.value, onChange = _this$props.onChange; var data = getData(value, { id: id, dataSource: list, totalProportion: totalProportion }); onChange(data); }; _this.onAddChannel = function () { var _this$props2 = _this.props, value = _this$props2.value, onChange = _this$props2.onChange, warehouseName = _this$props2.warehouseName, warehouseId = _this$props2.warehouseId; if (!warehouseId && !warehouseName) { _Message.warning('未选择仓库/门店,无法新增同步规则'); return; } var oldValue = Array.isArray(value) ? value : []; var index = oldValue.length; _this.fields.addArrayValue(fieldKey, index, []); onChange([].concat(oldValue, [{ channelId: '', id: "" + index, dataSource: [], totalProportion: 0 }])); }; _this.onChangeChannel = function (channelId, key) { var _this$props3 = _this.props, value = _this$props3.value, onChange = _this$props3.onChange, onChannelChange = _this$props3.onChannelChange, validatorChannel = _this$props3.validatorChannel; if (validatorChannel && !validatorChannel(channelId, key)) { // 存在校验方法,且校验不通过时,结束,不执行下面操作 return; } var setValue = _this.fields.setValue; var data = value.map(function (item, index) { var sort = "" + index; if (item.id === key || sort === key) { setValue(fieldKey + "." + index, []); return { channelId: channelId, dataSource: [], totalProportion: 0, id: key }; } return item; }); onChannelChange(channelId); onChange(data); }; _this.fieldsldChange = function (name, val) { var keys = getFiledkeys(name); var _this$props4 = _this.props, value = _this$props4.value, onChange = _this$props4.onChange, ratioKey = _this$props4.ratioKey; var newValue = getValues({ value: value, keys: keys, val: val, ratioKey: ratioKey }); onChange(newValue); }; _this.onDeleteTable = function (key) { var _this$props5 = _this.props, value = _this$props5.value, onChange = _this$props5.onChange; _Dialog.confirm({ content: '是否删除该渠道和渠道下的店铺信息', onOk: function onOk() { var newValue = deleteTable(value, key); onChange(newValue); } }); }; _this.validata = function (callback) { var _this$props6 = _this.props, columns = _this$props6.columns, value = _this$props6.value; _this.fields.validate(getValidataKeys(columns, value), callback); }; _this.setErrors = function (err) { var _this$fields = _this.fields, getError = _this$fields.getError, setErrors = _this$fields.setErrors; var currentErr = getError('table'); var errInfo = getErrInfo(err, currentErr); setErrors(errInfo); }; _this.fields = new _Field(_assertThisInitialized(_this), { parseName: true, onChange: _this.fieldsldChange, values: (_values = {}, _values[fieldKey] = [], _values) }); _this.state = { warehouseSearchRes: [], isWareHouseSearch: false }; return _this; } // 仓库修改 var _proto = SupplyRelationshipRatio.prototype; _proto.render = function render() { var _this2 = this; var _this$props7 = this.props, warehouseName = _this$props7.warehouseName, warehouseList = _this$props7.warehouseList, columns = _this$props7.columns, value = _this$props7.value, channelList = _this$props7.channelList, storeData = _this$props7.storeData, maxRatio = _this$props7.maxRatio, ratioKey = _this$props7.ratioKey, warehouseId = _this$props7.warehouseId; var _this$state = this.state, warehouseSearchRes = _this$state.warehouseSearchRes, isWareHouseSearch = _this$state.isWareHouseSearch; var _this$fields2 = this.fields, fieldInit = _this$fields2.init, fieldGetError = _this$fields2.getError, addArrayValue = _this$fields2.addArrayValue, deleteArrayValue = _this$fields2.deleteArrayValue; var warehouseData = isWareHouseSearch ? warehouseSearchRes : warehouseList; return /*#__PURE__*/React.createElement("div", { "data-name": "AliretailSupplyRelationshipRatio", className: "aliretail-supply-relationship-ratio" }, /*#__PURE__*/React.createElement("div", { className: "aliretail-supply-relationship-ratio-warehouse" }, warehouseName || /*#__PURE__*/React.createElement(_Select, { onChange: this.warehouseChange, className: "ratio-warehouse-select", value: warehouseId, dataSource: warehouseData || [], filterLocal: false, showSearch: true, onSearch: this.onWarehouseSearch }) // {/* {warehouseList.map((item) => { // const { label, value: key, name } = item || {}; // return ( // <Option value={key} key={key}> // {name || label} // </Option> // ); // })} // </Select> */} ), /*#__PURE__*/React.createElement("div", { className: "relationship-ratio-tables" }, Array.isArray(value) ? value.map(function (item, index) { var channelId = item.channelId, dataSource = item.dataSource, id = item.id, totalProportion = item.totalProportion; var storeList = storeData ? storeData[channelId] : []; var tableKey = fieldKey + "." + index; return /*#__PURE__*/React.createElement(StoreTable, { ratioKey: ratioKey, channelId: channelId, channelList: channelList, storeList: storeList, dataSource: dataSource, columns: columns, status: status, tableKey: tableKey, dataKey: String(index), totalProportion: totalProportion, onChange: _this2.onChange, maxRatio: maxRatio, onChangeChannel: _this2.onChangeChannel, fieldInit: fieldInit, fieldGetError: fieldGetError, addArrayValue: addArrayValue, deleteArrayValue: deleteArrayValue, filed: _this2.fields, hasDelete: index !== 0, onDeleteTable: _this2.onDeleteTable, key: id || "" + index }); }) : null, /*#__PURE__*/React.createElement("div", { className: "aliretail-supply-relationship-ratio-add-channel", onClick: this.onAddChannel }, /*#__PURE__*/React.createElement("span", { className: "ratio-add-channel-icon" }, "+"), "\u6DFB\u52A0\u540C\u6B65\u89C4\u5219"))); }; return SupplyRelationshipRatio; }(React.Component); SupplyRelationshipRatio.propTypes = { maxRatio: PropTypes.number, value: PropTypes.array, warehouseId: PropTypes.string, columns: PropTypes.array, ratioKey: PropTypes.string, warehouseName: PropTypes.string, warehouseList: PropTypes.array, channelList: PropTypes.array, storeData: PropTypes.any, onWarehouseChange: PropTypes.func, onChannelChange: PropTypes.func, onChange: PropTypes.func }; SupplyRelationshipRatio.defaultProps = { title: '设置同步比例', visible: false, maxRatio: 100, status: 'normal', value: [], warehouseList: [], channelList: [], storeData: {}, onCancel: function onCancel() {}, onWarehouseChange: function onWarehouseChange() {}, onChannelChange: function onChannelChange() {}, onChange: function onChange() {} }; export default SupplyRelationshipRatio;