deming/pageC/cart/cashier.vue
2020-07-14 17:43:15 +08:00

188 lines
4.0 KiB
Vue

<template>
<view class="cashier">
<view class="top">
<view class="title">支付金额</view>
<view class="price">{{ price }}</view>
</view>
<view class="pay-view">
<u-radio-group v-model="pay_way" @change="radioGroupChange" size="16">
<view v-for="(item, index) in payLiat" :key="index" class="pay-item">
<view class="pay-way">
<image :src="item.icon"></image>
<text class="name">{{ item.pay_way }}</text>
</view>
<view class="radio-view" :class="pay_way == item.name ? 'active' : 'default'">
<u-radio :name="item.name" active-color="#FF780F" :disabled="item.disabled"></u-radio>
</view>
</view>
</u-radio-group>
</view>
<view class="pay-btn" @click="sendPay">去支付</view>
</view>
</template>
<script>
export default {
data() {
return {
payLiat: [
{
name: 'wxpay_app',
icon: '/static/image/common/14.png',
pay_way: '微信支付',
disabled: false,
},
{
name: 'alipay_app',
icon: '/static/image/common/13.png',
pay_way: '支付宝',
disabled: false,
}
],
pay_way: '',
pay_sn: '',
price: '',
}
},
onLoad(option) {
this.pay_sn = option.pay_sn;
this.price = option.price;
},
methods: {
radioGroupChange(e) {
// console.log(e);
},
// getProvider() {
// uni.getProvider({service: 'payment'})
// },
// 支付宝支付
payByAlipay (orderInfo) {
uni.requestPayment({
provider: 'alipay',
orderInfo: orderInfo, //支付宝订单数据
success: function (res) {
console.log('success:' + JSON.stringify(res));
},
fail: function (err) {
console.log('fail:' + JSON.stringify(err));
}
});
},
// 微信支付
payByWxpay (orderInfo) {
uni.requestPayment({
provider: 'wxpay',
orderInfo: orderInfo, //微信订单数据
success: function (res) {
console.log('success:' + JSON.stringify(res));
},
fail: function (err) {
console.log('fail:' + JSON.stringify(err));
}
});
},
sendPay() {
this.$u.api.sendPay({
pay_sn: this.pay_sn,
payment_code: this.pay_way,
}).then(res => {
if(res.errCode == 0) {
// this.$u.toast(res.message);
// uni.navigateBack();
const orderInfo = JSON.parse(res.data.content);
console.log(orderInfo);
this.pay_way == 'wxpay_app' ? this.payByWxpay(orderInfo) : this.payByAlipay(orderInfo);
}
})
}
}
};
</script>
<style lang="scss" scoped>
.cashier {
min-height: calc(100vh - var(--window-top));
background-color: #ECECEC;
padding-top: 1rpx;
.top {
margin-bottom: 20rpx;
height: 240rpx;
background:rgba(255,255,255,1);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.title {
font-size: 32rpx;
color: rgba(51,51,51,1);
margin-bottom: 50rpx;
}
.price {
font-size: 42rpx;
font-weight: 500;
color: rgba(243,13,13,1);
}
}
.pay-view {
/deep/ .u-radio-group {
width: 100%;
flex-direction: column;
.radio-view {
padding: 6rpx;
border-radius: 50%;
}
.active {
border: 2rpx solid rgba(255,120,15,1);
}
.default {
border: 2rpx solid rgba(219,219,219,1);
}
.u-radio {
.u-icon {
border-color: rgba(219,219,219,1);
background-color: rgba(219,219,219,1);
.u-icon__icon::before {
display: none;
}
}
}
.pay-item {
height: 98rpx;
background: rgba(255,255,255,1);
padding: 24rpx 30rpx;
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 2rpx;
.pay-way {
display: flex;
align-items: center;
> image {
width: 50rpx;
height: 50rpx;
margin-right: 20rpx;
}
.name {
font-size: 30rpx;
color: rgba(51,51,51,1);
}
}
}
}
}
.pay-btn {
z-index: 9;
position: fixed;
bottom: 200rpx;
left: 30rpx;
width: 690rpx;
height: 98rpx;
background: rgba(255,120,15,1);
border-radius: 49rpx;
font-size: 36rpx;
font-weight: 500;
color: rgba(255,255,255,1);
display: flex;
align-items: center;
justify-content: center;
}
}
</style>