购物车逻辑完善

个人信息存储优化
团购下单
This commit is contained in:
2024-03-31 03:19:19 +08:00
parent 074b0057da
commit 1fc0aa432b
17 changed files with 316 additions and 166 deletions

View File

@@ -24,6 +24,7 @@ export interface GoodsBean {
material_name: string; material_name: string;
name: string; name: string;
price: number; price: number;
send_num: number;
price_ext: number; price_ext: number;
profile: string; profile: string;
remark: string; remark: string;
@@ -52,4 +53,5 @@ export interface StockBean {
sizeId: string; sizeId: string;
sizeName: string; sizeName: string;
stockId: string; stockId: string;
count: number;
} }

View File

@@ -15,5 +15,5 @@ export const getGroupBuyRecordList = (groupId: string, pageNum: number, pageSize
url: `wechat/coupons/group/order/list?groupId=${groupId}&pageNum=${pageNum}&pageSize=${pageSize}` url: `wechat/coupons/group/order/list?groupId=${groupId}&pageNum=${pageNum}&pageSize=${pageSize}`
}); });
export const preOrder = (data: any) => post({ url: 'wechat/coupons/group/pre', data }); export const preOrder = (data: any) => post({ url: 'wechat/coupons/group/pre_v2', data });

View File

@@ -5,7 +5,7 @@
<image class='goods-image' :src='bean?.images' /> <image class='goods-image' :src='bean?.images' />
<view class='c-flex-column' style='flex: 1'> <view class='c-flex-column' style='flex: 1'>
<text class='goods-name'>{{ bean?.name }}</text> <text class='goods-name'>{{ bean?.name }}</text>
<text class='goods-price'>{{ bean?.price||0 }}</text> <text class='goods-price'>{{ bean?.price || 0 }}</text>
</view> </view>
<image class='close-image' :src='assetsUrl("ic_close.png")' @click.stop='close' /> <image class='close-image' :src='assetsUrl("ic_close.png")' @click.stop='close' />
</view> </view>
@@ -48,28 +48,60 @@
</template> </template>
<script lang='ts' setup> <script lang='ts' setup>
import { ref } from 'vue'; import { PropType, ref } from 'vue';
import { assetsUrl } from '@/utils/assets'; import { assetsUrl } from '@/utils/assets';
import { GoodsBean } from '@/api/goods/types'; import {showToast} from '@/utils';
import { GoodsBean, StockBean } from '@/api/goods/types';
const props = defineProps({ const props = defineProps({
bean: Object as Proptype<GoodsBean> bean: Object as PropType<GoodsBean>,
exists: Object as PropType<StockBean>
}); });
const emits = defineEmits(['confirm']);
const popupRef = ref(); const popupRef = ref();
const skuColorList = ref<string[]>([]); const skuColorList = ref<string[]>([]);
const currentColorIndex = ref(0); const currentColorIndex = ref(0);
const currentSizeIndex = ref(0); const currentSizeIndex = ref(0);
const goodsCount = ref(1); const goodsCount = ref(1);
let callback: Function;
const show = (fn: Function) => {
callback = fn;
// new Promise((resolve, reject) => {
// props.bean?.stocks?.map((res: { colorName: string }) => res.colorName).forEach((colorName: string) => {
// if(!skuColorList.value.includes(colorName)) {
// skuColorList.value.push(colorName);
// }
// });
// resolve(skuColorList.value);
// }).then(res => {
// popupRef.value.open();
// });
if(props?.bean?.stocks?.length == 0) {
showToast('暂无库存')
return;
}
const show = () => {
props.bean?.stocks?.map((res: { colorName: string }) => res.colorName).forEach((colorName: string) => { props.bean?.stocks?.map((res: { colorName: string }) => res.colorName).forEach((colorName: string) => {
if(!skuColorList.value.includes(colorName)) { if(!skuColorList.value.includes(colorName)) {
skuColorList.value.push(colorName); skuColorList.value.push(colorName);
} }
}); });
popupRef.value.open();
setTimeout(() => {
popupRef.value.open();
}, 200);
if(props.exists) {
const colorIndex = skuColorList.value?.findIndex(res => res === props.exists?.colorName);
const sizeIndex = skuSizeList.value?.findIndex(res => res.sizeId === props.exists?.sizeId);
colorChange(colorIndex || 0);
sizeChange(sizeIndex || 0);
goodsCount.value = props.exists?.count;
}
}; };
const skuSizeList = computed(() => { const skuSizeList = computed(() => {
@@ -93,17 +125,17 @@ const sizeChange = (index: number) => {
const countChange = (isPlus: boolean) => { const countChange = (isPlus: boolean) => {
if(isPlus) { if(isPlus) {
goodsCount.value++; goodsCount.value += 1;
} else { } else {
if(goodsCount.value > 1) { if(goodsCount.value > 1) {
goodsCount.value--; goodsCount.value -= 1;
} }
} }
}; };
const confirm = () => { const confirm = () => {
emits('confirm', { callback({
...skuSizeList.value[currentSizeIndex.value], ...skuSizeList.value![currentSizeIndex.value],
count: goodsCount.value count: goodsCount.value
}); });
popupRef.value.close(); popupRef.value.close();

View File

@@ -33,7 +33,7 @@
<view class='goods-info-view c-flex-column'> <view class='goods-info-view c-flex-column'>
<view class='c-flex-row'> <view class='c-flex-row'>
<text class='goods-price accent-text-color'>39.89</text> <text class='goods-price accent-text-color'>{{ detailBean?.payPrice || 0 }}</text>
<text>销量{{ detailBean?.totalNum || 0 }}</text> <text>销量{{ detailBean?.totalNum || 0 }}</text>
</view> </view>
@@ -90,7 +90,7 @@
</view> </view>
<text style='color: #a6a6a6'>不参与会员折扣</text> <text style='color: #a6a6a6'>不参与会员折扣</text>
<text style='color: #F32B2B'>¥{{ detailBean?.goods?.payPrice }}</text> <text style='color: #F32B2B'>¥{{ detailBean?.goods?.payPrice }}</text>
<text class='bought_count'>已团{{detailBean?.sendNum}}</text> <text class='bought_count'>已团{{ detailBean?.sendNum }}</text>
</view> </view>
</view> </view>
</view> </view>
@@ -164,6 +164,7 @@ const currentPageNum = ref(1);
onLoad(async (e: any) => { onLoad(async (e: any) => {
detailBean.value = await getGroupBuyDetail(e.id); detailBean.value = await getGroupBuyDetail(e.id);
detailBean.value.goods.price = detailBean.value.price;
bannerList.value = JSON.parse(detailBean.value.content).filter((item: any) => item.type === 2).map((item: any) => item.images); bannerList.value = JSON.parse(detailBean.value.content).filter((item: any) => item.type === 2).map((item: any) => item.images);
countdown(); countdown();
await fetchRecommendList(); await fetchRecommendList();
@@ -226,8 +227,8 @@ const countdown = () => {
}, 1000); }, 1000);
}; };
const showSkuDialog = () => { const showSkuDialog = (fn: Function) => {
skuDialogRef.value.show(); skuDialogRef.value.show(fn);
}; };
const confirmGoodsSku = (e: any) => { const confirmGoodsSku = (e: any) => {
@@ -235,18 +236,24 @@ const confirmGoodsSku = (e: any) => {
}; };
const placeOrder = async () => { const placeOrder = async () => {
goPath('/pages/common/groupbuy/order');
const params = { async function create() {
'colorId': '1725029269178814466', const params = {
'sizeId': '0', 'colorId': '1725029269178814466',
'goodsId': detailBean.value.goods.goodsId, 'sizeId': '0',
'groupId': detailBean.value.id, 'goodsId': detailBean.value.goods.goodsId,
'memberId': userInfo.value.id, 'groupId': detailBean.value.id,
'shareId': '123456' 'memberId': userInfo.value.id,
}; 'shareId': '123456'
};
const result = await preOrder(params); const result = await preOrder(params);
goPath('/pages/common/groupbuy/order');
}
showSkuDialog(() => {
create();
});
}; };
</script> </script>

View File

@@ -12,10 +12,10 @@
<view class='c-flex-column' style='flex: 1'> <view class='c-flex-column' style='flex: 1'>
<view class='goods-name'>{{ item.name }}</view> <view class='goods-name'>{{ item.name }}</view>
<view class='middle-view c-flex-row'> <view class='middle-view c-flex-row'>
<text>原价{{ item.goodsPrice }}</text> <text>原价{{ item.price }}</text>
<view v-if='(item.goodsPrice - item.payPrice)>0' class='decline c-flex-row'> <view v-if='(item.price - item.payPrice)>0' class='decline c-flex-row'>
<image :src='assetsUrl("ic_decline.png")' /> <image :src='assetsUrl("ic_decline.png")' />
<text>直降¥{{ (item.goodsPrice - item.payPrice).toFixed(2) }}</text> <text>直降¥{{ (item.price - item.payPrice).toFixed(2) }}</text>
</view> </view>
<text>即将恢复</text> <text>即将恢复</text>
</view> </view>

View File

@@ -66,7 +66,7 @@
import { getCompanyInfo, getCompanyList } from '@/api/company'; import { getCompanyInfo, getCompanyList } from '@/api/company';
import { useUserStore } from '@/store'; import { useUserStore } from '@/store';
import { assetsUrl } from '@/utils/assets'; import { assetsUrl } from '@/utils/assets';
import { goPath, setCompanyId } from '@/utils'; import { getCompanyId, goPath, isLogin, setCompanyId } from '@/utils';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
const store = useUserStore(); const store = useUserStore();
@@ -93,22 +93,30 @@ const submenuList = [
} }
]; ];
onLoad(async (e) => { onLoad((e) => {
const data = await getCompanyInfo(userInfo.value.companyId); console.log('home load e ', e);
bannerList.value = data.bannerinx?.map((res: { src: string }) => res.src); });
recommendBannerList.value = data.bannerhot?.map((res: { src: string }) => res.src);
getCompanyList(userInfo.value.maOpenId).then(res => { onShow(async () => {
const companyList = res.map((res: { company: any }) => res.company); if(isLogin()) {
const userList = res.map((res: { user: any }) => res.user); const data = await getCompanyInfo(userInfo.value.companyId);
uni.showActionSheet({ bannerList.value = data.bannerinx?.map((res: { src: string }) => res.src);
itemList: companyList.map((res: { companyName: string }) => res.companyName), recommendBannerList.value = data.bannerhot?.map((res: { src: string }) => res.src);
success: (res) => {
setCompanyId(companyList[res.tapIndex].id); getCompanyList(userInfo.value.maOpenId).then(res => {
store.setUserInfo(userList[res.tapIndex]); const companyList = res.map((res: { company: any }) => res.company);
const userList = res.map((res: { user: any }) => res.user);
if(getCompanyId() == undefined) {
uni.showActionSheet({
itemList: companyList.map((res: { companyName: string }) => res.companyName),
success: (res) => {
setCompanyId(companyList[res.tapIndex].id);
store.setUserInfo(userList[res.tapIndex]);
}
});
} }
}); });
}); }
}); });
const swiperChange = (e: any) => { const swiperChange = (e: any) => {

View File

@@ -20,7 +20,7 @@
<grid-view type='masonry' :cross-axis-count='2'> <grid-view type='masonry' :cross-axis-count='2'>
<view v-for='(item, index) in goodsList' :key='index' class='goods-item' <view v-for='(item, index) in goodsList' :key='index' class='goods-item'
@click.stop='goPath(`/pages/mall/subs/goods/detail?goodsId=${item.goodsId}`)'> @click.stop='goPath(`/pages/mall/subs/goods/detail?goodsId=${item.goodsId}`)'>
<image class='goods-image' :src='item.images' /> <image class='goods-image' :src='item.images' />
<text class='goods-name'>{{ item.goodsName }}</text> <text class='goods-name'>{{ item.goodsName }}</text>
<text class='goods-price'>¥{{ item.price }}</text> <text class='goods-price'>¥{{ item.price }}</text>
<image class='add-image' :src='assetsUrl("ic_add_goods.png")' @click.stop='addShoppingCart(item)' /> <image class='add-image' :src='assetsUrl("ic_add_goods.png")' @click.stop='addShoppingCart(item)' />
@@ -84,10 +84,6 @@ const randomImageHeight = () => {
return height; return height;
}; };
const getRandomIntegerInRange = (a: number, b: number) => {
return Math.floor(Math.random() * (b - a + 1)) + a;
};
const getRandomFloatInRange = (a: number, b: number) => { const getRandomFloatInRange = (a: number, b: number) => {
return Math.random() * (b - a) + a; return Math.random() * (b - a) + a;
}; };

View File

@@ -1,13 +1,13 @@
<template> <template>
<uni-popup type='bottom' ref='popupRef' :mask-click='false'> <uni-popup type='bottom' ref='popupRef' :is-mask-click='false'>
<view class='popup-content c-flex-column'> <view class='popup-content c-flex-column'>
<view class='c-flex-row'> <view class='c-flex-row'>
<text>优惠券</text> <text>优惠券</text>
<text @click.stop='close'>确定</text> <text @click.stop='close'>确定</text>
</view> </view>
<scroll-view> <scroll-view scroll-y>
<coupon-item v-for='item in coupons' :item='item' /> <coupon-item v-for='(item,index) in coupons' :item='item' :key='index' />
</scroll-view> </scroll-view>
</view> </view>
</uni-popup> </uni-popup>
@@ -17,7 +17,7 @@
import CouponItem from '../components/coupon-item.vue'; import CouponItem from '../components/coupon-item.vue';
const popupRef = ref(); const popupRef = ref();
const coupons = [{ const coupons = ref([{
id: 1, id: 1,
title: '优惠券', title: '优惠券',
desc: '满100减10', desc: '满100减10',
@@ -67,7 +67,7 @@ const coupons = [{
useTime: '2024-12-31', useTime: '2024-12-31',
status: 0, status: 0,
useStatus: '未使用' useStatus: '未使用'
}]; }]);
const show = () => { const show = () => {
popupRef.value.open(); popupRef.value.open();
@@ -86,7 +86,7 @@ defineExpose({
.popup-content { .popup-content {
background: #FFFFFF; background: #FFFFFF;
border-radius: 20rpx 20rpx 0 0; border-radius: 20rpx 20rpx 0 0;
padding: 38rpx 45rpx 0 45rpx; padding: 38rpx 45rpx 10rpx 45rpx;
view:nth-of-type(1) { view:nth-of-type(1) {
display: flex; display: flex;

View File

@@ -15,7 +15,7 @@
<view class='goods-info-view c-flex-column' style='margin-right: 10rpx'> <view class='goods-info-view c-flex-column' style='margin-right: 10rpx'>
<view class='c-flex-row'> <view class='c-flex-row'>
<text class='goods-price accent-text-color'>{{ goodsBean?.price || 0 }}</text> <text class='goods-price accent-text-color'>{{ goodsBean?.price || 0 }}</text>
<text>销量2653</text> <text>销量{{ goodsBean?.send_num || 0 }}</text>
</view> </view>
<view class='c-flex-row'> <view class='c-flex-row'>
@@ -90,7 +90,7 @@
</view> </view>
</view> </view>
</view> </view>
<sku-dialog ref='skuDialogRef' :bean='goodsBean' @confirm='confirmGoodsSku' /> <sku-dialog ref='skuDialogRef' :bean='goodsBean' />
</template> </template>
<script lang='ts' setup> <script lang='ts' setup>
@@ -98,17 +98,16 @@ import { assetsUrl } from '@/utils/assets';
import SkuDialog from '@/components/sku-dialog.vue'; import SkuDialog from '@/components/sku-dialog.vue';
import { goPath, showToast } from '@/utils'; import { goPath, showToast } from '@/utils';
import { getGoodsDetail, getGoodsList } from '@/api/goods'; import { getGoodsDetail, getGoodsList } from '@/api/goods';
import { GoodsBean } from '@/api/goods/types'; import { GoodsBean, StockBean } from '@/api/goods/types';
import useShoppingCartStore from '@/store/modules/shoppingcart'; import useShoppingCartStore from '@/store/modules/shoppingcart';
const shoppingCart = useShoppingCartStore(); const shoppingCartStore = useShoppingCartStore();
const { shoppingCartList } = storeToRefs(shoppingCart); const { shoppingCartList } = storeToRefs(shoppingCartStore);
const goodsBean = ref<GoodsBean>(); const goodsBean = ref<GoodsBean>();
const recommendList = ref<GoodsBean[]>(); const recommendList = ref<GoodsBean[]>();
const skuDialogRef = ref(); const skuDialogRef = ref();
const skuBean = ref();
const bannerList = ref([]); const bannerList = ref([]);
const swiperIndex = ref(0); const swiperIndex = ref(0);
@@ -136,27 +135,31 @@ const goBack = () => {
uni.navigateBack(); uni.navigateBack();
}; };
const showSkuDialog = () => { const showSkuDialog = (fn: Function) => {
skuDialogRef.value.show(); skuDialogRef.value.show(fn);
};
const confirmGoodsSku = (e: any) => {
skuBean.value = e;
}; };
const addShoppingCart = () => { const addShoppingCart = () => {
shoppingCart.save( showSkuDialog((e: StockBean) => {
{ const index = shoppingCartStore.getSameGoodsIndex(goodsBean.value?.id || '', e.colorId, e.sizeId);
...goodsBean.value, if(index >= 0) {
...skuBean.value, shoppingCartStore.updateCount(index, e.count);
count: 1 } else {
shoppingCartStore.save(
{
...goodsBean.value,
checkedStock: e
}
);
} }
); showToast('加入购物车成功');
showToast('加入购物车成功'); });
}; };
const placeOrder = () => { const placeOrder = () => {
goPath('/pages/mall/subs/order/order-confirm'); showSkuDialog((e: StockBean) => {
goPath('/pages/mall/subs/order/order-confirm');
});
}; };
</script> </script>

View File

@@ -1,28 +1,36 @@
<template> <template>
<view class='content'> <view class='content'>
<view class='c-flex-row'> <view class='c-flex-row'>
<text class='manage' @click.stop='isEditMode = !isEditMode'>管理</text> <text class='manage' @click.stop='isEditMode = !isEditMode' :style='isEditMode?"color:#F32B2B":"color:#333333"'>
{{ isEditMode ? '退出管理' : '管理' }}
</text>
</view> </view>
<view class='card-view'> <view class='card-view' v-if='shoppingCartList.length>0'>
<scroll-view> <scroll-view>
<view class='c-flex-column' v-for='(item, index) in shoppingCartList' :key='index'> <view class='c-flex-column' v-for='(item, index) in shoppingCartList' :key='index'>
<view class='c-flex-row'> <view class='c-flex-row'>
<image v-show='isEditMode' class='checkbox' :src='assetsUrl("ic_checkbox_active_red.png")' /> <image v-show='isEditMode' class='checkbox'
:src='assetsUrl(item.checked?"ic_checkbox_active_red.png":"ic_checkbox_normal.png")'
@click.stop='item.checked=!item.checked' />
<image class='goods-image' :src='item.images' /> <image class='goods-image' :src='item.images' />
<view class='c-flex-column'> <view class='c-flex-column'>
<text>{{ item.name }}</text> <text>{{ item.name }}</text>
<view class='sku-view'> <view class='c-flex-row'>
<text>{{ item?.colorName }}{{ item?.sizeName }} x{{ item?.count }}</text> <view class='sku-view' @click.stop='showSkuDialog(index)'>
<image :src='assetsUrl("ic_arrow_down_gray.png")' /> <text>{{ item?.checkedStock.colorName }}{{ item?.checkedStock.sizeName }}
x{{ item?.checkedStock.count }}
</text>
<image :src='assetsUrl("ic_arrow_down_gray.png")' />
</view>
</view> </view>
<text style='margin-top: 50rpx'>¥{{ item.price }}</text> <text style='margin-top: 50rpx'>¥{{ item.price }}</text>
<view class='count-change-view c-flex-row'> <view class='count-change-view c-flex-row'>
<view class='count-image' @click.stop='countChange(false)'> <view class='count-image' @click.stop='countChange(index,false)'>
<image :src='assetsUrl("ic_reduce.png")' /> <image :src='assetsUrl("ic_reduce.png")' />
</view> </view>
<text>{{ item.count || 0 }}</text> <text>{{ item?.checkedStock.count || 0 }}</text>
<view class='count-image' @click.stop='countChange(true)'> <view class='count-image' @click.stop='countChange(index,true)'>
<image :src='assetsUrl("ic_plus.png")' /> <image :src='assetsUrl("ic_plus.png")' />
</view> </view>
</view> </view>
@@ -38,31 +46,88 @@
<text>全选</text> <text>全选</text>
</view> </view>
<view style='flex: 1' /> <view style='flex: 1' />
<text>合计
<text>29.90</text> <text v-if='isEditMode' class='settlement' @click.stop='deleteShoppingCart'>删除</text>
</text> <view v-else class='c-flex-row'>
<text class='settlement' @click.stop='settlement'>结算</text> <text>合计:
<text>¥{{ totalPayPrice }}</text>
</text>
<text class='settlement' @click.stop='settlement'>结算</text>
</view>
</view> </view>
</view> </view>
<sku-dialog ref='skuDialogRef' :bean='temporaryGoodsBean' :exists='temporaryStockBean' />
</template> </template>
<script lang='ts' setup> <script lang='ts' setup>
import { assetsUrl } from '@/utils/assets'; import { assetsUrl } from '@/utils/assets';
import useShoppingCartStore from '@/store/modules/shoppingcart'; import useShoppingCartStore from '@/store/modules/shoppingcart';
import { goPath } from '@/utils';
import { GoodsBean, StockBean } from '@/api/goods/types';
import SkuDialog from '@/components/sku-dialog.vue';
import { ref } from 'vue';
const isEditMode = ref(false); const isEditMode = ref(false);
const checkedAll = ref(false); const checkedAll = ref(false);
const shoppingCart = useShoppingCartStore(); const shoppingCartStore = useShoppingCartStore();
const { shoppingCartList } = storeToRefs(shoppingCart); const { shoppingCartList } = storeToRefs(shoppingCartStore);
const countChange = (isPlus: Boolean) => { const skuDialogRef = ref();
const temporaryGoodsBean = ref<GoodsBean>();
const temporaryStockBean = ref<StockBean>();
watch(checkedAll, (newValue) => {
shoppingCartList.value.forEach(res => {
res.checked = newValue;
});
});
const totalPayPrice = computed(() => {
return shoppingCartList.value.reduce((a, b) => a + b.price * b.checkedStock.count, 0);
});
const deleteShoppingCart = () => {
shoppingCartStore.deleteIfChecked();
};
const showSkuDialog = (index: number) => {
new Promise((resolve, reject) => {
temporaryGoodsBean.value = shoppingCartList.value[index];
temporaryStockBean.value = shoppingCartList.value[index].checkedStock;
resolve(temporaryGoodsBean.value);
}).then(res => {
skuDialogRef.value.show((e: StockBean) => {
//重新选择sku后判断当前购物中是否存在相同sku的商品
const existsIndex = shoppingCartStore.getSameGoodsIndex(temporaryGoodsBean.value?.id || '', e.colorId, e.sizeId);
//不存在则更新当前商品sku
if(existsIndex < 0) {
shoppingCartStore.updateStock(index, e);
}
//如果已存在,则更新已存在商品数量,并删除当前商品
else {
shoppingCartStore.updateCount(existsIndex, e.count);
if(existsIndex != index) {
shoppingCartStore.delete(index);
}
}
});
});
};
const countChange = (index: number, isPlus: Boolean) => {
if(isPlus) {
shoppingCartStore.updateCount(index, 1);
} else {
if(shoppingCartList.value[index].checkedStock.count > 1) {
shoppingCartStore.updateCount(index, -1);
}
}
}; };
const settlement = () => { const settlement = () => {
goPath('/pages/mall/subs/order/order-confirm');
}; };
</script> </script>
@@ -82,10 +147,10 @@ const settlement = () => {
} }
.card-view { .card-view {
margin: 30rpx; margin: 30rpx 30rpx 180rpx 30rpx;
border-radius: 10rpx; border-radius: 10rpx;
background: #FFFFFF; background: #FFFFFF;
padding: 10rpx 20rpx 120rpx 17rpx; padding: 10rpx 20rpx 10rpx 17rpx;
.c-flex-column:nth-of-type(1) { .c-flex-column:nth-of-type(1) {
margin: 20rpx 0; margin: 20rpx 0;
@@ -112,16 +177,16 @@ const settlement = () => {
text:nth-of-type(1) { text:nth-of-type(1) {
font-weight: 400; font-weight: 400;
font-size: 28rpx; font-size: 30rpx;
color: #333333; color: #333333;
-webkit-line-clamp: 2; -webkit-line-clamp: 2;
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden;
} }
.sku-view { .sku-view {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
width: 210rpx;
position: relative; position: relative;
background: #F2F2F2; background: #F2F2F2;
margin-top: 10rpx; margin-top: 10rpx;
@@ -213,7 +278,6 @@ const settlement = () => {
text:nth-of-type(1) { text:nth-of-type(1) {
font-size: 30rpx; font-size: 30rpx;
color: #333333;
text { text {
font-weight: bold; font-weight: bold;

View File

@@ -2,20 +2,21 @@
<view class='content'> <view class='content'>
<view class='c-flex-row'> <view class='c-flex-row'>
<text>收货人</text> <text>收货人</text>
<input placeholder='请输入收货人姓名' /> <input placeholder='请输入收货人姓名' @input='bindConsignee' />
</view> </view>
<view class='divider' /> <view class='divider' />
<view class='c-flex-row'> <view class='c-flex-row'>
<text>手机号</text> <text>手机号</text>
<input placeholder='请输入收货人手机号' maxlength='11' /> <input placeholder='请输入收货人手机号' @input='bindMobile' :maxlength='11' />
</view> </view>
<view class='divider' /> <view class='divider' />
<view class='c-flex-row detail-row'> <view class='c-flex-row detail-row'>
<text>详细地址</text> <text>详细地址</text>
<view class='c-flex-column'> <view class='c-flex-column'>
<textarea placeholder='详细地址:如街道、门牌\n号、楼栋号、单元室等' /> <textarea placeholder='详细地址:如街道、门牌\n号、楼栋号、单元室等'
@input='bindAddress' />
<view class='tips-view c-flex-row'> <view class='tips-view c-flex-row'>
<image :src='assetsUrl("ic_tips.png")' /> <image :src='assetsUrl("ic_tips.png")' />
<text>记得完善门牌号</text> <text>记得完善门牌号</text>
@@ -27,7 +28,8 @@
<view class='c-flex-column'> <view class='c-flex-column'>
<text style='width: auto'>设为默认地址</text> <text style='width: auto'>设为默认地址</text>
<text style='width: auto'>提醒每次下单会默认推荐使用该地址</text> <text style='width: auto'>提醒每次下单会默认推荐使用该地址</text>
<switch color='#F32B2B' /> <!-- @change='ev=>{params.defaultstatus = ev.detail.value}'-->
<switch color='#F32B2B' @change='bindStatus' />
</view> </view>
<view class='bottom-button-view'> <view class='bottom-button-view'>
@@ -41,16 +43,40 @@
import { assetsUrl } from '@/utils/assets'; import { assetsUrl } from '@/utils/assets';
import { addressCreate } from '@/api/user'; import { addressCreate } from '@/api/user';
const params = ref<{
name: string,
mobile: string,
zonecode: string,
addr: string,
defaultstatus: number
}>({
name: '',
mobile: '',
zonecode: '',
addr: '',
defaultstatus: 0
});
const bindConsignee = (e: any) => {
params.value.name = e.detail.value;
};
const bindMobile = (e: any) => {
params.value.mobile = e.detail.value;
};
const bindAddress = (e: any) => {
params.value.addr = e.detail.value;
};
const bindStatus = (e: any) => {
params.value.defaultstatus = e.detail.value == true ? 1 : 0;
};
const save = () => { const save = () => {
addressCreate( addressCreate(
{ {
bean: { bean: params.value
'name': '高昂',
'mobile': '15475655487',
'zonecode': '420101001001',
'addr': '肯德基挂',
'defaultstatus': 1
}
} }
).then(() => { ).then(() => {
uni.showToast({ uni.showToast({

View File

@@ -24,6 +24,10 @@ const addressList = ref<{
}[]>([]); }[]>([]);
onLoad((e) => { onLoad((e) => {
// fetchAddressList();
});
onShow(() => {
fetchAddressList(); fetchAddressList();
}); });

View File

@@ -3,22 +3,22 @@
<view class='top-card-view'> <view class='top-card-view'>
<image class='bg-image' :src='assetsUrl("test_bg.png")' /> <image class='bg-image' :src='assetsUrl("test_bg.png")' />
<image class='avatar-image' :src='userInfo.image' /> <image class='avatar-image' :src='userInfo.image' />
<text>{{ userInfo.nickName }}</text> <text>{{ userInfo.name }}</text>
<text>会员卡</text> <text>{{ userInfo.levelName }}</text>
</view> </view>
<view class='basic-info-view c-flex-column'> <view class='basic-info-view c-flex-column'>
<view class='c-flex-row'> <view class='c-flex-row'>
<text>头像</text> <text>头像</text>
<view class='avatar-view'> <view class='avatar-view'>
<image class='avatar-image' :src='userInfo.image' /> <image class='avatar-image' :src='params.avatarUrl' />
<button class='avatar-btn' open-type='chooseAvatar' @chooseavatar='chooseAvatar' /> <button class='avatar-btn' open-type='chooseAvatar' @chooseavatar='chooseAvatar' />
</view> </view>
</view> </view>
<view class='c-flex-row'> <view class='c-flex-row'>
<text class='nickname'>姓名</text> <text class='nickname'>姓名</text>
<input placeholder='请输入姓名' type='nickname' v-model='userInfo.nickName' @input='bindNickname' /> <input placeholder='请输入姓名' type='nickname' v-model='userInfo.nickName' @change='bindNickname' />
</view> </view>
<view class='divider' /> <view class='divider' />
@@ -32,12 +32,12 @@
<text>性别</text> <text>性别</text>
<view class='c-flex-row' @click.stop='changeGender(0)'> <view class='c-flex-row' @click.stop='changeGender(0)'>
<image class='gender-image' <image class='gender-image'
:src='assetsUrl(currentGender==0?"ic_checkbox_active.png":"ic_checkbox_normal.png")' /> :src='assetsUrl(params?.gender==0?"ic_checkbox_active.png":"ic_checkbox_normal.png")' />
<text class='gender-text'></text> <text class='gender-text'></text>
</view> </view>
<view class='c-flex-row' @click.stop='changeGender(1)'> <view class='c-flex-row' @click.stop='changeGender(1)'>
<image class='gender-image' <image class='gender-image'
:src='assetsUrl(currentGender==1?"ic_checkbox_active.png":"ic_checkbox_normal.png")' /> :src='assetsUrl(params?.gender==1?"ic_checkbox_active.png":"ic_checkbox_normal.png")' />
<text class='gender-text'></text> <text class='gender-text'></text>
</view> </view>
</view> </view>
@@ -46,7 +46,7 @@
<view class='c-flex-row'> <view class='c-flex-row'>
<text>生日</text> <text>生日</text>
<picker mode='date' @change='changeDate'> <picker mode='date' @change='changeDate'>
<text>{{ userInfo.birthday || '请选择生日' }}</text> <text>{{ params?.birthday || '请选择生日' }}</text>
</picker> </picker>
</view> </view>
</view> </view>
@@ -63,7 +63,21 @@ import { showToast } from '@/utils';
const store = useUserStore(); const store = useUserStore();
const { userInfo } = storeToRefs(store); const { userInfo } = storeToRefs(store);
const currentGender = ref<number>(0); const params = ref<{
avatarUrl: string;
image: string;
nickName: string;
telephone: string;
gender: number;
birthday: string;
}>({
avatarUrl: userInfo.value.image,
image: userInfo.value.image,
nickName: userInfo.value.nickName,
telephone: userInfo.value.telephone,
gender: userInfo.value.gender,
birthday: userInfo.value.birthday
});
onLoad(() => { onLoad(() => {
store.getProfile(); store.getProfile();
@@ -79,7 +93,8 @@ const chooseAvatar = (e: any) => {
'Content-Type': 'multipart/form-data' 'Content-Type': 'multipart/form-data'
}, },
success: (res: any) => { success: (res: any) => {
userInfo.value.image = JSON.parse(res.data).data; params.value!.avatarUrl = JSON.parse(res.data).data;
params.value!.image = JSON.parse(res.data).data;
}, },
error: (err: any) => { error: (err: any) => {
showToast('上传失败'); showToast('上传失败');
@@ -91,40 +106,30 @@ const chooseAvatar = (e: any) => {
}; };
const bindNickname = (e: any) => { const bindNickname = (e: any) => {
userInfo.value.nickName = e.detail.value; console.log('---------->>>>', e.detail.value);
params.value!.nickName = e.detail.value;
}; };
const bindTelephone = (e: any) => { const bindTelephone = (e: any) => {
userInfo.value.telephone = e.detail.value; params.value!.telephone = e.detail.value;
}; };
const changeGender = (index: number) => { const changeGender = (index: number) => {
currentGender.value = index; params.value!.gender = index;
userInfo.value.gender = index;
}; };
const changeDate = (e: any) => { const changeDate = (e: any) => {
userInfo.value.birthday = e.detail.value; params.value!.birthday = e.detail.value;
}; };
const save = async () => { const save = async () => {
// const registerForm = { console.log('---------->>>>', params.value);
// unionId: userInfo.value.unionId, const newUserInfo = {
// openId: userInfo.value.openId, ...userInfo.value,
// maOpenId: userInfo.value.maOpenId, ...params.value
// image: userInfo.value.image, };
// nickName: userInfo.value.nickName, console.log('---------->>>>', newUserInfo);
// telephone: userInfo.value.telephone, store.setUserInfo(newUserInfo);
// birthday: userInfo.value.birthday,
// gender: userInfo.value.gender,
// companyId: userInfo.value.companyId,
// creatorId: userInfo.value.creatorId
// };
// console.log('--------_>>>userInfo.value ', userInfo.value);
// const result = await store.userRegister(registerForm);
// console.log('--------->>>', result);
store.setUserInfo(userInfo.value)
}; };
</script> </script>

View File

@@ -1,4 +1,5 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { StockBean } from '@/api/goods/types';
const useShoppingCartStore = defineStore('shoppingCart', { const useShoppingCartStore = defineStore('shoppingCart', {
state: (): { shoppingCartList: any[] } => ({ state: (): { shoppingCartList: any[] } => ({
@@ -27,14 +28,35 @@ const useShoppingCartStore = defineStore('shoppingCart', {
getTotalCount(): number { getTotalCount(): number {
return this.shoppingCartList.length; return this.shoppingCartList.length;
},
getSameGoodsIndex: (state) => (goodsId: string, colorId: string, sizeId: string) => {
return state.shoppingCartList.findIndex(res => res.id === goodsId && res.checkedStock.colorId === colorId && res.checkedStock.sizeId === sizeId);
} }
}, },
actions: { actions: {
save(partial: Partial<any>) { save(partial: Partial<any>) {
this.shoppingCartList.push(partial); this.shoppingCartList.push(partial);
}, },
clear() { updateCount(index: number, count: number) {
this.shoppingCartList[index].checkedStock.count += count;
},
updateStock(index: number, stock: StockBean) {
this.shoppingCartList[index].checkedStock = stock;
},
delete(index: number) {
this.shoppingCartList.splice(index, 1);
},
deleteIfChecked() {
this.shoppingCartList = this.shoppingCartList.filter(res => res.checked == undefined || res.checked === false);
},
clearAll() {
this.shoppingCartList = []; this.shoppingCartList = [];
} }
} }

View File

@@ -5,26 +5,8 @@ import { clearToken, setCompanyId, setToken } from '@/utils/auth';
import type { LoginResult, RegisterParams } from '@/api/user/types'; import type { LoginResult, RegisterParams } from '@/api/user/types';
const useUserStore = defineStore('user', { const useUserStore = defineStore('user', {
state: (): UserState => <UserState>({ state: () => ({
id: '', userInfo: {} as UserState
unionId: '',
openId: '',
maOpenId: '',
name: '未登录',
nickName: '未登录',
image: '',
telephone: '',
gender: 0,
birthday: '',
address: '',
balance: 0,
integration: 0,
creatorId: '',
companyId: '',
levelName: '',
orderNum: 0,
storeId: '',
creatorName: ''
}), }),
persist: { persist: {
@@ -43,15 +25,15 @@ const useUserStore = defineStore('user', {
}, },
getters: { getters: {
userInfo(state: UserState): UserState { // getUserInfo(state: UserState): UserState {
return { ...state }; // return state.address;
} // }
}, },
actions: { actions: {
// 设置用户的信息 // 设置用户的信息
setUserInfo(partial: Partial<UserState>) { setUserInfo(partial: Partial<UserState>) {
this.$patch(partial); this.userInfo = partial as UserState;
}, },
// 重置用户信息 // 重置用户信息
resetInfo() { resetInfo() {
@@ -118,7 +100,6 @@ const useUserStore = defineStore('user', {
gender: res.user.gender gender: res.user.gender
}; };
const registerResult = await this.userRegister(registerForm); const registerResult = await this.userRegister(registerForm);
console.log(registerResult);
this.setUserInfo(registerResult as LoginResult); this.setUserInfo(registerResult as LoginResult);
setToken(res.token); setToken(res.token);
setCompanyId(res.user.companyId); setCompanyId(res.user.companyId);

View File

@@ -21,7 +21,7 @@ export interface UserState {
gold: string; gold: string;
goodsNum: number; goodsNum: number;
id: string; id: string;
image: string; image: string | 'https://img.1216.top/lake/def_avatar.png';
integration: number; integration: number;
lastConsumTime: string; lastConsumTime: string;
levelEntity: any; levelEntity: any;

View File

@@ -1,4 +1,4 @@
const TokenKey = 'access-token'; const TokenKey = 'accessToken';
const CompanyIdKey = 'companyId'; const CompanyIdKey = 'companyId';
const TokenPrefix = 'Bearer '; const TokenPrefix = 'Bearer ';