订单支付
This commit is contained in:
parent
cb9683a9e8
commit
285a9afa94
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"pages": [
|
"pages": [
|
||||||
"pages/order/show",
|
|
||||||
"pages/order/list",
|
|
||||||
"pages/shop/show",
|
|
||||||
"pages/mine/mine",
|
|
||||||
"pages/index/index",
|
"pages/index/index",
|
||||||
|
"pages/shop/show",
|
||||||
|
"pages/order/list",
|
||||||
|
"pages/order/show",
|
||||||
|
"pages/mine/mine",
|
||||||
"pages/address/select",
|
"pages/address/select",
|
||||||
"pages/order/quasi",
|
"pages/order/quasi",
|
||||||
"pages/address/list",
|
"pages/address/list",
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
// pages/order/list.js
|
// pages/order/list.js
|
||||||
import { ORDER_STATES } from './constant'
|
import { ORDER_STATES } from './constant'
|
||||||
import {
|
import {
|
||||||
getOrders
|
getOrders, getPayment
|
||||||
} from '../../utils/apis'
|
} from '../../utils/apis'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
datetimeFormat
|
datetimeFormat, requestPayment
|
||||||
} from '../../utils/util'
|
} from '../../utils/util'
|
||||||
|
|
||||||
var initData = {
|
var initData = {
|
||||||
@ -21,6 +21,16 @@ Page({
|
|||||||
},
|
},
|
||||||
onLoad: function (options) {
|
onLoad: function (options) {
|
||||||
// 页面初始化 options为页面跳转所带来的参数
|
// 页面初始化 options为页面跳转所带来的参数
|
||||||
|
console.log('onLoad')
|
||||||
|
var that = this
|
||||||
|
getApp().getLoginInfo(loginInfo => {
|
||||||
|
that.setData({
|
||||||
|
loginInfo: loginInfo
|
||||||
|
})
|
||||||
|
if (loginInfo.is_login) {
|
||||||
|
that.initData()
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
onReady: function () {
|
onReady: function () {
|
||||||
// 页面渲染完成
|
// 页面渲染完成
|
||||||
@ -32,10 +42,6 @@ Page({
|
|||||||
that.setData({
|
that.setData({
|
||||||
loginInfo: loginInfo
|
loginInfo: loginInfo
|
||||||
})
|
})
|
||||||
var {list} = that.data
|
|
||||||
if (loginInfo.is_login && !list) {
|
|
||||||
that.initData()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onHide: function () {
|
onHide: function () {
|
||||||
@ -45,6 +51,7 @@ Page({
|
|||||||
// 页面关闭
|
// 页面关闭
|
||||||
},
|
},
|
||||||
initData(cb) {
|
initData(cb) {
|
||||||
|
this.setData(initData)
|
||||||
this.loadData(cb)
|
this.loadData(cb)
|
||||||
},
|
},
|
||||||
loadData(cb) {
|
loadData(cb) {
|
||||||
@ -80,6 +87,40 @@ Page({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
onPayTap(e) {
|
||||||
|
var {id} = e.currentTarget
|
||||||
|
var that = this
|
||||||
|
var {list, loading} = this.data
|
||||||
|
if (loading) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setData({
|
||||||
|
loading: true
|
||||||
|
})
|
||||||
|
var {order_id} = list[id]
|
||||||
|
getPayment({
|
||||||
|
order_id,
|
||||||
|
success(data) {
|
||||||
|
requestPayment({
|
||||||
|
data,
|
||||||
|
success(data) {
|
||||||
|
that.initData()
|
||||||
|
},
|
||||||
|
complete() {
|
||||||
|
that.setData({
|
||||||
|
loading: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
error() {
|
||||||
|
that.setData({
|
||||||
|
loading: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
onReachBottom(e) {
|
onReachBottom(e) {
|
||||||
var {
|
var {
|
||||||
loginInfo: {is_login},
|
loginInfo: {is_login},
|
||||||
@ -101,7 +142,10 @@ Page({
|
|||||||
wx.stopPullDownRefresh()
|
wx.stopPullDownRefresh()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
callback(loginInfo) {
|
callback(loginInfo) {
|
||||||
this.setData(initData)
|
if (this.data.list) {
|
||||||
|
this.onLoad()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
@ -17,8 +17,8 @@
|
|||||||
</view>
|
</view>
|
||||||
</navigator>
|
</navigator>
|
||||||
<view wx:if="{{item.state == 1 || item.state == 4}}" class="order-item__ft">
|
<view wx:if="{{item.state == 1 || item.state == 4}}" class="order-item__ft">
|
||||||
<button wx:if="{{item.state == 1}}" class="weui-btn_primary weui-btn_mini">立即付款</button>
|
<button id="{{index}}" bindtap="onPayTap" wx:if="{{item.state == 1}}" class="weui-btn_primary weui-btn_mini">立即付款</button>
|
||||||
<navigator wx:else url="url" class="weui-btn_primary weui-btn_mini">去评论</navigator>
|
<navigator wx:elif="{{item.state == 4}}" url="url" class="weui-btn_primary weui-btn_mini">去评论</navigator>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -5,7 +5,7 @@ import {
|
|||||||
} from '../../utils/apis'
|
} from '../../utils/apis'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
requestPayment
|
requestPayment, getCurrentPage
|
||||||
} from '../../utils/util'
|
} from '../../utils/util'
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
@ -106,8 +106,12 @@ Page({
|
|||||||
that.setData({
|
that.setData({
|
||||||
loading: false
|
loading: false
|
||||||
})
|
})
|
||||||
wx.redirectTo({
|
wx.switchTab({
|
||||||
url: `/pages/order/show?id=${order_id}`
|
url: '/pages/order/list',
|
||||||
|
success(res) {
|
||||||
|
var {callback} = getCurrentPage()
|
||||||
|
callback && callback()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
import Countdown from '../../utils/countdown'
|
import Countdown from '../../utils/countdown'
|
||||||
import {
|
import {
|
||||||
countdownFormat, datetimeFormat,
|
countdownFormat, datetimeFormat,
|
||||||
makePhoneCall, requestPayment
|
makePhoneCall, requestPayment, confirm, alert
|
||||||
} from '../../utils/util'
|
} from '../../utils/util'
|
||||||
import {
|
import {
|
||||||
getOrderInfo, getPayment
|
getOrderInfo, getPayment,
|
||||||
|
cancelOrder
|
||||||
} from '../../utils/apis'
|
} from '../../utils/apis'
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
@ -23,7 +24,7 @@ Page({
|
|||||||
},
|
},
|
||||||
onLoad: function (options) {
|
onLoad: function (options) {
|
||||||
// 页面初始化 options为页面跳转所带来的参数
|
// 页面初始化 options为页面跳转所带来的参数
|
||||||
this.id = options.id || 1409
|
this.id = options.id || 1413
|
||||||
this.loadData()
|
this.loadData()
|
||||||
},
|
},
|
||||||
onReady: function () {
|
onReady: function () {
|
||||||
@ -55,6 +56,7 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
initCountdown(count) {
|
initCountdown(count) {
|
||||||
|
var that = this
|
||||||
this.setData({
|
this.setData({
|
||||||
count
|
count
|
||||||
})
|
})
|
||||||
@ -63,6 +65,9 @@ Page({
|
|||||||
this.setData({
|
this.setData({
|
||||||
countLabel: countdownFormat(count)
|
countLabel: countdownFormat(count)
|
||||||
})
|
})
|
||||||
|
}, () => {
|
||||||
|
console.log('complete')
|
||||||
|
that.loadData()
|
||||||
})
|
})
|
||||||
this.countdown = countdown
|
this.countdown = countdown
|
||||||
},
|
},
|
||||||
@ -85,6 +90,9 @@ Page({
|
|||||||
wx.setNavigationBarTitle({
|
wx.setNavigationBarTitle({
|
||||||
title: data['seller_name'],
|
title: data['seller_name'],
|
||||||
})
|
})
|
||||||
|
if (that.countdown) {
|
||||||
|
that.countdown.stop()
|
||||||
|
}
|
||||||
if (data.left_time > 0) {
|
if (data.left_time > 0) {
|
||||||
that.initCountdown(+data.left_time)
|
that.initCountdown(+data.left_time)
|
||||||
}
|
}
|
||||||
@ -131,7 +139,8 @@ Page({
|
|||||||
getPayment({
|
getPayment({
|
||||||
order_id,
|
order_id,
|
||||||
success(data) {
|
success(data) {
|
||||||
wx.requestPayment({
|
requestPayment({
|
||||||
|
data,
|
||||||
success(data) {
|
success(data) {
|
||||||
that.loadData()
|
that.loadData()
|
||||||
},
|
},
|
||||||
@ -149,6 +158,23 @@ Page({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
onCancelTap(e) {
|
||||||
|
var that = this;
|
||||||
|
var {info: {order_id, title}} = this.data
|
||||||
|
confirm({
|
||||||
|
content: `是否取消订单 ${title}`,
|
||||||
|
confirmText: '取消订单',
|
||||||
|
ok() {
|
||||||
|
cancelOrder({
|
||||||
|
order_id,
|
||||||
|
success(data) {
|
||||||
|
alert('取消订单成功')
|
||||||
|
that.loadData()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
onPullDownRefresh() {
|
onPullDownRefresh() {
|
||||||
this.loadData(function () {
|
this.loadData(function () {
|
||||||
wx.stopPullDownRefresh()
|
wx.stopPullDownRefresh()
|
||||||
|
@ -18,12 +18,13 @@
|
|||||||
<view class="flow-item__time">{{item.time_format}}</view>
|
<view class="flow-item__time">{{item.time_format}}</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view wx:if="{{count > 0}}" class="order-show__left-time">
|
<view wx:if="{{info.left_time > 0}}" class="order-show__left-time">
|
||||||
支付剩余时间
|
<text wx:if="{{info.state == 1}}">支付剩余时间</text>
|
||||||
<text class="primary-color">{{countLabel}}</text>
|
<text wx:elif="{{info.state == 2}}">等待商家接单</text>
|
||||||
|
<text class="primary-color order-show__left-time-label">{{countLabel}}</text>
|
||||||
</view>
|
</view>
|
||||||
<view wx:if="{{info.state < 4}}" class="actionbar">
|
<view wx:if="{{info.state <= 2 || info.state == 4}}" class="actionbar">
|
||||||
<button wx:if="{{info.state < 4}}" class="weui-btn actionbar-btn actionbar-btn_action">取消订单</button>
|
<button bindtap="onCancelTap" wx:if="{{info.state <= 2}}" class="weui-btn actionbar-btn actionbar-btn_action">取消订单</button>
|
||||||
<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>
|
<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>
|
||||||
|
@ -134,6 +134,9 @@
|
|||||||
left: 10px;
|
left: 10px;
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
}
|
}
|
||||||
|
.order-show__left-time-label {
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
.phone {
|
.phone {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
@ -393,6 +393,29 @@ export function addOrder(options) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 取消订单
|
||||||
|
export function cancelOrder(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=Order&a=cancelOrder',
|
||||||
|
data: {
|
||||||
|
user_id, user_token,
|
||||||
|
order_id
|
||||||
|
},
|
||||||
|
success, error
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 获取订单列表
|
// 获取订单列表
|
||||||
export function getOrders(options) {
|
export function getOrders(options) {
|
||||||
var {
|
var {
|
||||||
|
@ -4,11 +4,12 @@ export default class Countdown {
|
|||||||
this.prop = prop
|
this.prop = prop
|
||||||
}
|
}
|
||||||
|
|
||||||
start(cb) {
|
start(cb, complete) {
|
||||||
var that = this;
|
var that = this;
|
||||||
var {page, prop} = that
|
var {page, prop} = that
|
||||||
var second = page.data[prop]
|
var second = page.data[prop]
|
||||||
if (second <= 0) {
|
if (second <= 0) {
|
||||||
|
complete && complete()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cb && cb(second)
|
cb && cb(second)
|
||||||
@ -16,7 +17,7 @@ export default class Countdown {
|
|||||||
page.setData({
|
page.setData({
|
||||||
[prop]: second - 1
|
[prop]: second - 1
|
||||||
});
|
});
|
||||||
that.start(cb);
|
that.start(cb, complete);
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +161,10 @@ export function getPrevPage() {
|
|||||||
const pages = getCurrentPages()
|
const pages = getCurrentPages()
|
||||||
return pages[pages.length - 2]
|
return pages[pages.length - 2]
|
||||||
}
|
}
|
||||||
|
export function getCurrentPage() {
|
||||||
|
const pages = getCurrentPages()
|
||||||
|
return pages[pages.length - 1]
|
||||||
|
}
|
||||||
|
|
||||||
export function fetch(options) {
|
export function fetch(options) {
|
||||||
wx.request({
|
wx.request({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user