!129 【缺陷修复】购物车提交前校验

Merge pull request !129 from puhui999/dev
pull/131/MERGE
芋道源码 2024-12-11 05:01:19 +00:00 committed by Gitee
commit 39869cd92d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
16 changed files with 224 additions and 191 deletions

View File

@ -1,6 +1,6 @@
<!-- 拼团活动列表 --> <!-- 拼团活动列表 -->
<template> <template>
<s-layout navbar="inner" :bgStyle="{ color: '#FE832A' }"> <s-layout :bgStyle="{ backgroundColor: '#FE832A' }" navbar="inner">
<view class="page-bg" :style="[{ marginTop: '-' + Number(statusBarHeight + 88) + 'rpx' }]" /> <view class="page-bg" :style="[{ marginTop: '-' + Number(statusBarHeight + 88) + 'rpx' }]" />
<view class="list-content"> <view class="list-content">
<!-- 参团会员统计 --> <!-- 参团会员统计 -->

View File

@ -1,6 +1,6 @@
<!-- 秒杀活动列表 --> <!-- 秒杀活动列表 -->
<template> <template>
<s-layout navbar="inner" :bgStyle="{ color: 'rgb(245,28,19)' }"> <s-layout :bgStyle="{ backgroundColor: 'rgb(245,28,19)' }" navbar="inner">
<!--顶部背景图--> <!--顶部背景图-->
<view <view
class="page-bg" class="page-bg"
@ -146,7 +146,7 @@
</s-layout> </s-layout>
</template> </template>
<script setup> <script setup>
import { reactive, computed, ref, nextTick } from 'vue'; import { computed, nextTick, reactive, ref } from 'vue';
import { onLoad, onReachBottom } from '@dcloudio/uni-app'; import { onLoad, onReachBottom } from '@dcloudio/uni-app';
import sheep from '@/sheep'; import sheep from '@/sheep';
import { useDurationTime } from '@/sheep/hooks/useGoods'; import { useDurationTime } from '@/sheep/hooks/useGoods';

View File

@ -1,6 +1,6 @@
<!-- 优惠券中心 --> <!-- 优惠券中心 -->
<template> <template>
<s-layout title="优惠券" :bgStyle="{ color: '#f2f2f2' }"> <s-layout :bgStyle="{ backgroundColor: '#f2f2f2' }" title="优惠券">
<su-sticky bgColor="#fff"> <su-sticky bgColor="#fff">
<su-tabs <su-tabs
:list="tabMaps" :list="tabMaps"

View File

@ -1,192 +1,220 @@
<template> <template>
<s-layout title="购物车" tabbar="/pages/index/cart" :bgStyle="{ color: '#fff' }"> <s-layout :bgStyle="{ backgroundColor: '#fff' }" tabbar="/pages/index/cart" title="购物车">
<s-empty v-if="state.list.length === 0" text="购物车空空如也,快去逛逛吧~" icon="/static/cart-empty.png" /> <s-empty v-if="state.list.length === 0" icon="/static/cart-empty.png" text="购物车空空如也,快去逛逛吧~" />
<!-- 头部 --> <!-- 头部 -->
<view class="cart-box ss-flex ss-flex-col ss-row-between" v-if="state.list.length"> <view v-if="state.list.length" class="cart-box ss-flex ss-flex-col ss-row-between">
<view class="cart-header ss-flex ss-col-center ss-row-between ss-p-x-30"> <view class="cart-header ss-flex ss-col-center ss-row-between ss-p-x-30">
<view class="header-left ss-flex ss-col-center ss-font-26"> <view class="header-left ss-flex ss-col-center ss-font-26">
<text class="goods-number ui-TC-Main ss-flex">{{ state.list.length }}</text> <text class="goods-number ui-TC-Main ss-flex">{{ state.list.length }}</text>
件商品 件商品
</view> </view>
<view class="header-right"> <view class="header-right">
<button v-if="state.editMode" class="ss-reset-button" @tap="state.editMode = false"> <button v-if="state.editMode" class="ss-reset-button" @tap="state.editMode = false">
取消 取消
</button> </button>
<button v-else class="ss-reset-button ui-TC-Main" @tap="state.editMode = true"> <button v-else class="ss-reset-button ui-TC-Main" @tap="state.editMode = true">
编辑 编辑
</button> </button>
</view> </view>
</view> </view>
<!-- 内容 --> <!-- 内容 -->
<view class="cart-content ss-flex-1 ss-p-x-30 ss-m-b-40"> <view class="cart-content ss-flex-1 ss-p-x-30 ss-m-b-40">
<view class="goods-box ss-r-10 ss-m-b-14" v-for="item in state.list" :key="item.id"> <view v-for="item in state.list" :key="item.id" class="goods-box ss-r-10 ss-m-b-14">
<view class="ss-flex ss-col-center"> <view class="ss-flex ss-col-center">
<label class="check-box ss-flex ss-col-center ss-p-l-10" @tap="onSelectSingle(item.id)"> <label class="check-box ss-flex ss-col-center ss-p-l-10" @tap="onSelectSingle(item.id)">
<radio :checked="state.selectedIds.includes(item.id)" color="var(--ui-BG-Main)" <radio :checked="state.selectedIds.includes(item.id)" color="var(--ui-BG-Main)"
style="transform: scale(0.8)" @tap.stop="onSelectSingle(item.id)" /> style="transform: scale(0.8)" @tap.stop="onSelectSingle(item.id)" />
</label> </label>
<s-goods-item :title="item.spu.name" :img="item.spu.picUrl || item.goods.image" <s-goods-item :img="item.spu.picUrl || item.goods.image" :price="item.sku.price"
:price="item.sku.price" :skuText="item.sku.properties.length>1? item.sku.properties.reduce((items2,items)=>items2.valueName+' '+items.valueName):item.sku.properties[0].valueName"
:skuText="item.sku.properties.length>1? item.sku.properties.reduce((items2,items)=>items2.valueName+' '+items.valueName):item.sku.properties[0].valueName" :title="item.spu.name"
priceColor="#FF3000" :titleWidth="400"> :titleWidth="400" priceColor="#FF3000">
<template v-if="!state.editMode" v-slot:tool> <template v-if="!state.editMode" v-slot:tool>
<su-number-box :min="0" :max="item.sku.stock" :step="1" v-model="item.count" @change="onNumberChange($event, item)" /> <su-number-box v-model="item.count" :max="item.sku.stock" :min="0" :step="1"
</template> @change="onNumberChange($event, item)" />
</s-goods-item> </template>
</view> </s-goods-item>
</view> </view>
</view> </view>
<!-- 底部 --> </view>
<su-fixed bottom :val="48" placeholder v-if="state.list.length > 0" :isInset="false"> <!-- 底部 -->
<view class="cart-footer ss-flex ss-col-center ss-row-between ss-p-x-30 border-bottom"> <su-fixed v-if="state.list.length > 0" :isInset="false" :val="48" bottom placeholder>
<view class="footer-left ss-flex ss-col-center"> <view class="cart-footer ss-flex ss-col-center ss-row-between ss-p-x-30 border-bottom">
<label class="check-box ss-flex ss-col-center ss-p-r-30" @tap="onSelectAll"> <view class="footer-left ss-flex ss-col-center">
<radio :checked="state.isAllSelected" color="var(--ui-BG-Main)" <label class="check-box ss-flex ss-col-center ss-p-r-30" @tap="onSelectAll">
style="transform: scale(0.8)" @tap.stop="onSelectAll" /> <radio :checked="state.isAllSelected" color="var(--ui-BG-Main)"
<view class="ss-m-l-8"> 全选 </view> style="transform: scale(0.8)" @tap.stop="onSelectAll" />
</label> <view class="ss-m-l-8"> 全选</view>
<text>合计</text> </label>
<view class="text-price price-text"> <text>合计</text>
{{ fen2yuan(state.totalPriceSelected) }} <view class="text-price price-text">
</view> {{ fen2yuan(state.totalPriceSelected) }}
</view> </view>
<view class="footer-right"> </view>
<button v-if="state.editMode" class="ss-reset-button ui-BG-Main-Gradient pay-btn ui-Shadow-Main" <view class="footer-right">
@tap="onDelete"> <button v-if="state.editMode" class="ss-reset-button ui-BG-Main-Gradient pay-btn ui-Shadow-Main"
删除 @tap="onDelete">
</button> 删除
<button v-else class="ss-reset-button ui-BG-Main-Gradient pay-btn ui-Shadow-Main" </button>
@tap="onConfirm"> <button v-else class="ss-reset-button ui-BG-Main-Gradient pay-btn ui-Shadow-Main"
去结算 @tap="onConfirm">
{{ state.selectedIds?.length ? `(${state.selectedIds.length})` : '' }} 去结算
</button> {{ state.selectedIds?.length ? `(${state.selectedIds.length})` : '' }}
</view> </button>
</view> </view>
</su-fixed> </view>
</view> </su-fixed>
</s-layout> </view>
</s-layout>
</template> </template>
<script setup> <script setup>
import sheep from '@/sheep'; import sheep from '@/sheep';
import { computed, reactive } from 'vue'; import SpuApi from '@/sheep/api/product/spu';
import { fen2yuan } from '../../sheep/hooks/useGoods'; import { computed, reactive } from 'vue';
import { fen2yuan } from '@/sheep/hooks/useGoods';
import { isEmpty } from '@/sheep/helper/utils';
import { DeliveryTypeEnum } from '@/sheep/util/const';
const sys_navBar = sheep.$platform.navbar; const sys_navBar = sheep.$platform.navbar;
const cart = sheep.$store('cart'); const cart = sheep.$store('cart');
const state = reactive({ const state = reactive({
editMode: false, editMode: false,
list: computed(() => cart.list), list: computed(() => cart.list),
selectedList: [], selectedList: [],
selectedIds: computed(() => cart.selectedIds), selectedIds: computed(() => cart.selectedIds),
isAllSelected: computed(() => cart.isAllSelected), isAllSelected: computed(() => cart.isAllSelected),
totalPriceSelected: computed(() => cart.totalPriceSelected), totalPriceSelected: computed(() => cart.totalPriceSelected),
}); });
// //
function onSelectSingle(id) { function onSelectSingle(id) {
cart.selectSingle(id); cart.selectSingle(id);
} }
// //
function onSelectAll() { function onSelectAll() {
cart.selectAll(!state.isAllSelected); cart.selectAll(!state.isAllSelected);
} }
// //
function onConfirm() { async function onConfirm() {
let items = [] const items = [];
let goods_list = []; state.selectedList = state.list.filter((item) => state.selectedIds.includes(item.id));
state.selectedList = state.list.filter((item) => state.selectedIds.includes(item.id)); state.selectedList.map((item) => {
state.selectedList.map((item) => { //
// items.push({
items.push({ skuId: item.sku.id,
skuId: item.sku.id, count: item.count,
count: item.count, cartId: item.id,
cartId: item.id, categoryId: item.spu.categoryId,
categoryId: item.spu.categoryId });
}) });
goods_list.push({ if (isEmpty(items)) {
// goods_id: item.goods_id, sheep.$helper.toast('请先选择商品');
goods_id: item.spu.id, return;
// goods_num: item.goods_num, }
goods_num: item.count, await validateDeliveryType(state.selectedList.map((item) => item.spu).map((spu) => spu.id));
// id sheep.$router.go('/pages/order/confirm', {
// goods_sku_price_id: item.goods_sku_price_id, data: JSON.stringify({
}); items,
}); }),
// return; });
if (goods_list.length === 0) { }
sheep.$helper.toast('请选择商品');
return;
}
sheep.$router.go('/pages/order/confirm', {
data: JSON.stringify({
items
}),
});
}
function onNumberChange(e, cartItem) { /** 校验配送方式 */
if (e === 0) { function validateDeliveryType(spuIds) {
cart.delete(cartItem.id); return new Promise(async (resolve, reject) => {
return; const { data } = await SpuApi.getSpuListByIds(spuIds.join(','));
} if (isEmpty(data)) {
if (cartItem.goods_num === e) return; reject('获取商品信息失败!!!');
cartItem.goods_num = e; return;
cart.update({ }
goods_id: cartItem.id, let onlyExpress = false; //
goods_num: e, let onlyPickup = false; //
goods_sku_price_id: cartItem.goods_sku_price_id, const deliveryTypes = data.map((item) => item.deliveryTypes);
}); for (const deliveryType of deliveryTypes) {
} //
async function onDelete() { if (deliveryType.length > 1) {
cart.delete(state.selectedIds); continue;
} }
//
if (deliveryType[0] === DeliveryTypeEnum.EXPRESS.type) {
onlyExpress = true;
} else if (deliveryType[0] === DeliveryTypeEnum.PICK_UP.type) {
onlyPickup = true;
}
}
if (onlyExpress || onlyPickup) {
reject('选中商品存在只支持特定配送方式的情况不允许提交!!!');
sheep.$helper.toast('选中商品存在只支持特定配送方式的情况不允许提交!!!');
return;
}
resolve();
});
}
function onNumberChange(e, cartItem) {
if (e === 0) {
cart.delete(cartItem.id);
return;
}
if (cartItem.goods_num === e) return;
cartItem.goods_num = e;
cart.update({
goods_id: cartItem.id,
goods_num: e,
goods_sku_price_id: cartItem.goods_sku_price_id,
});
}
async function onDelete() {
cart.delete(state.selectedIds);
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
:deep(.ui-fixed) { :deep(.ui-fixed) {
height: 72rpx; height: 72rpx;
} }
.cart-box { .cart-box {
width: 100%; width: 100%;
.cart-header { .cart-header {
height: 70rpx; height: 70rpx;
background-color: #f6f6f6; background-color: #f6f6f6;
width: 100%; width: 100%;
position: fixed; position: fixed;
left: 0; left: 0;
top: v-bind('sys_navBar') rpx; top: v-bind('sys_navBar') rpx;
z-index: 1000; z-index: 1000;
box-sizing: border-box; box-sizing: border-box;
} }
.cart-footer { .cart-footer {
height: 100rpx; height: 100rpx;
background-color: #fff; background-color: #fff;
.pay-btn { .pay-btn {
width: 180rpx; width: 180rpx;
height: 70rpx; height: 70rpx;
font-size: 28rpx; font-size: 28rpx;
line-height: 28rpx; line-height: 28rpx;
font-weight: 500; font-weight: 500;
border-radius: 40rpx; border-radius: 40rpx;
} }
} }
.cart-content { .cart-content {
margin-top: 70rpx; margin-top: 70rpx;
.goods-box { .goods-box {
background-color: #fff; background-color: #fff;
} }
} }
} }
</style> </style>

View File

@ -1,6 +1,6 @@
<!-- 商品分类列表 --> <!-- 商品分类列表 -->
<template> <template>
<s-layout title="分类" tabbar="/pages/index/category" :bgStyle="{ color: '#fff' }"> <s-layout :bgStyle="{ backgroundColor: '#fff' }" tabbar="/pages/index/category" title="分类">
<view class="s-category"> <view class="s-category">
<view class="three-level-wrap ss-flex ss-col-top" :style="[{ height: pageHeight + 'px' }]"> <view class="three-level-wrap ss-flex ss-col-top" :style="[{ height: pageHeight + 'px' }]">
<!-- 商品分类 --> <!-- 商品分类 -->

View File

@ -1,6 +1,6 @@
<!-- 搜索界面 --> <!-- 搜索界面 -->
<template> <template>
<s-layout class="set-wrap" title="搜索" :bgStyle="{ color: '#FFF' }"> <s-layout :bgStyle="{ backgroundColor: '#FFF' }" class="set-wrap" title="搜索">
<view class="ss-p-x-24"> <view class="ss-p-x-24">
<view class="ss-flex ss-col-center"> <view class="ss-flex ss-col-center">
<uni-search-bar <uni-search-bar

View File

@ -228,6 +228,7 @@
import OrderApi from '@/sheep/api/trade/order'; import OrderApi from '@/sheep/api/trade/order';
import TradeConfigApi from '@/sheep/api/trade/config'; import TradeConfigApi from '@/sheep/api/trade/config';
import { fen2yuan } from '@/sheep/hooks/useGoods'; import { fen2yuan } from '@/sheep/hooks/useGoods';
import { DeliveryTypeEnum } from '@/sheep/util/const';
const state = reactive({ const state = reactive({
orderPayload: {}, orderPayload: {},
@ -376,14 +377,14 @@
// //
// //
addressState.value.deliveryType = 1; addressState.value.deliveryType = DeliveryTypeEnum.EXPRESS.type;
let orderCode = await getOrderInfo(); let orderCode = await getOrderInfo();
if (orderCode === 0) { if (orderCode === 0) {
return; return;
} }
// //
if (addressState.value.isPickUp) { if (addressState.value.isPickUp) {
addressState.value.deliveryType = 2; addressState.value.deliveryType = DeliveryTypeEnum.PICK_UP.type;
let orderCode = await getOrderInfo(); let orderCode = await getOrderInfo();
if (orderCode === 0) { if (orderCode === 0) {
return; return;

View File

@ -1,6 +1,6 @@
<!-- 支付结果页面 --> <!-- 支付结果页面 -->
<template> <template>
<s-layout title="支付结果" :bgStyle="{ color: '#FFF' }"> <s-layout :bgStyle="{ backgroundColor: '#FFF' }" title="支付结果">
<view class="pay-result-box ss-flex-col ss-row-center ss-col-center"> <view class="pay-result-box ss-flex-col ss-row-center ss-col-center">
<!-- 信息展示 --> <!-- 信息展示 -->
<view class="pay-waiting ss-m-b-30" v-if="payResult === 'waiting'" /> <view class="pay-waiting ss-m-b-30" v-if="payResult === 'waiting'" />
@ -63,8 +63,8 @@
</template> </template>
<script setup> <script setup>
import { onLoad, onHide, onShow } from '@dcloudio/uni-app'; import { onHide, onLoad, onShow } from '@dcloudio/uni-app';
import { reactive, computed, ref } from 'vue'; import { computed, reactive, ref } from 'vue';
import { isEmpty } from 'lodash-es'; import { isEmpty } from 'lodash-es';
import sheep from '@/sheep'; import sheep from '@/sheep';
import PayOrderApi from '@/sheep/api/pay/order'; import PayOrderApi from '@/sheep/api/pay/order';

View File

@ -1,6 +1,6 @@
<!-- FAQ 常见问题 --> <!-- FAQ 常见问题 -->
<template> <template>
<s-layout class="set-wrap" title="常见问题" :bgStyle="{ color: '#FFF' }"> <s-layout :bgStyle="{ backgroundColor: '#FFF' }" class="set-wrap" title="常见问题">
<uni-collapse> <uni-collapse>
<uni-collapse-item v-for="(item, index) in state.list" :key="item"> <uni-collapse-item v-for="(item, index) in state.list" :key="item">
<template v-slot:title> <template v-slot:title>

View File

@ -1,6 +1,6 @@
<!-- 文章展示 --> <!-- 文章展示 -->
<template> <template>
<s-layout class="set-wrap" :title="state.title" :bgStyle="{ color: '#FFF' }"> <s-layout :bgStyle="{ backgroundColor: '#FFF' }" :title="state.title" class="set-wrap">
<view class="ss-p-30"> <view class="ss-p-30">
<mp-html class="richtext" :content="state.content" /> <mp-html class="richtext" :content="state.content" />
</view> </view>

View File

@ -1,5 +1,5 @@
<template> <template>
<s-layout class="set-wrap" title="系统设置" :bgStyle="{ color: '#fff' }"> <s-layout :bgStyle="{ backgroundColor: '#fff' }" class="set-wrap" title="系统设置">
<view class="header-box ss-flex-col ss-row-center ss-col-center"> <view class="header-box ss-flex-col ss-row-center ss-col-center">
<image <image
class="logo-img ss-m-b-46" class="logo-img ss-m-b-46"

View File

@ -1,6 +1,6 @@
<!-- 收件地址列表 --> <!-- 收件地址列表 -->
<template> <template>
<s-layout title="收货地址" :bgStyle="{ color: '#FFF' }"> <s-layout :bgStyle="{ backgroundColor: '#FFF' }" title="收货地址">
<view v-if="state.list.length"> <view v-if="state.list.length">
<s-address-item <s-address-item
hasBorderBottom hasBorderBottom
@ -40,7 +40,7 @@
<script setup> <script setup>
import { onBeforeMount, reactive } from 'vue'; import { onBeforeMount, reactive } from 'vue';
import { onShow, onLoad } from '@dcloudio/uni-app'; import { onLoad, onShow } from '@dcloudio/uni-app';
import sheep from '@/sheep'; import sheep from '@/sheep';
import { isEmpty } from 'lodash-es'; import { isEmpty } from 'lodash-es';
import AreaApi from '@/sheep/api/system/area'; import AreaApi from '@/sheep/api/system/area';

View File

@ -1,6 +1,6 @@
<!-- 商品浏览记录 --> <!-- 商品浏览记录 -->
<template> <template>
<s-layout title="我的足迹" :bgStyle="{ color: '#f2f2f2' }"> <s-layout :bgStyle="{ backgroundColor: '#f2f2f2' }" title="我的足迹">
<view class="cart-box ss-flex ss-flex-col ss-row-between"> <view class="cart-box ss-flex ss-flex-col ss-row-between">
<!-- 头部 --> <!-- 头部 -->
<view class="cart-header ss-flex ss-col-center ss-row-between ss-p-x-30"> <view class="cart-header ss-flex ss-col-center ss-row-between ss-p-x-30">

View File

@ -1,5 +1,5 @@
<template> <template>
<s-layout title="选择自提门店" :bgStyle="{ color: '#FFF' }"> <s-layout :bgStyle="{ backgroundColor: '#FFF' }" title="选择自提门店">
<view class="storeBox" ref="container"> <view class="storeBox" ref="container">
<view <view
class="storeBox-box" class="storeBox-box"

View File

@ -107,7 +107,7 @@
type: Object, type: Object,
default: () => ({ default: () => ({
src: '', src: '',
color: 'var(--ui-BG-1)', backgroundColor: 'var(--ui-BG-1)',
}), }),
}, },
tabbar: { tabbar: {

View File

@ -119,7 +119,11 @@ export const PromotionActivityTypeEnum = {
name: '积分商城', name: '积分商城',
}, },
}; };
/** 配送方式枚举 */
export const DeliveryTypeEnum = {
EXPRESS: { type: 1, name: '快递发货' },
PICK_UP: { type: 2, name: '用户自提' },
};
export const getTimeStatusEnum = (startTime, endTime) => { export const getTimeStatusEnum = (startTime, endTime) => {
const now = dayjs(); const now = dayjs();
if (now.isBefore(startTime)) { if (now.isBefore(startTime)) {