UNPKG

@sishuguojixuefu/react-native-form

Version:
87 lines 3.85 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importStar(require("react")); const antd_mobile_rn_1 = require("@sishuguojixuefu/antd-mobile-rn"); const react_native_1 = require("react-native"); const string_width_1 = __importDefault(require("string-width")); const nzh_1 = __importDefault(require("nzh")); const lodash_omit_1 = __importDefault(require("lodash.omit")); const getFieldDecorator_1 = __importDefault(require("../utils/getFieldDecorator")); const Label_1 = __importDefault(require("./helper/Label")); const ErrorTip_1 = __importDefault(require("./helper/ErrorTip")); const nzhCn = nzh_1.default.cn; class SsAmount extends react_1.Component { constructor() { super(...arguments); this.chineseAmount = ''; this._onChange = (value) => { const { onChange, upper } = this.props; if (upper) { this._getChineseAmount(value); } onChange && onChange(value); }; this._getChineseAmount = (value = '') => { if (isNaN(Number(value))) { this.chineseAmount = ''; } else if (value.length > 16) { this.chineseAmount = '大写转换最多支持16位数的金额!'; } else { this.chineseAmount = nzhCn.toMoney(value, { outSymbol: false }); } }; } componentWillMount() { const { form, id, initialValue, rules } = this.props; const defaultStrValue = initialValue && initialValue.toString(); this._getChineseAmount(defaultStrValue); this.fieldDecorator = getFieldDecorator_1.default(form, id, defaultStrValue, rules ? [...rules, 'money'] : ['money']); } render() { const { placeholder, label, required, form, id, textAlign, upper } = this.props; const omitProps = lodash_omit_1.default(this.props, ['error', 'labelNumber']); return (react_1.default.createElement(ErrorTip_1.default, { error: form.getFieldError(id) }, this.fieldDecorator(react_1.default.createElement(antd_mobile_rn_1.InputItem, Object.assign({}, omitProps, { last: true, clear: true, extra: "\uFFE5", type: "number", itemStyle: { marginLeft: 0 }, textAlign: textAlign, onChange: this._onChange, labelNumber: label ? string_width_1.default(label) / 2 + 1 : 0, placeholder: placeholder }), react_1.default.createElement(Label_1.default, { required: required, label: label }))), upper && (react_1.default.createElement(react_native_1.View, { style: styles.amountText }, react_1.default.createElement(react_native_1.Text, { style: styles.amountLabel }, "\u5927\u5199"), react_1.default.createElement(react_native_1.Text, { style: [styles.amountValue], numberOfLines: 1 }, this.chineseAmount))))); } } exports.default = SsAmount; SsAmount.defaultProps = { required: false, placeholder: '请输入', textAlign: 'right', upper: true, }; const styles = react_native_1.StyleSheet.create({ amountLabel: { flex: 1, textAlign: 'left', }, amountText: { color: '#888888', flexDirection: 'row', fontSize: 14, paddingBottom: 5, paddingHorizontal: 15, }, amountValue: { flex: 4, textAlign: 'right', }, }); //# sourceMappingURL=SsAmount.js.map