提交 9e0080c0 authored 作者: 刘旭's avatar 刘旭

优化

上级 8a48774d
......@@ -9,6 +9,9 @@ export const indexDetails = (data: any) => request('/wx/goods/detail', 'GET', da
// 加入购物车
export const addCart = (data: any) => request('/wx/cart/add', 'POST', data);
// 加入购物车后重新选择规格
export const readdCart = (data: any) => request('/wx/cart/readd', 'POST', data);
// 立即购买
export const fastaddCart = (data: any) => request('/wx/cart/fastadd', 'POST', data);
......@@ -53,6 +56,6 @@ export const pushOrder = (data: any) => request('/wx/order/push', 'GET', data);
// 获取商品配件
export const goodsParts = (data: any) => request('/wx/goods/parts', 'GET', data);
// 查询商品参数属性 ?productId=1
export const orderAttribute = (data: any) => request('/wx/cart/attribute', 'GET', data);
......@@ -25,7 +25,7 @@
<script setup lang="ts">
import { ref, watch } from 'vue';
import { addCart, fastaddCart } from '@/api/index';
import { addCart, fastaddCart, readdCart } from '@/api/index';
// SKU弹窗模式
let skuMode = ref(1);
......@@ -174,23 +174,42 @@ let addCartFn = (obj: any) => {
specificationCustom,
partIds: partsIds.value
}
if(props.cartId) data = { ...{id: props.cartId }, ...data }
addCart(data).then((res: any) => {
if(res.data.code === 200) {
uni.showToast({
title: '已添加至购物车',
icon: 'none',
duration: 300,
success() {
handleClose()
emits('partsClose') // 还原
skuKey.value = false
}
});
} else {
console.log(res, '加入购物车错误');
}
})
if(props.cartId) {
data = { ...{id: props.cartId }, ...data }
readdCart(data).then((res: any) => {
if(res.data.code === 200) {
uni.showToast({
title: '已添加至购物车',
icon: 'none',
duration: 300,
success() {
handleClose()
emits('partsClose') // 还原
skuKey.value = false
}
});
} else {
console.log(res, '加入购物车错误');
}
})
} else {
addCart(data).then((res: any) => {
if(res.data.code === 200) {
uni.showToast({
title: '已添加至购物车',
icon: 'none',
duration: 300,
success() {
handleClose()
emits('partsClose') // 还原
skuKey.value = false
}
});
} else {
console.log(res, '加入购物车错误');
}
})
}
};
// 加入购物车按钮
let addCarts = (selectShop: any) => {
......
......@@ -167,14 +167,26 @@ const onsubmit = () => {
});
};
let addressId = ref(null); // 但值为null时,显示为默认地址
// 重新选择地址时的回调
uni.$on('updataAddressId', (data: any) => {
uni.setStorage({
key: 'addressId',
data: data.id,
success() {
addressId.value = uni.getStorageSync('addressId');
},
});
});
// 初始化数据
const initCheckoutCart = (cartId: number, types: number) => {
let couponId = uni.getStorageSync('couponId');
let addressId = uni.getStorageSync('addressId');
// let addressId = uni.getStorageSync('addressId');
checkoutCart({
cartId,
couponId,
addressId,
addressId: addressId.value,
type: types,
}).then((res: any) => {
if (res.data.code === 200) {
......
......@@ -334,6 +334,10 @@ let priceCheck = (val: any, index: number) => {
if(val <= 0) {
nextTick(() => {
detailData.value[index].unitPrice = ''
uni.showToast({
title: '不能为负数',
icon: 'none'
})
})
}
}
......
......@@ -88,6 +88,8 @@ const setAddress = (item: any) => {
success: function() {
if (beforePage.route === 'pages/order/quotation')
uni.$emit('updateAddress', { addr: item });
if (beforePage.route === 'pages/order/checkout')
uni.$emit('updataAddressId', { id: item.id });
},
});
},
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论