deming/pageC/cart/cashier.vue

215 lines
5.4 KiB
Vue
Raw Normal View History

2020-07-14 17:43:15 +08:00
<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>
2020-08-03 19:51:05 +08:00
<view class="" :class="pay_way == item.name ? 'active' : 'default'">
<u-radio class="radio-view" shape="circle" :name="item.name" active-color="#FF780F" :disabled="item.disabled"></u-radio>
2020-07-14 17:43:15 +08:00
</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,
}
],
2020-07-22 18:51:48 +08:00
pay_way: 'wxpay_app',
2020-07-14 17:43:15 +08:00
price: '',
2020-08-03 19:51:05 +08:00
pay_sn: '',
ifcart: '',
order_id: '',
2020-07-14 17:43:15 +08:00
}
},
onLoad(option) {
2020-08-03 19:51:05 +08:00
console.log(option);
this.ifcart = option.ifcart;
2020-07-14 17:43:15 +08:00
this.price = option.price;
2020-08-03 19:51:05 +08:00
this.pay_sn = option.pay_sn;
this.order_id = option.order_id;
2020-07-14 17:43:15 +08:00
},
methods: {
radioGroupChange(e) {
// console.log(e);
},
// getProvider() {
// uni.getProvider({service: 'payment'})
// },
2020-07-24 19:48:57 +08:00
payOrder(provider, orderInfo) {
2020-08-03 19:51:05 +08:00
let me = this;
2020-07-14 17:43:15 +08:00
uni.requestPayment({
2020-07-24 19:48:57 +08:00
provider: provider,
orderInfo: orderInfo, //订单数据
2020-08-03 19:51:05 +08:00
success: (res) => {
2020-07-14 17:43:15 +08:00
console.log('success:' + JSON.stringify(res));
2020-08-03 19:51:05 +08:00
this.$u.toast("支付成功!");
setTimeout(function(){
if (Boolean(parseInt(me.ifcart))) {
me.$u.route({
type: 'redirect',
url: '/pageE/order/Index',
})
} else {
me.$u.route({
type: 'redirect',
url: '/pageE/order/Details?oid=' + me.order_id,
})
}
},2000)
2020-07-14 17:43:15 +08:00
},
2020-08-03 19:51:05 +08:00
fail: (err) => {
2020-07-14 17:43:15 +08:00
console.log('fail:' + JSON.stringify(err));
2020-08-03 19:51:05 +08:00
this.$u.toast("支付失败,支付已取消!");
setTimeout(function(){
if (Boolean(parseInt(me.ifcart))) {
me.$u.route({
type: 'redirect',
url: '/pageE/order/Index',
})
} else {
me.$u.route({
type: 'redirect',
url: '/pageE/order/Details?oid=' + me.order_id,
})
}
},2000)
2020-07-14 17:43:15 +08:00
}
});
},
sendPay() {
this.$u.api.sendPay({
pay_sn: this.pay_sn,
payment_code: this.pay_way,
}).then(res => {
if(res.errCode == 0) {
2020-07-24 19:48:57 +08:00
let orderInfo, provider;
if(res.data.payment_code == 'wxpay_app') {
provider = 'wxpay';
orderInfo = JSON.parse(res.data.content);
} else if(res.data.payment_code == 'alipay_app') {
provider = 'alipay';
orderInfo = res.data.content;
}
this.payOrder(provider, orderInfo);
2020-07-14 17:43:15 +08:00
}
})
}
}
};
</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;
2020-08-03 19:51:05 +08:00
.u-radio__icon-wrap {
width: 30rpx !important;
height: 30rpx !important;
padding: 4rpx;
border: 1px solid #FF780F;
}
.active {
}
.default {
}
2020-07-14 17:43:15 +08:00
.radio-view {
2020-08-03 19:51:05 +08:00
2020-07-14 17:43:15 +08:00
}
.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 {
display: flex;
align-items: center;
justify-content: space-between;
2020-08-03 19:51:05 +08:00
height: 98rpx;
padding: 24rpx 30rpx;
2020-07-14 17:43:15 +08:00
margin-bottom: 2rpx;
2020-08-03 19:51:05 +08:00
background: rgba(255,255,255,1);
2020-07-14 17:43:15 +08:00
.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>