微信支付
This commit is contained in:
parent
185e822b5d
commit
cb9683a9e8
@ -1,8 +1,12 @@
|
|||||||
// pages/order/quasi.js
|
// pages/order/quasi.js
|
||||||
import {
|
import {
|
||||||
getQuasiOrderInfo, updateOrderAddr,
|
getQuasiOrderInfo, updateOrderAddr,
|
||||||
addOrder
|
addOrder, getPayment
|
||||||
} from '../../utils/apis'
|
} from '../../utils/apis'
|
||||||
|
|
||||||
|
import {
|
||||||
|
requestPayment
|
||||||
|
} from '../../utils/util'
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
|
|
||||||
@ -92,6 +96,28 @@ Page({
|
|||||||
addOrder({
|
addOrder({
|
||||||
quasi_order_id: id,
|
quasi_order_id: id,
|
||||||
success(data) {
|
success(data) {
|
||||||
|
var order_id = data['order']['order_id']
|
||||||
|
getPayment({
|
||||||
|
order_id,
|
||||||
|
success(data) {
|
||||||
|
requestPayment({
|
||||||
|
data,
|
||||||
|
complete() {
|
||||||
|
that.setData({
|
||||||
|
loading: false
|
||||||
|
})
|
||||||
|
wx.redirectTo({
|
||||||
|
url: `/pages/order/show?id=${order_id}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
error() {
|
||||||
|
that.setData({
|
||||||
|
loading: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
that.setData({
|
that.setData({
|
||||||
loading: false
|
loading: false
|
||||||
})
|
})
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
// pages/order/show.js
|
// pages/order/show.js
|
||||||
import Countdown from '../../utils/countdown'
|
import Countdown from '../../utils/countdown'
|
||||||
import {
|
import {
|
||||||
countdownFormat, datetimeFormat,
|
countdownFormat, datetimeFormat,
|
||||||
makePhoneCall
|
makePhoneCall, requestPayment
|
||||||
} from '../../utils/util'
|
} from '../../utils/util'
|
||||||
import { getOrderInfo } from '../../utils/apis'
|
import {
|
||||||
|
getOrderInfo, getPayment
|
||||||
|
} from '../../utils/apis'
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
activeNavIndex: 0,
|
activeNavIndex: 0,
|
||||||
@ -21,7 +23,7 @@ Page({
|
|||||||
},
|
},
|
||||||
onLoad: function (options) {
|
onLoad: function (options) {
|
||||||
// 页面初始化 options为页面跳转所带来的参数
|
// 页面初始化 options为页面跳转所带来的参数
|
||||||
this.id = options.id || 1395
|
this.id = options.id || 1409
|
||||||
this.loadData()
|
this.loadData()
|
||||||
},
|
},
|
||||||
onReady: function () {
|
onReady: function () {
|
||||||
@ -65,7 +67,7 @@ Page({
|
|||||||
this.countdown = countdown
|
this.countdown = countdown
|
||||||
},
|
},
|
||||||
|
|
||||||
loadData() {
|
loadData(cb) {
|
||||||
var that = this
|
var that = this
|
||||||
var order_id = this.id
|
var order_id = this.id
|
||||||
wx.showNavigationBarLoading()
|
wx.showNavigationBarLoading()
|
||||||
@ -74,16 +76,20 @@ Page({
|
|||||||
success(data) {
|
success(data) {
|
||||||
data['add_time_format'] = datetimeFormat(data.add_time)
|
data['add_time_format'] = datetimeFormat(data.add_time)
|
||||||
data['flow'] = data.flow.map(item => {
|
data['flow'] = data.flow.map(item => {
|
||||||
item['time_format'] = datetimeFormat(item.time)
|
item['time_format'] = datetimeFormat(item.time)
|
||||||
return item
|
return item
|
||||||
})
|
})
|
||||||
that.setData({
|
that.setData({
|
||||||
info: data
|
info: data
|
||||||
})
|
})
|
||||||
if(data.left_time > 0) {
|
wx.setNavigationBarTitle({
|
||||||
|
title: data['seller_name'],
|
||||||
|
})
|
||||||
|
if (data.left_time > 0) {
|
||||||
that.initCountdown(+data.left_time)
|
that.initCountdown(+data.left_time)
|
||||||
}
|
}
|
||||||
wx.hideNavigationBarLoading()
|
wx.hideNavigationBarLoading()
|
||||||
|
cb && cb()
|
||||||
},
|
},
|
||||||
error() {
|
error() {
|
||||||
wx.hideNavigationBarLoading()
|
wx.hideNavigationBarLoading()
|
||||||
@ -101,9 +107,9 @@ Page({
|
|||||||
],
|
],
|
||||||
success: function (res) {
|
success: function (res) {
|
||||||
var {tapIndex} = res
|
var {tapIndex} = res
|
||||||
if(tapIndex == 0) {
|
if (tapIndex == 0) {
|
||||||
makePhoneCall(seller_phone)
|
makePhoneCall(seller_phone)
|
||||||
} else if(tapIndex == 1) {
|
} else if (tapIndex == 1) {
|
||||||
makePhoneCall(localphone)
|
makePhoneCall(localphone)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -111,6 +117,42 @@ Page({
|
|||||||
console.log(res.errMsg)
|
console.log(res.errMsg)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
|
onPayTap(e) {
|
||||||
|
var that = this
|
||||||
|
var {info: {order_id}, loading} = this.data
|
||||||
|
if (loading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setData({
|
||||||
|
loading: true
|
||||||
|
})
|
||||||
|
getPayment({
|
||||||
|
order_id,
|
||||||
|
success(data) {
|
||||||
|
wx.requestPayment({
|
||||||
|
success(data) {
|
||||||
|
that.loadData()
|
||||||
|
},
|
||||||
|
complete () {
|
||||||
|
that.setData({
|
||||||
|
loading: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
error() {
|
||||||
|
that.setData({
|
||||||
|
loading: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
onPullDownRefresh() {
|
||||||
|
this.loadData(function () {
|
||||||
|
wx.stopPullDownRefresh()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
})
|
})
|
@ -1 +1,4 @@
|
|||||||
{}
|
{
|
||||||
|
"navigationBarTitleText": "订单详情",
|
||||||
|
"enablePullDownRefresh": true
|
||||||
|
}
|
@ -23,8 +23,8 @@
|
|||||||
<text class="primary-color">{{countLabel}}</text>
|
<text class="primary-color">{{countLabel}}</text>
|
||||||
</view>
|
</view>
|
||||||
<view wx:if="{{info.state < 4}}" class="actionbar">
|
<view wx:if="{{info.state < 4}}" class="actionbar">
|
||||||
<view wx:if="{{info.state < 4}}" class="actionbar-btn actionbar-btn_action">取消订单</view>
|
<button wx:if="{{info.state < 4}}" class="weui-btn actionbar-btn actionbar-btn_action">取消订单</button>
|
||||||
<view wx:if="{{info.state == 1}}" class="actionbar-btn actionbar-btn_action actionbar-btn_primary">立即付款</view>
|
<button loading="{{loading}}" disabled="{{loading}}" bindtap="onPayTap" wx:if="{{info.state == 1}}" class="weui-btn actionbar-btn actionbar-btn_action actionbar-btn_primary" type="primary">立即付款</button>
|
||||||
<view wx:if="{{info.state == 4}}" class="actionbar-btn actionbar-btn_action actionbar-btn_primary">评价</view>
|
<view wx:if="{{info.state == 4}}" class="actionbar-btn actionbar-btn_action actionbar-btn_primary">评价</view>
|
||||||
</view>
|
</view>
|
||||||
</swiper-item>
|
</swiper-item>
|
||||||
|
@ -110,9 +110,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.actionbar-btn_action {
|
.actionbar-btn_action {
|
||||||
|
margin-top: 0;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
line-height: 50px;
|
line-height: 50px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
border-radius: 0;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
.actionbar-btn_action::after {
|
||||||
|
border: none;
|
||||||
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.actionbar-btn_primary {
|
.actionbar-btn_primary {
|
||||||
|
@ -436,5 +436,28 @@ export function getOrderInfo(options) {
|
|||||||
success, error
|
success, error
|
||||||
})
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取支付参数
|
||||||
|
export function getPayment(options) {
|
||||||
|
var {
|
||||||
|
order_id,
|
||||||
|
success, error
|
||||||
|
} = options
|
||||||
|
getApp().getLoginInfo(loginInfo => {
|
||||||
|
if (!loginInfo.user_info) {
|
||||||
|
return alert('用户未登录')
|
||||||
|
}
|
||||||
|
var {user_id, user_token} = loginInfo.user_info
|
||||||
|
fetch({
|
||||||
|
url: 'index.php?m=Mall&c=WeixinMall&a=getPayment',
|
||||||
|
data: {
|
||||||
|
user_id, user_token,
|
||||||
|
order_id
|
||||||
|
},
|
||||||
|
success, error
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
@ -308,4 +308,31 @@ export function getUserInfo(cb) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 微信支付
|
||||||
|
export function requestPayment(options) {
|
||||||
|
var {
|
||||||
|
data, success, error, complete
|
||||||
|
} = options
|
||||||
|
wx.requestPayment(Object.assign({
|
||||||
|
complete(res) {
|
||||||
|
if (res.errMsg == 'requestPayment:ok') {
|
||||||
|
alert('支付成功', function () {
|
||||||
|
success && success()
|
||||||
|
complete && complete()
|
||||||
|
})
|
||||||
|
} else if (res.errMsg == 'requestPayment:fail cancel') {
|
||||||
|
alert('用户取消支付', function () {
|
||||||
|
error && error()
|
||||||
|
complete && complete()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
alert('支付失败', function () {
|
||||||
|
error && error()
|
||||||
|
complete && complete()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, data))
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user