Files
kangyuan-mobile/pages/AI/giftCashierDesk.vue
T

365 lines
10 KiB
Vue

<template>
<s-pages title="收银台" :pink_bg="true" :goLeft="false" @onClickLeft="onClickLeft">
<view class="p-x-32">
<view class="center p-t-96 weight500 size100"
><span class="size48">¥</span>
<!-- {{ fen2yuan(state.orderInfo.totalPrice) }} -->
{{ fen2yuan(state.orderInfo.payPrice) }}
</view>
<view class="center m-t-20 m-b-66">{{ payDescText }}</view>
<view>
<radio-group @change="onTapPay">
<label class="" v-for="item in state.payMethods" :key="item.title">
<view
class="flex-center ju-between m-b-40"
:class="{ 'disabled-pay-item': item.disabled }"
>
<view class="flex-center">
<image
class="h_64 w_64"
v-if="item.disabled"
:src="sheep.$url.static('/static/img/shop/pay/cod_disabled.png')"
mode="aspectFit"
/>
<image
class="h_64 w_64"
v-else
:src="sheep.$url.static(item.icon)"
mode="aspectFit"
/>
<text class="pay-title m-l-12">{{ item.title }}</text>
</view>
<view class="check-box ss-flex ss-col-center ss-p-l-10">
<view class="userInfo-money ss-m-r-10" v-if="item.value === 'wallet'">
余额: {{ fen2yuan(totalRecharge) }}元
</view>
<view class="">
<radio
:value="item.value"
color="#366DEE"
backgroundColor="rgba(255, 255, 255, 0)"
:disabled="item.disabled"
:checked="state.payment === item.value"
/>
</view>
</view>
<!-- <view class="">
<radio :value="item.value" color="#366DEE" backgroundColor="rgba(255, 255, 255, 0)"
:disabled="item.disabled" :checked="state.payment === item.value" />
</view> -->
</view>
</label>
</radio-group>
</view>
<!-- 工具 -->
<view class="modal-footer ss-flex ss-row-center ss-col-center ss-m-t-80 ss-m-b-40">
<button v-if="state.payStatus === 0" class="ss-reset-button past-due-btn">
检测支付环境中
</button>
<button v-else-if="state.payStatus === -1" class="ss-reset-button past-due-btn" disabled>
支付已过期
</button>
<button
v-else
class="ai-button2"
@tap="onPay"
:disabled="state.payStatus !== 1"
:class="{ 'disabled-btn': state.payStatus !== 1 }"
>
立即支付
</button>
</view>
</view>
</s-pages>
</template>
<script setup lang="ts">
import {
ref,
reactive,
onMounted,
onUnmounted,
getCurrentInstance,
watch,
nextTick,
computed,
} from 'vue';
let { proxy } = getCurrentInstance();
import { onLoad, onShow } from '@dcloudio/uni-app';
import * as api from '@/sheep/api/ai/index';
import sheep from '@/sheep';
import PayChannelApi from '@/sheep/api/pay/channel';
import { fen2yuan, useDurationTime } from '@/sheep/hooks/useGoods';
import { getPayMethods, goPayResult } from '@/sheep/platform/pay';
import { SYSCONST } from '@/sheep/helper/const';
import { getWallet } from '@/sheep/api/home/pay';
let id = ref('');
let payOrderId = ref('');
let orderInfo = ref({});
const userWallet = ref();
const returnTo = ref('');
let totalRecharge = ref();
// 检测支付环境
const state = reactive({
orderType: 'aiGoods', // 订单类型; goods - 商品订单, recharge - 充值订单 aiRecharge
orderInfo: {}, // 支付单信息
payStatus: 0, // 0=检测支付环境, -2=未查询到支付单信息, -1=支付已过期, 1=待支付,2=订单已支付
payMethods: [], // 可选的支付方式
payment: '', // 选中的支付方式
});
const getOrderDetail = async () => {
let { code, data } = await api.getGiftOrderDetail({ id: id.value });
if (code !== 0 || !data) {
state.payStatus = -2;
return;
}
state.orderInfo = data || {};
// 设置支付状态
checkPayStatus();
// 获得支付方式
await setPayMethods();
};
// 获得支付方式
async function setPayMethods() {
const { data, code } = await PayChannelApi.getEnableChannelCodeList(state.orderInfo.appId || 1);
if (code !== 0) {
return;
}
state.payMethods = getPayMethods(data);
// 金额超出阈值,仅允许余额支付
if (state.orderInfo?.totalPrice >= SYSCONST.MAX_PRICE) {
state.payMethods = state.payMethods.map((item) => ({
...item,
disabled: item.value !== 'wallet' ? true : item.disabled,
}));
state.payment = 'wallet';
}
state.payMethods.find((item) => {
if (item.value && !item.disabled) {
state.payment = item.value;
return true;
}
});
}
// 支付文案提示
const payDescText = computed(() => {
if (state.payStatus === 2) {
return '该订单已支付';
}
if (state.payStatus === 1 && state.orderInfo?.payExpireTime) {
const time = useDurationTime(state.orderInfo.payExpireTime);
if (time?.ms <= 0) {
state.payStatus = -1;
return '';
}
return `剩余支付时间 ${time?.h}:${time?.m}:${time?.s} `;
}
if (state.payStatus === -2) {
return '未查询到支付单信息';
}
return '';
});
// 状态转换:payOrder.status => payStatus
function checkPayStatus() {
if (state.orderInfo.status === 10 || state.orderInfo.status === 20) {
// 支付成功
state.payStatus = 2;
// 跳转回支付成功页
uni.showModal({
title: '提示',
content: '订单已支付',
confirmColor: '#FA7E31',
showCancel: false,
success: function () {
goPayResult(state.orderInfo.id, state.orderType);
},
});
return;
}
if (state.orderInfo.status === 30) {
// 支付关闭
state.payStatus = -1;
return;
}
state.payStatus = 1; // 待支付
}
// 切换支付方式
function onTapPay(e) {
state.payment = e.detail.value;
}
let type = ref(); //2充值
onLoad(async (options) => {
// console.log(options);
id.value = options.id || '';
payOrderId.value = options.payOrderId || '';
type.value = options.type || '';
returnTo.value = options.returnTo || '';
if (type.value == 2) {
state.orderType = 'aiRecharge';
state.orderInfo.totalPrice = options.price * 100;
// state.orderInfo.price = options.price;
// 设置支付状态
checkPayStatus();
// 获得支付方式
await setPayMethods();
} else {
getOrderDetail();
}
});
onShow(() => {
getWallet().then((res) => {
if (res.code === 0) {
totalRecharge.value = res.data.totalRecharge;
}
});
});
const onPay = () => {
// console.log(userWallet.value.totalRecharge);
if (state.payment === '') {
sheep.$helper.toast('请选择支付方式');
return;
}
if (state.orderInfo.totalPrice >= SYSCONST.MAX_PRICE && state.payment !== 'wallet') {
sheep.$helper.toast('请选择余额支付');
return;
}
if (returnTo.value) {
uni.setStorageSync('pay_return_to', returnTo.value);
} else if (state.orderType === 'aiGoods') {
uni.setStorageSync('pay_return_to', 'aiStore_myshop');
}
if (state.payment === 'wallet') {
uni.showModal({
title: '提示',
content: '确定要支付吗?',
confirmColor: '#FA7E31',
success: function (res) {
if (res.confirm) {
// sheep.$platform.pay(state.payment, state.orderType, payOrderId.value);
if (totalRecharge.value < state.orderInfo.totalPrice) {
uni.showToast({
title: '余额不足请充值',
icon: 'none',
});
setTimeout(() => {
uni.navigateTo({
url: '/pages/home/recharge',
});
}, 1000);
} else {
sheep.$platform.pay(state.payment, state.orderType, payOrderId.value);
}
}
},
});
} else {
sheep.$platform.pay(state.payment, state.orderType, payOrderId.value);
}
};
const onClickLeft = () => {
uni.navigateBack({
delta: 1,
});
};
</script>
<style lang="scss" scoped>
.pay-icon {
width: 36rpx;
height: 36rpx;
margin-right: 26rpx;
}
.ss-modal-box {
// max-height: 1000rpx;
.modal-header {
position: relative;
padding: 60rpx 20rpx 40rpx;
.money-text {
color: $red;
font-size: 46rpx;
font-weight: bold;
font-family: OPPOSANS;
&::before {
content: '¥';
font-size: 30rpx;
}
}
.time-text {
font-size: 26rpx;
color: $gray-b;
}
.close-icon {
position: absolute;
top: 10rpx;
right: 20rpx;
font-size: 46rpx;
opacity: 0.2;
}
}
.modal-content {
overflow-y: auto;
.pay-title {
font-size: 26rpx;
font-weight: 500;
color: #333333;
}
.pay-tip {
font-size: 26rpx;
color: #bbbbbb;
}
.pay-item {
height: 86rpx;
}
.disabled-pay-item {
.pay-title {
color: #999999;
}
}
.userInfo-money {
font-size: 26rpx;
color: #bbbbbb;
line-height: normal;
}
}
.save-btn {
width: 710rpx;
height: 80rpx;
border-radius: 40rpx;
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
color: $white;
}
.disabled-btn {
background: #e5e5e5;
color: #999999;
}
.past-due-btn {
width: 710rpx;
height: 80rpx;
border-radius: 40rpx;
background-color: #999;
color: #fff;
}
}
</style>