skuPage.vue 9.2 KB
<template>
    <view class="container">
        <view class="goods_type_box" v-for="(item, index) in skuList" :key="index">
            <view class="goods_type_title">{{ item.itemName }}</view>
            <view class="goods_type_list_box">
                <view class="goods_type_list" :class="[item.select == inde ? 'now' : '',ite.skuStatus ? 'active1' : '']" v-for="(ite, inde) in item.skuProValueList" :key="inde" @click="skuFun(item, ite, index, inde)">
                    {{ ite.valueName }}
                </view>
            </view>
        </view>
    </view>
 
</template>

<script>
export default {
    data() {
        return {
            
            skuList: [
                {
                    itemId: 20,
                    itemName: '颜色',
                    currentValue: 36,
                    select: null,
                    skuProValueList: [
                        {
                            valueId: 35,
                            valueName: '红',
                            skuIds: '22',
                            skuStatus: false,
                            sk: false,
                        },
                        {
                            valueId: 36,
                            valueName: '蓝',
                            skuIds: '23',
                            skuStatus: false,
                            sk: false,
                        },
                        {
                            valueId: 37,
                            valueName: '白',
                            skuIds: '24,25,26',
                            skuStatus: false,
                            sk: false,
                        }
                    ]
                },
                {
                    itemId: 21,
                    itemName: '制冷方式',
                    currentValue: 38,
                    select: null,
                    skuProValueList: [
                        {
                            valueId: 38,
                            valueName: '风冷',
                            skuIds: '23,25,26',
                            skuStatus: false,
                            sk: false,
                        },
                        {
                            valueId: 39,
                            valueName: '直冷',
                            skuIds: '24,22',
                            skuStatus: false,
                            sk: false,
                        }
                    ]
                },
                {
                    itemId: 21,
                    itemName: '尺寸',
                    currentValue: 38,
                    select: null,
                    skuProValueList: [
                        {
                            valueId: 38,
                            valueName: '大',
                            skuIds: '22,25,26',
                            skuStatus: false,
                            sk: false,
                        },
                        {
                            valueId: 39,
                            valueName: '中',
                            skuIds: '24,23,22',
                            skuStatus: false,
                            sk: false,
                        },
                        {
                            valueId: 39,
                            valueName: '小',
                            skuIds: '23,25',
                            skuStatus: false,
                            sk: false,
                        }
                    ]
                }
            ],
            skuId: '',
            j: '',
            jList: [],
            sList: [
                {
                    itemId: 20,
                    itemName: '颜色',
                    currentValue: 36,
                    select: null,
                    skuProValueList: [
                        {
                            valueId: 35,
                            valueName: '红',
                            skuIds: '22',
                            skuStatus: false,
                            sk: false,
                        },
                        {
                            valueId: 36,
                            valueName: '蓝',
                            skuIds: '23',
                            skuStatus: false,
                            sk: false,
                        },
                        {
                            valueId: 37,
                            valueName: '白',
                            skuIds: '24,25,26',
                            skuStatus: false,
                            sk: false,
                        }
                    ]
                },
                {
                    itemId: 21,
                    itemName: '制冷方式',
                    currentValue: 38,
                    select: null,
                    skuProValueList: [
                        {
                            valueId: 38,
                            valueName: '风冷',
                            skuIds: '23,25,26',
                            skuStatus: false,
                            sk: false,
                        },
                        {
                            valueId: 39,
                            valueName: '直冷',
                            skuIds: '24,22',
                            skuStatus: false,
                            sk: false,
                        }
                    ]
                },
                {
                    itemId: 21,
                    itemName: '尺寸',
                    currentValue: 38,
                    select: null,
                    skuProValueList: [
                        {
                            valueId: 38,
                            valueName: '大',
                            skuIds: '22,26',
                            skuStatus: false,
                            sk: false,
                        },
                        {
                            valueId: 39,
                            valueName: '中',
                            skuIds: '24,23,22',
                            skuStatus: false,
                            sk: false,
                        },
                        {
                            valueId: 39,
                            valueName: '小',
                            skuIds: '23,25',
                            skuStatus: false,
                            sk: false,
                        }
                    ]
                }
            ],
        };
    },
	onLoad() {
		uni.getSystemInfo({
			success(r) {
				
				console.log(r)
			}
		})
	},
    methods: {
        
        // 选择属性,循环判断
        skuFun(iteml, obj, i, x) {
            var t = this;
            console.log(iteml);
            console.log(obj);
            console.log(i);
            console.log(x);
			if(!obj.skuStatus) {
				// 该属性可以选择
				t.skuList[i].select = x;  // 当前选中,改变背景颜色
				if(t.jList.length == 0 || t.j == i) {
				    // 还未选择属性或者是选择的同一类别里的属性
				    t.skuList.forEach(function(sitem,sindex) {
				        sitem.skuProValueList.forEach(function(site, sinde) {
				            site.sk = false;
				        })
				    })
				    t.j = i; 
				    var idList = obj.skuIds.split(',');  // 把字符串转为数组, 方便循环
				    t.jList = idList;
				    idList.forEach(function(item, index) {
				        // 循环当前选中的属性所带有的skuid
				        console.log(item+'自己自己自')
				        t.skuList.forEach(function(ite, inde) {
				            // 这个数组是属性数组去掉当前选中的属性类别后的数组
				                console.log(ite)
				            if(inde != i) {
				                ite.skuProValueList.forEach(function(it, ind) {
				                    // 这个数组是每个类型下是属性数组,判断是否有相同的字段
				                    console.log(it.skuIds,'当前选中的')
									
				                    if(it.skuIds.indexOf(item) > -1 || it.sk) {
				                        // 已经判断过是否有相同的字段,或者有相同的字段,更改状态
				                        it.skuStatus = false;
				                        it.sk = true;
										console.log('9999999999999', item)
				                    }else {
				                        it.skuStatus = true;
				                    }
				                })
				            }else {
								// 当前选中属性
								console.log(ite)
							}
				            
				        })
				    })
				    
				    // console.log(JSON.stringify(t.skuList))
				}
			}
            
        }
        
    }
};
</script>

<style>
@import url('../../common/shop.css');
.container {
    padding-top: var(--status-bar-height);
    background: rgba(255, 255, 255, 1);
    padding: 120rpx;
    box-sizing: border-box;
}
.status_bar {
    height: var(--status-bar-height);
    width: 100%;
    background: rgba(255, 255, 255, 1);
    position: fixed;
    top: 0;
    left: 0;
    z-index: 3;
}

.shop_list_box {
    margin-top: 208rpx;
}

.swiper {
    width: 100%;
    height: 100%;
}

.goods_type_list.active1 {
    background: rgba(249, 249, 249, 0.5);
    color: rgba(6, 18, 30, 0.3);
    
}


</style>