!175 feat: 初始化默认选中规格中的第一个

Merge pull request !175 from steven/feat-新增购买商品默认选中规格
pull/177/head
芋道源码 2026-01-18 04:08:02 +00:00 committed by Gitee
commit becfc58eca
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 24 additions and 3 deletions

View File

@ -109,7 +109,7 @@
<script setup>
import { computed, reactive, watch } from 'vue';
import sheep from '@/sheep';
import { convertProductPropertyList, 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']);
@ -315,7 +315,8 @@
}
changeDisabled(false);
// TODO 12
//
initDefaultSelect(propertyList, onSelectSku);
</script>
<style lang="scss" scoped>

View File

@ -305,7 +305,8 @@
}
changeDisabled(false);
// TODO 12
//
initDefaultSelect(propertyList, onSelectSku);
</script>
<style lang="scss" scoped>

View File

@ -497,3 +497,22 @@ 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);
}
}
}
}