123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- <template>
- <view class="app">
- <view class="bg">
- </view>
- <view class="moneyBox">
- <view class="price-box">
- <text>支付金额</text>
- <text class="price">{{ money }}</text>
- </view>
- <view class="yt-list">
- <view class="yt-list-cell b-b" v-if="fx" @click="payType='weixin'">
- <view class="cell-tit flex">
- <image class="orderIcon" src="../../../static/icon/orderWx.png" mode="widthFix"></image>
- <text class="margin-l-10">微信支付</text>
- </view>
- <image class="checked" v-if="payType=='weixin'" src="../../../static/icon/addressIconXz.png"
- mode="widthFix"></image>
- <view v-else class="noChecked"></view>
- </view>
- <!-- #ifdef APP-PLUS -->
- <view class="yt-list-cell b-b" @click="payType='ali'">
- <view class="cell-tit flex">
- <image class="orderIcon" src="../../../static/icon/orderAli.png" mode="widthFix"></image>
- <text class="margin-l-10">支付宝</text>
- </view>
- <image class="checked" v-if="payType=='ali'" src="../../../static/icon/addressIconXz.png"
- mode="widthFix">
- </image>
- <view v-else class="noChecked"></view>
- </view>
- <!-- #endif -->
- <view class="yt-list-cell" @click="payType='yue'">
- <view class="cell-tit flex">
- <image class="orderIcon" src="../../../static/icon/ye.png" mode="widthFix"></image>
- <text class="margin-l-10">余额({{now_money}})</text>
- </view>
- <image class="checked" v-if="payType=='yue'" src="../../../static/icon/addressIconXz.png"
- mode="widthFix">
- </image>
- <view v-else class="noChecked"></view>
- </view>
- </view>
- </view>
- <view class="base-buttom" :class="{ clickbg: payLoding }" @click="!payLoding ? confirm() : ''">确认支付</view>
- </view>
- </template>
- <script>
- import {
- mapState
- } from 'vuex'
- import {
- balance
- } from '@/api/wallet.js';
- import {
- orderPay
- } from '@/api/order.js';
- // #ifdef H5
- import weixinObj from "@/plugin/jweixin-module/index.js";
- // #endif
- export default {
- data() {
- return {
- // #ifdef H5
- payType: 'ali',
- // #endif
- // #ifdef MP-WEIXIN
- payType: 'ali',
- // #endif
- money: 0.0, //订单金额
- now_money: 0.0, //余额
- orderId: '', //保存订单id
- payLoding: false, //判断是否支付中
- payType: 'ali',
- // #ifdef H5
- froms: '', //保存h5中数据来源对象
- // #endif
- };
- },
- onLoad(options) {
- // 判断是否为已创建单号订单
- this.type = 1;
- this.orderId = options.ordid;
- this.money = options.money;
- // 载入余额
- balance({}).then(({
- data
- }) => {
- // 获取余额
- this.now_money = data.now_money;
- });
- },
- computed:{
- ...mapState(['fx'])
- },
- methods: {
- // 支付金额
- orderMoneyPay() {
- let obj = this;
- orderPay({
- uni: obj.orderId,
- // #ifdef H5
- from: obj.froms ? 'weixin' : 'H5', //来源
- // #endif
- // #ifdef MP-WEIXIN
- from: 'routine', //来源
- // #endif
- // #ifdef APP-PLUS
- from: 'app', //来源
- // #endif
- paytype: obj.payType //支付类型 weixin-微信 yue-余额
- })
- .then(e => {
- // 判断是否为余额支付
- if (obj.payType == 'yue' && e.data.status == 'SUCCESS') {
- if (e.status == 200) {
- obj.paySuccessTo();
- } else {
- uni.showToast({
- title:msg,
- icon:"none"
- })
- }
- }
- if (obj.payType == 'weixin') {
- let da = e.data.result.jsConfig;
- let data = {
- // #ifdef H5
- timestamp: da.timestamp,
- // #endif
- // #ifdef MP
- timeStamp: da.timestamp,
- // #endif
- nonceStr: da.nonceStr,
- package: da.package,
- signType: da.signType,
- paySign: da.paySign,
- success: function(res) {
- obj.paySuccessTo();
- },
- fail: () => {
- uni.navigateTo({
- url: '/pages/order/order?state=0'
- });
- }
- };
- // #ifdef H5
- if (obj.payType == 'weixin') {
- weixinObj.chooseWXPay(data);
- }
- // #endif
- // #ifdef MP-WEIXIN
- if (obj.payType == 'weixin') {
- wx.requestPayment(data);
- }
- // #endif
- }
- uni.hideLoading();
- obj.payLoding = false;
- })
- .catch(e => {
- // 支付完成
- uni.hideLoading();
- obj.payLoding = false;
- console.log(e);
- });
- },
- // 支付成功跳转
- paySuccessTo() {
- uni.hideLoading();
- uni.redirectTo({
- url: './paySuccess?orderid=' + this.orderId
- });
- },
- //确认支付
- confirm: async function() {
- let obj = this;
- uni.showLoading({
- title: '支付中',
- mask: true
- })
- // 判断是否余额不足
- if (obj.payType == 'yue' && +obj.now_money < obj.money) {
- uni.showModal({
- title: '提示',
- content: '账户余额不足!',
- showCancel: false,
- success: res => {},
- fail: () => {},
- complete: () => {}
- });
- return;
- }
- // 支付中
- obj.payLoding = true;
- // #ifdef H5
- // 获取当前是否为微信浏览器
- obj.froms = uni.getStorageSync('weichatBrowser') || '';
- // #endif
- // 判断是否为未支付订单中跳转进入
- obj.orderMoneyPay();
- }
- }
- };
- </script>
- <style lang="scss">
- .app {
- width: 100%;
- padding-top: 30rpx;
- }
- .moneyBox {
- position: relative;
- margin: 0 $page-row-spacing;
- border-radius: 20rpx;
- overflow: hidden;
- background-color: #FFFFFF;
- }
- .bg {
- background-color: $color-green;
- width: 950rpx;
- position: absolute;
- left: -100rpx;
- border-bottom-left-radius: 1000rpx;
- border-bottom-right-radius: 1000rpx;
- top: 0rpx;
- height: 300rpx;
- }
- .price-box {
- background-color: #fff;
- height: 200rpx;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- font-size: 28upx;
- color: #909399;
- .price {
- font-size: 50upx;
- color: #303133;
- margin-top: 12upx;
- &:before {
- content: '¥';
- font-size: 40upx;
- }
- }
- }
- .pay-type-list {
- margin-top: 20upx;
- background-color: #fff;
- padding-left: 60upx;
- .type-item {
- height: 120upx;
- padding: 20upx 0;
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding-right: 60upx;
- font-size: 30upx;
- position: relative;
- }
- .icon {
- width: 100upx;
- font-size: 52upx;
- }
- .iconyue {
- color: #fe8e2e;
- }
- .iconweixin {
- color: #36cb59;
- }
- .iconzhifubao {
- color: #01aaef;
- }
- .tit {
- font-size: $font-lg;
- color: $font-color-dark;
- margin-bottom: 4upx;
- }
- .con {
- flex: 1;
- display: flex;
- flex-direction: column;
- font-size: $font-sm;
- color: $font-color-light;
- }
- }
- .clickbg {
- background-color: $color-gray !important;
- }
- .yt-list {
- background: #fff;
- margin: 0 $page-row-spacing;
- border-radius: 20rpx;
- padding-bottom: 20rpx;
- }
- .yt-list-cell {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 10rpx 30rpx 10rpx 40rpx;
- line-height: 70rpx;
- position: relative;
- .checked,
- .noChecked {
- width: 36rpx;
- height: 36rpx;
- }
- .noChecked {
- border: 1px solid $font-color-light;
- border-radius: 100rpx;
- }
- &.cell-hover {
- background: #fafafa;
- }
- &.b-b:after {
- left: 30rpx;
- }
- .cell-icon {
- height: 32rpx;
- width: 32rpx;
- font-size: 22rpx;
- color: #fff;
- text-align: center;
- line-height: 32rpx;
- background: #f85e52;
- border-radius: 4rpx;
- margin-right: 12rpx;
- &.hb {
- background: #ffaa0e;
- }
- &.lpk {
- background: #3ab54a;
- }
- }
- .cell-more {
- align-self: center;
- font-size: 24rpx;
- color: $font-color-light;
- margin-left: 8rpx;
- margin-right: -10rpx;
- }
- .cell-tit {
- font-size: 26rpx;
- color: $font-color-light;
- margin-right: 10rpx;
- .orderIcon {
- width: 48rpx;
- }
- }
- .cell-tip {
- font-size: 26rpx;
- color: $font-color-dark;
- &.disabled {
- color: $font-color-light;
- }
- &.active {
- color: $base-color;
- }
- &.red {
- color: $base-color;
- }
- }
- &.desc-cell {
- .cell-tit {
- max-width: 90rpx;
- }
- }
- .desc {
- text-align: right;
- font-size: $font-base;
- color: $font-color-light;
- }
- }
- </style>
|