订单支付

This commit is contained in:
Kiyan 2017-05-15 15:17:59 +08:00
parent cb9683a9e8
commit 285a9afa94
10 changed files with 153 additions and 47 deletions

View File

@ -1,10 +1,10 @@
{
"pages": [
"pages/order/show",
"pages/order/list",
"pages/shop/show",
"pages/mine/mine",
"pages/index/index",
"pages/shop/show",
"pages/order/list",
"pages/order/show",
"pages/mine/mine",
"pages/address/select",
"pages/order/quasi",
"pages/address/list",

View File

@ -1,11 +1,11 @@
// pages/order/list.js
import { ORDER_STATES } from './constant'
import {
getOrders
getOrders, getPayment
} from '../../utils/apis'
import {
datetimeFormat
datetimeFormat, requestPayment
} from '../../utils/util'
var initData = {
@ -21,6 +21,16 @@ Page({
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
console.log('onLoad')
var that = this
getApp().getLoginInfo(loginInfo => {
that.setData({
loginInfo: loginInfo
})
if (loginInfo.is_login) {
that.initData()
}
})
},
onReady: function () {
// 页面渲染完成
@ -32,10 +42,6 @@ Page({
that.setData({
loginInfo: loginInfo
})
var {list} = that.data
if (loginInfo.is_login && !list) {
that.initData()
}
})
},
onHide: function () {
@ -45,6 +51,7 @@ Page({
// 页面关闭
},
initData(cb) {
this.setData(initData)
this.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) {
var {
loginInfo: {is_login},
@ -101,7 +142,10 @@ Page({
wx.stopPullDownRefresh()
}
},
callback(loginInfo) {
this.setData(initData)
if (this.data.list) {
this.onLoad()
}
}
})

View File

@ -17,8 +17,8 @@
</view>
</navigator>
<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>
<navigator wx:else url="url" class="weui-btn_primary weui-btn_mini">去评论</navigator>
<button id="{{index}}" bindtap="onPayTap" wx:if="{{item.state == 1}}" class="weui-btn_primary weui-btn_mini">立即付款</button>
<navigator wx:elif="{{item.state == 4}}" url="url" class="weui-btn_primary weui-btn_mini">去评论</navigator>
</view>
</view>
</view>

View File

@ -5,7 +5,7 @@ import {
} from '../../utils/apis'
import {
requestPayment
requestPayment, getCurrentPage
} from '../../utils/util'
Page({
data: {
@ -106,8 +106,12 @@ Page({
that.setData({
loading: false
})
wx.redirectTo({
url: `/pages/order/show?id=${order_id}`
wx.switchTab({
url: '/pages/order/list',
success(res) {
var {callback} = getCurrentPage()
callback && callback()
}
})
}
})

View File

@ -2,10 +2,11 @@
import Countdown from '../../utils/countdown'
import {
countdownFormat, datetimeFormat,
makePhoneCall, requestPayment
makePhoneCall, requestPayment, confirm, alert
} from '../../utils/util'
import {
getOrderInfo, getPayment
getOrderInfo, getPayment,
cancelOrder
} from '../../utils/apis'
Page({
data: {
@ -23,7 +24,7 @@ Page({
},
onLoad: function (options) {
// 页面初始化 options为页面跳转所带来的参数
this.id = options.id || 1409
this.id = options.id || 1413
this.loadData()
},
onReady: function () {
@ -55,6 +56,7 @@ Page({
},
initCountdown(count) {
var that = this
this.setData({
count
})
@ -63,6 +65,9 @@ Page({
this.setData({
countLabel: countdownFormat(count)
})
}, () => {
console.log('complete')
that.loadData()
})
this.countdown = countdown
},
@ -85,6 +90,9 @@ Page({
wx.setNavigationBarTitle({
title: data['seller_name'],
})
if (that.countdown) {
that.countdown.stop()
}
if (data.left_time > 0) {
that.initCountdown(+data.left_time)
}
@ -131,11 +139,12 @@ Page({
getPayment({
order_id,
success(data) {
wx.requestPayment({
requestPayment({
data,
success(data) {
that.loadData()
},
complete () {
complete() {
that.setData({
loading: false
})
@ -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() {
this.loadData(function () {
wx.stopPullDownRefresh()

View File

@ -18,12 +18,13 @@
<view class="flow-item__time">{{item.time_format}}</view>
</view>
</view>
<view wx:if="{{count > 0}}" class="order-show__left-time">
支付剩余时间
<text class="primary-color">{{countLabel}}</text>
<view wx:if="{{info.left_time > 0}}" class="order-show__left-time">
<text wx:if="{{info.state == 1}}">支付剩余时间</text>
<text wx:elif="{{info.state == 2}}">等待商家接单</text>
<text class="primary-color order-show__left-time-label">{{countLabel}}</text>
</view>
<view wx:if="{{info.state < 4}}" class="actionbar">
<button wx:if="{{info.state < 4}}" class="weui-btn actionbar-btn actionbar-btn_action">取消订单</button>
<view wx:if="{{info.state <= 2 || info.state == 4}}" class="actionbar">
<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>
<view wx:if="{{info.state == 4}}" class="actionbar-btn actionbar-btn_action actionbar-btn_primary">评价</view>
</view>

View File

@ -134,6 +134,9 @@
left: 10px;
font-size: 0.8em;
}
.order-show__left-time-label {
margin-left: 5px;
}
.phone {
position: absolute;

View File

@ -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) {
var {

View File

@ -1,26 +1,27 @@
export default class Countdown {
constructor(page, prop) {
this.page = page
this.prop = prop
}
constructor(page, prop) {
this.page = page
this.prop = prop
}
start(cb) {
var that = this;
var {page, prop} = that
var second = page.data[prop]
if (second <= 0) {
return
}
cb && cb(second)
that.timer = setTimeout(function () {
page.setData({
[prop]: second - 1
});
that.start(cb);
}, 1000)
start(cb, complete) {
var that = this;
var {page, prop} = that
var second = page.data[prop]
if (second <= 0) {
complete && complete()
return
}
cb && cb(second)
that.timer = setTimeout(function () {
page.setData({
[prop]: second - 1
});
that.start(cb, complete);
}, 1000)
}
stop() {
clearTimeout(this.timer)
}
stop() {
clearTimeout(this.timer)
}
}

View File

@ -161,6 +161,10 @@ export function getPrevPage() {
const pages = getCurrentPages()
return pages[pages.length - 2]
}
export function getCurrentPage() {
const pages = getCurrentPages()
return pages[pages.length - 1]
}
export function fetch(options) {
wx.request({