| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- import { use } from '../../utils';
- import Stepper from '../../stepper';
- import { LIMIT_TYPE } from '../constants';
- var _use = use('sku-stepper'),
- sfc = _use[0];
- var QUOTA_LIMIT = LIMIT_TYPE.QUOTA_LIMIT,
- STOCK_LIMIT = LIMIT_TYPE.STOCK_LIMIT;
- export 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, {
- "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])]);
- }
- });
|