mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 18:13:26 +08:00
uniapp【修复】:商品分类sku弹框取消默认选中的问题
This commit is contained in:
@@ -169,6 +169,7 @@
|
|||||||
cartMoney : number,
|
cartMoney : number,
|
||||||
showSku : boolean;
|
showSku : boolean;
|
||||||
goodsDetailData : any;
|
goodsDetailData : any;
|
||||||
|
selectGoodsId : number;
|
||||||
}>({
|
}>({
|
||||||
classifyData: [],
|
classifyData: [],
|
||||||
topTabId: 0,
|
topTabId: 0,
|
||||||
@@ -186,14 +187,15 @@
|
|||||||
cartMoney: 0,
|
cartMoney: 0,
|
||||||
showSku: false,
|
showSku: false,
|
||||||
goodsDetailData: {},
|
goodsDetailData: {},
|
||||||
|
selectGoodsId: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
const buyNowLoading = ref(false);
|
const buyNowLoading = ref(false);
|
||||||
const addCartLoading = ref(false);
|
const addCartLoading = ref(false);
|
||||||
|
|
||||||
const handleBuyNow = useLoadingFn(onBuyNow, buyNowLoading);
|
const handleBuyNow = useLoadingFn(onBuyNow, buyNowLoading);
|
||||||
const handleAddCart = useLoadingFn(onAddCart, addCartLoading)
|
const handleAddCart = useLoadingFn(onAddCart, addCartLoading)
|
||||||
|
|
||||||
const emit = defineEmits(['getCartNumAndMoney'])
|
const emit = defineEmits(['getCartNumAndMoney'])
|
||||||
|
|
||||||
watch(() => props.data, (newVal : Array<CategoriesType>) => {
|
watch(() => props.data, (newVal : Array<CategoriesType>) => {
|
||||||
@@ -253,6 +255,10 @@
|
|||||||
|
|
||||||
/** 选择sku */
|
/** 选择sku */
|
||||||
const handleSelectSku = (id : number) => {
|
const handleSelectSku = (id : number) => {
|
||||||
|
if (state.selectGoodsId == id) {
|
||||||
|
state.showSku = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
_useLoginStore.checkLogin(async () => {
|
_useLoginStore.checkLogin(async () => {
|
||||||
let goodsDetail : any = null;
|
let goodsDetail : any = null;
|
||||||
if (uni.getStorageSync(UserToken)) {
|
if (uni.getStorageSync(UserToken)) {
|
||||||
|
|||||||
@@ -110,6 +110,7 @@
|
|||||||
cartMoney : number,
|
cartMoney : number,
|
||||||
showSku : boolean;
|
showSku : boolean;
|
||||||
goodsDetailData : any;
|
goodsDetailData : any;
|
||||||
|
selectGoodsId:number;
|
||||||
}>({
|
}>({
|
||||||
classifyData: [],
|
classifyData: [],
|
||||||
leftTabId: 0,
|
leftTabId: 0,
|
||||||
@@ -122,6 +123,7 @@
|
|||||||
cartMoney: 0,
|
cartMoney: 0,
|
||||||
showSku: false,
|
showSku: false,
|
||||||
goodsDetailData: {},
|
goodsDetailData: {},
|
||||||
|
selectGoodsId:0,
|
||||||
});
|
});
|
||||||
|
|
||||||
const buyNowLoading = ref(false);
|
const buyNowLoading = ref(false);
|
||||||
@@ -178,6 +180,11 @@
|
|||||||
|
|
||||||
/** 选择sku */
|
/** 选择sku */
|
||||||
const handleSelectSku = (id : number) => {
|
const handleSelectSku = (id : number) => {
|
||||||
|
if(state.selectGoodsId == id){
|
||||||
|
state.showSku = true;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
_useLoginStore.checkLogin(async () => {
|
_useLoginStore.checkLogin(async () => {
|
||||||
let goodsDetail : any = null;
|
let goodsDetail : any = null;
|
||||||
if (uni.getStorageSync(UserToken)) {
|
if (uni.getStorageSync(UserToken)) {
|
||||||
@@ -191,6 +198,7 @@
|
|||||||
data: true,
|
data: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
state.selectGoodsId = id;
|
||||||
state.goodsDetailData = goodsDetail.data;
|
state.goodsDetailData = goodsDetail.data;
|
||||||
state.showSku = true;
|
state.showSku = true;
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -49,8 +49,7 @@
|
|||||||
}
|
}
|
||||||
.tag-box {
|
.tag-box {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
gap: 25rpx;
|
|
||||||
max-height: 500rpx;
|
max-height: 500rpx;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
.tag {
|
.tag {
|
||||||
@@ -60,6 +59,8 @@
|
|||||||
border-radius: 15rpx;
|
border-radius: 15rpx;
|
||||||
margin: inherit;
|
margin: inherit;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
|
margin-right: 15rpx;
|
||||||
|
margin-bottom: 15rpx;
|
||||||
.icon-select {
|
.icon-select {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 0;
|
right: 0;
|
||||||
|
|||||||
@@ -26,16 +26,13 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="number-box">
|
<view class="number-box">
|
||||||
<view class="tit">数量:</view>
|
<view class="tit">数量:</view>
|
||||||
<uv-number-box v-model="state.numberVal"
|
<uv-number-box v-model="state.numberVal" @change="handleChangeNumberVal"></uv-number-box>
|
||||||
@change="handleChangeNumberVal"></uv-number-box>
|
|
||||||
</view>
|
</view>
|
||||||
<view class="btn-box">
|
<view class="btn-box">
|
||||||
<!-- <view v-if="props.isShowAddCartBtn" class="btn add-cart" @click="handleAddCart">加入购物车</view> -->
|
|
||||||
<view v-if="props.isShowAddCartBtn" class="core-button-confirm add-cart">
|
<view v-if="props.isShowAddCartBtn" class="core-button-confirm add-cart">
|
||||||
<coreshop-button :loading="props.addCartloading" class="core-button-confirm_" :radius="0"
|
<coreshop-button :loading="props.addCartloading" class="core-button-confirm_" :radius="0"
|
||||||
title="加入购物车" :customStyle="addCartCustomStyle" @onClick="handleAddCart()"></coreshop-button>
|
title="加入购物车" :customStyle="addCartCustomStyle" @onClick="handleAddCart()"></coreshop-button>
|
||||||
</view>
|
</view>
|
||||||
<!-- <view class="btn buy-now" @click="handleBuyNow">{{ props.btnBuyTitlt }}</view> -->
|
|
||||||
<view class="core-button-confirm">
|
<view class="core-button-confirm">
|
||||||
<coreshop-button :loading="props.buyNowNowloading" class="core-button-confirm_" :radius="0"
|
<coreshop-button :loading="props.buyNowNowloading" class="core-button-confirm_" :radius="0"
|
||||||
:title="props.btnBuyTitlt" :customStyle="buyNowCustomStyle"
|
:title="props.btnBuyTitlt" :customStyle="buyNowCustomStyle"
|
||||||
@@ -131,6 +128,9 @@
|
|||||||
|
|
||||||
watch(() => props.goodsDetailData, (newVal : any) => {
|
watch(() => props.goodsDetailData, (newVal : any) => {
|
||||||
if (newVal) {
|
if (newVal) {
|
||||||
|
state.specMap = {};
|
||||||
|
state.specCombinationList = [];
|
||||||
|
state.selectedSpecs = [];
|
||||||
// 构造规格权重
|
// 构造规格权重
|
||||||
let i = 0, j = 0;
|
let i = 0, j = 0;
|
||||||
state.spec_list = deepClone(newVal?.skuList?.spec_list.map((item : GoodsSpecListType) => {
|
state.spec_list = deepClone(newVal?.skuList?.spec_list.map((item : GoodsSpecListType) => {
|
||||||
@@ -151,17 +151,17 @@
|
|||||||
weight: item.sku_name_arr.reduce((prev, current) => prev + state.specMap[current]?.weight, 0),
|
weight: item.sku_name_arr.reduce((prev, current) => prev + state.specMap[current]?.weight, 0),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/** 获取数据返回的默认sku,如果有就用没有就找第一个库存不为0的sku */
|
/** 获取数据返回的默认sku,如果有就用没有就找第一个库存不为0的sku */
|
||||||
let systemDefaultSku:Array<string> = (props.goodsDetailData?.product?.spesDesc?.split(',')).map((item:string)=> item.split(':')[1]);
|
let systemDefaultSku : Array<string> = (props.goodsDetailData?.product?.spesDesc?.split(',')).map((item : string) => item.split(':')[1]);
|
||||||
let skuDefaultSku:GoodsSkuListType = state.specCombinationList.find((item:GoodsSkuListType)=> item.sku_name_arr.every((name:string)=> systemDefaultSku.includes(name)));
|
let skuDefaultSku : GoodsSkuListType = state.specCombinationList.find((item : GoodsSkuListType) => item.sku_name_arr.every((name : string) => systemDefaultSku.includes(name)));
|
||||||
if(!systemDefaultSku || !skuDefaultSku){
|
if (!systemDefaultSku || !skuDefaultSku) {
|
||||||
state.specCombinationList[0].sku_name_arr.forEach((item:string)=>{
|
state.specCombinationList[0].sku_name_arr.forEach((item : string) => {
|
||||||
handleChooseSku(item);
|
handleChooseSku(item);
|
||||||
});
|
});
|
||||||
return ;
|
return;
|
||||||
}
|
}
|
||||||
skuDefaultSku.sku_name_arr.forEach((item:string)=>{
|
skuDefaultSku.sku_name_arr.forEach((item : string) => {
|
||||||
handleChooseSku(item);
|
handleChooseSku(item);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -223,6 +223,10 @@
|
|||||||
|
|
||||||
/** sku选择 */
|
/** sku选择 */
|
||||||
const handleChooseSku = (name : string) => {
|
const handleChooseSku = (name : string) => {
|
||||||
|
/** 只有一层的时候,当自己选中时,不能点击自己取消选择 */
|
||||||
|
if (state.spec_list.length === 1 && state.selectedSpecs.find((item)=> item.name == name)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const spec = state.specMap[name];
|
const spec = state.specMap[name];
|
||||||
const eleIndex = state.selectedSpecs.findIndex(item => item.name === name);
|
const eleIndex = state.selectedSpecs.findIndex(item => item.name === name);
|
||||||
const sortIndex = state.selectedSpecs.findIndex(item => item.sort === spec.sort);
|
const sortIndex = state.selectedSpecs.findIndex(item => item.sort === spec.sort);
|
||||||
@@ -238,9 +242,9 @@
|
|||||||
state.selectedSpecs.push({ name: name, weight: spec.weight, sort: spec.sort });
|
state.selectedSpecs.push({ name: name, weight: spec.weight, sort: spec.sort });
|
||||||
|
|
||||||
/** 判断sku是否选择完毕 */
|
/** 判断sku是否选择完毕 */
|
||||||
if(state.selectedSpecs.length === state.spec_list.length){
|
if (state.selectedSpecs.length === state.spec_list.length) {
|
||||||
let skuName:Array<string> = state.selectedSpecs.map(item => item.name);
|
let skuName : Array<string> = state.selectedSpecs.map(item => item.name);
|
||||||
state.chooseSku = state.specCombinationList.find((item:GoodsSkuListType)=> item.sku_name_arr.every((name:string)=> skuName.includes(name)));
|
state.chooseSku = state.specCombinationList.find((item : GoodsSkuListType) => item.sku_name_arr.every((name : string) => skuName.includes(name)));
|
||||||
emits('handleChangeGoodSku', state.chooseSku);
|
emits('handleChangeGoodSku', state.chooseSku);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -270,9 +274,9 @@
|
|||||||
|
|
||||||
/** 判断库存 */
|
/** 判断库存 */
|
||||||
const handleHaveStock = () => {
|
const handleHaveStock = () => {
|
||||||
let skuName:Array<string> = state.selectedSpecs.map(item => item.name) || [];
|
let skuName : Array<string> = state.selectedSpecs.map(item => item.name) || [];
|
||||||
let sku = state.spec_list.find((item:any)=> !item.list.some((itemChild:any)=> skuName.includes(itemChild.name)));
|
let sku = state.spec_list.find((item : any) => !item.list.some((itemChild : any) => skuName.includes(itemChild.name)));
|
||||||
if (sku) {
|
if (sku) {
|
||||||
handleShowToast(`请选择 ${sku.name} 规格`);
|
handleShowToast(`请选择 ${sku.name} 规格`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user