"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var props_1 = require("./props"); var utils_1 = require("./utils"); var fmtEvent_1 = tslib_1.__importDefault(require("../_util/fmtEvent")); var value_1 = tslib_1.__importDefault(require("../mixins/value")); Component({ props: props_1.StepperDefaultProps, mixins: [(0, value_1.default)({ transformValue: function (num) { var _a = this.getValidNumber(num), valid = _a.valid, value = _a.value; if (valid && this.getValue() !== value) { return { needUpdate: true, value: value, }; } return { needUpdate: false, }; }, })], methods: { getValidNumber: function (value) { if (typeof value === 'undefined' || value === null) { return { valid: true, value: '', }; } var num; var _a = this.props, _b = _a.min, min = _b === void 0 ? -Infinity : _b, _c = _a.max, max = _c === void 0 ? Infinity : _c; if (typeof value === 'string') { if (/^\s*$/.test(value)) { return { valid: true, value: '', }; } if (!isNaN(Number(value))) { num = Number(value); } } else { num = value; } if (num > max) { num = max; } else if (num < min) { num = min; } if (typeof num === 'number' && !isNaN(value)) { return { valid: true, value: String(num), }; } return { valid: false, }; }, onFocus: function (e) { var value = this.getValue(); if (this.props.onFocus) { this.props.onFocus(value === '' ? null : Number(value), (0, fmtEvent_1.default)(this.props, e)); } }, onChange: function (val, e) { var _a = this.update(val), needUpdate = _a.needUpdate, value = _a.value; if (this.props.onChange && needUpdate) { this.props.onChange(value === '' ? null : Number(value), (0, fmtEvent_1.default)(this.props, e)); } }, onBlur: function (e) { var value = this.getValue(); if (this.isControlled()) { this.update(this.props.value); } if (this.props.onBlur) { this.props.onBlur(value === '' ? null : Number(value), (0, fmtEvent_1.default)(this.props, e)); } }, onTap: function (e) { var _a = this.props, step = _a.step, disabled = _a.disabled, precision = _a.precision; var _b = this.props, _c = _b.min, min = _c === void 0 ? -Infinity : _c, _d = _b.max, max = _d === void 0 ? Infinity : _d; var value = this.getValue(); if (value === '') { value = 0; } if (!disabled) { var mode = e.currentTarget.dataset.mode; var result = value; if (mode === 'minus') { // 【减】按钮的操作 var minusTemp = (0, utils_1.downStep)(value, step, precision); result = Math.max(minusTemp, min); } else if (mode === 'add') { // 【加】按钮的操作 var addTemp = (0, utils_1.upStep)(value, step, precision); result = Math.min(addTemp, max); } var needUpdate = this.update(result).needUpdate; if (this.props.onChange && needUpdate) { this.props.onChange(result, (0, fmtEvent_1.default)(this.props, e)); } } }, }, });