new_shop_app/pages/payment/get_payment.vue

521 lines
11 KiB
Vue
Raw Normal View History

2024-03-15 17:01:27 +08:00
<template>
<view class="container">
2024-03-23 11:03:38 +08:00
<!-- #ifdef APP-PLUS -->
2024-03-15 17:01:27 +08:00
<view v-if="!isWeixin" class="v-navbar">
2024-04-07 17:16:33 +08:00
<u-navbar title="支付" :safeAreaInsetTop="false" :fixed="false" @leftClick="leftClick" bgColor="transparent"
2024-03-19 09:32:24 +08:00
leftIconColor="#333" :titleStyle="{color:'#333',fontWeight:'bold',fontSize:'32rpx'}">
2024-03-15 17:01:27 +08:00
</u-navbar>
</view>
2024-03-23 11:03:38 +08:00
<!-- #endif -->
2024-03-23 13:47:13 +08:00
<!-- #ifdef H5 -->
<view style="height: 100rpx;"></view>
<!-- #endif -->
2024-03-19 09:32:24 +08:00
<view style="height: 50rpx;"></view>
2024-03-19 11:49:20 +08:00
<view class="wrap">
2024-03-18 18:05:09 +08:00
<view class="shop">
<image src="@/static/shop_logo.webp" style="width: 62rpx;height: 54rpx;" />
2024-03-19 09:32:24 +08:00
<text class="shop-name" v-if="mer_name">{{mer_name||''}}</text>
2024-03-15 17:01:27 +08:00
</view>
<!-- 付款金额 -->
<view class="v-con">
2024-03-18 18:05:09 +08:00
<view class="v-con-text">订单金额</view>
2024-03-19 11:49:20 +08:00
<view class="v-con-input" @click="handleOpenKeyboard">
2024-03-18 18:05:09 +08:00
<text style="color: #303133;font-size:32rpx;"></text>
2024-03-19 11:49:20 +08:00
<u--input type="text" fontSize="23" height="112rpx" placeholder="请输入金额" border="none" readonly
2024-03-20 11:55:11 +08:00
v-model="cartForm.total_amount" placeholderStyle="color:#999;font-size:32rpx">
2024-03-15 17:01:27 +08:00
</u--input>
2024-03-19 11:49:20 +08:00
<view class="placeholder"></view>
2024-03-15 17:01:27 +08:00
</view>
2024-03-18 18:05:09 +08:00
<view class="v-con-group">
2024-04-01 13:44:37 +08:00
<!-- <view class="v-con-group-title">
2024-03-18 18:05:09 +08:00
<view class="v-con-group-title-left">套餐详情</view>
<view class="v-con-group-title-right" @click.stop="handleOpen">
<text>{{isOpen?'折叠':'展开'}}</text>
<u-icon :name="isOpen?'arrow-down' : 'arrow-right'" size="15"></u-icon>
</view>
2024-04-01 13:44:37 +08:00
</view> -->
<!-- <scroll-view scroll-y>
2024-03-18 18:05:09 +08:00
<view class="v-con-group-list" :style="{'max-height':isOpen?'400rpx':'0'}">
<block v-for="(item,indx) in merchantInfo" :key="indx">
<view class="v-con-group-list-item">
<image :src="item.image" :showLoading="true" style="width:86rpx;height:86rpx;" />
<text class="line1">{{item.store_name}}</text>
</view>
</block>
</view>
2024-04-01 13:44:37 +08:00
</scroll-view> -->
2024-03-15 17:01:27 +08:00
</view>
</view>
2024-04-07 17:16:33 +08:00
<!-- #ifdef H5 -->
<!-- <view class="v-btn-wrap" @click="submitOrder">
2024-03-23 13:47:13 +08:00
<u-button class="v-btn" :loading="loading"
:text="Number(cartForm.total_amount||0).toFixed(2)+'元 确认支付'"></u-button>
2024-04-07 17:16:33 +08:00
</view> -->
<!-- #endif -->
2024-03-15 17:01:27 +08:00
<!-- 登陆 -->
2024-04-03 16:56:52 +08:00
<authorize :isAuto="isAuto" :is-pay="true" :isShowAuth="isShowAuth" @authColse="authColse"
@onLoadFun="onLoadFun" />
2024-03-15 17:01:27 +08:00
</view>
<!-- 无商户信息提示 -->
2024-03-18 18:05:09 +08:00
<!-- <view class="empty">
2024-03-20 11:55:11 +08:00
<authorize v-show="!isWeixin" ref="authRef" :isAuto="isAuto" :isGoIndex="false" :isShowAuth="isShowAuth"
@authColse="authColse" @onLoadFun="onLoadFun">
</authorize>
</view> -->
<!-- 键盘 -->
2024-03-19 11:49:20 +08:00
<popups ref="popups" @confirm="handleConfirm" @clear="handleClear" @change="handleChange"></popups>
2024-03-15 17:01:27 +08:00
</view>
</template>
<script>
2024-03-18 18:05:09 +08:00
var that;
2024-03-21 18:05:01 +08:00
2024-03-15 17:01:27 +08:00
import {
getProductInfo,
addCart,
orderCheck
} from "@/api/payment.js";
import Cache from '@/utils/cache';
import {
mapGetters
} from "vuex";
import authorize from '@/components/Authorize';
2024-03-18 18:05:09 +08:00
import {
Toast
} from "../../libs/uniApi";
2024-03-19 11:49:20 +08:00
import popups from "@/components/popups/index.vue";
2024-03-15 17:01:27 +08:00
export default {
components: {
2024-03-18 18:05:09 +08:00
authorize,
2024-03-19 11:49:20 +08:00
popups
2024-03-15 17:01:27 +08:00
},
computed: {
...mapGetters(['isLogin']),
},
data() {
return {
2024-03-18 18:05:09 +08:00
isEmpty: true,
2024-03-19 09:32:24 +08:00
// isWeixin: this.$wechat.isWeixin(),
isWeixin: false,
2024-03-15 17:01:27 +08:00
cartForm: {
product_id: '',
product_attr_unique: '',
cart_num: 1,
is_new: 1,
product_type: 0,
source: 999,
total_amount: ''
},
merchantInfo: '',
checkForm: {
address_id: '',
cart_id: [],
consumption_id: '',
product_type: 0,
source: 999,
takes: [],
use_coupon: {},
use_integral: false
},
isAuto: false, //没有授权的不会自动授权
isShowAuth: false, //是否隐藏授权
mer_id: '',
2024-03-18 18:05:09 +08:00
changeTxt: '展开',
2024-03-19 11:49:20 +08:00
isOpen: false,
2024-03-18 18:05:09 +08:00
keyBoardShow: false,
2024-03-23 13:47:13 +08:00
mer_name: '',
loading: false
2024-03-15 17:01:27 +08:00
}
},
onLoad(opt) {
2024-03-18 18:05:09 +08:00
that = this;
2024-03-15 17:01:27 +08:00
this.mer_id = opt.mer_id;
},
2024-03-19 11:49:20 +08:00
2024-03-15 17:01:27 +08:00
onShow() {
if (!this.isLogin) {
Cache.set("login_back_url_weixin", "/" + getCurrentPages()[0].route + "?mer_id=" + this.mer_id);
this.isAuto = true;
this.isShowAuth = true;
2024-03-18 18:05:09 +08:00
if (this.isWeixin) {
this.$nextTick(() => {
this.$refs.authRef.toWecahtAuth();
})
}
2024-03-15 17:01:27 +08:00
} else {
2024-03-18 18:05:09 +08:00
this.checkForm.cart_id = [];
2024-03-20 11:55:11 +08:00
this.getProductInfoByMerid();
2024-03-15 17:01:27 +08:00
}
},
methods: {
2024-03-19 11:49:20 +08:00
// 打开键盘
handleOpenKeyboard() {
if (!this.isLogin) {
Cache.set("login_back_url_weixin", "/" + getCurrentPages()[0].route + "?mer_id=" + this.mer_id);
this.isAuto = true;
this.isShowAuth = true;
if (this.isWeixin) {
this.$nextTick(() => {
this.$refs.authRef.toWecahtAuth();
})
}
} else {
2024-03-23 13:47:13 +08:00
this.$refs.popups.handleOpen('money');
2024-03-19 11:49:20 +08:00
}
},
2024-03-20 11:55:11 +08:00
// 键盘提交
2024-03-19 11:49:20 +08:00
handleConfirm(e) {
if (!e) return;
this.cartForm.total_amount = e;
this.submitOrder();
},
// 清空
handleClear() {
this.cartForm.total_amount = '';
2024-03-20 11:55:11 +08:00
this.merchantInfo = [];
2024-03-19 11:49:20 +08:00
},
// 输入数字
handleChange(e) {
this.cartForm.total_amount = e;
2024-03-22 11:07:06 +08:00
uni.$u.debounce(that.getProductInfoByMerid, 200)
2024-03-15 17:01:27 +08:00
},
leftClick(e) {
uni.switchTab({
url: '/pages/index/index'
})
},
2024-03-18 18:05:09 +08:00
2024-03-15 17:01:27 +08:00
// 授权关闭
authColse: function(e) {
this.isShowAuth = e;
},
2024-03-18 18:05:09 +08:00
2024-03-15 17:01:27 +08:00
onLoadFun() {
this.getProductInfoByMerid(this.mer_id);
this.isShowAuth = false;
},
// 提交订单
2024-03-18 18:05:09 +08:00
async submitOrder() {
2024-04-01 13:44:37 +08:00
if (!this.cartForm.total_amount || this.cartForm.total_amount == 0) {
2024-03-15 17:01:27 +08:00
return this.$util.Tips({
2024-04-01 13:44:37 +08:00
title: "请输入付款金额"
2024-03-15 17:01:27 +08:00
})
}
2024-04-02 16:37:05 +08:00
if (!this.merchantInfo || this.merchantInfo.length == 0) {
return this.$util.Tips({
title: "该商家当前价格下,无对应商品!"
})
}
2024-03-23 13:47:13 +08:00
this.loading = true;
2024-04-01 13:44:37 +08:00
if (that.merchantInfo && that.merchantInfo.length > 0) {
// 循环加入购物车
for (var i = 0; i < that.merchantInfo.length; i++) {
let info = {
product_id: that.merchantInfo[i].product_id,
product_attr_unique: that.merchantInfo[i].unique,
cart_num: that.merchantInfo[i].num,
is_new: 1,
product_type: 0,
source: 999,
total_amount: that.cartForm.total_amount
};
2024-03-15 17:01:27 +08:00
2024-04-01 13:44:37 +08:00
try {
let res = await addCart(info);
that.checkForm.cart_id.push(res.data.cart_id);
} catch (err) {
that.loading = false;
return that.$util.Tips({
title: err.message || err.msg || err
})
}
2024-03-18 18:05:09 +08:00
}
2024-04-01 13:44:37 +08:00
if (that.checkForm.cart_id && that.checkForm.cart_id.length > 0) {
return uni.navigateTo({
url: "/pages/payment/settlement?cartId=" + this.checkForm.cart_id.join(',') +
"&money=" + this.cartForm.total_amount,
2024-03-22 11:07:06 +08:00
})
2024-04-01 13:44:37 +08:00
}
2024-03-22 11:07:06 +08:00
}
2024-03-15 17:01:27 +08:00
},
2024-03-20 11:55:11 +08:00
// 折叠商品
2024-03-18 18:05:09 +08:00
handleOpen() {
this.isOpen = !this.isOpen;
},
2024-03-20 11:55:11 +08:00
// 根据店铺获取商品
2024-03-18 18:05:09 +08:00
getProductInfoByMerid(merid, money) {
2024-03-23 13:47:13 +08:00
this.loading = true;
2024-03-15 17:01:27 +08:00
getProductInfo({
2024-03-18 18:05:09 +08:00
mer_id: that.mer_id,
money: that.cartForm.total_amount
2024-03-15 17:01:27 +08:00
}).then(res => {
2024-03-23 13:47:13 +08:00
this.loading = false;
2024-04-02 16:37:05 +08:00
if (!that.cartForm.total_amount && !this.mer_name) {
2024-03-18 18:05:09 +08:00
this.mer_name = res.data.merchant;
} else {
that.merchantInfo = res.data.list;
2024-03-26 12:00:35 +08:00
if (res.data.count == 0) {
that.$util.Tips({
title: "当前价格下,暂无商品信息~"
})
}
2024-03-18 18:05:09 +08:00
}
2024-03-15 17:01:27 +08:00
}).catch((err) => {
2024-03-23 13:47:13 +08:00
that.loading = false;
2024-03-18 18:05:09 +08:00
that.$util.Tips({
2024-03-15 17:01:27 +08:00
title: err.message || err.msg || err
2024-03-20 17:35:35 +08:00
}, () => {
2024-03-15 17:01:27 +08:00
})
// #ifdef APP
setTimeout(() => {
uni.navigateBack({
delta: 1
})
}, 1500)
// #endif
// #ifndef APP
that.isEmpty = true;
// #endif
})
}
}
}
</script>
2024-03-19 17:11:30 +08:00
<style lang="scss">
2024-03-15 17:01:27 +08:00
page {
2024-03-19 11:49:20 +08:00
background-color: #F9F9F9;
2024-03-15 17:01:27 +08:00
}
.empty {
margin: 0;
text-align: center;
image,
uni-image {
display: inline-block;
width: 414rpx;
height: 305rpx;
}
text {
display: block;
color: #666;
font-size: 26rpx;
}
}
.container {
position: relative;
height: 100vh;
2024-03-18 18:05:09 +08:00
// background-image: url("https://lihai001.oss-cn-chengdu.aliyuncs.com/def/c582c202402291601584806.webp");
2024-03-15 17:01:27 +08:00
background-size: 100% auto;
background-repeat: no-repeat;
padding-top: var(--status-bar-height);
.v-desc {
position: absolute;
top: 196rpx;
z-index: 10;
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
padding: 0 20rpx;
background: transparent;
.v-desc-main {
margin-bottom: 30rpx;
font-weight: 600;
font-size: 42rpx;
color: #FFFFFF;
}
.v-desc-sub {
font-weight: 500;
font-size: 24rpx;
color: #FFFFFF;
}
}
2024-03-18 18:05:09 +08:00
.wrap {
margin: 0 52rpx 0 54rpx;
}
.shop {
display: flex;
align-items: center;
margin-bottom: 54rpx;
text {
margin-left: 32rpx;
}
}
2024-03-15 17:01:27 +08:00
.v-con {
2024-03-18 18:05:09 +08:00
margin: 0 auto 150rpx;
2024-03-15 17:01:27 +08:00
.v-con-text {
font-weight: 400;
2024-03-18 18:05:09 +08:00
font-size: 30rpx;
color: #000000;
2024-03-15 17:01:27 +08:00
}
.v-con-input {
2024-03-18 18:05:09 +08:00
position: relative;
2024-03-15 17:01:27 +08:00
display: flex;
align-items: center;
2024-03-18 18:05:09 +08:00
height: 112rpx;
margin-bottom: 32rpx;
2024-03-15 17:01:27 +08:00
border-bottom: 1rpx solid #D6D6D6;
2024-03-18 18:05:09 +08:00
/deep/.uni-input-input {
height: 112rpx;
font-weight: bold;
font-size: 72rpx;
}
text {
font-weight: 400;
font-size: 32rpx;
color: #000000;
}
2024-03-19 11:49:20 +08:00
.placeholder {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
2024-03-15 17:01:27 +08:00
}
.v-wrap {
display: flex;
align-items: center;
padding-left: 20rpx;
width: 666rpx;
height: 210rpx;
.v-wrap-money {
display: flex;
align-items: center;
color: #FF5E0C;
margin-right: 30rpx;
.icon {
font-size: 34rpx;
}
.num {
font-size: 46rpx;
display: inline-block;
overflow: auto;
width: 180rpx;
}
}
.v-wrap-desc {
.v-wrap-desc-main {
margin-bottom: 16rpx;
font-weight: 600;
font-size: 32rpx;
color: #2E2E2E;
}
.v-wrap-desc-sub {
font-weight: 400;
font-size: 24rpx;
color: #2E2E2E;
}
}
}
2024-03-18 18:05:09 +08:00
.v-con-group {
.v-con-group-title {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 32rpx;
.v-con-group-title-left {
font-weight: 400;
font-size: 30rpx;
color: #000000;
}
.v-con-group-title-right {
display: flex;
align-items: center;
text {
margin-right: 18rpx;
font-weight: 400;
font-size: 30rpx;
color: #000000;
}
}
}
.v-con-group-list {
transition: max-height linear .1s;
.v-con-group-list-item {
display: flex;
align-items: center;
margin-bottom: 14rpx;
text {
margin-left: 30rpx;
font-size: 26rpx;
color: #333333;
}
}
2024-03-15 17:01:27 +08:00
}
}
}
2024-03-18 18:05:09 +08:00
.v-btn-wrap {
2024-03-23 13:47:13 +08:00
display: flex;
justify-content: center;
align-items: center;
2024-03-18 18:05:09 +08:00
width: 100%;
height: 90rpx;
background: #40AE36;
border-radius: 10rpx;
2024-03-23 13:47:13 +08:00
/deep/.u-button {
background: transparent;
color: #fff;
height: 100%;
}
/deep/.u-loading-icon__spinner {
color: #fff !important;
margin-right: 10rpx;
}
2024-03-23 17:03:21 +08:00
/deep/.u-button__text {
font-size: 32rpx !important;
}
2024-03-18 18:05:09 +08:00
}
2024-03-15 17:01:27 +08:00
}
</style>