功能完善

This commit is contained in:
2024-04-13 17:20:09 +08:00
parent be328f9243
commit 23af4c25e3
15 changed files with 253 additions and 90 deletions

View File

@@ -4,6 +4,7 @@ export interface OrderBean {
allowIntegral: boolean;
bizId: string;
classify: number;
address: any,
companyId: string;
consignTime: string;
consumerId: string;
@@ -71,4 +72,7 @@ export interface OrderBean {
updated: boolean;
useGold: number;
wholePrice: number;
//extra field
countdown: number;
}

View File

@@ -12,7 +12,8 @@
<view class='sku-view c-flex-column'>
<view class='sku-title'>颜色</view>
<view class='sku-color-list c-flex-row'>
<view class='sku-item' :class='{"sku-item-active":currentColorIndex==index}'
<view class='sku-item'
:class='{"sku-item-active":currentColorIndex==index}'
v-for='(item, index) in skuColorList' :key='index'
@click='colorChange(index)'>
<text>{{ item }}</text>
@@ -22,11 +23,13 @@
<view class='sku-title' style='margin-top: 43rpx'>尺码</view>
<view class='sku-color-list c-flex-row'>
<view class='sku-item'
:class='{"sku-item-active":currentSizeIndex==index,"sku-item-disabled":item.existingNumber<=-1}'
v-if='(skuSizeList?.length||0)>0'
:class='{"sku-item-active":currentSizeIndex==index,"sku-item-disabled":item.existingNumber<=0}'
v-for='(item, index) in skuSizeList' :key='index'
@click='sizeChange(index)'>
<text>{{ item.sizeName }}</text>
</view>
<text v-else style='color: #999999;font-size: 30rpx'>暂无库存</text>
</view>
<view class='c-flex-row' style='margin-top: 52rpx'>
@@ -41,7 +44,9 @@
</view>
</view>
</view>
<button class='primary-button' @click='confirm'>确定</button>
<button class='primary-button' :plain='currentSizeIndex<=0' :disabled='currentSizeIndex<=0' @click='confirm'>
确定
</button>
</view>
</view>
</uni-popup>
@@ -65,7 +70,7 @@ const popupRef = ref();
const goodsDetailBean = ref<GoodsBean>();
const skuColorList = ref<string[]>([]);
const currentColorIndex = ref(0);
const currentSizeIndex = ref(0);
const currentSizeIndex = ref(-1);
const goodsCount = ref(1);
let callback: Function;
@@ -96,25 +101,31 @@ const show = async (goodsId: string, fn: Function) => {
sizeChange(sizeIndex || 0);
goodsCount.value = props.exists?.count;
}
if(skuSizeList) {
// skuSizeList.value![2].existingNumber = 2;
}
};
const skuSizeList = computed(() => {
const currentColorName = skuColorList.value[currentColorIndex.value];
return goodsDetailBean.value?.stocks?.filter((res: { colorName: string }) => {
let sizeList = goodsDetailBean.value?.stocks?.filter((res: { colorName: string }) => {
return res.colorName === currentColorName;
});
currentSizeIndex.value = sizeList?.findIndex(res => res.existingNumber > 0) || 0;
return sizeList;
});
const close = () => {
popupRef.value.close();
};
const colorChange = (index: number) => {
currentColorIndex.value = index;
};
const sizeChange = (index: number) => {
currentSizeIndex.value = index;
if((skuSizeList.value![index].existingNumber || 0) <= 0) {
showToast('库存不足');
} else {
currentSizeIndex.value = index;
}
};
const countChange = (isPlus: boolean) => {
@@ -140,6 +151,10 @@ const confirm = () => {
popupRef.value.close();
};
const close = () => {
popupRef.value.close();
};
defineExpose({
show
});
@@ -262,6 +277,7 @@ defineExpose({
.primary-button {
width: 100%;
margin-top: 50rpx;
border: none;
}
}
}

View File

@@ -14,12 +14,17 @@
</template>
<script lang='ts' setup>
defineProps({
const props = defineProps({
titles: {
type: Object as PropType<string[]>,
default: ''
},
index: {
type: Number,
default: 0
},
fixed: {
type: Boolean,
default: true
@@ -42,6 +47,10 @@ defineProps({
const emits = defineEmits(['change']);
const currentIndex = ref<number>(0);
watch(() => props.index, (newVal) => {
currentIndex.value = newVal;
});
const onChange = (index: number) => {
currentIndex.value = index;
emits('change', index);

View File

@@ -26,7 +26,7 @@
</view>
<view class='bottom-view c-flex-row'>
<sqb-pay @bindnavigateTo='navigateTo'
<sqb-pay @navigateTo='navigateTo'
:return_url='buildSqbParams.return_url'
:total_amount='buildSqbParams.total_amount'
:terminal_sn='buildSqbParams.terminal_sn'
@@ -49,6 +49,7 @@ import { OrderBean } from '@/api/order/types';
import { parseParameter, sortASCII } from '@/utils';
import { hexMD5 } from '@/utils/common/md5';
import { useUserStore } from '@/store';
import { handlePayResult } from '@/utils/order';
const userState = useUserStore();
const { terminalInfo } = storeToRefs(userState);
@@ -78,11 +79,12 @@ const buildSqbParams = computed(() => {
});
const navigateTo = (e: any) => {
uni.redirectTo({
url: e.detail.url,
fail(e) {
uni.showToast({
title: '支付失败'
console.log('----------->>>>>navigateTo ', e);
handlePayResult(orderBean.value?.id, e, {
onSuccess: () => {
pay({
'orderId': orderBean.value?.id,
'result': 'xxx'
});
}
});
@@ -95,14 +97,8 @@ const payment = () => {
'terminal_key': terminalInfo.value.terminalKey,
'terminal_sn': terminalInfo.value.terminalSn
};
progress(params);
pay({
'orderId': orderBean.value?.id,
'result': '{payResult:xxx}'
});
};
</script>
<style lang='scss' scoped>

View File

@@ -140,7 +140,7 @@ const swiperChange = (e: any) => {
image {
width: 100%;
height: 100%;
height: 520rpx;
}
}
@@ -154,8 +154,11 @@ const swiperChange = (e: any) => {
.indicator-view {
display: flex;
flex-direction: row;
position: relative;
position: absolute;
justify-content: center;
left: 0;
right: 0;
top: -20rpx;
.normal {
width: 16rpx;
@@ -235,7 +238,7 @@ const swiperChange = (e: any) => {
}
.divider {
margin: 0 40rpx;
margin: 0 30rpx;
width: 0.5rpx;
height: 100%;
background: #C7C7C7;

View File

@@ -16,7 +16,7 @@
</view>
</scroll-view>
<scroll-view class='goods-list' :scroll-y='true' type='custom'>
<scroll-view class='goods-list' :scroll-y='true' type='custom' @scrolltolower='loadMore'>
<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}`)'>
@@ -43,7 +43,7 @@
<script setup lang='ts'>
import SkuDialog from '@/components/sku-dialog.vue';
import { assetsUrl } from '@/utils/assets';
import { goLogin, goPath, isLogin } from '@/utils';
import { goLogin, goPath, isLogin, showToast } from '@/utils';
import { getCategoryList, getGoodsList } from '@/api/goods';
import { CategoryBean, GoodsBean } from '@/api/goods/types';
import useShoppingCartStore from '@/store/modules/shoppingcart';
@@ -58,6 +58,7 @@ const skuDialogRef = ref();
const categoryList = ref<CategoryBean[]>([]);
const categorySelectedIndex = ref<number>(0);
const goodsList = ref<GoodsBean[]>([]);
const currentPageNum = ref<number>(1);
onLoad(() => {
if(!isLogin()) {
@@ -87,18 +88,27 @@ const changeCategory = async (index: number) => {
await fetchGoodsList();
};
const fetchGoodsList = async () => {
const fetchGoodsList = async (refresh: boolean = true) => {
currentPageNum.value = refresh ? 1 : currentPageNum.value + 1;
const { rows } = await getGoodsList({
page: {
pageNum: 1,
pageSize: 100,
pageNum: currentPageNum.value,
pageSize: 30,
bean: {
keyword: '',
typeIds: [categoryList.value[categorySelectedIndex.value].typeId]
}
}
});
goodsList.value = rows;
if(refresh) {
goodsList.value = rows;
} else {
goodsList.value = goodsList.value.concat(rows);
}
};
const loadMore = () => {
fetchGoodsList(false);
};
const randomImageHeight = () => {
@@ -114,6 +124,7 @@ const getRandomFloatInRange = (a: number, b: number) => {
const addShoppingCart = (goodsBean: GoodsBean) => {
skuDialogRef.value.show(goodsBean.goodsId, (e: GoodsBean) => {
shoppingCartStore.save(e);
showToast('添加购物车成功');
});
};
</script>

View File

@@ -94,14 +94,14 @@
<view class='payment-way c-flex-row' @click.stop='changePayment'>
<text>支付方式</text>
<view>{{ paymentType === 0 ? '微信支付' : '余额' }}
<image :src='assetsUrl("ic_arrow_right_gray.png")' />
<image style='display: none' :src='assetsUrl("ic_arrow_right_gray.png")' />
</view>
</view>
<view class='bottom-view c-flex-row'>
<text>合计</text>
<text>{{ orderBean?.totalPrice || 0 }}</text>
<sqb-pay @bindnavigateTo='navigateTo'
<sqb-pay @navigateTo='navigateTo'
:return_url='buildSqbParams.return_url'
:total_amount='buildSqbParams.total_amount'
:terminal_sn='buildSqbParams.terminal_sn'
@@ -130,6 +130,7 @@ import { getPaymentList, orderCreate, overPayment } from '@/api/order';
import { CouponBean } from '@/api/user/types';
import { OrderBean } from '@/api/order/types';
import { useUserStore } from '@/store';
import { handlePayResult } from '@/utils/order';
const userStore = useUserStore();
const { terminalInfo, deliveryAddress } = storeToRefs(userStore);
@@ -176,15 +177,14 @@ const showCouponDialog = () => {
const confirmCoupon = (item: CouponBean) => {
checkedCoupon.value = item;
};
const navigateTo = (e: any) => {
console.log('----------->>>>>navigateTo ', e);
uni.redirectTo({
url: e.detail.url,
fail(e) {
uni.showToast({
title: '支付失败'
});
console.log('--------------_>>>>>>navigateTo ', e);
handlePayResult(orderBean.value?.id, e, {
onSuccess: () => {
// pay({
// 'orderId': orderBean.value?.order.id,
// 'result': 'xxx'
// });
}
});
};
@@ -237,7 +237,6 @@ const payment = async () => {
}]
};
await overPayment(paymentParams);
uni.navigateBack();
uni.hideLoading();
};

View File

@@ -73,17 +73,17 @@ import { useUserStore } from '@/store';
const officialAccountDialogRef = ref();
const orderActionList = ref([{
title: '进行中',
title: '未支付',
icon: assetsUrl('ic_order_progressing.png'),
path: '/pages/mine/subs/order/index'
}, {
title: '已结束',
icon: assetsUrl('ic_order_finish.png'),
path: '/pages/mine/subs/order/index?index=1'
}, {
title: '已支付',
icon: assetsUrl('ic_order_finish.png'),
path: '/pages/mine/subs/order/index?index=2'
}, {
title: '全部订单',
icon: assetsUrl('ic_order_all.png'),
path: '/pages/mine/subs/order/index?index=2'
path: '/pages/mine/subs/order/index?index=0'
}]);
const serviceList = [

View File

@@ -6,7 +6,9 @@
<view class='c-flex-row'>
<text class='goods-name'>{{ item?.orderGoods[0].goodsName }}</text>
<text class='status'>
{{ item?.payStatus == 2 ? '已支付' : '未支付' }}
<text v-if='item?.payStatus == 2'>已支付</text>
<text v-else-if='isPending(item)'>待支付</text>
<text v-else style='color: #999999'>已过期</text>
</text>
</view>
<view class='bottom-view c-flex-row'>
@@ -21,17 +23,17 @@
</view>
</view>
<view class='action-view c-flex-row'>
<view class='countdown c-flex-row' v-if='item?.payStatus==1'>
<view class='countdown c-flex-row' v-if='isPending(item)'>
<image :src='assetsUrl("ic_time.png")' />
<text class='primary-text-color'>支付剩余时间
<text class='accent-text-color'>05:23</text>
<text class='accent-text-color'>{{ dayjs.unix(item?.countdown || 0).format('mm:ss') || '00:00' }}</text>
</text>
</view>
<view v-else style='flex: 1' />
<view class='c-flex-row'>
<text class='add-shoppingcart secondary-text-color' @click.stop='add(item?.orderGoods[0])'>加入购物车</text>
<text class='payment accent-text-color' v-if='item?.payStatus==1' @click.stop='pay(item?.id)'>立即支付
<text class='payment accent-text-color' v-if='isPending(item)' @click.stop='pay(item?.id)'>立即支付
</text>
</view>
</view>
@@ -42,8 +44,10 @@
import { PropType } from 'vue';
import { assetsUrl } from '@/utils/assets';
import { goPath } from '@/utils';
import { isPending } from '@/utils/order';
import { OrderBean } from '@/api/order/types';
import { GoodsBean } from '@/api/goods/types';
import dayjs from 'dayjs';
const emits = defineEmits(['addShoppingCart', 'payment']);
@@ -55,7 +59,7 @@ const add = (item: GoodsBean | undefined) => {
emits('addShoppingCart', item);
};
const pay = (orderId: string) => {
const pay = (orderId: string | undefined) => {
emits('payment', orderId);
};
</script>

View File

@@ -1,7 +1,7 @@
<template>
<scroll-view scroll-y>
<view class='content'>
<view class='countdown c-flex-row' v-if='orderBean?.order.payStatus==1'>
<view class='countdown c-flex-row' v-if='isPending(orderBean?.order)'>
<image :src='assetsUrl("ic_order.png")' />
<view class='c-flex-column'>
<text>
@@ -10,23 +10,23 @@
<view class='c-flex-row'>
<image :src='assetsUrl("ic_time.png")' />
<text>支付剩余时间
<text style='color: #F32B2B'>05:23</text>
<text style='color: #F32B2B'>{{ dayjs.unix(orderBean?.order?.countdown || 0).format('mm:ss') }}</text>
</text>
</view>
</view>
</view>
<view class='address-view c-flex-column'>
<view class='address-view c-flex-column' v-if='orderBean?.order?.address'>
<view class='user-info c-flex-row'>
<text>默认</text>
<text>黄先生</text>
<text>155****6532</text>
<text v-if='orderBean.order.address.defaultstatus==1'>默认</text>
<text>{{ orderBean?.order?.address.name }}</text>
<text>{{ orderBean?.order?.address.mobile }}</text>
<view style='flex: 1' />
<text style='color: #5B96FB'>复制</text>
</view>
<view class='addr c-flex-row'>
<image :src='assetsUrl("ic_location.png")' />
<text>湖南省 长沙市 详细地址详细地址详细地址</text>
<text>{{ orderBean?.order?.address.addr }}</text>
</view>
<image class='dashed-line' :src='assetsUrl("ic_address_dashed_line.png")' />
</view>
@@ -93,9 +93,9 @@
<text>下单时间{{ orderBean?.order?.createTime }}</text>
</view>
<view class='bottom-action-view c-flex-row' v-if='orderBean?.order.payStatus==1'>
<view class='bottom-action-view c-flex-row' v-if='isPending(orderBean?.order)'>
<text @click.stop='cancel' style='display: none'>取消订单</text>
<sqb-pay @bindnavigateTo='navigateTo'
<sqb-pay @navigateTo='navigateTo'
:return_url='buildSqbParams.return_url'
:total_amount='buildSqbParams.total_amount'
:terminal_sn='buildSqbParams.terminal_sn'
@@ -118,6 +118,9 @@ import { OrderBean } from '@/api/order/types';
import { parseParameter, sortASCII } from '@/utils';
import { hexMD5 } from '@/utils/common/md5';
import { useUserStore } from '@/store';
import { handlePayResult, isPending } from '@/utils/order';
import dayjs from 'dayjs';
import { pay } from '@/api/groupbuy';
const userState = useUserStore();
const { terminalInfo } = storeToRefs(userState);
@@ -128,12 +131,19 @@ const orderBean = ref<{
paymentList: []
}>();
let currentInterval = 0;
onLoad(async (e: any) => {
await uni.showLoading();
orderBean.value = await getOrderDetail(e.orderId);
handleCountdown();
uni.hideLoading();
});
onUnload(() => {
clearInterval(currentInterval);
});
const buildSqbParams = computed(() => {
const params = sortASCII({
client_sn: orderBean.value?.order?.id || '',
@@ -152,16 +162,32 @@ const buildSqbParams = computed(() => {
const navigateTo = (e: any) => {
console.log('--------------_>>>>>>navigateTo ', e);
uni.redirectTo({
url: e.detail.url,
fail(e) {
uni.showToast({
title: '支付失败'
});
handlePayResult(orderBean.value?.order.id, e, {
onSuccess: () => {
// pay({
// 'orderId': orderBean.value?.order.id,
// 'result': 'xxx'
// });
}
});
};
const handleCountdown = () => {
clearInterval(currentInterval);
let second = 30 * 60;
currentInterval = setInterval(() => {
if(isPending(orderBean.value?.order)) {
orderBean.value!.order!.countdown = second;
if(orderBean.value!.order!.countdown <= 0) {
orderBean.value!.order!.countdown = 0;
} else {
uni.navigateBack();
}
second--;
}
}, 1000);
};
const cancel = () => {
};
const payment = () => {

View File

@@ -1,5 +1,5 @@
<template>
<tabbar :titles="['全部', '进行中', '已结束']" @change='tabChange' />
<tabbar :titles="['全部', '未支付', '已支付']" :index='payStatus' @change='tabChange' />
<u-list :list='orderList' :border='false' @scrolltolower='loadMore'>
<u-list-item v-for='(item,index) in orderList' :key='index'>
<order-item :item='item' @addShoppingCart='addShoppingCart' @pay='payment' />
@@ -13,12 +13,13 @@
<script lang='ts' setup>
import { ref } from 'vue';
import { showToast } from '@/utils';
import { isPending } from '@/utils/order';
import { getOrderList } from '@/api/order';
import OrderItem from '@/pages/mine/subs/order/components/order-item.vue';
import { OrderBean } from '@/api/order/types';
import SkuDialog from '@/components/sku-dialog.vue';
import { GoodsBean, StockBean } from '@/api/goods/types';
import { showToast } from '@/utils';
import useShoppingCartStore from '@/store/modules/shoppingcart';
const shoppingCartStore = useShoppingCartStore();
@@ -28,8 +29,15 @@ const orderList = ref<OrderBean[]>([]);
const currentPageNum = ref(1);
const payStatus = ref(0);
onLoad((e) => {
fetchData();
let currentInterval = 0;
onLoad((e: any) => {
const index = Number(e.index) || 0;
tabChange(index);
});
onUnload(() => {
clearInterval(currentInterval);
});
const tabChange = (index: number) => {
@@ -51,8 +59,26 @@ const fetchData = async (refresh: boolean = true) => {
} else {
orderList.value = orderList.value.concat(list);
}
handleCountdown(orderList.value.filter(item => item.payStatus == 1));
};
const handleCountdown = (items: OrderBean[]) => {
clearInterval(currentInterval);
let second = 30 * 60;
currentInterval = setInterval(() => {
items.forEach(item => {
if(isPending(item)) {
item.countdown = second;
if(item.countdown <= 0) {
item.countdown = 0;
}
second--;
}
});
}, 1000);
};
const loadMore = () => {
fetchData(false);
};

View File

@@ -28,7 +28,7 @@
<view class='bottom-button-view'>
<!-- <payment-button style='flex: 1' :payParams='buildSignParams'>-->
<sqb-pay style='width: 100%;' @bindnavigateTo='navigateTo'
<sqb-pay style='width: 100%;' @navigateTo='navigateTo'
:return_url='buildSqbParams.return_url'
:total_amount='buildSqbParams.total_amount'
:terminal_sn='buildSqbParams.terminal_sn'
@@ -50,6 +50,7 @@ import { useUserStore } from '@/store';
import { getRechargeList, preRecharge, recharge, rechargeVerify } from '@/api/user';
import { parseParameter, sortASCII } from '@/utils';
import { hexMD5 } from '@/utils/common/md5';
import { handlePayResult } from '@/utils/order';
const userState = useUserStore();
const { userInfo, terminalInfo } = storeToRefs(userState);
@@ -96,12 +97,9 @@ const buildSqbParams = computed(() => {
const navigateTo = (e: any) => {
console.log('--------------_>>>>>>navigateTo ', e);
uni.redirectTo({
url: e.detail.url,
fail(e) {
uni.showToast({
title: '支付失败'
});
handlePayResult(preRechargeOrderId.value, e, {
onSuccess: () => {
console.log('---------->>> recharge success ');
}
});
};

View File

@@ -52,9 +52,9 @@ const useUserStore = defineStore('user', {
// 设置用户的信息
async setUserInfo(partial: Partial<UserBean>) {
this.userInfo = partial as UserBean;
setCompanyId(this.userInfo.companyId);
await this.fetchCompanyInfo();
await setCompanyId(this.userInfo.companyId);
await this.fetchTerminal();
await this.fetchCompanyInfo();
},
setDeliveryAddress(partial: Partial<any>) {
@@ -129,14 +129,12 @@ const useUserStore = defineStore('user', {
creatorId: res.user.creatorId,
gender: res.user.gender
};
setToken(res.token);
const registerResult = await this.userRegister(registerForm);
await this.setUserInfo(registerResult as LoginResult);
setToken(res.token);
setCompanyId(res.user.companyId);
} else {
await this.setUserInfo(res.user);
setToken(res.token);
setCompanyId(res.user.companyId);
await this.setUserInfo(res.user);
}
resolve(res);
} else {

View File

@@ -1,4 +1,5 @@
// 小程序更新检测
export function mpUpdate() {
const updateManager = uni.getUpdateManager();
updateManager.onCheckForUpdate((res) => {
@@ -27,11 +28,25 @@ export function mpUpdate() {
});
}
export function showToast(title: string, icon: 'none' | 'success' | 'loading' | 'error' | 'fail' | 'exception' | undefined = 'none', duration: number = 2000) {
interface ToastOption {
icon?: 'none' | 'success' | 'loading' | 'error' | 'fail' | 'exception' | undefined,
duration?: number,
complete?: Function
}
export function showToast(title: string, { icon, duration, complete }: ToastOption = {}) {
const defaultDuration = 1500;
uni.showToast({
title,
icon,
duration
title: title,
icon: icon || 'none',
duration: duration || defaultDuration,
complete(result) {
setTimeout(() => {
if(complete != undefined) {
complete();
}
}, duration || defaultDuration);
}
});
}

58
src/utils/order/index.ts Normal file
View File

@@ -0,0 +1,58 @@
import { OrderBean } from '@/api/order/types';
import dayjs from 'dayjs';
import { showToast } from '@/utils';
/**
* 获取订单支付过期时间
* @param order
*/
export function getOrderDeadline(order: OrderBean) {
// return dayjs(order?.createTime).add(30, 'minute').toDate().getTime();
return dayjs(order?.createTime).add(10, 'day').toDate().getTime();
}
/**
* 订单已过期
* @param item
*/
export const isExpired = (item: OrderBean) => {
return item?.payStatus == 1 && getOrderDeadline(item) < Date.now();
};
/**
* 订单待支付
* @param item
*/
export const isPending = (item: OrderBean | undefined) => {
return item?.payStatus == 1 && getOrderDeadline(item) > Date.now();
};
export const handlePayResult = (orderId: string | undefined, e: any, { onSuccess, onFailure }: any) => {
const payDetail = e.detail;
let url = payDetail.url;
const str = url.split('?')[1];
const resultObj = JSON.parse(str.replaceAll('result=', ''));
if(resultObj?.is_success === true) {
if(onSuccess) {
onSuccess();
} else {
showToast('支付成功', {
icon: 'success',
complete: () => {
uni.navigateBack();
}
});
}
} else {
if(onFailure) {
onFailure();
}
const msg = resultObj?.error_message || '支付失败';
showToast(msg, {
complete: () => {
uni.navigateBack();
}
});
}
};