Pre Merge pull request !175 from steven/feat-新增购买商品默认选中规格
commit
4d2d72b9a4
|
|
@ -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 芋艿:待讨论的优化点:1)单规格,要不要默认选中;2)默认要不要选中第一个规格
|
||||
// 初始化默认选中规格中的第一个,如果不需要,注释这段代码即可
|
||||
initDefaultSelect(propertyList, onSelectSku);
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
|
|
|||
|
|
@ -305,7 +305,8 @@
|
|||
}
|
||||
|
||||
changeDisabled(false);
|
||||
// TODO 芋艿:待讨论的优化点:1)单规格,要不要默认选中;2)默认要不要选中第一个规格
|
||||
// 初始化默认选中规格中的第一个,如果不需要,注释这段代码即可
|
||||
initDefaultSelect(propertyList, onSelectSku);
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue