<import src="../../template/baseNavigationBar.wxml"/>
<template is="navigationBar" data="{{...item}}"></template>
<view class="order_address" bindtap="bindaddress">
<view class="select_address"><text class="iconfont icon-map_line-"></text>点击去选择地址</view>
<view><text class="iconfont icon-arrowright"></text></view>
</view>
<view class="Receiving_address" bindtap="bindaddress">
<view>
<view class="name_iphone">天津 天津市 津南区</view>
<view class="address">天安门后广场</view>
<view class="name_iphone">张三 1313212313</view>
</view>
<view><text class="iconfont icon-arrowright"></text></view>
</view>
<view class="goods_msg">
<view class="goods_img"><image src="../../images/img.png" mode="widthFix"></image></view>
<view class="goods_content">共1件 <text class="iconfont icon-arrowright"></text></view>
</view>
<view class="msg_list">
<view class="msg_item">
<view>商品原价</view>
<view>¥11.8</view>
</view>
<view class="msg_item">
<view>配送费</view>
<view>包邮</view>
</view>
<view class="msg_item">
<view>商品优惠</view>
<view>-¥11.8</view>
</view>
<view class="Total">
合计 <text class="Total_price">¥9.8</text>
</view>
</view>
<view class="order_pay">
<view class="pay_money">付款 <text class="Total_price">¥9.8</text></view>
<view class="submit_order" bindtap="bindSubmitOrder">提交订单</view>
</view>
@import "../../lib/style/iconfont.wxss";
@import "../../lib/style/base.wxss";
@import "../../lib/style/baseNavigationBar.wxss";
page {
background-color: #f3f3f3;
}
.order_address {
display: flex;
justify-content: space-between;
align-items: center;
margin: 160rpx 20rpx 20rpx;
height: 200rpx;
line-height: 200rpx;
background: white;
border-radius: 10rpx;
padding: 30rpx;
}
.Receiving_address {
display: flex;
justify-content: space-between;
align-items: center;
margin: 20rpx;
height: 200rpx;
background: white;
border-radius: 10rpx;
padding: 30rpx;
}
.name_iphone {
color: #7e7e7e;
font-size: 24rpx;
}
.address {
font-size: 32rpx;
padding: 20rpx 0;
}
.select_address {
color: #7e7e7e;
}
.icon-arrowright {
font-size: 28rpx;
}
.icon-map_line- {
margin-right: 10rpx;
}
.goods_msg {
display: flex;
margin: 20rpx;
background: white;
border-radius: 10rpx;
padding: 30rpx;
align-items: center;
}
.goods_img {
width: 100rpx;
height: 100rpx;
overflow: hidden;
margin-right: 20rpx;
flex-shrink: 0;
}
.goods_img image {
width: 100%;
border-radius: 50%;
}
.goods_content {
flex: 1;
text-align: right;
font-size: 24rpx;
}
.msg_list {
margin: 20rpx;
background: white;
border-radius: 10rpx;
}
.msg_item {
display: flex;
justify-content: space-between;
margin: 0 20rpx;
padding: 30rpx 0;
border-bottom: 2rpx solid #f3f3f3;
}
.Total {
text-align: right;
margin: 0 20rpx;
padding: 30rpx 0;
font-size: 32rpx;
}
.Total_price {
color: #ad0e12;
font-size: 32rpx;
}
.order_pay {
display: flex;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 93rpx;
line-height: 93rpx;
justify-content: space-between;
background: white;
}
.submit_order {
width: 32%;
background: #ad0e12;
color: white;
font-size: 32rpx;
text-align: center;
}
.pay_money {
font-size: 32rpx;
margin-left: 30rpx;
}
// pages/confirm_order/confirm_order.js
const app = getApp();
var MBC = require("../../../../core/core.js");
var api = require("../../../../config/api.config.js");
Page({
/**
* 页面的初始数据
*/
data: {
address_info: {}, //地址信息
goods_info: [], //商品信息
goods_count: '', //商品件数
goods_freight: '', //运费
goods_price: '', //商品价格
total_price: '', //合计价格
item: {
iconfontBack: "icon-arrowleft",
navigationBarTitle: "确认订单",
statusBarHeight: app.globalData.statusBarHeight
},
statusBarHeight: app.globalData.statusBarHeight,
goods_id: '', //商品id
goods_num: '', //商品数量
type: '', //选项
order_message: '', //订单留言
cart_ids: [], // 购物车商品id
},
//选择地址
bindaddress: function() {
var type = this.data.type;
if (type == 1) {
var goods_id = this.data.goods_id;
var goods_num = this.data.goods_num;
wx.navigateTo({
url: '../myAddress/myAddress' + '?goods_id=' + goods_id + '&goods_num=' + goods_num + '&type=' + type
})
} else {
var cart_ids = JSON.stringify(this.data.cart_ids);
wx.navigateTo({
url: '../myAddress/myAddress?cart_ids=' + cart_ids + '&type=' + type
})
}
},
// 留言
bindwaitMsg: function(event) {
console.log(event.detail.value);
this.setData({
order_message: event.detail.value, // 订单留言
})
},
/**
* 支付订单
*/
payOrder: function(orderHash, order_id) {
var that = this;
var order_hash = orderHash;
console.log(order_hash)
//呼起微信支付
MBC.Ajax({
url: api.getPayConfig,
is_login: true,
data: {
hash: order_hash,
platform: 'miniProgram',
channel: 'weixin'
},
success: function(res) {
wx.requestPayment({
'timeStamp': res.result.parameters.timeStamp,
'nonceStr': res.result.parameters.nonceStr,
'package': res.result.parameters.package,
'signType': 'MD5',
'paySign': res.result.parameters.paySign,
'success': function(res) {
console.log(res);
MBC.Ajax({
url: api.payOrder,
is_login: true,
data: {
hash: order_hash
},
success: function(res) {
console.log(res)
var status = res.result.status;
if (status == 2) {
wx.showToast({
title: '支付成功',
});
wx.redirectTo({
url: '../orderInfo/orderInfo?order_id=' + order_id,
})
} else {
wx.showToast({
title: '支付失败,请稍后刷新',
})
}
}
})
},
'fail': function(res) {
console.log(res);
wx.redirectTo({
url: '../orderInfo/orderInfo?order_id=' + order_id,
})
}
})
}
})
},
// 提交订单
bindSubmitOrder: function(e) {
var form_id = e.detail.formId;
var that = this;
var type = this.data.type;
if (type == 1) {
MBC.Ajax({
url: api.submit,
is_login: true,
data: {
form_id: form_id,
order_message: this.data.order_message, //地址信息
address_id: this.data.address_info.address_id, //地址id
receiver_name: this.data.address_info.receiver_name, //收件人姓名
receiver_phone: this.data.address_info.receiver_phone, //收件手机号
receiver_city: this.data.address_info.city, //收件城市
receiver_address_details: this.data.address_info.detail_address, //收件详细地址
type: this.data.type, //选项
goods_id: this.data.goods_id, //商品id
goods_num: this.data.goods_num, //商品数量
},
success: function(res) {
that.payOrder(res.result.hash, res.result.order_id);
},
fail: function(res) {
}
})
} else if (type == 2) {
MBC.Ajax({
url: api.submit,
is_login: true,
data: {
form_id: form_id,
order_message: this.data.order_message, //地址信息
address_id: this.data.address_info.address_id, //地址id
receiver_name: this.data.address_info.receiver_name, //收件人姓名
receiver_phone: this.data.address_info.receiver_phone, //收件手机号
receiver_city: this.data.address_info.city, //收件城市
receiver_address_details: this.data.address_info.detail_address, //收件详细地址
type: this.data.type, //选项
cart_ids: this.data.cart_ids, //购物车id
},
success: function(res) {
that.payOrder(res.result.hash, res.result.order_id);
},
fail: function(res) {
}
})
}
},
//返回上一页
onBack: function() {
wx.navigateBack({
delta: 1
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
var that = this;
var type = options.type;
if (type == 1) {
that.setData({
goods_id: options.goods_id,
goods_num: options.goods_num,
type: options.type,
})
// 立即购买
//直接购买
MBC.Ajax({
url: api.confirm,
is_login: true,
data: {
goods_id: that.data.goods_id,
goods_num: that.data.goods_num,
type: type
},
success: function (res) {
console.log(res);
that.setData({
address_info: res.result.address_info, //地址信息
goods_info: res.result.goods_info, //商品信息
goods_count: res.result.goods_count, //商品件数
goods_freight: res.result.goods_freight, //运费
goods_price: res.result.goods_price, //商品价格
total_price: res.result.total_price, //合计价格
})
},
fail: function (res) {
console.log(res);
//获取信息失败
}
})
} else {
that.setData({
type: options.type,
cart_ids: JSON.parse(options.cart_ids),
})
// 购物车
MBC.Ajax({
url: api.confirm,
is_login: true,
data: {
cart_ids: that.data.cart_ids,
type: type
},
success: function (res) {
console.log(res);
that.setData({
address_info: res.result.address_info, //地址信息
goods_info: res.result.goods_info, //商品信息
goods_count: res.result.goods_count, //商品件数
goods_freight: res.result.goods_freight, //运费
goods_price: res.result.goods_price, //商品价格
total_price: res.result.total_price, //合计价格
})
},
fail: function (res) {
console.log(res);
//获取信息失败
}
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function(options) {
var that = this;
var goods_id = that.data.goods_id;
var goods_num = that.data.goods_num;
var type = that.data.type;
var cart_ids = that.data.cart_ids;
console.log(that.data.address_id);
// if (type == 1) {
// } else if (type == 2) {
// }
if (that.data.address_id){
// 获取指定地址信息
MBC.Ajax({
url: api.getOne,
is_login: true,
data: {
address_id: that.data.address_id
},
success: function (res) {
that.setData({
address_info: res.result.address_info
})
},
fail: function (res) {
}
})
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})