76 lines
1.6 KiB
Vue
76 lines
1.6 KiB
Vue
<template>
|
|
<view class="count-modify" :class="[number > 0 ? 'between' : 'end']">
|
|
<view v-if="number > 0" class="btn sub" @click="sub">
|
|
<text class="iconfont icon-jianhao"></text>
|
|
</view>
|
|
<view v-if="number > 0" class="num">{{ number }}</view>
|
|
<view class="btn add" @click="add">
|
|
<text class="iconfont icon-jiahao-"></text>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
name: "widget-count-modify",
|
|
data() {
|
|
return {
|
|
number: 0,
|
|
};
|
|
},
|
|
props: {
|
|
initNumber: {
|
|
type: Number,
|
|
default: 0,
|
|
},
|
|
data: {
|
|
type: Object,
|
|
default: () => {},
|
|
},
|
|
},
|
|
components: {},
|
|
created() {
|
|
this.number = this.initNumber;
|
|
},
|
|
mounted() {},
|
|
destroyed() {},
|
|
methods: {
|
|
sub() {
|
|
if (this.number > 0) {
|
|
this.number--;
|
|
} else {
|
|
this.number = 0;
|
|
}
|
|
this.$emit("onSub", this.data, this.number);
|
|
},
|
|
add() {
|
|
this.number++;
|
|
this.$emit("onAdd", this.data, this.number);
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.count-modify {
|
|
width: 130rpx;
|
|
height: 35rpx;
|
|
display: flex;
|
|
align-items: center;
|
|
.num {
|
|
color: #2d2d2d;
|
|
font-size: 30rpx;
|
|
}
|
|
}
|
|
.count-modify.between {
|
|
justify-content: space-between;
|
|
}
|
|
.count-modify.end {
|
|
justify-content: flex-end;
|
|
}
|
|
.btn.sub .iconfont,
|
|
.btn.add .iconfont {
|
|
color: #4b65ed;
|
|
font-size: 35rpx;
|
|
}
|
|
</style> |