UNPKG

@aliretail/react-materials-components

Version:
317 lines (270 loc) 11.4 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports["default"] = void 0; var _select = _interopRequireDefault(require("@alifd/next/lib/select")); var _field = _interopRequireDefault(require("@alifd/next/lib/field")); var _dialog = _interopRequireDefault(require("@alifd/next/lib/dialog")); var _message = _interopRequireDefault(require("@alifd/next/lib/message")); var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")); var React = _interopRequireWildcard(require("react")); var PropTypes = _interopRequireWildcard(require("prop-types")); var _dataAdaptor = require("./config/data-adaptor"); var _StoreTable = _interopRequireDefault(require("./components/StoreTable")); 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; } /** * 当前先不管数据调用,该组件只接受数据,不调用接口处理数据 */ // const { Option } = Select; var SupplyRelationshipRatio = /*#__PURE__*/function (_React$Component) { (0, _inheritsLoose2["default"])(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(_dataAdaptor.fieldKey); onWarehouseChange(id); // 这个不做修改数据 // onChange([]); }; _this.onWarehouseSearch = function (val) { var warehouseList = _this.props.warehouseList; var list = (0, _dataAdaptor.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 = (0, _dataAdaptor.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["default"].warning('未选择仓库/门店,无法新增同步规则'); return; } var oldValue = Array.isArray(value) ? value : []; var index = oldValue.length; _this.fields.addArrayValue(_dataAdaptor.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(_dataAdaptor.fieldKey + "." + index, []); return { channelId: channelId, dataSource: [], totalProportion: 0, id: key }; } return item; }); onChannelChange(channelId); onChange(data); }; _this.fieldsldChange = function (name, val) { var keys = (0, _dataAdaptor.getFiledkeys)(name); var _this$props4 = _this.props, value = _this$props4.value, onChange = _this$props4.onChange, ratioKey = _this$props4.ratioKey; var newValue = (0, _dataAdaptor.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["default"].confirm({ content: '是否删除该渠道和渠道下的店铺信息', onOk: function onOk() { var newValue = (0, _dataAdaptor.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((0, _dataAdaptor.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 = (0, _dataAdaptor.getErrInfo)(err, currentErr); setErrors(errInfo); }; _this.fields = new _field["default"]((0, _assertThisInitialized2["default"])(_this), { parseName: true, onChange: _this.fieldsldChange, values: (_values = {}, _values[_dataAdaptor.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["default"], { 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 = _dataAdaptor.fieldKey + "." + index; return /*#__PURE__*/React.createElement(_StoreTable["default"], { 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() {} }; var _default = SupplyRelationshipRatio; exports["default"] = _default;