"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports["default"] = void 0; var _utils = require("../../utils"); var _stepper = _interopRequireDefault(require("../../stepper")); var _constants = require("../constants"); var _use = (0, _utils.use)('sku-stepper'), sfc = _use[0]; var QUOTA_LIMIT = _constants.LIMIT_TYPE.QUOTA_LIMIT, STOCK_LIMIT = _constants.LIMIT_TYPE.STOCK_LIMIT; var _default = sfc({ props: { quota: Number, quotaUsed: Number, hideStock: Boolean, skuEventBus: Object, skuStockNum: Number, selectedSku: Object, selectedNum: Number, stepperTitle: String, hideQuotaText: Boolean, selectedSkuComb: Object, disableStepperInput: Boolean, customStepperConfig: Object }, data: function data() { return { currentNum: this.selectedNum, // 购买限制类型: 限购/库存 limitType: STOCK_LIMIT }; }, watch: { currentNum: function currentNum(num) { this.skuEventBus.$emit('sku:numChange', num); }, stepperLimit: function stepperLimit(limit) { if (limit < this.currentNum) { this.currentNum = limit; } } }, computed: { stock: function stock() { var stockNum = this.customStepperConfig.stockNum; if (stockNum !== undefined) { return stockNum; } if (this.selectedSkuComb) { return this.selectedSkuComb.stock_num; } return this.skuStockNum; }, stockText: function stockText() { var stockFormatter = this.customStepperConfig.stockFormatter; if (stockFormatter) return stockFormatter(this.stock); return "\u5269\u4F59" + this.stock + "\u4EF6"; }, quotaText: function quotaText() { var _this$customStepperCo = this.customStepperConfig, quotaText = _this$customStepperCo.quotaText, hideQuotaText = _this$customStepperCo.hideQuotaText; if (hideQuotaText) return ''; var text = ''; if (quotaText) { text = quotaText; } else if (this.quota > 0) { text = "\u6BCF\u4EBA\u9650\u8D2D" + this.quota + "\u4EF6"; } return text; }, stepperLimit: function stepperLimit() { var quotaLimit = this.quota - this.quotaUsed; var limit; // 无限购时直接取库存,有限购时取限购数和库存数中小的那个 if (this.quota > 0 && quotaLimit <= this.stock) { // 修正负的limit limit = quotaLimit < 0 ? 0 : quotaLimit; this.limitType = QUOTA_LIMIT; } else { limit = this.stock; this.limitType = STOCK_LIMIT; } return limit; } }, methods: { setCurrentNum: function setCurrentNum(num) { this.currentNum = num; }, onOverLimit: function onOverLimit(action) { this.skuEventBus.$emit('sku:overLimit', { action: action, limitType: this.limitType, quota: this.quota, quotaUsed: this.quotaUsed }); }, onChange: function onChange(currentValue) { var handleStepperChange = this.customStepperConfig.handleStepperChange; handleStepperChange && handleStepperChange(currentValue); this.$emit('change', currentValue); } }, render: function render(h) { var _this = this; return h("div", { "class": "van-sku-stepper-stock" }, [h("div", { "class": "van-sku-stepper-container" }, [h("div", { "class": "van-sku__stepper-title" }, [this.stepperTitle || '购买数量', "\uFF1A"]), h(_stepper["default"], { "class": "van-sku__stepper", "attrs": { "max": this.stepperLimit, "disableInput": this.disableStepperInput }, "on": { "overlimit": this.onOverLimit, "change": this.onChange }, "model": { value: _this.currentNum, callback: function callback($$v) { _this.currentNum = $$v; } } })]), !this.hideStock && h("div", { "class": "van-sku__stock" }, [this.stockText]), !this.hideQuotaText && this.quotaText && h("div", { "class": "van-sku__quota" }, [this.quotaText])]); } }); exports["default"] = _default;