feat:初始化默认选中规格中的第一个(代码优化)
parent
becfc58eca
commit
beca206592
|
|
@ -109,7 +109,7 @@
|
|||
<script setup>
|
||||
import { computed, reactive, watch } from 'vue';
|
||||
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 emits = defineEmits(['change', 'addCart', 'buy', 'close', 'ladder']);
|
||||
|
|
|
|||
|
|
@ -95,7 +95,12 @@
|
|||
<script setup>
|
||||
import { computed, reactive, watch } from 'vue';
|
||||
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 props = defineProps({
|
||||
|
|
|
|||
|
|
@ -498,21 +498,17 @@ export function getRewardActivityRuleItemDescriptions(activity) {
|
|||
return result;
|
||||
}
|
||||
|
||||
// 单规格,要默认选中;
|
||||
/** 单规格,要默认选中 */
|
||||
export function initDefaultSelect(propertyList, onSelectSku) {
|
||||
if (propertyList.length > 0) {
|
||||
// 遍历每一个属性
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (propertyList.length === 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 遍历每一个属性
|
||||
for (const property of propertyList) {
|
||||
const firstValue = (property.values || [])[0];
|
||||
// 不是禁用直接选中
|
||||
if (firstValue && !firstValue.disabled) {
|
||||
onSelectSku(property.id, firstValue.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue