|
|
@ -1,67 +1,70 @@ |
|
|
|
<template> |
|
|
|
<view class="min-height bg-gray p-20"> |
|
|
|
<header-item title="结算台"></header-item> |
|
|
|
<view class="card my-20 flex justify-between items-center" @click="toAddress"> |
|
|
|
<view class="flex justify-start items-center"> |
|
|
|
<uv-icon name="map"/> |
|
|
|
<view class="ml-15 flex flex-col justify-start items-start text-25"> |
|
|
|
<text v-if="!address">点击选择地址</text> |
|
|
|
<template v-else> |
|
|
|
<view class="text-35 u-line-1">{{ address.name }}</view> |
|
|
|
<view class="my-20"> |
|
|
|
<uv-text :text="address.phone" size="25rpx" color="#bbb"/> |
|
|
|
</view> |
|
|
|
<text style="color: #666666;" class="text-25">{{ address.fullAddress }}</text> |
|
|
|
</template> |
|
|
|
</view> |
|
|
|
<view class="min-height bg-gray p-20"> |
|
|
|
<header-item title="结算台"></header-item> |
|
|
|
<view class="card my-20 flex justify-between items-center" @click="toAddress"> |
|
|
|
<view class="flex justify-start items-center"> |
|
|
|
<uv-icon name="map"/> |
|
|
|
<view class="ml-15 flex flex-col justify-start items-start text-25"> |
|
|
|
<text v-if="!address">点击选择地址</text> |
|
|
|
<template v-else> |
|
|
|
<view class="text-35 u-line-1">{{ address.name }}</view> |
|
|
|
<view class="my-20"> |
|
|
|
<uv-text :text="address.phone" size="25rpx" color="#bbb"/> |
|
|
|
</view> |
|
|
|
<uv-icon name="arrow-right"/> |
|
|
|
<text style="color: #666666;" class="text-25">{{ address.fullAddress }}</text> |
|
|
|
</template> |
|
|
|
</view> |
|
|
|
<template v-if="cartData && cartData.goods"> |
|
|
|
<view class="card flex justify-between mb-20"> |
|
|
|
<view class="flex justify-start items-start"> |
|
|
|
<uv-image radius="15" :src="cartData.goods.image" width="150rpx" height="150rpx"/> |
|
|
|
<view class="flex justify-start items-start flex-col"> |
|
|
|
<text class="text-30 font-bold">{{ cartData.goods.goodsName }}</text> |
|
|
|
<text class="text-25 text-gray mt-20">{{ cartData.spec }}</text> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
<view class="flex justify-end items-end flex-col"> |
|
|
|
<text class="text-35">¥{{ |
|
|
|
cartData.price |
|
|
|
}}{{ `${cartData.point > 0 ? ` +${cartData.point}积分` : ''}` }} |
|
|
|
</text> |
|
|
|
<text class="text-25 text-gray mt-20">x{{ cartData.cartNum }}</text> |
|
|
|
<text class="text-25 text-gray mt-20">小计: ¥{{ cartData.totalPrice }}</text> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
<view class="card flex justify-between mb-20"> |
|
|
|
<uv-cell-group :border="false"> |
|
|
|
<uv-cell title="商品总价" :value="`¥${cartData.totalPrice}`"></uv-cell> |
|
|
|
<uv-cell title="商品数量" :value="`x${cartData.cartNum}`"></uv-cell> |
|
|
|
<uv-cell v-if="cartData.point > 0" title="使用积分" :value="`${cartData.point}积分`" |
|
|
|
:border="false"></uv-cell> |
|
|
|
</uv-cell-group> |
|
|
|
</view> |
|
|
|
<view class="card flex justify-between mb-20" v-if="cartData.totalPrice > 0"> |
|
|
|
<uv-cell-group :border="false"> |
|
|
|
<!-- <uv-cell isLink @click="payMethod = 'wechat' " title="微信支付" icon="/static/image/wechat-pay.png"--> |
|
|
|
<!-- :rightIcon="payMethod === 'wechat' ? '/static/image/radio-checked.png' : '/static/image/radio.png'"></uv-cell>--> |
|
|
|
<uv-cell isLink @click="selectPayMethod('alipay')" title="支付宝支付" |
|
|
|
icon="/static/image/alipay-pay.png" :border="false" |
|
|
|
:rightIcon="payMethod === 'alipay' ? '/static/image/radio-checked.png' : '/static/image/radio.png'"></uv-cell> |
|
|
|
</uv-cell-group> |
|
|
|
</view> |
|
|
|
</template> |
|
|
|
<view class="footer"> |
|
|
|
<view class="p-20"> |
|
|
|
<uv-button :text="payStr" :disabled="!canPay || disabled" |
|
|
|
:custom-style="{background: COLORS.LINEAR, width: '100%', color: 'white'}" |
|
|
|
shape="circle" |
|
|
|
@click="action"></uv-button> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
<uv-icon name="arrow-right"/> |
|
|
|
</view> |
|
|
|
<template v-if="cartData && cartData.goods"> |
|
|
|
<view class="card flex justify-between mb-20"> |
|
|
|
<view class="flex justify-start items-start"> |
|
|
|
<uv-image radius="15" :src="cartData.goods.image" width="150rpx" height="150rpx"/> |
|
|
|
<view class="flex justify-start items-start flex-col"> |
|
|
|
<text class="text-30 font-bold">{{ cartData.goods.goodsName }}</text> |
|
|
|
<text class="text-25 text-gray mt-20">{{ cartData.spec }}</text> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
<view class="flex justify-end items-end flex-col"> |
|
|
|
<text class="text-35">¥{{ |
|
|
|
cartData.price |
|
|
|
}}{{ `${cartData.point > 0 ? ` +${cartData.point}积分` : ''}` }} |
|
|
|
</text> |
|
|
|
<text class="text-25 text-gray mt-20">x{{ cartData.cartNum }}</text> |
|
|
|
<text class="text-25 text-gray mt-20">小计: ¥{{ cartData.totalPrice }}</text> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
<view class="card flex justify-between mb-20"> |
|
|
|
<uv-cell-group :border="false"> |
|
|
|
<uv-cell title="商品总价" :value="`¥${cartData.totalPrice}`"></uv-cell> |
|
|
|
<uv-cell title="商品数量" :value="`x${cartData.cartNum}`"></uv-cell> |
|
|
|
<uv-cell v-if="cartData.point > 0" title="使用积分" :value="`${cartData.point}积分`" |
|
|
|
:border="false"></uv-cell> |
|
|
|
</uv-cell-group> |
|
|
|
</view> |
|
|
|
<view class="card flex justify-between mb-20" v-if="cartData.totalPrice > 0"> |
|
|
|
<uv-cell-group :border="false"> |
|
|
|
<!-- <uv-cell isLink @click="payMethod = 'wechat' " title="微信支付" icon="/static/image/wechat-pay.png"--> |
|
|
|
<!-- :rightIcon="payMethod === 'wechat' ? '/static/image/radio-checked.png' : '/static/image/radio.png'"></uv-cell>--> |
|
|
|
<uv-cell isLink @click="selectPayMethod('balance')" :title="`余额支付(余额:${userInfo.balance}元)`" |
|
|
|
icon="/static/image/balance.png" :border="false" |
|
|
|
:rightIcon="payMethod === 'balance' ? '/static/image/radio-checked.png' : '/static/image/radio.png'"></uv-cell> |
|
|
|
<uv-cell isLink @click="selectPayMethod('alipay')" title="支付宝支付" |
|
|
|
icon="/static/image/alipay-pay.png" :border="false" |
|
|
|
:rightIcon="payMethod === 'alipay' ? '/static/image/radio-checked.png' : '/static/image/radio.png'"></uv-cell> |
|
|
|
</uv-cell-group> |
|
|
|
</view> |
|
|
|
</template> |
|
|
|
<view class="footer"> |
|
|
|
<view class="p-20"> |
|
|
|
<uv-button :text="payStr" :disabled="!canPay || disabled" |
|
|
|
:custom-style="{background: COLORS.LINEAR, width: '100%', color: 'white'}" |
|
|
|
shape="circle" |
|
|
|
@click="action"></uv-button> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</template> |
|
|
|
|
|
|
|
<script setup> |
|
|
@ -70,26 +73,26 @@ import HeaderItem from "@/components/HeaderItem.vue"; |
|
|
|
import {addOrderReq, cartListReq} from "@/api/shop"; |
|
|
|
import {onLoad} from "@dcloudio/uni-app"; |
|
|
|
import * as COLORS from "@/config/color"; |
|
|
|
import {userDetailReq} from "@/api/user"; |
|
|
|
import {getUser, userDetailReq} from "@/api/user"; |
|
|
|
import {toast} from "@/uni_modules/uv-ui-tools/libs/function"; |
|
|
|
import {userAddressDefaultReq} from "@/api/address"; |
|
|
|
|
|
|
|
const address = ref() |
|
|
|
const toAddress = () => { |
|
|
|
uni.navigateTo({ |
|
|
|
url: '/pages/user/address/list?isSelect=1', |
|
|
|
events: { |
|
|
|
select: res => { |
|
|
|
address.value = res |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
uni.navigateTo({ |
|
|
|
url: '/pages/user/address/list?isSelect=1', |
|
|
|
events: { |
|
|
|
select: res => { |
|
|
|
address.value = res |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
const cartData = ref() |
|
|
|
const getCartList = async () => { |
|
|
|
const {data} = await cartListReq(cartId.value) |
|
|
|
cartData.value = data |
|
|
|
const {data} = await cartListReq(cartId.value) |
|
|
|
cartData.value = data |
|
|
|
} |
|
|
|
|
|
|
|
const payStr = ref('立即支付') |
|
|
@ -97,97 +100,109 @@ const payMethod = ref('') |
|
|
|
const canPay = ref(true) |
|
|
|
const disabled = ref(false) |
|
|
|
|
|
|
|
const userInfo = ref({}) |
|
|
|
const getUserInfo = async () => { |
|
|
|
const {data} = await getUser() |
|
|
|
userInfo.value = data |
|
|
|
} |
|
|
|
getUserInfo() |
|
|
|
|
|
|
|
const userDetail = ref() |
|
|
|
const getUserDetail = async () => { |
|
|
|
const {data} = await userDetailReq() |
|
|
|
userDetail.value = data |
|
|
|
if (cartData.value.totalPrice === 0) { |
|
|
|
if (cartData.value.point > 0) { |
|
|
|
if (userDetail.value.point >= cartData.value.point) payStr.value = '使用积分0元支付' |
|
|
|
else { |
|
|
|
payStr.value = '积分不足,无法支付' |
|
|
|
canPay.value = false |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
payStr.value = '立即支付' |
|
|
|
if (!payMethod.value) canPay.value = false |
|
|
|
const {data} = await userDetailReq() |
|
|
|
userDetail.value = data |
|
|
|
if (cartData.value.totalPrice === 0) { |
|
|
|
if (cartData.value.point > 0) { |
|
|
|
if (userDetail.value.point >= cartData.value.point) payStr.value = '使用积分0元支付' |
|
|
|
else { |
|
|
|
payStr.value = '积分不足,无法支付' |
|
|
|
canPay.value = false |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
payStr.value = '立即支付' |
|
|
|
if (!payMethod.value) canPay.value = false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const selectPayMethod = (method) => { |
|
|
|
payMethod.value = method |
|
|
|
canPay.value = true |
|
|
|
if (method === 'balance' && userInfo.value.balance < cartData.value.totalPrice) return toast('余额不足,无法支付') |
|
|
|
payMethod.value = method |
|
|
|
canPay.value = true |
|
|
|
} |
|
|
|
|
|
|
|
const action = async () => { |
|
|
|
if (!address.value) return toast('请先选择地址') |
|
|
|
if (!payMethod.value && cartData.value.totalPrice > 0) return toast('请先选择支付方式') |
|
|
|
disabled.value = true |
|
|
|
const {data} = await addOrderReq({ |
|
|
|
realName: address.value.name, |
|
|
|
phone: address.value.phone, |
|
|
|
address: address.value.fullAddress, |
|
|
|
orderId: null, |
|
|
|
totalPrice: cartData.value.totalPrice, |
|
|
|
type: 0, |
|
|
|
payType: payMethod.value ? (payMethod.value === 'alipay' ? 3 : 1) : 2, |
|
|
|
goodsList: [ |
|
|
|
{ |
|
|
|
goodsId: cartData.value.goods.goodsId, |
|
|
|
goodsName: cartData.value.goods.goodsName, |
|
|
|
cartNum: cartData.value.cartNum, |
|
|
|
price: cartData.value.price, |
|
|
|
image: cartData.value.goods.image, |
|
|
|
point: cartData.value.point, |
|
|
|
skuName: cartData.value.spec, |
|
|
|
} |
|
|
|
] |
|
|
|
}).catch(() => { |
|
|
|
disabled.value = false |
|
|
|
}) |
|
|
|
if (!address.value) return toast('请先选择地址') |
|
|
|
if (!payMethod.value && cartData.value.totalPrice > 0) return toast('请先选择支付方式') |
|
|
|
disabled.value = true |
|
|
|
let payType = 2 |
|
|
|
if (payMethod.value === 'alipay') payType = 3 |
|
|
|
else if (payMethod.value === 'wechat') payType = 1 |
|
|
|
else if (payMethod.value === 'balance') payType = 0 |
|
|
|
const {data} = await addOrderReq({ |
|
|
|
realName: address.value.name, |
|
|
|
phone: address.value.phone, |
|
|
|
address: address.value.fullAddress, |
|
|
|
orderId: null, |
|
|
|
totalPrice: cartData.value.totalPrice, |
|
|
|
type: 0, |
|
|
|
payType, |
|
|
|
goodsList: [ |
|
|
|
{ |
|
|
|
goodsId: cartData.value.goods.goodsId, |
|
|
|
goodsName: cartData.value.goods.goodsName, |
|
|
|
cartNum: cartData.value.cartNum, |
|
|
|
price: cartData.value.price, |
|
|
|
image: cartData.value.goods.image, |
|
|
|
point: cartData.value.point, |
|
|
|
skuName: cartData.value.spec, |
|
|
|
} |
|
|
|
] |
|
|
|
}).catch(() => { |
|
|
|
disabled.value = false |
|
|
|
if (data && data.noNeedPay !== undefined && data.noNeedPay === 1) { |
|
|
|
toast('支付成功') |
|
|
|
await uni.redirectTo({url: '/pages/user/order/list?tab=1'}) |
|
|
|
} else { |
|
|
|
uni.requestPayment({ |
|
|
|
provider: payMethod.value, |
|
|
|
orderInfo: data, |
|
|
|
success: async (res) => { |
|
|
|
console.log('success', payMethod.value, res, payMethod.value === 'alipay') |
|
|
|
if (payMethod.value === 'alipay') { |
|
|
|
const rawData = JSON.parse(res.rawdata) |
|
|
|
// console.log(res.errMsg, parseInt(rawData.resultCode), rawData.resultCode) |
|
|
|
if (res.errMsg === 'requestPayment:ok' && parseInt(rawData.resultStatus) === 9000) { |
|
|
|
toast('支付成功') |
|
|
|
await uni.redirectTo({url: '/pages/user/order/list?tab=1'}) |
|
|
|
} else { |
|
|
|
toast('支付失败') |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
disabled.value = false |
|
|
|
if (data && data.noNeedPay !== undefined && data.noNeedPay === 1) { |
|
|
|
toast('支付成功') |
|
|
|
await uni.redirectTo({url: '/pages/user/order/list?tab=1'}) |
|
|
|
} else { |
|
|
|
uni.requestPayment({ |
|
|
|
provider: payMethod.value, |
|
|
|
orderInfo: data, |
|
|
|
success: async (res) => { |
|
|
|
console.log('success', payMethod.value, res, payMethod.value === 'alipay') |
|
|
|
if (payMethod.value === 'alipay') { |
|
|
|
const rawData = JSON.parse(res.rawdata) |
|
|
|
// console.log(res.errMsg, parseInt(rawData.resultCode), rawData.resultCode) |
|
|
|
if (res.errMsg === 'requestPayment:ok' && parseInt(rawData.resultStatus) === 9000) { |
|
|
|
toast('支付成功') |
|
|
|
await uni.redirectTo({url: '/pages/user/order/list?tab=1'}) |
|
|
|
} else { |
|
|
|
toast('支付失败') |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
complete: async (res) => { |
|
|
|
console.log('complete', res) |
|
|
|
}, |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
complete: async (res) => { |
|
|
|
console.log('complete', res) |
|
|
|
}, |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const userDefaultAddress = ref() |
|
|
|
const getUserDefaultAddress = async () => { |
|
|
|
const {data} = await userAddressDefaultReq() |
|
|
|
userDefaultAddress.value = data |
|
|
|
if(userDefaultAddress.value) address.value = userDefaultAddress.value |
|
|
|
const {data} = await userAddressDefaultReq() |
|
|
|
userDefaultAddress.value = data |
|
|
|
if (userDefaultAddress.value) address.value = userDefaultAddress.value |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const cartId = ref(null) |
|
|
|
onLoad(async option => { |
|
|
|
cartId.value = option.id |
|
|
|
await getCartList() |
|
|
|
await getUserDetail() |
|
|
|
await getUserDefaultAddress() |
|
|
|
cartId.value = option.id |
|
|
|
await getCartList() |
|
|
|
await getUserDetail() |
|
|
|
await getUserDefaultAddress() |
|
|
|
}) |
|
|
|
</script> |