This commit is contained in:
pushuo 2022-07-21 10:40:12 +08:00
parent 925f372fb4
commit 55df50520a
3 changed files with 39 additions and 6 deletions

View File

@ -393,11 +393,17 @@ body.page-product .variables-wrap .variable-info > div {
padding: 0.5rem; padding: 0.5rem;
cursor: pointer; cursor: pointer;
text-align: center; text-align: center;
font-weight: bold;
transition: all 0.1s ease-in-out; transition: all 0.1s ease-in-out;
} }
body.page-product .variables-wrap .variable-info > div:hover, body.page-product .variables-wrap .variable-info > div.active { body.page-product .variables-wrap .variable-info > div:hover, body.page-product .variables-wrap .variable-info > div.selected {
border-color: #222; border-color: #222;
} }
body.page-product .variables-wrap .variable-info > div:not(.selected).disabled {
border: 1px dashed #bfbfbf;
color: #999;
font-weight: initial;
}
body.page-product .peoduct-info .rating-wrap { body.page-product .peoduct-info .rating-wrap {
margin-bottom: 2rem; margin-bottom: 2rem;
} }

View File

@ -25,10 +25,20 @@ body.page-product {
padding: 0.5rem; padding: 0.5rem;
cursor: pointer; cursor: pointer;
text-align: center; text-align: center;
font-weight: bold;
// border-radius: 2rem;
transition: all .1s ease-in-out; transition: all .1s ease-in-out;
&:hover, &.active { &:hover, &.selected {
border-color: #222; border-color: #222;
} }
&:not(.selected) {
&.disabled {
border: 1px dashed #bfbfbf;
color: #999;
font-weight: initial;
}
}
} }
} }
} }

View File

@ -47,14 +47,14 @@
</div> </div>
<div class="variables-wrap" v-if="source.variables.length"> <div class="variables-wrap" v-if="source.variables.length">
<div class="variable-group mb-3" v-for="variable, variable_index in source.variables" :key="variable_index"> <div class="variable-group mb-2" v-for="variable, variable_index in source.variables" :key="variable_index">
<p class=""><strong>@{{ variable.name }}</strong></p> <p class="mb-2"><strong>@{{ variable.name }}</strong></p>
<div class="variable-info"> <div class="variable-info">
<div <div
v-for="value, value_index in variable.values" v-for="value, value_index in variable.values"
@click="checkedVariableValue(variable_index, value_index, value)" @click="checkedVariableValue(variable_index, value_index, value)"
:key="value_index" :key="value_index"
:class="value.selected ? 'active' : ''"> :class="[value.selected ? 'selected' : '', value.disabled ? 'disabled' : '']">
@{{ value.name }} @{{ value.name }}
</div> </div>
</div> </div>
@ -178,6 +178,7 @@
this.checkedVariants() this.checkedVariants()
this.getSelectedSku(); this.getSelectedSku();
this.updateSelectedVariantsStatus()
} }
}, },
@ -189,6 +190,7 @@
this.updateSelectedVariantsIndex(); this.updateSelectedVariantsIndex();
this.getSelectedSku(); this.getSelectedSku();
this.updateSelectedVariantsStatus()
}, },
// 把对应 selectedVariantsIndex 下标选中 variables -> values 的 selected 字段为 true // 把对应 selectedVariantsIndex 下标选中 variables -> values 的 selected 字段为 true
@ -224,7 +226,22 @@
}) })
}, },
// 根据 skus 中 quantity 字段,对应到 variants 的 每种组合 variables 的 selected 字段 updateSelectedVariantsStatus() {
// skus 里面 quantity 不为 0 的 sku.variants
const skus = this.source.skus.filter(sku => sku.quantity > 0).map(sku => sku.variants);
this.source.variables.forEach((variable, index) => {
variable.values.forEach((value, value_index) => {
const selectedVariantsIndex = this.selectedVariantsIndex.slice(0);
selectedVariantsIndex[index] = value_index;
const selectedSku = skus.find(sku => sku.toString() == selectedVariantsIndex.toString());
if (selectedSku) {
value.disabled = false;
} else {
value.disabled = true;
}
})
});
},
} }
}) })
</script> </script>