|
@@ -1,46 +1,63 @@
|
|
|
<template>
|
|
|
<div class="ss-modal-box bg-white ss-flex-col">
|
|
|
- <!-- SKU 信息 - 属性选择 -->
|
|
|
- <div class="modal-content ss-flex-1">
|
|
|
- <div class="modal-content-scroll">
|
|
|
- <div class="sku-item ss-m-b-20" v-for="property in propertyList" :key="property.id">
|
|
|
- <span class="label-text ss-m-b-20">{{ property.name }}:</span>
|
|
|
- <span class="ss-flex ss-col-center ss-flex-wrap">
|
|
|
- <!-- :disabled="value.disabled === true" -->
|
|
|
- <v-chip
|
|
|
- class="spec-btn mr-3"
|
|
|
- :class="[
|
|
|
- { 'ui-BG-Main-Gradient': state.currentPropertyArray[property.id] === value.id, },
|
|
|
- { 'disabled-btn': value.disabled === true, },
|
|
|
- ]"
|
|
|
- v-for="value in property.values"
|
|
|
- :key="value.id"
|
|
|
- size="small"
|
|
|
- label
|
|
|
- density="comfortable"
|
|
|
- color="primary"
|
|
|
- variant="outlined"
|
|
|
- :disabled="value.disabled === true"
|
|
|
- @click="onSelectSku(property.id, value.id)"
|
|
|
- >
|
|
|
- {{ value.name }}
|
|
|
- </v-chip>
|
|
|
- </span>
|
|
|
- </div>
|
|
|
+ <!-- SKU 信息 -->
|
|
|
+ <!-- 属性选择 -->
|
|
|
+ <div class="d-flex mb-5" v-for="property in propertyList" :key="property.id">
|
|
|
+ <span class="l-s-10 parameterColor mb-1">{{ property.name }}</span>:
|
|
|
+ <span style="flex: 1;">
|
|
|
+ <v-chip
|
|
|
+ class="spec-btn mb-1 mr-3"
|
|
|
+ :class="[
|
|
|
+ { 'ui-BG-Main-Gradient': state.currentPropertyArray[property.id] === value.id, },
|
|
|
+ { 'disabled-btn': value.disabled === true, },
|
|
|
+ ]"
|
|
|
+ v-for="value in property.values"
|
|
|
+ :key="value.id"
|
|
|
+ size="small"
|
|
|
+ label
|
|
|
+ density="comfortable"
|
|
|
+ color="primary"
|
|
|
+ variant="outlined"
|
|
|
+ :disabled="value.disabled === true"
|
|
|
+ @click="onSelectSku(property.id, value.id)"
|
|
|
+ >
|
|
|
+ {{ value.name }}
|
|
|
+ </v-chip>
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+ <!-- 购买数量 -->
|
|
|
+ <div class="buyCount mb-10">
|
|
|
+ <span class="parameterColor"><span class="l-s-10">数量</span>:</span>
|
|
|
+ <div class="d-flex">
|
|
|
+ <v-btn icon="mdi-minus" size="x-small" :disabled="number<=1" @click="number > 1 ? number-- : 0"></v-btn>
|
|
|
+ <input
|
|
|
+ v-model="state.selectedSku.goods_num"
|
|
|
+ class="inputItem mx-2"
|
|
|
+ type="number"
|
|
|
+ :disabled="!goodsInfo.stock"
|
|
|
+ @change="onNumberChange"
|
|
|
+ >
|
|
|
+ <v-btn icon="mdi-plus" size="x-small" :disabled="goodsInfo.stock ? number >= (state.selectedSku.stock) : true" @click="number ? number++ : 0"></v-btn>
|
|
|
</div>
|
|
|
+ <!-- 库存 -->
|
|
|
+ <div class="ml-3" style="color: #b7b7b7; font-size: 14px;">{{ formatStock('exact', state.selectedSku.stock || goodsInfo.stock) }}</div>
|
|
|
+ <!-- <div class="ml-3" style="color: #b7b7b7; font-size: 14px;">库存:{{ goodsInfo.stock || 0 }}</div> -->
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <v-btn class="buttons" color="primary" @click="null">立即购买</v-btn>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
+defineOptions({name: 'wares-s-select-sku'})
|
|
|
import { computed, reactive, watch, ref } from 'vue'
|
|
|
import { convertProductPropertyList } from '@/views/mall/utils'
|
|
|
-
|
|
|
const emits = defineEmits(['change', 'addCart', 'buy', 'close']);
|
|
|
const props = defineProps({
|
|
|
- skus: {
|
|
|
- type: Array,
|
|
|
- default: () => []
|
|
|
+ goodsInfo: {
|
|
|
+ type: Object,
|
|
|
+ default() {},
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -49,22 +66,37 @@ const state = reactive({
|
|
|
currentPropertyArray: [], // 当前选中的属性,实际是个 Map。key 是 property 编号,value 是 value 编号
|
|
|
});
|
|
|
|
|
|
+const onNumberChange = () => {
|
|
|
+ if (number.value === 0) return
|
|
|
+ if (state.selectedSku.goods_num === number.value) return
|
|
|
+ state.selectedSku.goods_num = number.value
|
|
|
+ // if ( number.value < 0) return number.value = goodsInfo.value.stock ? 1 : 0
|
|
|
+ // if ( number.value > goodsInfo.value.stock) number.value = goodsInfo.value.stock
|
|
|
+ // number.value = parseInt( number.value)
|
|
|
+}
|
|
|
+
|
|
|
// SKU 列表
|
|
|
const skuList = computed(() => {
|
|
|
- let skuPrices = props.skus?.length ? props.skus : []
|
|
|
+ let skuPrices = props.goodsInfo.skus?.length ? props.goodsInfo.skus : []
|
|
|
for (let price of skuPrices) {
|
|
|
price.value_id_array = price.properties.map((item) => item.valueId);
|
|
|
}
|
|
|
return skuPrices;
|
|
|
});
|
|
|
|
|
|
+const number = ref(0)
|
|
|
+const stockShow = ref(0)
|
|
|
const propertyList = ref([])
|
|
|
watch(
|
|
|
- () => props.skus,
|
|
|
+ () => props.goodsInfo,
|
|
|
(newVal) => {
|
|
|
- if (newVal && newVal.length) {
|
|
|
- propertyList.value = props.skus?.length ? convertProductPropertyList(props.skus) : []
|
|
|
- console.log('propertyList:', propertyList.value)
|
|
|
+ if (newVal && Object.keys(newVal)) {
|
|
|
+ stockShow.value = newVal.goodsInfo.stock-0
|
|
|
+ number.value = stock.value ? 1 : 0
|
|
|
+ if (newVal.skus && newVal.skus.length) {
|
|
|
+ propertyList.value = newVal.goodsInfo.skus?.length ? convertProductPropertyList(newVal.goodsInfo.skus) : []
|
|
|
+ // console.log('propertyList:', propertyList.value)
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
{
|
|
@@ -231,9 +263,18 @@ changeDisabled(false);
|
|
|
background: var(--v-primary-base);
|
|
|
color: #fff !important;
|
|
|
}
|
|
|
-
|
|
|
.disabled-btn {
|
|
|
color: #c6c6c6;
|
|
|
background: #f8f8f8;
|
|
|
}
|
|
|
+.parameterColor {
|
|
|
+ color: #7a7a7a;
|
|
|
+}
|
|
|
+input::-webkit-outer-spin-button, input::-webkit-inner-spin-button{
|
|
|
+ -webkit-appearance: none !important;
|
|
|
+ margin: 0;
|
|
|
+}
|
|
|
+.inputItem {
|
|
|
+ width: 70px; border: 1px solid #eee; padding: 0 5px; text-align: center;
|
|
|
+}
|
|
|
</style>
|