|
|
@@ -1,4 +1,5 @@
|
|
|
// pages/order/confirmOrder/confirmOrder.js
|
|
|
+import { API } from "../../../service/api";
|
|
|
import {formatPrice} from "../../../utils/utils";
|
|
|
|
|
|
Page({
|
|
|
@@ -9,20 +10,59 @@ Page({
|
|
|
data: {
|
|
|
prods:[],
|
|
|
totalPrice:0, // 订单总金额
|
|
|
+ address:""
|
|
|
+ },
|
|
|
+ // 获取地址列表
|
|
|
+ getAddressList(){
|
|
|
+ API.getAddressList().then(res=>{
|
|
|
+ let address = res.userAddressList.filter(item=>item.defaultFlag === "1");
|
|
|
+ if(address.length === 0){
|
|
|
+ address = res.userAddressList[0];
|
|
|
+ }else{
|
|
|
+ address = address[0];
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ address
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 去地址管理页面
|
|
|
+ goAddressMange(){
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/pages/my/addressManage/addressManage',
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 确认订单
|
|
|
+ submitOrder(){
|
|
|
+ let data = {
|
|
|
+ orderItemDTOS:this.data.orderItemDTOS,
|
|
|
+ userAddressId:this.data.address.userAddressId
|
|
|
+ }
|
|
|
+ API.createOrder(data).then(res=>{
|
|
|
+
|
|
|
+ })
|
|
|
},
|
|
|
-
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad(options) {
|
|
|
let list = JSON.parse(decodeURIComponent(options.prods));
|
|
|
let total = 0;
|
|
|
+ let orderItemDTOS = [];
|
|
|
list.forEach(item=>{
|
|
|
total += item.quantity*item.price;
|
|
|
+ orderItemDTOS.push({
|
|
|
+ cartsId:item.cartsId,
|
|
|
+ mercId:item.mercId || item.mercProdId,
|
|
|
+ prodId:item.id,
|
|
|
+ prodAttrId:item.prodAttrId,
|
|
|
+ count:item.quantity
|
|
|
+ })
|
|
|
})
|
|
|
this.setData({
|
|
|
prods:list,
|
|
|
- totalPrice:formatPrice(total)
|
|
|
+ totalPrice:formatPrice(total),
|
|
|
+ orderItemDTOS
|
|
|
})
|
|
|
},
|
|
|
|
|
|
@@ -37,7 +77,7 @@ Page({
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow() {
|
|
|
-
|
|
|
+ this.getAddressList();
|
|
|
},
|
|
|
|
|
|
/**
|