UNPKG

maycur-business

Version:

maycur business react components of web

312 lines (252 loc) 14.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; require("maycur-antd/lib/modal/style/css"); var _modal = _interopRequireDefault(require("maycur-antd/lib/modal")); require("maycur-antd/lib/alert/style/css"); var _alert = _interopRequireDefault(require("maycur-antd/lib/alert")); require("maycur-antd/lib/message/style/css"); var _message2 = _interopRequireDefault(require("maycur-antd/lib/message")); var _react = _interopRequireWildcard(require("react")); var _EditPaymentForm = _interopRequireDefault(require("./EditPaymentForm")); var _i18next = _interopRequireDefault(require("i18next")); var _lodash = _interopRequireDefault(require("lodash")); function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } var PaymentAccountModal = /*#__PURE__*/ function (_Component) { _inherits(PaymentAccountModal, _Component); function PaymentAccountModal(props) { var _this; _classCallCheck(this, PaymentAccountModal); _this = _possibleConstructorReturn(this, _getPrototypeOf(PaymentAccountModal).call(this, props)); var data = props.data || {}; if (data.hasBankBranch === false && data.bankBranchName) { data = _objectSpread({}, data, { bankBranchBizCode: data.bankBranchName }); } _this.state = { data: data, fields: {}, loading: false }; _this.onErrors = _this.onErrors.bind(_assertThisInitialized(_this)); _this.onSubmit = _this.onSubmit.bind(_assertThisInitialized(_this)); _this.submit = _this.submit.bind(_assertThisInitialized(_this)); _this.onChangeBank = _this.onChangeBank.bind(_assertThisInitialized(_this)); _this.onChangeBankBranch = _this.onChangeBankBranch.bind(_assertThisInitialized(_this)); _this.onFieldChange = _this.onFieldChange.bind(_assertThisInitialized(_this)); return _this; } _createClass(PaymentAccountModal, [{ key: "onErrors", value: function onErrors() { _message2["default"].warning(_i18next["default"].t('PaymentAccountModal:warnMsg')); } }, { key: "onSubmit", value: function onSubmit() { var _this2 = this; var _this$props = this.props, onSubmit = _this$props.onSubmit, promise = _this$props.promise, isCompany = _this$props.isCompany; if (typeof onSubmit === 'function') { this.setState({ loading: true }); var data = _lodash["default"].clone(this.state.data); // hard code data.paymentScope = ['pay_employee']; data.bankCountry = 'CHINA'; data.account = _lodash["default"].replace(data.account, /\s/g, ''); // clear data var needClearValues = []; switch (data.paymentType) { case 'CASH': needClearValues.push('bankAcctNumber'); // fallthrough // 不要 break 因为 CASH 和 ALIPAY 都需要重置以下属性的值 case 'ALIPAY': needClearValues.push('bankCountry', 'bankCode', 'bankName', 'bankLocation', 'bankBranchBizCode', 'bankBranchNo', 'bankBranchName'); break; case 'BANK': if (data.bankBranchBizCode === data.bankBranchName) // 手动添加的分支行 因为展示需要 所以将 bankBranchBizCode 和 bankBranchName 设为同样的值了,这里需要再改回bankBranchNo data.bankBranchBizCode = data.bankBranchNo; break; default: break; } needClearValues.forEach(function (key) { return data[key] = undefined; }); if (!isCompany || data.bankCode !== 'cmbc') { data.agencyBizCode = undefined; } var _this$props2 = this.props, showDescription = _this$props2.showDescription, showActive = _this$props2.showActive; if (!showDescription) data.description = undefined; if (!showActive) data.active = undefined; onSubmit(data).then(function () { _this2.setState({ loading: false }); if (promise) promise.resolve(); }, function (err) { _this2.setState({ loading: false }); if (err) _message2["default"].error(err); }); } } }, { key: "submit", value: function submit() { if (this.formRef) { this.formRef.handleSubmit({}); } } }, { key: "onFieldChange", value: function onFieldChange(changedFields) { var _this$state = this.state, data = _this$state.data, fields = _this$state.fields; _lodash["default"].map(_lodash["default"].values(changedFields), function (item) { data[item.name] = item.value; }); this.setState({ data: _lodash["default"].clone(data), fields: _lodash["default"].assign({}, fields, changedFields) }); } }, { key: "onChangeBank", value: function onChangeBank(bank) { if (bank) { var data = this.state.data; data.bankName = bank.name; this.setState({ data: _objectSpread({}, data) }); } } }, { key: "onChangeBankBranch", value: function onChangeBankBranch(branch) { // 支行改变时更新 bankBranchName 和 bankBranchNo var data = this.state.data; if (branch) { data.bankBranchName = branch.name; data.bankBranchNo = branch.branchNo; } else { data.bankBranchName = ''; data.bankBranchNo = undefined; } this.setState({ data: _objectSpread({}, data) }); } }, { key: "render", value: function render() { var _this3 = this; var _this$state2 = this.state, data = _this$state2.data, fields = _this$state2.fields, loading = _this$state2.loading; var _this$props3 = this.props, isCompany = _this$props3.isCompany, showDescription = _this$props3.showDescription, showActive = _this$props3.showActive, showCurrency = _this$props3.showCurrency, currencyLabel = _this$props3.currencyLabel, fetchCities = _this$props3.fetchCities, cities = _this$props3.cities, currencys = _this$props3.currencys, fetchBanks = _this$props3.fetchBanks, banks = _this$props3.banks, fetchBankBranches = _this$props3.fetchBankBranches, fetchCertificationTypes = _this$props3.fetchCertificationTypes, getBankname = _this$props3.getBankname, extra = _this$props3.extra, extraName = _this$props3.extraName, paymentTypes = _this$props3.paymentTypes, autoRequired = _this$props3.autoRequired, resprops = _objectWithoutProperties(_this$props3, ["isCompany", "showDescription", "showActive", "showCurrency", "currencyLabel", "fetchCities", "cities", "currencys", "fetchBanks", "banks", "fetchBankBranches", "fetchCertificationTypes", "getBankname", "extra", "extraName", "paymentTypes", "autoRequired"]); return _react["default"].createElement(_modal["default"], _extends({}, resprops, { onOk: this.submit, destroyOnClose: true, confirmLoading: loading, maskClosable: false, keyboard: false, visible: true, cancelButtonProps: { type: 'info', size: 'large' } }), data.paymentType === 'BANK' && _react["default"].createElement(_alert["default"], { style: { marginBottom: 10 }, message: _i18next["default"].t('PaymentAccountModal:alertMsg'), type: "info", showIcon: true }), _react["default"].createElement(_EditPaymentForm["default"], { data: data, fields: fields, cities: cities, banks: banks, currencys: currencys, wrappedComponentRef: function wrappedComponentRef(ref) { _this3.formRef = ref; }, extra: extra, extraName: extraName, isCompany: isCompany, fetchCities: fetchCities, fetchBanks: fetchBanks, paymentTypes: paymentTypes, autoRequired: autoRequired, fetchBankBranches: fetchBankBranches, fetchCertificationTypes: fetchCertificationTypes, getBankname: getBankname, showDescription: showDescription, showActive: showActive, showCurrency: showCurrency, currencyLabel: currencyLabel, onChangeBank: this.onChangeBank, onChangeBankBranch: this.onChangeBankBranch, onErrors: this.onErrors, onSubmit: this.onSubmit, onChange: this.onFieldChange })); } }]); return PaymentAccountModal; }(_react.Component); PaymentAccountModal.defaultProps = { okText: _i18next["default"].t('MkGlobal:ok'), paymentTypes: [] }; var _default = PaymentAccountModal; exports["default"] = _default;