Browse Source

支付:方案1

test
Enzo 4 years ago
parent
commit
0835b89976
  1. 2
      App.vue
  2. 6
      pages.json
  3. 117
      pages/order/confirm_atonce.vue
  4. 209
      pages/order/confirm_fromorder.vue
  5. 84
      pages/order/confirm_order.vue
  6. 4
      pages/order/order.vue
  7. 33
      pages/order/order_details.vue

2
App.vue

@ -20,7 +20,7 @@
setTimeout(() => { setTimeout(() => {
if(e.referrerInfo.extraData) { if(e.referrerInfo.extraData) {
uni.$emit('payState',{msg:e.referrerInfo.extraData.backPayState})
uni.$emit('payState',{msg:e.referrerInfo.extraData.backPayState,payorder_id:e.referrerInfo.extraData.payorder_id})
uni.$emit('order_id',{msg:e.referrerInfo.extraData.order_id}) uni.$emit('order_id',{msg:e.referrerInfo.extraData.order_id})
console.log('订单状态',e.referrerInfo.extraData.backPayState) console.log('订单状态',e.referrerInfo.extraData.backPayState)

6
pages.json

@ -70,6 +70,12 @@
"navigationBarTitleText": "确认订单" "navigationBarTitleText": "确认订单"
} }
}, },
{
"path": "pages/order/confirm_fromorder",
"style": {
"navigationBarTitleText": "确认订单"
}
},
{ {
"path": "pages/order/order_details", "path": "pages/order/order_details",
"style": { "style": {

117
pages/order/confirm_atonce.vue

@ -1,13 +1,14 @@
<template>
<view></view>
</template>
<template></template>
<script> <script>
export default { export default {
data() { data() {
return { return {
order_id: 0, order_id: 0,
timesIndex: 0
timesIndex: 0,
userInfo: {},
payErr: {},
paySuccecc: {}
} }
}, },
onShow(e) { onShow(e) {
@ -27,58 +28,39 @@
// //
getUserProfile() { getUserProfile() {
let that = this let that = this
return new Promise((resolve, rejecj) => {
uni.login({
complete: result => {
if (result.errMsg == 'login:ok') {
let code = result.code;
that.$http(that.API.API_WXLOGIN, {
code
}).then(res => {
uni.setStorageSync('userinfo', res.data);
resolve(res.data);
if(res.data) {
that.payOnce();
}
// uni.showModal({
// title: '',
// content: JSON.stringify(res.data),
// confirmColor: '#1998FE',
// showCancel: false,
// success(res2) {
// if (res2.confirm) {
// that.payOnce();
// }
// }
// });
})
}
uni.login({
complete: result => {
if (result.errMsg == 'login:ok') {
let code = result.code;
that.$http(that.API.API_WXLOGIN, {
code
}).then(res => {
uni.setStorageSync('userinfo', res.data);
that.userInfo = JSON.stringify(res.data)
if(res.data) {
uni.showModal({
title: '支付提示',
content: '确认支付吗?',
confirmColor: '#1998FE',
showCancel: false,
success(res2) {
if (res2.confirm) {
that.payOnce();
}
}
});
}
})
} }
})
}
}) })
}, },
payOnce() { payOnce() {
let that = this
uni.showModal({
title: '订单id提示',
content: JSON.stringify(that.order_id),
showCancel: false,
});
let that = this;
that.$http(that.API.API_LF_PAY, { that.$http(that.API.API_LF_PAY, {
id: that.order_id id: that.order_id
}).then(res => { }).then(res => {
uni.showModal({
title: '进入支付接口',
content: '',
showCancel: false,
});
uni.showModal({
title: '接口返回信息',
content: JSON.stringify(res),
showCancel: false,
});
uni.requestPayment({ uni.requestPayment({
orderInfo: res.data.order_num, orderInfo: res.data.order_num,
timeStamp: res.data.timeStamp, timeStamp: res.data.timeStamp,
@ -87,27 +69,19 @@
signType: res.data.signType, signType: res.data.signType,
paySign: res.data.paySign, paySign: res.data.paySign,
success: (res) => { success: (res) => {
uni.showModal({
title: '支付成功提示',
content: JSON.stringify(res),
showCancel: false,
});
wx.navigateBackMiniProgram({ wx.navigateBackMiniProgram({
extraData: { extraData: {
backPayState: true
backPayState: true,
payorder_id: that.order_id
}, },
success(res) {} success(res) {}
}) })
}, },
fail: (err) => { fail: (err) => {
uni.showModal({
title: '支付失败提示',
content: JSON.stringify(err),
showCancel: false,
});
wx.navigateBackMiniProgram({ wx.navigateBackMiniProgram({
extraData: { extraData: {
backPayState: false
backPayState: false,
payorder_id: that.order_id
}, },
success(res) {} success(res) {}
}) })
@ -115,36 +89,21 @@
}) })
}).catch(err => { }).catch(err => {
uni.showModal({ uni.showModal({
title: '接口报错',
content: JSON.stringify(err),
title: '提示',
content: '支付获取订单失败',
showCancel: false, showCancel: false,
success(res2) { success(res2) {
if (res2.confirm) { if (res2.confirm) {
wx.navigateBackMiniProgram({ wx.navigateBackMiniProgram({
extraData: { extraData: {
backPayState: false
backPayState: false,
payorder_id: that.order_id
}, },
success(res) {} success(res) {}
}) })
} }
} }
}); });
// uni.showModal({
// title: '',
// content: '',
// confirmColor: '#1998FE',
// showCancel: false,
// success(res2) {
// if (res2.confirm) {
// wx.navigateBackMiniProgram({
// extraData: {
// backPayState: false
// },
// success(res) {}
// })
// }
// }
// });
}) })
} }
} }

209
pages/order/confirm_fromorder.vue

@ -0,0 +1,209 @@
<template>
<view v-if="$isRight(goods_details)">
<view class="lf-bg-white lf-p-t-30 lf-p-b-30 lf-p-l-32 lf-p-r-32">
<view class="lf-row-between">
<image :src="goods_details.picture" mode="aspectFill" style="width: 240rpx; height: 240rpx;border-radius: 20rpx;"></image>
<view class="flex-sub padding-left-sm">
<view class="bref-box lf-font-32 lf-color-333 lf-line-2" style="height: 88rpx;line-height: 44rpx;">
{{goods_details.title}}
</view>
<view class="flex lf-m-t-25 align-center text-center">
<text class="block lf-color-gray lf-font-24" style="line-height: 40rpx;">数量</text>
<text class="lf-m-l-10 lf-color-gray lf-font-24">x {{goods_details.num}}</text>
</view>
<view class="flex align-center text-center lf-m-t-25">
<lf-price :price="goods_details.price" />
<view class="lf-m-l-20 lf-line-through lf-color-gray">
{{goods_details.original_price}}
</view>
</view>
</view>
</view>
</view>
<!-- <self-line/>
<view class="bg-white">
<view class="cu-bar padding-lr">
<text class="lf-color-555 lf-font-28">优惠</text>
<view v-if="goods_details.coupon != ''">
<text class="lf-color-price lf-font-28 lf-m-l-10" v-for="(item,index) of goods_details.coupon">{{item.tag}}</text>
</view>
<view v-else>
<text class="lf-color-price lf-font-28 lf-m-l-10">暂无优惠</text>
</view>
</view>
</view> -->
<self-line/>
<view class="bg-white" v-if="enter_type!=1">
<view class="cu-bar padding-lr solid-bottom">
<text class="lf-color-555 lf-font-28">联系人</text>
<input type="text" v-model="contact" class="lf-color-999 lf-font-28 lf-text-right" placeholder="请输入联系人" />
</view>
<view class="cu-bar padding-lr">
<text class="lf-color-555 lf-font-28">联系方式</text>
<input type="text" v-model="phone" class="lf-color-999 lf-font-28 lf-text-right" placeholder="请输入联系电话" maxlength="11" />
</view>
</view>
<self-line/>
<view class="bg-white" v-if="enter_type!=1">
<view class="lf-p-t-30 lf-p-l-32 lf-p-b-36">
<view class="lf-font-28 lf-color-555">支付方式</view>
</view>
<view class="lf-p-r-32 lf-p-l-32">
<button class="cu-btn bg-white margin-self" :class="pay_type==0?'border-green':'border'" @tap="payStatus(0)">
<text class="lf-iconfont lf-icon-weixin text-green lf-font-44 lf-m-r-23"></text>
<text class="lf-font-32" :class="pay_type==0?'text-green':'lf-color-333'">微信支付</text>
<text class="lf-iconfont lf-icon-dui lf-font-44 lf-color-primary" v-if="pay_type==0" style="position: absolute;right: 22rpx;"></text>
</button>
</view>
<view class="lf-p-r-32 lf-p-l-32 lf-m-t-30">
<button class="cu-btn bg-white margin-self" :class="pay_type==1?'border-green':'border'" @tap="payStatus(1)">
<text class="lf-font-32" :class="pay_type==1?'text-green':'lf-color-333'">线下支付</text>
<text class="lf-iconfont lf-icon-dui lf-font-44 lf-color-primary" v-if="pay_type==1" style="position: absolute;right: 22rpx;"></text>
</button>
</view>
<view class="lf-p-r-32 lf-p-l-32 lf-m-t-30" v-if="goods_details.deposit != '0.00'">
<button class="cu-btn bg-white margin-self" :class="pay_type==2?'border-green':'border'" @tap="payStatus(2)">
<text class="lf-font-32" :class="pay_type==2?'text-green':'lf-color-333'">订金支付</text>
<text class="lf-iconfont lf-icon-dui lf-font-44 lf-color-primary" v-if="pay_type==2" style="position: absolute;right: 22rpx;"></text>
</button>
</view>
<view class="lf-p-r-32 lf-p-l-32 lf-m-t-30">
<button class="cu-btn bg-white margin-self" v-if="goods_details.earnest != '0.00'" :class="pay_type==3?'border-green':'border'" @tap="payStatus(3)">
<text class="lf-font-32" :class="pay_type==3?'text-green':'lf-color-333'">定金支付</text>
<text class="lf-iconfont lf-icon-dui lf-font-44 lf-color-primary" v-if="pay_type==3" style="position: absolute;right: 22rpx;"></text>
</button>
</view>
<!-- <view class="lf-p-r-32 lf-p-l-32 lf-m-t-30">
<button class="cu-btn bg-white margin-self" :class="pay_type==4?'border-green':'border'" @tap="payStatus(4)">
<text class="lf-font-32" :class="pay_type==4?'text-green':'lf-color-333'">首款支付</text>
<text class="lf-iconfont lf-icon-dui lf-font-44 lf-color-primary" v-if="pay_type==4" style="position: absolute;right: 22rpx;"></text>
</button>
</view> -->
</view>
<view class="btn-bottom solid-top1">
<view class="padding-lr lf-p-t-10 lf-p-b-10 bg-white flex justify-between align-center shadow">
<view class="flex align-center">
<text class="lf-font-24 lf-font-555">应付款</text>
<lf-price :price="goods_details.final_price" />
</view>
<button class="btn" @tap="payOnce()">
<text class="lf-font-32 text-white" v-if="btn_type == 1">下单付款</text>
<text class="lf-font-32 text-white" v-else>支付尾款</text>
</button>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
goods_id: 0,
goods_details: {},
contact: '',
phone: '',
pay_type: 0,
btn_type: 1,
ifPay: true,
order_id: 0,
enter_type: 0,
payState: true,
pay_order_id: 0
}
},
onLoad(e) {
this.goods_id = e.goods_id;
this.btn_type = e.btn_type;
this.order_id = e.order_id;
this.enter_type = e.enter_type;
if(this.goods_id) {
this.getGoodsData(this.pay_type);
}
if(this.order_id && this.enter_type == 1) {
this.payOnce()
}else {
this.$msg('订单号获取失败!')
}
},
methods: {
payStatus(type) {
if(type == this.pay_type) {
this.pay_type = type;
return
}else {
this.pay_type = type;
this.getGoodsData(type);
}
},
getGoodsData(type){
this.$http(this.API.API_CONFIRMDETAILS,{id: this.goods_id,num: 1,pay_type: type}).then(res => {
this.goods_details = res.data;
console.log('数据',res)
})
},
submit() {
if(this.order_id && this.enter_type == 1) {
this.payOnce()
return
}
},
payOnce() {
this.$http(this.API.API_ORDERPAY,{id: this.order_id}).then(res => {
if(res.data.jump) {
console.log('立即付款')
wx.navigateToMiniProgram({
appId: res.data.jump_appid,
path: '/pages/order/confirm_atonce',
envVersion: 'release',
extraData: {
order_id: res.data.id
},
success(res) {
console.log('---res---')
console.log(res)
},
fail(err) {
console.log('---err---')
console.log(err)
}
})
}
}).catch(err => {})
}
}
}
</script>
<style>
.btn{
margin: 0;
padding: 0;
width: 212rpx;
height: 82rpx;
background-color: #1998FE;
color: #FFFFFF;
line-height: 80rpx;
font-size: 32rpx;
border-radius: 41rpx;
}
.bref-box {
text-overflow: -o-ellipsis-lastline;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
</style>

84
pages/order/confirm_order.vue

@ -119,7 +119,8 @@
ifPay: true, ifPay: true,
order_id: 0, order_id: 0,
enter_type: 0, enter_type: 0,
payState: true
payState: true,
pay_order_id: 0
} }
}, },
onLoad(e) { onLoad(e) {
@ -131,37 +132,21 @@
this.getGoodsData(this.pay_type); this.getGoodsData(this.pay_type);
} }
if(this.order_id && this.enter_type == 1) { if(this.order_id && this.enter_type == 1) {
this.$http(this.API.API_CREATEORDER,{id: this.goods_id,num: 1,pay_type: this.pay_type,name:this.contact,mobile:this.phone}).then(res => {
this.order_id = res.data.id
wx.navigateToMiniProgram({
appId: res.data.jump_appid,
path: '/pages/order/confirm_atonce',
envVersion: 'release',
extraData: {
order_id: res.data.id
},
success(res) {
console.log('---res---')
console.log(res)
},
fail(err) {
console.log('---err---')
console.log(err)
}
})
}).catch(err => {
})
console.log('con列表执行')
this.payOnce()
} }
}, },
onShow(e) { onShow(e) {
// this.backPayState = uni.getStorageSync('backPayState') // this.backPayState = uni.getStorageSync('backPayState')
let that = this let that = this
uni.$on('payState',(data) => { uni.$on('payState',(data) => {
that.payState = data.msg
that.payState = data.msg;
that.pay_order_id = data.payorder_id;
console.log('传来的订单id',that.pay_order_id)
if(that.payState == true) { if(that.payState == true) {
that.$url('/pages/payState/paystate?ifSuccess=1&order_id='+that.order_id,{type: 'redirect'})
that.$url('/pages/payState/paystate?ifSuccess=1&order_id='+that.pay_order_id,{type: 'redirect'})
}else { }else {
that.$url('/pages/payState/paystate?ifSuccess=2&order_id='+that.order_id,{type: 'redirect'})
that.$url('/pages/payState/paystate?ifSuccess=2&order_id='+that.pay_order_id,{type: 'redirect'})
} }
}) })
@ -183,6 +168,10 @@
}) })
}, },
submit() { submit() {
if(this.order_id && this.enter_type == 1) {
this.payOnce()
return
}
if(!this.contact) { if(!this.contact) {
this.$msg('请输入联系人!'); this.$msg('请输入联系人!');
return; return;
@ -195,12 +184,13 @@
if(!this.ifPay) return; if(!this.ifPay) return;
this.ifPay = false; this.ifPay = false;
this.$http(this.API.API_CREATEORDER,{id: this.goods_id,num: 1,pay_type: this.pay_type,name:this.contact,mobile:this.phone}).then(res => { this.$http(this.API.API_CREATEORDER,{id: this.goods_id,num: 1,pay_type: this.pay_type,name:this.contact,mobile:this.phone}).then(res => {
this.order_id = res.data.id
this.pay_order_id = res.data.id
if(this.pay_type == 1) { if(this.pay_type == 1) {
this.ifPay = true this.ifPay = true
this.$url('/pages/payState/paystate?ifSuccess=1&order_id='+this.order_id,{type: 'redirect'})
this.$url('/pages/payState/paystate?ifSuccess=1&order_id='+res.data.id,{type: 'redirect'})
}else if(res.data.jump == true) { }else if(res.data.jump == true) {
let that = this;
wx.navigateToMiniProgram({ wx.navigateToMiniProgram({
appId: res.data.jump_appid, appId: res.data.jump_appid,
path: '/pages/order/confirm_atonce', path: '/pages/order/confirm_atonce',
@ -209,12 +199,14 @@
order_id: res.data.id order_id: res.data.id
}, },
success(res) { success(res) {
console.log('---res---')
console.log(res)
console.log('---res---');
that.ifPay = true;
console.log(res);
}, },
fail(err) { fail(err) {
console.log('---err---')
console.log(err)
console.log('---err---');
console.log(err);
that.ifPay = true;
} }
}) })
} }
@ -225,20 +217,24 @@
}, },
payOnce() { payOnce() {
this.$http(this.API.API_ORDERPAY,{id: this.order_id}).then(res => { this.$http(this.API.API_ORDERPAY,{id: this.order_id}).then(res => {
uni.requestPayment({
orderInfo: res.data.order_num,
timeStamp: res.data.timeStamp,
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: res.data.signType,
paySign: res.data.paySign,
success: (res) => {
this.$url('/pages/payState/paystate?ifSuccess=1&order_id='+this.order_id,{type: 'redirect'})
},
fail: (err) => {
this.$url('/pages/payState/paystate?ifSuccess=2&order_id='+this.order_id,{type: 'redirect'})
},
})
if(res.data.jump) {
wx.navigateToMiniProgram({
appId: res.data.jump_appid,
path: '/pages/order/confirm_atonce',
envVersion: 'release',
extraData: {
order_id: res.data.id
},
success(res) {
console.log('---res---')
console.log(res)
},
fail(err) {
console.log('---err---')
console.log(err)
}
})
}
}).catch(err => {}) }).catch(err => {})
} }
} }

4
pages/order/order.vue

@ -22,8 +22,8 @@
</view> </view>
<view class="lf-row-between price lf-m-t-16" style="padding-right: 6rpx;"> <view class="lf-row-between price lf-m-t-16" style="padding-right: 6rpx;">
<lf-price :price="item.price" style="margin-top: 10rpx;" /> <lf-price :price="item.price" style="margin-top: 10rpx;" />
<button class="lf-font-24 radius-order col-btn0" v-if="item.status == 0" @click="$url('/pages/order/confirm_order?order_id='+item.id+'&goods_id='+item.agent_product_id+'&btn_type=1&enter_type=1')">立即付款</button>
<button class="lf-font-24 radius-order col-btn0" v-if="item.status == 1" @click="$url('/pages/order/confirm_order?order_id='+item.id+'&goods_id='+item.agent_product_id+'&btn_type=2&enter_type=1')">支付尾款</button>
<button class="lf-font-24 radius-order col-btn0" v-if="item.status == 0" @click="$url('/pages/order/confirm_fromorder?order_id='+item.id+'&goods_id='+item.agent_product_id+'&btn_type=1&enter_type=1')">立即付款</button>
<button class="lf-font-24 radius-order col-btn0" v-if="item.status == 1" @click="$url('/pages/order/confirm_fromorder?order_id='+item.id+'&goods_id='+item.agent_product_id+'&btn_type=2&enter_type=1')">支付尾款</button>
<button class="lf-font-24 radius-order col-btn1" v-if="item.status == 2 || item.status == 3">立即使用</button> <button class="lf-font-24 radius-order col-btn1" v-if="item.status == 2 || item.status == 3">立即使用</button>
<button class="lf-font-24 radius-order col-btn16" v-if="item.status == 16">已使用</button> <button class="lf-font-24 radius-order col-btn16" v-if="item.status == 16">已使用</button>
<button class="lf-font-24 radius-order col-btn6" v-if="item.status == 6">等待审核</button> <button class="lf-font-24 radius-order col-btn6" v-if="item.status == 6">等待审核</button>

33
pages/order/order_details.vue

@ -192,20 +192,25 @@
}, },
payAtonce() { payAtonce() {
this.$http(this.API.API_ORDERPAY,{id: this.order_id}).then(res => { this.$http(this.API.API_ORDERPAY,{id: this.order_id}).then(res => {
uni.requestPayment({
orderInfo: res.data.order_num,
timeStamp: res.data.timeStamp,
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: res.data.signType,
paySign: res.data.paySign,
success: (res) => {
this.$url('/pages/payState/paystate?ifSuccess=1&order_id='+this.order_id,{type: 'redirect'})
},
fail: (err) => {
this.$url('/pages/payState/paystate?ifSuccess=2&order_id='+this.order_id,{type: 'redirect'})
},
})
console.log('从订单列表进入')
if(res.data.jump) {
wx.navigateToMiniProgram({
appId: res.data.jump_appid,
path: '/pages/order/confirm_atonce',
envVersion: 'release',
extraData: {
order_id: res.data.id
},
success(res) {
console.log('---res---')
console.log(res)
},
fail(err) {
console.log('---err---')
console.log(err)
}
})
}
}).catch(err => {}) }).catch(err => {})
}, },
// //

Loading…
Cancel
Save