为count-modify组件增加登录判断
This commit is contained in:
parent
68f0622384
commit
0c0d35dff7
|
@ -1,16 +1,17 @@
|
||||||
<template>
|
<template>
|
||||||
<view class="component-widget-count-modify" :class="[number > 0 ? 'between' : 'end']">
|
<view class="component-widget-count-modify" :class="[number > 0 ? 'between' : 'end']">
|
||||||
<view v-if="number > 0" class="btn sub" @click="sub">
|
<view v-if="number > 0" class="btn sub" @click="calc(0)">
|
||||||
<text class="iconfont icon-jianhao"></text>
|
<text class="iconfont icon-jianhao"></text>
|
||||||
</view>
|
</view>
|
||||||
<view v-if="number > 0" class="num">{{ number }}</view>
|
<view v-if="number > 0" class="num">{{ number }}</view>
|
||||||
<view class="btn add" @click="add">
|
<view class="btn add" @click="calc(1)">
|
||||||
<text class="iconfont icon-jiahao-"></text>
|
<text class="iconfont icon-jiahao-"></text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapGetters } from "vuex";
|
||||||
export default {
|
export default {
|
||||||
name: "component-widget-count-modify",
|
name: "component-widget-count-modify",
|
||||||
data() {
|
data() {
|
||||||
|
@ -19,6 +20,10 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
auth: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
min: {
|
min: {
|
||||||
type: [Number, String],
|
type: [Number, String],
|
||||||
default: 0,
|
default: 0,
|
||||||
|
@ -33,6 +38,11 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
components: {},
|
components: {},
|
||||||
|
computed: {
|
||||||
|
...mapGetters({
|
||||||
|
isLogin: "user/isLogin",
|
||||||
|
}),
|
||||||
|
},
|
||||||
created() {
|
created() {
|
||||||
this.number = this.init;
|
this.number = this.init;
|
||||||
},
|
},
|
||||||
|
@ -41,30 +51,36 @@ export default {
|
||||||
watch: {
|
watch: {
|
||||||
init(value) {
|
init(value) {
|
||||||
this.number = value;
|
this.number = value;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
sub() {
|
calc(type) {
|
||||||
if (this.number > this.min) {
|
let event = {};
|
||||||
this.number--;
|
if (!this.auth || (this.auth && this.isLogin)) {
|
||||||
|
if (type == 1) {
|
||||||
|
if (this.max == 0 || this.number < this.max) {
|
||||||
|
this.number++;
|
||||||
|
} else {
|
||||||
|
this.number = this.max;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.number > this.min) {
|
||||||
|
this.number--;
|
||||||
|
} else {
|
||||||
|
this.number = this.min;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event = {
|
||||||
|
type: type == 1 ? "add" : "sub",
|
||||||
|
value: this.number,
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
this.number = this.min;
|
event = {
|
||||||
|
type: "nologin",
|
||||||
|
value: 0,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
this.$emit("change", {
|
this.$emit("change", event);
|
||||||
type: "sub",
|
|
||||||
value: this.number,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
add() {
|
|
||||||
if (this.max == 0 || this.number < this.max) {
|
|
||||||
this.number++;
|
|
||||||
} else {
|
|
||||||
this.number = this.max;
|
|
||||||
}
|
|
||||||
this.$emit("change", {
|
|
||||||
type: "add",
|
|
||||||
value: this.number,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue