真食物配套的电商小程序.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
5.0 KiB

<template>
<view>
<view class="product-window" :class="attr.cartAttr === true ? 'on' : ''">
<view class="textpic acea-row row-between-wrapper" @touchmove.stop.prevent>
<view class="pictrue">
<image @tap="previewImage" :src="attr.productSelect.image" class="image" />
</view>
2 years ago
<view class="text acea-row row-column-between">
<view class="">
<view class="line2">{{ attr.productSelect.store_name }}</view>
<view class="info line2">{{storeInfo}}</view>
</view>
<view class="money acea-row" v-if="!isIntegral">
<view class="">¥{{ attr.productSelect.price }}</view>
<text class="num">¥{{ attr.productSelect.otPrice }}</text>
</view>
<view class="money" v-if="isIntegral">{{ attr.productSelect.integral }}积分</view>
<!-- <view class="money font-color-red" v-if="!isIntegral">
<text class="num">{{ attr.productSelect.price }}</text>
<text class="stock">库存: {{ attr.productSelect.stock }}</text>
</view>
<view class="money font-color-red" v-if="isIntegral">
<text class="num">{{ attr.productSelect.integral }}积分</text>
<text class="stock">库存: {{ attr.productSelect.stock }}</text>
2 years ago
</view> -->
</view>
2 years ago
<!-- <view class="iconfont icon-guanbi" @click="closeAttr"></view> -->
</view>
<view class="productWinList">
<view
class="item"
v-for="(item, indexw) in attr.productAttr"
:key="indexw"
>
<view class="title">{{ item.attrName }}</view>
<view class="listn acea-row row-middle">
<view
class="itemn"
:class="item.index == indexn? (attr.productSelect.stock!==0?'on':'isNo') : ''"
v-for="(itemn, indexn) in item.attrValue"
@click="tapAttr(indexw, indexn)"
:key="indexn"
>
{{ itemn.attr }}
</view
>
</view>
</view>
</view>
<view class="cart acea-row row-between-wrapper" @touchmove.stop.prevent>
2 years ago
<view class="">
<view class="title">¥{{ attr.productSelect.price }}</view>
<view >库存剩余{{ attr.productSelect.stock }}{{unitName}}</view>
</view>
<view class="carnum acea-row row-left">
<view
class="item reduce"
:class="cartNum <= 1 ? 'on' : ''"
@click="CartNumDes"
>-</view
>
<view class="item num">{{ cartNum }}</view>
<view
class="item plus"
:class="cartNum >= attr.productSelect.stock ? 'on' : ''"
@click="CartNumAdd"
>+</view
>
</view>
</view>
</view>
<view
class="mask"
@touchmove.stop.prevent
:hidden="attr.cartAttr === false"
@click="closeAttr"
></view>
</view>
</template>
<script>
export default {
name: "ProductWindow",
props: {
isIntegral:Boolean,
attr: {
type: Object,
5 years ago
default: () => {},
},
cartNum: {
type: Number,
5 years ago
default: () => 1,
},
2 years ago
storeInfo: {
type: String,
default: ''
},
unitName: {
type: String,
default: ''
},
},
5 years ago
data: function () {
return {};
},
5 years ago
mounted: function () {
console.log(this.attr)
console.log(this);
// this.tapAttr(0,0)
},
watch: {
attr(nextAttr) {
},
},
methods: {
5 years ago
closeAttr: function () {
this.$emit("changeFun", { action: "changeattr", value: false });
},
5 years ago
CartNumDes: function () {
this.$emit("changeFun", { action: "ChangeCartNum", value: false });
},
5 years ago
CartNumAdd: function () {
this.$emit("changeFun", { action: "ChangeCartNum", value: 1 });
},
5 years ago
tapAttr: function (indexw, indexn) {
// 修改商品规格不生效的原因:
// H5端下面写法,attr更新,但是除H5外其他端不支持,
// 尽量避免下面的骚写法,不要在子组件内更新props
// 这里修改是为了能获取到被选中的属性
this.attr.productAttr[indexw].index = indexn;
let that = this;
5 years ago
let value = that.getCheckedValue().sort().join(",");
that.$emit("changeFun", {
action: "ChangeAttr",
value: {
value,
indexw,
5 years ago
indexn,
},
});
},
//获取被选中属性;
5 years ago
getCheckedValue: function () {
let productAttr = this.attr.productAttr;
let value = [];
for (let i = 0; i < productAttr.length; i++) {
for (let j = 0; j < productAttr[i].attrValueArr.length; j++) {
if (productAttr[i].index === j) {
value.push(productAttr[i].attrValueArr[j]);
}
}
}
return value;
5 years ago
},
previewImage() {
uni.previewImage({
current: 0,
urls: [this.attr.productSelect.image],
});
},
5 years ago
},
};
</script>