new-mshop-view/pages/users/online_payment/payment/index.vue

893 lines
25 KiB
Vue

<template>
<view :style="viewColor">
<!--具体内容-->
<view class='content-box'>
<!--顶部内容-->
<view class="top">
<view class="left">
<image class="image" :src="mer_info.mer_avatar || '/static/images/f.png'"></image>
<view class="name" @click="merShowPopup">{{ mer_info.mer_name || '请选择门店' }}</view>
<view class="change-btn" @click="merShowPopup" v-if="mer_info.mer_id > 0 && default_mer_id <= 0">切换</view>
</view>
<view class="right" @click="goMenuPage('/pages/users/online_payment/payment/record')">消费记录</view>
</view>
<!--买单金额-->
<view class="money">
<view class="top-bg-line"></view>
<view class="money-box">
<view class="title">买单金额</view>
<view class="input-box">
<view class="unit">¥</view>
<input class="money-input" v-model.number="pay_info.money" type='number' step="0.01" placeholder="0.00" />
</view>
</view>
</view>
<!--积分抵扣-->
<view class="integral" v-if="Number(integral_surplus) > 0 && Number(pay_info.money) > 0">
<view class="box-title">餐费积分抵扣</view>
<view class="box-content">
<view class="use-info">
<text class="iconfont icon-pc-jifen"></text>
<view class="title">使用餐费积分</view>
<input class="use-input" v-model="integral_use" type='number' step="0.01" placeholder="请输入要使用的餐费积分数量!" />
</view>
<view class="hold-info">
<view class="left">剩余餐费积分:{{ integral_surplus || '0.00' }}</view>
<view class="right">餐费积分抵扣:{{ integral_use || '0.00' }}元</view>
</view>
</view>
</view>
<!--支付方式-->
<view class="pay-type">
<pay :payType="pay_info.pay_type" @change="changePayType"></pay>
</view>
<!--支付按钮-->
<view class="pay-btn" v-if="mer_info.mer_id > 0 && pay_info.money > 0" @click="confirmPayment">确认支付</view>
<view class="pay-btn not-btn" v-else>确认支付</view>
</view>
<!--授权登录-->
<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
<!--店铺选择-->
<uni-popup ref="selectedMer" type="center">
<view class="mer-content">
<view class="search-content">
<input class="money-input" v-model="mer_search.search_text" type='text' placeholder="商户名称/商户地址" />
<view class="search-btn" @click="getMerList">搜索</view>
<view class="close-btn" @click="merClosePopup">取消</view>
</view>
<view class="mer-list">
<view class="mer-box" v-for="(item,index) in mer_list" :key="index">
<view class="left">
<image class="image" :src="item.mer_avatar || '/static/images/f.png'"></image>
<view class="mer-info">
<view class="mer-name">{{ item.mer_name }}</view>
<view class="mer-address">{{ item.mer_address }}</view>
</view>
</view>
<view class="selected-btn" @click="selectedMer(item)">选中</view>
</view>
</view>
</view>
</uni-popup>
</view>
</template>
<script>
import {searchMer,onlinePayment} from '@/api/exchange.js';
import {mapGetters} from "vuex";
import authorize from '@/components/Authorize';
import emptyPage from '@/components/emptyPage.vue';
import spread from "@/libs/spread";
import {getUserInfo,merShareholdersIntegralStatistics} from "@/api/user";
import pay from "@/components/payment/pay";
const app = getApp();
export default {
components: {
authorize,
emptyPage,
pay
},
data() {
return {
// 登录相关
isAuto: false, //没有授权的不会自动授权
isShowAuth: false,//是否隐藏授权
// 商户相关
mer_info:{},
mer_list: {},
mer_search: {
mer_id: 0,
search_text: '',
},
// 买单相关
pay_info: {
money: 0.00,// 买单金额
pay_type: 'weixin',
// #ifdef H5
return_url: 'http://' + window.location.host + '/pages/users/order_list/index',
// #endif
},
default_mer_id: 0,
// 餐费积分
integral_surplus: 0,
integral_use: '',
};
},
computed: {
...mapGetters(['isLogin', 'userInfo', 'viewColor'])
},
onLoad(options) {
let mer_id = options.mer_id || 0;
// 二维码参数接收
if(options.scene){
console.log("接收参数 - 未转义",options.scene)
var scene = this.$util.getUrlParams(decodeURIComponent(options.scene));
// console.log("接收参数 - 转义后",scene)
mer_id = scene.mer_id || 0;
}
this.default_mer_id = mer_id || 0;
this.mer_search.mer_id = mer_id || 0;
// 判断:是否登录
if (!this.isLogin) {
// 未登录 授权登录
this.isAuto = true;
this.isShowAuth = true
}else{
// 已登录 获取信息
this.init();
}
// 关系处理
if(options.spread) spread(options.spread, this.isLogin)
},
onReachBottom: function () {},
watch: {
// 买单金额改变
'pay_info.money': {
handler() {
this.computeUseIntegral();
},
immediate: true
},
// 使用积分改变
'integral_use': {
handler() {
this.computeUseIntegral();
},
immediate: true
}
},
methods: {
// 授权回调
onLoadFun() {
if(this.isLogin){
this.isShowAuth = false;
this.init();
}
},
// 授权关闭
authColse(e) {
this.isShowAuth = e
},
// 授权成功 获取用户信息
init () {
let _this = this;
// 门店选择初始化
let merId = _this.mer_info.mer_id || 0;
if(merId <= 0) _this.merShowPopup();
// 获取用户餐费信息
_this.shareholdersIntegralInfo();
},
// 门店选择 - 显示弹框
merShowPopup(){
this.$refs.selectedMer.open('center');
if(Object.keys(this.mer_list).length <= 0) this.getMerList();
},
// 门店选择 - 隐藏弹框
merClosePopup(){
this.$refs.selectedMer.close();
},
// 门店选择 - 获取门店列表
getMerList(){
let _this = this;
searchMer(this.mer_search)
.then(res => {
_this.mer_list = res.data || {};
// 判断:是否存在默认商户 存在则使用默认商户,且不可变更
if(Number(_this.default_mer_id) > 0 && Object.values(_this.mer_list).length === 1){
this.selectedMer(_this.mer_list[0]);
}
})
.catch(err => {
this.$util.Tips({
title: err
});
});
},
// 门店选择 - 门店选中
selectedMer(item){
this.mer_info = item;
this.merClosePopup();
},
// 修改支付方式
changePayType(value){
this.pay_info.pay_type = value;
},
// 确认付款
confirmPayment(){
let _this = this;
let payInfo = Object.assign({},_this.pay_info);
payInfo.mer_id = _this.mer_info.mer_id;
payInfo.integral_use = _this.integral_use || 0;
console.log('支付类型', payInfo)
if (payInfo.pay_type == 'weixin') {
// #ifdef H5
payInfo.pay_type = _this.$wechat.isWeixin() ? 'weixin' : 'h5'
// #endif
// #ifdef MP
payInfo.pay_type = 'routine'
// #endif
// #ifdef APP-PLUS
payInfo.pay_type = 'weixin'
// #endif
}
uni.showLoading({
title: '订单处理中...',
mask: true
});
onlinePayment(payInfo).then(res => {
if (res.status == 200) {
let status = res.data.status,
orderId = res.data.result.order_id,
callback_key = res.data.result.pay_key,
jsConfig = res.data.result.config;
let backUrl = '/pages/order_pay_status/index?order_type=30&order_id=' + orderId + '&msg=' + res.message;
let backTab = 5;
let goPages = backUrl;
switch (status) {
case 'ORDER_EXIST':
case 'EXTEND_ORDER':
case 'PAY_ERROR':
case 'error':
return _this.$util.Tips({
title: res.message
}, {
tab: backTab,
url: goPages
});
break;
case 'success':
return _this.$util.Tips({
title: res.message,
icon: 'success'
}, {
tab: backTab,
url: goPages
});
break;
case 'alipay':
case "alipayQr":
uni.navigateTo({
url: '/pages/order_pay_back/index?keyCode=' + callback_key + '&url=' +
jsConfig
})
return;
break;
// #ifndef MP
case "wechat":
case "weixin":
case "weixinApp":
jsConfig.timeStamp = jsConfig.timestamp;
// #ifndef APP-PLUS
this.$wechat.pay(jsConfig).then(res => {
return _this.$util.Tips({
title: res.message,
icon: 'success'
}, {
tab: backTab,
url: goPages
});
}).catch(res => {
if (res.errMsg == 'chooseWXPay:cancel') return _this.$util.Tips({
title: '取消支付'
}, {
tab: backTab,
url: goPages + '&status=0'
});
})
// #endif
// #ifdef APP-PLUS
let mp_pay_name=''
if(uni.requestOrderPayment){
mp_pay_name='requestOrderPayment'
}else{
mp_pay_name='requestPayment'
}
uni[mp_pay_name]({
provider: 'wxpay',
orderInfo: jsConfig,
success: (e) => {
// let url = '/pages/order_pay_status/index?order_id=' + orderId + '&msg=支付成功';
return _this.$util.Tips({
title: '支付成功',
icon: 'success'
}, {
tab: backTab,
url: backUrl
});
},
fail: (e) => {
// let url = '/pages/order_pay_status/index?order_id=' + orderId + '&msg=取消支付';
return _this.$util.Tips({
title: '取消支付',
}, {
tab: backTab,
url: backUrl
});
},
complete: () => {
// let url = '/pages/order_pay_status/index?order_id=' + orderId + '&msg=取消支付';
return _this.$util.Tips({
title: '',
}, {
tab: backTab,
url: backUrl
});
},
});
// #endif
break;
// #endif
// #ifdef MP
case "routine":
jsConfig.timeStamp = jsConfig.timestamp;
_this.toPay = true;
let mp_pay_name=''
if(uni.requestOrderPayment){
mp_pay_name='requestOrderPayment'
}else{
mp_pay_name='requestPayment'
}
uni[mp_pay_name]({
...jsConfig,
success: function(res) {
uni.hideLoading();
return _this.$util.Tips({
title: '支付成功',
icon: 'success'
}, {
tab: backTab,
url: goPages
});
},
fail: function(e) {
// let pages = '/pages/order_pay_status/index?order_id=' + orderId + '&msg=取消支付'
return _this.$util.Tips({
title: '取消支付'
}, {
tab: backTab,
// url: pages + '&status=0'
url: backUrl
});
},
})
break;
// #endif
case "balance":
//余额
return _this.$util.Tips({
title: res.msg
}, {
tab: backTab,
url: goPages + '&status=1'
});
break;
// #ifdef H5
case 'h5':
let host = window.location.protocol + "//" + window.location.host;
// let url = `${host}/pages/order_pay_status/index?order_id=${orderId}&msg=${res.message}`
let eUrl = encodeURIComponent(backUrl)
let jsurl = jsConfig.mweb_url || jsConfig.h5_url
let locations = `${jsurl}&redirect_url=${eUrl}`
setTimeout(() => {
location.href = locations;
}, 100);
break;
// #endif
// #ifdef APP-PLUS
case 'alipayApp':
uni.requestPayment({
provider: 'alipay',
orderInfo: jsConfig,
success: (e) => {
return _this.$util.Tips({
title: '支付成功',
icon: 'success'
}, {
tab: backTab,
url: goPages
});
},
fail: (e) => {
// let pages = '/pages/order_pay_status/index?order_id=' + orderId + '&msg=支付失败'
return _this.$util.Tips({
title: '支付失败'
}, {
tab: backTab,
url: backUrl
});
},
complete: () => {
uni.hideLoading();
// let pages = '/pages/order_pay_status/index?order_id=' + orderId + '&msg=取消支付'
return _this.$util.Tips({
title: ''
}, {
tab: backTab,
url: backUrl
});
},
});
break;
// #endif
default:
// let pages = '/pages/order_pay_status/index?order_id=' + orderId + '&msg=取消支付'
return _this.$util.Tips({
title: '取消支付'
}, {
tab: backTab,
// url: pages + '&status=0'
url: backUrl
});
}
}
}).catch(err => {
uni.hideLoading();
this.$util.Tips({
title: err
});
});
},
// 跳转
goMenuPage(url) {
console.log(url)
if (this.isLogin) {
uni.navigateTo({
url
})
} else {
this.openAuto()
}
},
// 餐费积分 - 获取当前用户可用餐费积分
shareholdersIntegralInfo(){
let _this = this;
merShareholdersIntegralStatistics({mer_id: _this.mer_search.mer_id}).then(res => {
_this.integral_surplus = res.data.sum_used_surplus || 0;
}).catch(err => {
this.$util.Tips({title: err});
});
},
// 餐费积分 - 计算使用的积分
computeUseIntegral(){
let money = this.pay_info.money || 0;
let integralUse = this.integral_use || 0;
let integralSurplus = this.integral_surplus || 0;
// 判断:使用积分不能超过买单金额
let useIntegral = Number(integralUse) > Number(money) ? Number(money) : Number(integralUse);
// 判断:使用积分不能超过剩余可用积分
useIntegral = Number(useIntegral) > Number(integralSurplus) ? Number(integralSurplus) : Number(useIntegral);
this.$set(this, 'integral_use', useIntegral);
}
},
// #ifdef MP
// 分享给好友
onShareAppMessage () {
let pages = getCurrentPages();
let page = pages[pages.length - 1]
let shareData = {
title: '在线买单',
path: page.$page.fullPath || '/' + page.route,
};
// 判断:用户是否登录 已经登录则添加分享人信息,未登录则正常分享
if (this.isLogin) shareData.path = shareData.path + '?spread=' + this.uid;
// 返回最终的分享配置信息
return shareData
},
// 分享到朋友圈
onShareTimeline() {
let shareData = {
title: '在线买单',
query: {},
};
// 判断:用户是否登录 已经登录则添加分享人信息,未登录则正常分享
if (this.isLogin) shareData.query.spread = this.uid;
// 返回最终的分享配置信息
return shareData
},
// #endif
}
</script>
<style scoped lang="scss">
.content-box{
width: 100vw;
min-height: 100vh;
background-color: orange;
padding: 20rpx;
background: linear-gradient(to bottom, #1b79ff, #f6f6f6) no-repeat;
background-size: 100% 300rpx;
background-color: #f6f6f6;
// 公共内容
.box-title{
margin: 30rpx 0;
height: 50rpx;
line-height: 50rpx;
font-size: 28rpx;
padding-left: 20rpx;
font-weight: bold;
position: relative;
}
.box-title:after{
content: "";
position: absolute;
left: 0;
top: calc((50rpx - 30rpx) / 2);
width: 10rpx;
height: 30rpx;
background: #1777ff;
}
// 顶部内容
.top{
width: 100%;
height: 90rpx;
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-between;
align-items: center;
.left{
width: calc(100% - 150rpx);
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: center;
.image{
width: 70rpx;
height: 70rpx;
border-radius: 50%;
margin-right: 15rpx;
}
.name{
max-width: calc(100% - (70rpx + 15rpx + 80rpx + 15rpx));
font-size: 30rpx;
font-weight: bold;
color: #FFFFFF;
}
.change-btn{
width: 80rpx;
height: 40rpx;
text-align: center;
font-size: 24rpx;
border-radius: 40rpx;
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: center;
align-items: center;
background-color: #409eff;
color: #fff;
margin-left: 15rpx;
}
}
.right{
width: 140rpx;
height: 46rpx;
line-height: 44rpx;
border-radius: 45rpx;
text-align: center;
font-size: 26rpx;
border: 2rpx solid #ffffff;
color: #FFFFFF;
}
}
// 买单金额
.money{
position: relative;
padding: 15rpx;
.top-bg-line{
width: 100%;
background-color: #1256ad;
height: 20rpx;
border-radius: 50rpx;
position: absolute;
left: 0;
top: 0;
}
.money-box{
background: #FFFFFF;
position: relative;
width: 100%;
top: -5rpx;
border-radius: 15rpx;
padding: 20rpx;
box-shadow: 0px 3px 5px 0px #ececec;
.title{
height: 60rpx;
line-height: 60rpx;
font-size: 26rpx;
font-weight: bold;
}
.input-box{
height: 70rpx;
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: flex-end;
font-size: 50rpx;
font-weight: bold;
margin: 20rpx 0 30rpx 0;
}
.unit{
margin-right: 15rpx;
}
.money-input{
height: 70rpx;
}
}
}
// 积分抵扣
.integral{
width: 100%;
.box-content{
width: 100%;
background-color: #ffffff;
padding: 20rpx;
border-radius: 15rpx;
.use-info{
width: 100%;
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
justify-content: flex-start;
height: 70rpx;
padding-bottom: 20rpx;
border-bottom: 2rpx solid #fafafa;
.icon-pc-jifen{
background-color: #f4b00d;
color: #ffffff;
height: 40rpx;
width: 40rpx;
line-height: 40rpx;
text-align: center;
font-size: 28rpx;
}
.title{
font-size: 28rpx;
font-weight: bold;
width: 180rpx;
text-align: center;
}
.use-input{
width: calc(100% - 40rpx - 180rpx);
height: 45rpx;
line-height: 45rpx;
}
}
.hold-info{
width: 100%;
height: 70rpx;
padding-top: 20rpx;
display: inline-flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
flex-wrap: nowrap;
.left{
color: #aeaeae;
font-size: 26rpx;
}
.right{
color: #f4564f;
font-size: 26rpx;
}
}
}
}
// 支付方式
.pay-type{
.box-content{
.pay-label:not(:last-child){
margin-bottom: 20rpx;
}
.pay-item{
height: 120rpx;
padding: 20rpx;
width: 100%;
border: 2rpx solid #d9dce4;
border-radius: 15rpx;
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
justify-content: space-around;
.left{
width: calc(100% - 80rpx);
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
justify-content: flex-start;
.animated{
width: 44rpx;
height: 44rpx;
border-radius: 50%;
text-align: center;
line-height: 44rpx;
background-color: #fe960f;
color: #fff;
font-size: 30rpx;
margin-right: 15rpx;
}
.icon-weixin2 {
background-color: #41b035;
}
.icon-icon34 {
background-color: #4295D5;
}
.pay-item-info{
.pay-name{
text-align: left;
border-right: 1px solid #eee;
justify-content: left;
}
.tip{
text-align: left;
font-size: 26rpx;
color: #aaa;
}
}
}
.right{
width: 80rpx;
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
justify-content: flex-end;
}
}
}
}
// 确认支付
.pay-btn{
width: calc(100% - (20rpx * 2));
background: #1777ff;
color: #FFFFFF;
border-radius: 15rpx;
font-size: 30rpx;
text-align: center;
height: 70rpx;
line-height: 70rpx;
position: absolute;
left: 20rpx;
bottom: 150rpx;
}
.not-btn{
background-color: #909399;
color: #fff;
}
}
.mer-content{
background: #FFFFFF;
width: 90vw!important;
height: 90vh!important;
padding: 15rpx;
border-radius: 20rpx;
.search-content{
width: 100%;
height: 60rpx;
line-height: 60rpx;
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
justify-content: flex-start;
.money-input{
width: calc(100% - (100rpx * 2)) !important;
height: 60rpx;
line-height: 60rpx;
}
.search-btn{
width: 100rpx;
text-align: center;
font-size: 28rpx;
background-color: #409eff;
color: #fff;
}
.close-btn{
width: 100rpx;
text-align: center;
font-size: 28rpx;
background-color: #f56c6c;
color: #fff;
}
}
.mer-list{
overflow: auto;
height: calc(100% - 60rpx);
.mer-box{
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
justify-content: space-between;
padding: 20rpx 0;
width: 100%;
.left{
width: calc(100% - 110rpx);
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
justify-content: flex-start;
.image{
width: 70rpx;
height: 70rpx;
border-radius: 50%;
margin-right: 15rpx;
}
.mer-info{
width: calc(100% - 90rpx);
.mer-name{
height: 50rpx;
line-height: 50rpx;
font-size: 30rpx;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.mer-address{
height: 40rpx;
line-height: 40rpx;
font-size: 26rpx;
color: #cccccc;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
}
.selected-btn{
width: 100rpx;
height: 50rpx;
line-height: 50rpx;
text-align: center;
font-size: 28rpx;
background-color: #67c23a;
color: #fff;
border-radius: 50rpx;
}
}
.mer-box:not(:last-child){
border: 2rpx solid #f6f6f6;
}
}
}
</style>