123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541 |
- <template>
- <view class="app">
- <view class="price-box">
- <text>支付金额</text>
- <text class="price">{{ money }}</text>
- </view>
- <view class="pay-type-list">
- <view class="type-item b-b" @click="changePayType(1)" v-if="show">
- <uni-icons type="weixin" color="#00B848" size="25" />
- <view class="con">
- <text class="tit">微信支付</text>
- <text>推荐使用微信支付</text>
- </view>
- <label class="radio"><radio value="" color="#5dbc7c" :checked="payType == 1"></radio></label>
- </view>
- <!-- #ifdef APP-PLUS -->
- <view class="type-item b-b" @click="changePayType(2)" v-if="show">
- <text class="icon iconfont iconzhifubao"></text>
- <view class="con"><text class="tit">支付宝支付</text></view>
- <label class="radio"><radio value="" color="#5dbc7c" :checked="payType == 2"></radio></label>
- </view>
- <!-- #endif -->
- <view class="type-item flex_item" @click="changePayType(3)" v-if="show">
- <view class="img"><image class="yue" src="../../static/img/yue.png"></image></view>
- <view class="con">
- <text class="tit">余额支付</text>
- <text>可用余额 ¥{{ now_money }}</text>
- </view>
- <label class="radio"><radio value="" color="#5dbc7c" :checked="payType == 3"></radio></label>
- </view>
- </view>
- <text class="mix-btn" :class="{ clickbg: payLoding }" @click="!payLoding ? confirm() : ''">确认支付</text>
-
- <!-- <uni-popup ref="popup" type="center">
- <view class="pop-box">
- <view class="pop-text">
- 为了方便您查看您的拼团详细状况,我们需要您的通知授权
- </view>
- <view class="pop-button" @click="tongzhi()">
- 开启通知
- </view>
- </view>
- </uni-popup> -->
-
- </view>
- </template>
- <script>
- import { computedOrderkey, balance, createOrderkey, orderPay } from '@/api/money.js';
- import { orderDetail } from '@/api/order.js';
- import { mapState } from 'vuex';
- import uniPopup from '@/components/uni-popup/uni-popup.vue'
- export default {
- components: {
- uniPopup
- },
- data() {
- return {
- payType: 1, //支付类型
- // #ifdef H5
- payName: 'weixin',
- // #endif
- // #ifdef MP-WEIXIN
- payName: 'weixin',
- // #endif
- orderInfo: {},
- money: 0.0, //订单金额
- now_money: 0.0, //余额
- orderKey: '',
- orderId: '', //保存订单id
- payLoding: false, //判断是否支付中
- type: '', //判断是否从订单中进入
- // #ifdef H5
- froms: '', //保存h5中数据来源对象
- // #endif
- pinkid: '', //保存拼团商品id
- estimated_time:'',//配送时间
- isBuyVip:"",
- Deliveryid:'',
- free: '', // 是否需要食物 0是 1否 1 payName = 'free'
- pink: 0, // 是否為拼團
- show: true ,// 是否显示
- pinkUser: '' ,//是否为团长
- goodsDetail:'',
- isPink: 0, // 是否为拼团商品 0 普通 1 拼团
- klonId: '', // 接龙id
- };
- },
- computed: {
- // #ifdef H5
- ...mapState(['weichatObj'])
- // #endif
- },
- onLoad(options) {
- console.log(options)
- // 是否需要食物
- this.free = options.free;
- if(this.free == 1) {
- this.show == false
- }
- if(options.pinkUser) {
- this.pinkUser = options.pinkUser;
- }
- if(options.pink){
- this.pink = options.pink;
- }
- if(options.klonId){
- this.klonId = options.klonId;
- }
- console.log(this.pink,987)
- if(options.estimated_time){
- this.estimated_time = options.estimated_time;
- }
- if (options.type == 1) {
- this.type = 1;
- this.orderId = options.ordid;
- this.money = options.money;
- } else {
- this.orderKey = options.key;
- this.free = options.free;
- this.isPink = options.isPink;
- let prepage = this.$api.prePage();
- let isBuyVip = '';
- if(prepage.isBuyVip){
- isBuyVip = prepage.isBuyVip;
- }else{
- isBuyVip = '';
- }
- this.isBuyVip = isBuyVip;
- this.Deliveryid = prepage.Deliveryid;
- computedOrderkey({
- isBuyVip:prepage.isBuyVip,//是否开通美卡
- estimated_time:prepage.estimated_time,
- orderkey: this.orderKey,
- couponId: prepage.couponChecked.id, //优惠券编号
- goCouponId: prepage.Deliveryid, //配送券编号
- productCouponId: prepage.GoodsChecked.id, //商品券编号
- addressId: prepage.addressData.id, //地址编号
- useIntegral: prepage.checkedPoints ? 1 : 0,
- is_pink_free: this.free ,// 是否需要实物
- isPink: this.isPink, // 是否为拼团商品 0 普通 1 拼团
- pinkId: this.pinkid, // 拼团id
- jl_id: this.klonId, // 接龙id
- }).then(({ data }) => {
- // 获取支付金额
- this.money = data.result.pay_price;
- });
- }
- // 保存pinkid
- if (options.pinkid) {
- this.pinkid = options.pinkid;
- }
- // 载入余额
- balance({}).then(({ data }) => {
- // 获取余额
- this.now_money = data.now_money;
- });
- },
- // onReady() {
- // let obj = this;
- // console.log(obj.pink)
- // obj.popimg();
- // },
- methods: {
-
- // popimg() {
- // console.log(111)
- // if( this.pink == 1 ) {
- // console.log(this.pink,777)
- // this.$refs.popup.open()
- // }
- // },
- //选择支付方式
- changePayType(type) {
- this.payType = type;
- if(this.free == 1) {
- this.payName = 'free'
- } else {
- if (this.payType == 1) {
- this.payName = 'weixin';
- }
- if (this.payType == 2) {
- this.payName = 'ali';
- }
- if (this.payType == 3) {
- this.payName = 'yue';
- }
- }
-
- },
-
- // 消息通知
- // tongzhi() {
- // this.$refs.popup.close()
- // wx.requestSubscribeMessage({
- // tmplIds: ['upq4J5ZQqRx-se7KgRdWS5d-l7EXKdAKT8W_J6HF70g','XKBGRmGwCzpT6oZZ0m6CF8nOS-eyGoDAI2KMSO4R4JY', '93fUZzhSsYNpBcDgFSgTDk3raKodD-bedAvfl3V4Iho'],
- // success (res) {
- // uni.showToast({
- // title:'开启通知成功'
- // })
- // }
- // })
- // },
-
- // 支付金额
- orderMoneyPay() {
- let obj = this;
- if(obj.free == 1) {
- obj.payName = 'free'
- }
- 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.payName //支付类型 weixin-微信 yue-余额
- })
- .then(e => {
- // 判断是否为余额支付
- if (obj.payName == 'yue') {
- if(obj.free == 1) {
- obj.payName == 'free'
- }
- if (e.status == 200) {
- obj.paySuccessTo();
- } else {
- obj.$api.msg(msg);
- }
- }
- // #ifdef H5
- if (obj.payName == 'weixin') {
- let da = e.data.result.jsConfig;
- obj.weichatObj.chooseWXPay({
- timestamp: da.timestamp,
- nonceStr: da.nonceStr,
- package: da.package,
- signType: da.signType,
- paySign: da.paySign,
- success: function(res) {
- obj.paySuccessTo();
- },
- fail: function(res) {
- console.log(res, '失败');
- console.log(res.errMsg);
- }
- });
- }
- // #endif
- // #ifdef MP-WEIXIN
- if (obj.payName == 'weixin') {
- let da = e.data.result.jsConfig;
- wx.requestPayment({
- timeStamp: da.timestamp,
- nonceStr: da.nonceStr,
- package: da.package,
- signType: da.signType,
- paySign: da.paySign,
- success: function(res) {
- obj.paySuccessTo();
- }
- });
- }
- // #endif
- obj.payLoding = false;
- })
- .catch(e => {
- // 支付完成
- obj.payLoding = false;
- console.log(e);
- });
- },
- // 支付成功跳转
- paySuccessTo() {
- let obj = this;
- console.log(obj.pink,22)
- console.log(obj.pink == 'true',33)
- if(obj.pink == 1){
- console.log('111111')
- orderDetail({}, obj.orderId).then(e => {
- this.goodsDetail = e.data;
- console.log(e.data)
- this.$nextTick(() => {
- uni.navigateTo({
- url: '/pages/groupBooking/groupdetails?id='+ e.data.pink_id + '&pinkUser=' + obj.pinkUser + '&order_id=' + obj.orderId + '&pink=' + obj.pink + '&tongzhi=1'
- })
- });
- });
- }
- if(obj.pink == 0){
- console.log('222222')
- uni.redirectTo({
- url: '/pages/money/paySuccess?orderId='+ obj.orderId
- });
- }
- },
- //确认支付
- confirm: async function() {
- let obj = this;
- // 判断是否余额不足
- if (obj.payName == 'yue' && +obj.now_money < obj.money) {
- uni.showModal({
- title: '提示',
- content: '账户余额不足!',
- showCancel: false,
- success: res => {},
- fail: () => {},
- complete: () => {}
- });
- return;
- }
-
- if(obj.free == 1) {
- obj.payName = 'free'
- }
- // 支付中
- obj.payLoding = true;
- // #ifdef H5
- // 获取当前是否为微信浏览器
- obj.froms = uni.getStorageSync('weichatBrowser') || '';
- // #endif
- // 判断是否为未支付订单中跳转进入
- if (obj.type != 1) {
- // 初次生成订单
- obj.firstCreateOrder();
- } else {
- // 判断是否支付宝支付
- if (obj.payName == 'ali') {
- obj.payAli();
- }else{
- // 已经生成订单未支付
- obj.orderMoneyPay();
- }
- }
- },
- // 初次订单创建
- firstCreateOrder() {
- let obj = this;
- // 获取下单页面数据
- if(obj.free == 1) {
- obj.payName = 'free'
- }
- let prepage = obj.$api.prePage();
- let isBuyVip = '';
- if(prepage.isBuyVip){
- isBuyVip = prepage.isBuyVip;
- }else{
- isBuyVip = '';
- }
- let data = {
- isBuyVip:isBuyVip,//美卡
- productCouponId:prepage.GoodsChecked.id,//商品券
- goCouponId:prepage.Deliveryid,//配送券
- real_name: prepage.addressData.real_name, //联系人名称
- phone: prepage.addressData.phone, //联系人号码
- couponId: prepage.couponChecked.id, //优惠券编号
- addressId: prepage.addressData.id, //支付地址id
- useIntegral: prepage.checkedPoints ? 1 : 0, //是否积分抵扣1为是0为否
- payType: obj.payName, //支付类型 weixin-微信 yue-余额
- estimated_time:obj.estimated_time,
- mark: prepage.desc, //备注
- isPink: obj.isPink, // 是否为拼团商品 0 普通 1 拼团
-
- // #ifdef H5
- from: obj.froms ? 'weixin' : 'H5', //来源
- // #endif
- // #ifdef MP-WEIXIN
- from: 'routine', //来源
- // #endif
- // #ifdef APP-PLUS
- from: 'app', //来源
- // #endif
- shipping_type: 1 //提货方式 1 快递 2自提
- };
- // 判断是否拼团商品
- if (obj.pinkid) {
- data.pinkId = obj.pinkid;
- }
- // 判断是否接龙商品
- if (obj.klonId) {
- data.jl_id = obj.klonId;
- }
- // 生成订单
- createOrderkey(data, obj.orderKey)
- .then(({ data, status, msg }) => {
- // 判断是否支付失败
- if (data.status == 'ORDER_EXIST') {
- uni.showModal({
- title: '提示',
- content: msg,
- showCancel: false
- });
- obj.payLoding = false;
- return;
- }
- // 保存订单号
- obj.orderId = data.result.orderId;
- // 判断是否为余额支付
- if (obj.payName == 'yue') {
- if (status == 200 && data.status == 'SUCCESS') {
- obj.paySuccessTo();
- } else {
- obj.$api.msg(msg);
- }
- } else if(status == 200 && data.status == 'SUCCESS' && msg == '购买成功') {
- obj.paySuccessTo();
- } else {
- // 立即支付
- obj.orderMoneyPay();
- }
- })
- .catch(e => {
- obj.payLoding = false;
- console.log(e);
- this.$api.msg(e.msg)
- });
- }
- }
- };
- </script>
- <style lang="scss">
- .app {
- width: 100%;
- }
- .price-box {
- background-color: #fff;
- height: 265upx;
- 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;
- }
- .img{
- color: #fe8e2e;
- width: 52rpx;
- height: 52rpx;
- image{
- width: 100%;
- height: 100%;
- }
- }
- .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;
- padding-left: 25rpx;
- font-size: $font-sm;
- color: $font-color-light;
- }
- }
- .mix-btn {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 630upx;
- height: 80upx;
- margin: 80upx auto 30upx;
- font-size: $font-lg;
- color: #fff;
- background-color: $base-color;
- border-radius: 10upx;
- /* box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4); */
- }
- .clickbg {
- background-color: $color-gray !important;
- }
- .pop-box {
- background: #FFFFFF;
- width: 600rpx;
- border-radius: 20rpx;
- padding: 30rpx 20rpx;
- .pop-text {
- text-align: center;
- font-size: 32rpx;
- }
- .pop-button {
- margin: 0 auto;
- font-size: 30rpx;
- margin-top: 30rpx;
- padding: 10rpx 0;
- border-radius: 15rpx;
- text-align: center;
- width: 200rpx;
- color: #FFFFFF;
- background: $base-color;
- }
- }
- </style>
|