mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-05 19:41:45 +08:00
* add src dir && add build * add build watch && change dir name * bower ignore package.json
62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
function handle(e, num) {
|
|
var dataset = e.currentTarget.dataset;
|
|
var componentId = dataset.componentId;
|
|
var disabled = dataset.disabled;
|
|
var quantity = +dataset.quantity;
|
|
|
|
if (disabled) return null;
|
|
|
|
callback.call(this, componentId, quantity + num);
|
|
}
|
|
|
|
function callback(componentId, quantity) {
|
|
quantity = +quantity;
|
|
var e = { componentId, quantity };
|
|
console.info('[zan:quantity:change]', e);
|
|
|
|
if (this.handleZanQuantityChange) {
|
|
this.handleZanQuantityChange(e);
|
|
} else {
|
|
console.warn('页面缺少 handleZanQuantityChange 回调函数');
|
|
}
|
|
}
|
|
|
|
var Quantity = {
|
|
_handleZanQuantityMinus(e) {
|
|
handle.call(this, e, -1);
|
|
},
|
|
|
|
_handleZanQuantityPlus(e) {
|
|
handle.call(this, e, +1);
|
|
},
|
|
|
|
_handleZanQuantityBlur(e) {
|
|
var dataset = e.currentTarget.dataset;
|
|
var componentId = dataset.componentId;
|
|
var max = +dataset.max;
|
|
var min = +dataset.min;
|
|
var value = e.detail.value;
|
|
|
|
if (!value) {
|
|
setTimeout(() => {
|
|
callback.call(this, componentId, min);
|
|
}, 16);
|
|
callback.call(this, componentId, value);
|
|
return '' + value;
|
|
}
|
|
|
|
value = +value;
|
|
if (value > max) {
|
|
value = max;
|
|
} else if (value < min) {
|
|
value = min;
|
|
}
|
|
|
|
callback.call(this, componentId, value);
|
|
|
|
return '' + value;
|
|
}
|
|
};
|
|
|
|
module.exports = Quantity;
|