Browse Source

出版

master
jianglong 3 years ago
parent
commit
ba05a9618a
  1. 414
      bundle_b/pages/confirm_order/confirm_order.vue

414
bundle_b/pages/confirm_order/confirm_order.vue

@ -0,0 +1,414 @@
<template>
<view>
<view class="confirm-order">
<view class="confirm-con">
<navigator hover-class="none" url="/bundle/pages/user_address/user_address?type=1">
<view class="address flex bg-white">
<image class="icon-md m-r-20" src="/static/images/icon_address.png"></image>
<view class="flex-1 m-r-20">
<view class="black md" v-if="!address.contact">设置收货地址</view>
<view v-else>
<text class="name md m-r-10">{{address.contact}}</text>
<text class="phone md">{{address.telephone}}</text>
<view class="area sm m-t-10 lighter">
{{address.province}} {{address.city}} {{address.district}} {{address.address}}
</view>
</view>
</view>
<u-icon name="arrow-right"></u-icon>
</view>
</navigator>
<!-- 拼团商品 -->
<block v-if="teamId==undefined">
<view class="goods contain" v-for="(item,index) in shopLists" :key="index">
<order-shop :order-type="orderInfo.order_type" :item="item" :invoice="invoiceArr" @changeremark="changeRemark"
@changecoupon="changeCoupon($event,index)" @changeDeliveryType="changeDeliveryType($event,item)" :teamId="teamId" :bargainLaunchId="bargainLaunchId"></order-shop>
</view>
</block>
<!-- 其他商品 -->
<block v-else>
<view class="goods contain">
<order-shop :order-type="orderInfo.order_type" :item="shopLists" :invoice="invoiceArr" @changeremark="changeRemark"
@changeDeliveryType="changeDeliveryType($event, shopLists)" :teamId="teamId" :bargainLaunchId="bargainLaunchId"></order-shop>
</view>
</block>
</view>
<view class="footer bg-white flex row-between fixed">
<view class="all-price lg flex">
<text>合计</text>
<view class="primary">
<price-format weight="500" :first-size="36" :second-size="36" :price="orderInfo.total_amount">
</price-format>
</view>
</view>
<button class="btn br60 white" size="md" hover-class="none" @tap="onSubmitOrder">
提交订单
</button>
</view>
</view>
<loading-view v-if="showLoading" background-color="transparent" :size="50"></loading-view>
<loading-view v-if="isFirstLoading"></loading-view>
</view>
</template>
<script>
import {
orderInfo,
orderBuy,
getOrderCoupon
} from '@/api/order';
import {
teamBuy,
teamKaiTuan
} from '@/api/activity'
import {
prepay,
getMnpNotice,
getPayway
} from '@/api/app';
import {
wxpay,
alipay
} from '@/utils/pay'
// total_amount
export default {
data() {
return {
isFirstLoading: true,
showLoading: false,
address: {},
orderInfo: {},
shopLists: [],
addressId: '',
useIntegral: 0,
userRemark: [],
couponId: [],
teamId: undefined,
carts: [],
type: '',
goods: '',
bargainLaunchId: -1,
invoiceArr: [] //
};
},
onLoad(options) {
uni.$on("selectaddress", (e) => {
this.addressId = e.id;
this.orderBuyFun();
})
//
uni.$on('invoice', params => {
const index = this.invoiceArr.findIndex(el => el.shop_id == params.shop_id)
if ( params.del == true && this.invoiceArr.length) {
this.invoiceArr.splice(index, 1);
} else {
if ( index == -1 ) this.invoiceArr = [...this.invoiceArr, params]
else this.invoiceArr.splice(index, 1, params);
}
})
const {
data: {
goods,
carts,
teamId,
foundId,
type
}
} = this.$Route.query
this.goods = goods
this.bargainLaunchId = goods[0].bargain_launch_id || -1
this.carts = carts || []
this.type = type
this.teamId = teamId
// id
this.foundId = foundId || ''
this.orderBuyFun();
},
onUnload() {
uni.$off("selectaddress")
uni.$off("payment")
uni.$off("invoice")
},
methods: {
//
changeRemark(e) {
let index = this.userRemark.findIndex((item) => item.shop_id == e.shop_id)
if (index == -1) {
this.userRemark.push(e)
} else {
this.userRemark[index].remark = e.remark
}
this.userRemark = this.userRemark.filter((item) => item.remark)
},
//
changeCoupon(e, index) {
this.couponId[index] = e
this.orderBuyFun()
},
//
changeDeliveryType(type, row) {
row.delivery_type = type;
for(let i=0;i<this.goods.length;i++) {
const item = this.goods[i];
if(row.shop_id == item.shop_id) {
this.goods[i].delivery_type = type;
}
}
this.orderBuyFun();
},
getAuthMsg() {
return new Promise(resolve => {
getMnpNotice({
scene: 1
}).then(res => {
if (res.code == 1) {
uni.requestSubscribeMessage({
tmplIds: res.data,
fail(res) {
console.log(res.errMsg);
},
complete() {
resolve();
}
});
} else {
resolve();
}
});
});
},
onSubmitOrder() {
uni.showModal({
title: '温馨提示',
content: '是否确认下单?',
confirmColor: '#FF2C3C',
success: async res => {
let {
confirm
} = res;
if (confirm) {
// #ifdef MP-WEIXIN
await this.getAuthMsg();
//#endif
this.showLoading = true
this.orderBuyFun('submit');
}
}
});
},
async orderBuyFun(action = 'info') {
const {
userRemark,
useIntegral,
carts,
goods,
bargainLaunchId,
couponId
} = this;
const submitObj = {
goods: JSON.stringify(goods),
address_id: this.addressId,
cart_id: carts.join(),
coupon_id: couponId.filter(item => item),
// bargain_launch_id
bargain_launch_id: this.bargainLaunchId == -1 ? '' : this.bargainLaunchId
};
//
if (this.teamId && action == 'info') {
delete submitObj.goods;
submitObj.action = 'info';
submitObj.item_id = this.goods[0].item_id;
submitObj.delivery_type = this.goods[0].delivery_type;
submitObj.count = this.goods[0].num;
submitObj.goods_id = this.goods[0].goods_id
submitObj.team_id = this.teamId;
}
//
if (this.teamId && action == 'submit') {
submitObj.action = 'buy';
submitObj.item_id = this.goods[0].item_id;
submitObj.delivery_type = this.goods[0].delivery_type;
submitObj.count = this.goods[0].num;
submitObj.goods_id = this.goods[0].goods_id
submitObj.team_id = this.foundId;
}
if (action == 'submit') {
// delivery_type
submitObj.delivery_type = this.shopLists[0]?.delivery_type || 0
submitObj.remark = userRemark.length ? JSON.stringify(userRemark) : ''
submitObj.invoice = JSON.stringify(this.invoiceArr)
}
let {
data: orderData,
code: orderCode,
msg: orderMsg
} = action == 'info' ? this.teamId ? await teamKaiTuan(submitObj) : await orderInfo(submitObj) :
this.teamId ? await teamKaiTuan(submitObj) : await orderBuy(submitObj)
// infoidteamKaiTuanorderInfo
// teamKaiTuanorderBuy
if(orderMsg == '抱歉,库存不足') {
setTimeout(() => {
uni.navigateBack(1)
},500)
}
if (orderCode !== 1) return this.showLoading = false
if (action == 'info') {
const {
shop,
address
} = orderData
this.address = address
this.shopLists = shop
this.orderInfo = orderData
this.$nextTick(() => {
this.isFirstLoading = false
});
} else if (action == 'submit') {
this.showLoading = false
let order_id = ''
const type = orderData.type
switch(type) {
case 'order': order_id = orderData.order_id; break;
case 'trade': order_id = orderData.trade_id; break;
}
uni.$on('payment', params => {
setTimeout(() => {
if (params.result) {
console.log('Jason', this)
this.$Router.replace({
path: '/pages/pay_result/pay_result',
query: {
id: params.order_id,
from: params.from
}
})
} else {
this.$Router.replace({
path: '/bundle/pages/user_order/user_order'
})
}
}, 1 * 1000)
})
uni.navigateTo({
url: `/pages/payment/payment?from=${type}&order_id=${order_id}`
})
}
}
},
watch: {
address(val) {
this.addressId = val.id
}
}
}
</script>
<style lang="scss" scoped>
.confirm-order {
.confirm-con {
overflow: hidden;
padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
.address {
min-height: 164rpx;
padding: 0 24rpx;
border-radius: 14rpx;
margin: 20rpx 20rpx 0;
}
.img-line {
height: 1.5px;
width: 100%;
display: block;
}
}
.price {
padding: 28rpx 20rpx;
.item:not(:last-of-type) {
margin-bottom: 20rpx;
}
}
.contain {
border-radius: 14rpx;
margin: 20rpx 20rpx 0;
background-color: #fff;
overflow: hidden;
}
.radio-group {
display: block;
}
.footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 99;
height: 100rpx;
padding: 0 30rpx;
box-sizing: content-box;
padding-bottom: env(safe-area-inset-bottom);
.btn {
background: linear-gradient(90deg, rgba(249, 95, 47, 1) 0%, rgba(255, 44, 60, 1) 100%);
padding: 0 50rpx;
}
}
}
// .confirm-order .van-cell:after {
// border: none;
// }
// .goods .shop-icon {
// width: 40rpx;
// height: 40rpx;
// }
// .pop-title {
// height: 100rpx;
// border-bottom: 1rpx solid #F2F2F2;
// }
// .pop-title .title {
// margin-left: 30rpx;
// font-size: 34rpx;
// font-weight: bold;
// line-height: 36rpx;
// }
</style>
Loading…
Cancel
Save