mall-uniapp/components/productWindow/index.vue

341 lines
8.1 KiB
Vue
Raw Normal View History

2020-08-13 08:12:57 +00:00
<template>
<view>
<view class="product-window"
:class="(attr.cartAttr === true ? 'on' : '') + ' ' + (iSbnt ? 'join':'') + ' ' + (iScart ? 'joinCart':'')">
2020-08-13 08:12:57 +00:00
<view class="textpic acea-row row-between-wrapper">
<view class="pictrue">
<image :src="attr.productSelect.picUrl"></image>
2020-08-13 08:12:57 +00:00
</view>
<view class="text">
<view class="line1">
{{ attr.productSelect.spuName }}
2020-08-13 08:12:57 +00:00
</view>
<view class="money font-color">
<text class="num">{{ attr.productSelect.price }}</text>
<text class="stock" v-if='isShow'>库存: {{ attr.productSelect.stock }}</text>
<text class='stock' v-if="limitNum">: {{ attr.productSelect.quota }}</text>
2020-08-13 08:12:57 +00:00
</view>
</view>
<view class="iconfont icon-guanbi" @click="closeAttr"></view>
</view>
<view class="rollTop">
<!-- 属性 key + value 列表 -->
<view class="productWinList">
<view class="item" v-for="(property, indexw) in attr.properties" :key="indexw">
<view class="title">{{ property.name }}</view>
<view class="listn acea-row row-middle">
<view class="itemn" :class="property.index === value.name ? 'on' : ''"
v-for="(value, indexn) in property.values" @click="clickProperty(indexw, indexn)"
:key="indexn">
{{ value.name }}
</view>
2020-08-13 08:12:57 +00:00
</view>
</view>
</view>
<view class="cart acea-row row-between-wrapper">
<view class="title">数量</view>
<view class="carnum acea-row row-left">
<view class="item reduce" :class="attr.productSelect.cart_num <= 1 ? 'on' : ''"
@click="CartNumDes">
-
</view>
<view class='item num'>
<input type="number" v-model="attr.productSelect.cart_num"
data-name="productSelect.cart_num"
@input="bindCode(attr.productSelect.cart_num)" />
</view>
<view v-if="iSplus" class="item plus" :class="attr.productSelect.cart_num >= attr.productSelect.stock ? 'on' : ''" @click="CartNumAdd">
+
</view>
<view v-else class='item plus'
:class='(attr.productSelect.cart_num >= attr.productSelect.quota) || (attr.productSelect.cart_num >= attr.productSelect.stock) || (attr.productSelect.cart_num >= attr.productSelect.num)? "on":""'
@click='CartNumAdd'>+</view>
2020-08-13 08:12:57 +00:00
</view>
</view>
</view>
<view class="joinBnt bg-color" v-if="iSbnt && attr.productSelect.stock > 0 && attr.productSelect.quota > 0"
@click="goCat">我要参团</view>
<view class="joinBnt on"
v-else-if="(iSbnt && attr.productSelect.quota<=0)||(iSbnt &&attr.productSelect.stock<=0)">已售罄</view>
2020-08-13 08:12:57 +00:00
<view class="joinBnt bg-color" v-if="iScart && attr.productSelect.stock" @click="goCat"></view>
<!-- <view class="joinBnt bg-color" v-if="iSbnt && attr.productSelect.stock && attr.productSelect.quota" @click="goCat"></view> -->
<view class="joinBnt on" v-else-if="(iScart && !attr.productSelect.stock)">已售罄</view>
2020-08-13 08:12:57 +00:00
</view>
<view class="mask" @touchmove.prevent :hidden="attr.cartAttr === false" @click="closeAttr"></view>
</view>
</template>
<script>
export default {
props: {
attr: {
type: Object,
default: () => {}
},
limitNum: { // TODO 芋艿:是否限流
type: Number,
value: 0
},
isShow: { // 是否展示库存
type: Number,
value: 0
},
iSbnt: {
type: Number,
value: 0
},
iSplus: {
type: Number,
value: 0
},
iScart: {
type: Number,
value: 0
}
2020-08-13 08:12:57 +00:00
},
data() {
return {};
},
mounted() {},
2020-08-13 08:12:57 +00:00
methods: {
goCat: function() {
this.$emit('goCat');
},
/**
* 购物车手动输入数量
*/
bindCode: function(e) {
this.$emit('iptCartNum', this.attr.productSelect.cart_num);
},
2020-08-13 08:12:57 +00:00
closeAttr: function() {
this.$emit('myevent');
},
CartNumDes: function() {
this.$emit('ChangeCartNum', false);
},
CartNumAdd: function() {
this.$emit('ChangeCartNum', true);
},
/**
* 选中某个规格属性
*
* @param indexw properties 的下标
* @param indexn properties 的下标
*/
clickProperty: function(indexw, indexn) {
this.$set(this.attr.properties[indexw], 'index', this.attr.properties[indexw].values[indexn].name);
let newSkuKey = this.getCheckedValueNames().join(",");
this.$emit("ChangeAttr", newSkuKey);
2020-08-13 08:12:57 +00:00
},
/**
* 获取被选中属性值的数组
*
* @returns {*[]} 例如说['红色', '大']
*/
getCheckedValueNames: function() {
let properties = this.attr.properties;
let valueNames = [];
for (let i = 0; i < properties.length; i++) {
for (let j = 0; j < properties[i].values.length; j++) {
if (properties[i].index === properties[i].values[j].name) {
valueNames.push(properties[i].values[j].name);
2020-08-13 08:12:57 +00:00
}
}
}
return valueNames;
2020-08-13 08:12:57 +00:00
}
}
}
</script>
<style scoped lang="scss">
.product-window {
position: fixed;
bottom: 0;
width: 100%;
left: 0;
background-color: #fff;
z-index: 77;
border-radius: 16rpx 16rpx 0 0;
padding-bottom: 140rpx;
transform: translate3d(0, 100%, 0);
transition: all .3s cubic-bezier(.25, .5, .5, .9);
}
2020-08-13 08:12:57 +00:00
.product-window.on {
transform: translate3d(0, 0, 0);
}
.product-window.join {
padding-bottom: 30rpx;
}
.product-window.joinCart {
2020-08-13 08:12:57 +00:00
padding-bottom: 30rpx;
z-index: 999;
}
2020-08-13 08:12:57 +00:00
.product-window .textpic {
padding: 0 130rpx 0 30rpx;
margin-top: 29rpx;
position: relative;
}
2020-08-13 08:12:57 +00:00
.product-window .textpic .pictrue {
width: 150rpx;
height: 150rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .textpic .pictrue image {
width: 100%;
height: 100%;
border-radius: 10rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .textpic .text {
width: 410rpx;
font-size: 32rpx;
color: #333333;
2020-08-13 08:12:57 +00:00
}
2020-08-13 08:12:57 +00:00
.product-window .textpic .text .money {
font-size: 24rpx;
margin-top: 40rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .textpic .text .money .num {
font-size: 36rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .textpic .text .money .stock {
color: #999;
margin-left: 18rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .textpic .iconfont {
position: absolute;
right: 30rpx;
top: -5rpx;
font-size: 35rpx;
color: #8a8a8a;
}
.product-window .rollTop {
max-height: 500rpx;
2020-08-13 08:12:57 +00:00
overflow: auto;
margin-top: 36rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .productWinList .item~.item {
margin-top: 36rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .productWinList .item .title {
font-size: 30rpx;
color: #999;
padding: 0 30rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .productWinList .item .listn {
padding: 0 30rpx 0 16rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .productWinList .item .listn .itemn {
border: 1px solid #F2F2F2;
2020-08-13 08:12:57 +00:00
font-size: 26rpx;
color: #282828;
padding: 7rpx 33rpx;
border-radius: 40rpx;
margin: 20rpx 0 0 14rpx;
background-color: #F2F2F2;
2020-08-13 08:12:57 +00:00
}
2020-08-13 08:12:57 +00:00
.product-window .productWinList .item .listn .itemn.on {
color: $theme-color;
background: rgba(255, 244, 243, 1);
border-color: $theme-color;
2020-08-13 08:12:57 +00:00
}
.product-window .productWinList .item .listn .itemn.limit {
color: #999;
text-decoration: line-through;
}
2020-08-13 08:12:57 +00:00
.product-window .cart {
margin-top: 36rpx;
padding: 0 30rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .cart .title {
font-size: 30rpx;
color: #999;
}
2020-08-13 08:12:57 +00:00
.product-window .cart .carnum {
height: 54rpx;
margin-top: 24rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .cart .carnum view {
// border: 1px solid #a4a4a4;
2020-08-13 08:12:57 +00:00
width: 84rpx;
text-align: center;
height: 100%;
line-height: 54rpx;
color: #282828;
2020-08-13 08:12:57 +00:00
font-size: 45rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .cart .carnum .reduce {
border-right: 0;
border-radius: 6rpx 0 0 6rpx;
line-height: 48rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .cart .carnum .reduce.on {
// border-color: #e3e3e3;
color: #DEDEDE;
font-size: 44rpx;
2020-08-13 08:12:57 +00:00
}
2020-08-13 08:12:57 +00:00
.product-window .cart .carnum .plus {
border-left: 0;
border-radius: 0 6rpx 6rpx 0;
line-height: 46rpx;
}
2020-08-13 08:12:57 +00:00
.product-window .cart .carnum .plus.on {
border-color: #e3e3e3;
color: #dedede;
}
2020-08-13 08:12:57 +00:00
.product-window .cart .carnum .num {
background: rgba(242, 242, 242, 1);
2020-08-13 08:12:57 +00:00
color: #282828;
font-size: 28rpx;
border-radius: 12rpx;
line-height: 29px;
height: 54rpx;
input {
display: -webkit-inline-box;
}
}
.product-window .joinBnt {
font-size: 30rpx;
width: 620rpx;
height: 86rpx;
border-radius: 50rpx;
text-align: center;
line-height: 86rpx;
color: #fff;
margin: 21rpx auto 0 auto;
}
.product-window .joinBnt.on {
background-color: #bbb;
color: #fff;
2020-08-13 08:12:57 +00:00
}
</style>