feat:初始化默认选中规格中的第一个(代码优化)
parent
becfc58eca
commit
beca206592
|
|
@ -109,7 +109,7 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, reactive, watch } from 'vue';
|
import { computed, reactive, watch } from 'vue';
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
import { convertProductPropertyList,initDefaultSelect, fen2yuan } from '@/sheep/hooks/useGoods';
|
import { convertProductPropertyList, initDefaultSelect, fen2yuan } from '@/sheep/hooks/useGoods';
|
||||||
|
|
||||||
const headerBg = sheep.$url.css('/static/img/shop/goods/groupon-btn-long.png');
|
const headerBg = sheep.$url.css('/static/img/shop/goods/groupon-btn-long.png');
|
||||||
const emits = defineEmits(['change', 'addCart', 'buy', 'close', 'ladder']);
|
const emits = defineEmits(['change', 'addCart', 'buy', 'close', 'ladder']);
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,12 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed, reactive, watch } from 'vue';
|
import { computed, reactive, watch } from 'vue';
|
||||||
import sheep from '@/sheep';
|
import sheep from '@/sheep';
|
||||||
import { formatStock, convertProductPropertyList, fen2yuan } from '@/sheep/hooks/useGoods';
|
import {
|
||||||
|
formatStock,
|
||||||
|
convertProductPropertyList,
|
||||||
|
fen2yuan,
|
||||||
|
initDefaultSelect,
|
||||||
|
} from '@/sheep/hooks/useGoods';
|
||||||
|
|
||||||
const emits = defineEmits(['change', 'addCart', 'buy', 'close']);
|
const emits = defineEmits(['change', 'addCart', 'buy', 'close']);
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
|
|
||||||
|
|
@ -498,21 +498,17 @@ export function getRewardActivityRuleItemDescriptions(activity) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 单规格,要默认选中;
|
/** 单规格,要默认选中 */
|
||||||
export function initDefaultSelect(propertyList, onSelectSku) {
|
export function initDefaultSelect(propertyList, onSelectSku) {
|
||||||
if (propertyList.length > 0) {
|
if (propertyList.length === 0) {
|
||||||
// 遍历每一个属性
|
return;
|
||||||
for (let property of propertyList) {
|
|
||||||
const propertyId = property.id;
|
|
||||||
// 获取当前属性下可用的选项
|
|
||||||
const values = property.values || [];
|
|
||||||
const firstValue = values[0] || {}
|
|
||||||
// 不是禁用直接选中
|
|
||||||
if (!firstValue.disabled) {
|
|
||||||
const valueId = firstValue.id;
|
|
||||||
onSelectSku(propertyId, valueId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
// 遍历每一个属性
|
||||||
|
for (const property of propertyList) {
|
||||||
|
const firstValue = (property.values || [])[0];
|
||||||
|
// 不是禁用直接选中
|
||||||
|
if (firstValue && !firstValue.disabled) {
|
||||||
|
onSelectSku(property.id, firstValue.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue