购物车逻辑完善

个人信息存储优化
团购下单
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;
name: string;
price: number;
send_num: number;
price_ext: number;
profile: string;
remark: string;
@@ -52,4 +53,5 @@ export interface StockBean {
sizeId: string;
sizeName: 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}`
});
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' />
<view class='c-flex-column' style='flex: 1'>
<text class='goods-name'>{{ bean?.name }}</text>
<text class='goods-price'>{{ bean?.price||0 }}</text>
<text class='goods-price'>{{ bean?.price || 0 }}</text>
</view>
<image class='close-image' :src='assetsUrl("ic_close.png")' @click.stop='close' />
</view>
@@ -48,28 +48,60 @@
</template>
<script lang='ts' setup>
import { ref } from 'vue';
import { PropType, ref } from 'vue';
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({
bean: Object as Proptype<GoodsBean>
bean: Object as PropType<GoodsBean>,
exists: Object as PropType<StockBean>
});
const emits = defineEmits(['confirm']);
const popupRef = ref();
const skuColorList = ref<string[]>([]);
const currentColorIndex = ref(0);
const currentSizeIndex = ref(0);
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) => {
if(!skuColorList.value.includes(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(() => {
@@ -93,17 +125,17 @@ const sizeChange = (index: number) => {
const countChange = (isPlus: boolean) => {
if(isPlus) {
goodsCount.value++;
goodsCount.value += 1;
} else {
if(goodsCount.value > 1) {
goodsCount.value--;
goodsCount.value -= 1;
}
}
};
const confirm = () => {
emits('confirm', {
...skuSizeList.value[currentSizeIndex.value],
callback({
...skuSizeList.value![currentSizeIndex.value],
count: goodsCount.value
});
popupRef.value.close();

View File

@@ -33,7 +33,7 @@
<view class='goods-info-view c-flex-column'>
<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>
</view>
@@ -90,7 +90,7 @@
</view>
<text style='color: #a6a6a6'>不参与会员折扣</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>
@@ -164,6 +164,7 @@ const currentPageNum = ref(1);
onLoad(async (e: any) => {
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);
countdown();
await fetchRecommendList();
@@ -226,8 +227,8 @@ const countdown = () => {
}, 1000);
};
const showSkuDialog = () => {
skuDialogRef.value.show();
const showSkuDialog = (fn: Function) => {
skuDialogRef.value.show(fn);
};
const confirmGoodsSku = (e: any) => {
@@ -235,18 +236,24 @@ const confirmGoodsSku = (e: any) => {
};
const placeOrder = async () => {
goPath('/pages/common/groupbuy/order');
const params = {
'colorId': '1725029269178814466',
'sizeId': '0',
'goodsId': detailBean.value.goods.goodsId,
'groupId': detailBean.value.id,
'memberId': userInfo.value.id,
'shareId': '123456'
};
async function create() {
const params = {
'colorId': '1725029269178814466',
'sizeId': '0',
'goodsId': detailBean.value.goods.goodsId,
'groupId': detailBean.value.id,
'memberId': userInfo.value.id,
'shareId': '123456'
};
const result = await preOrder(params);
const result = await preOrder(params);
goPath('/pages/common/groupbuy/order');
}
showSkuDialog(() => {
create();
});
};
</script>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,28 +1,36 @@
<template>
<view class='content'>
<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 class='card-view'>
<view class='card-view' v-if='shoppingCartList.length>0'>
<scroll-view>
<view class='c-flex-column' v-for='(item, index) in shoppingCartList' :key='index'>
<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' />
<view class='c-flex-column'>
<text>{{ item.name }}</text>
<view class='sku-view'>
<text>{{ item?.colorName }}{{ item?.sizeName }} x{{ item?.count }}</text>
<image :src='assetsUrl("ic_arrow_down_gray.png")' />
<view class='c-flex-row'>
<view class='sku-view' @click.stop='showSkuDialog(index)'>
<text>{{ item?.checkedStock.colorName }}{{ item?.checkedStock.sizeName }}
x{{ item?.checkedStock.count }}
</text>
<image :src='assetsUrl("ic_arrow_down_gray.png")' />
</view>
</view>
<text style='margin-top: 50rpx'>¥{{ item.price }}</text>
<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")' />
</view>
<text>{{ item.count || 0 }}</text>
<view class='count-image' @click.stop='countChange(true)'>
<text>{{ item?.checkedStock.count || 0 }}</text>
<view class='count-image' @click.stop='countChange(index,true)'>
<image :src='assetsUrl("ic_plus.png")' />
</view>
</view>
@@ -38,31 +46,88 @@
<text>全选</text>
</view>
<view style='flex: 1' />
<text>合计
<text>29.90</text>
</text>
<text class='settlement' @click.stop='settlement'>结算</text>
<text v-if='isEditMode' class='settlement' @click.stop='deleteShoppingCart'>删除</text>
<view v-else class='c-flex-row'>
<text>合计:
<text>¥{{ totalPayPrice }}</text>
</text>
<text class='settlement' @click.stop='settlement'>结算</text>
</view>
</view>
</view>
<sku-dialog ref='skuDialogRef' :bean='temporaryGoodsBean' :exists='temporaryStockBean' />
</template>
<script lang='ts' setup>
import { assetsUrl } from '@/utils/assets';
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 checkedAll = ref(false);
const shoppingCart = useShoppingCartStore();
const { shoppingCartList } = storeToRefs(shoppingCart);
const shoppingCartStore = useShoppingCartStore();
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 = () => {
goPath('/pages/mall/subs/order/order-confirm');
};
</script>
@@ -82,10 +147,10 @@ const settlement = () => {
}
.card-view {
margin: 30rpx;
margin: 30rpx 30rpx 180rpx 30rpx;
border-radius: 10rpx;
background: #FFFFFF;
padding: 10rpx 20rpx 120rpx 17rpx;
padding: 10rpx 20rpx 10rpx 17rpx;
.c-flex-column:nth-of-type(1) {
margin: 20rpx 0;
@@ -112,16 +177,16 @@ const settlement = () => {
text:nth-of-type(1) {
font-weight: 400;
font-size: 28rpx;
font-size: 30rpx;
color: #333333;
-webkit-line-clamp: 2;
text-overflow: ellipsis;
overflow: hidden;
}
.sku-view {
display: flex;
flex-direction: row;
width: 210rpx;
position: relative;
background: #F2F2F2;
margin-top: 10rpx;
@@ -213,7 +278,6 @@ const settlement = () => {
text:nth-of-type(1) {
font-size: 30rpx;
color: #333333;
text {
font-weight: bold;

View File

@@ -2,20 +2,21 @@
<view class='content'>
<view class='c-flex-row'>
<text>收货人</text>
<input placeholder='请输入收货人姓名' />
<input placeholder='请输入收货人姓名' @input='bindConsignee' />
</view>
<view class='divider' />
<view class='c-flex-row'>
<text>手机号</text>
<input placeholder='请输入收货人手机号' maxlength='11' />
<input placeholder='请输入收货人手机号' @input='bindMobile' :maxlength='11' />
</view>
<view class='divider' />
<view class='c-flex-row detail-row'>
<text>详细地址</text>
<view class='c-flex-column'>
<textarea placeholder='详细地址:如街道、门牌\n号、楼栋号、单元室等' />
<textarea placeholder='详细地址:如街道、门牌\n号、楼栋号、单元室等'
@input='bindAddress' />
<view class='tips-view c-flex-row'>
<image :src='assetsUrl("ic_tips.png")' />
<text>记得完善门牌号</text>
@@ -27,7 +28,8 @@
<view class='c-flex-column'>
<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 class='bottom-button-view'>
@@ -41,16 +43,40 @@
import { assetsUrl } from '@/utils/assets';
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 = () => {
addressCreate(
{
bean: {
'name': '高昂',
'mobile': '15475655487',
'zonecode': '420101001001',
'addr': '肯德基挂',
'defaultstatus': 1
}
bean: params.value
}
).then(() => {
uni.showToast({

View File

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

View File

@@ -3,22 +3,22 @@
<view class='top-card-view'>
<image class='bg-image' :src='assetsUrl("test_bg.png")' />
<image class='avatar-image' :src='userInfo.image' />
<text>{{ userInfo.nickName }}</text>
<text>会员卡</text>
<text>{{ userInfo.name }}</text>
<text>{{ userInfo.levelName }}</text>
</view>
<view class='basic-info-view c-flex-column'>
<view class='c-flex-row'>
<text>头像</text>
<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' />
</view>
</view>
<view class='c-flex-row'>
<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 class='divider' />
@@ -32,12 +32,12 @@
<text>性别</text>
<view class='c-flex-row' @click.stop='changeGender(0)'>
<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>
</view>
<view class='c-flex-row' @click.stop='changeGender(1)'>
<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>
</view>
</view>
@@ -46,7 +46,7 @@
<view class='c-flex-row'>
<text>生日</text>
<picker mode='date' @change='changeDate'>
<text>{{ userInfo.birthday || '请选择生日' }}</text>
<text>{{ params?.birthday || '请选择生日' }}</text>
</picker>
</view>
</view>
@@ -63,7 +63,21 @@ import { showToast } from '@/utils';
const store = useUserStore();
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(() => {
store.getProfile();
@@ -79,7 +93,8 @@ const chooseAvatar = (e: any) => {
'Content-Type': 'multipart/form-data'
},
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) => {
showToast('上传失败');
@@ -91,40 +106,30 @@ const chooseAvatar = (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) => {
userInfo.value.telephone = e.detail.value;
params.value!.telephone = e.detail.value;
};
const changeGender = (index: number) => {
currentGender.value = index;
userInfo.value.gender = index;
params.value!.gender = index;
};
const changeDate = (e: any) => {
userInfo.value.birthday = e.detail.value;
params.value!.birthday = e.detail.value;
};
const save = async () => {
// const registerForm = {
// unionId: userInfo.value.unionId,
// openId: userInfo.value.openId,
// maOpenId: userInfo.value.maOpenId,
// image: userInfo.value.image,
// nickName: userInfo.value.nickName,
// telephone: userInfo.value.telephone,
// 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)
console.log('---------->>>>', params.value);
const newUserInfo = {
...userInfo.value,
...params.value
};
console.log('---------->>>>', newUserInfo);
store.setUserInfo(newUserInfo);
};
</script>

View File

@@ -1,4 +1,5 @@
import { defineStore } from 'pinia';
import { StockBean } from '@/api/goods/types';
const useShoppingCartStore = defineStore('shoppingCart', {
state: (): { shoppingCartList: any[] } => ({
@@ -27,14 +28,35 @@ const useShoppingCartStore = defineStore('shoppingCart', {
getTotalCount(): number {
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: {
save(partial: Partial<any>) {
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 = [];
}
}

View File

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

View File

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

View File

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