暂存code
This commit is contained in:
+142
-188
@@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<view class="order_submit_warp">
|
||||
<Header :leftTitle="$t('order.submit.title')" leftPathType="switchTab" leftPath="/pages/shopping_cart/shopping_cart"/>
|
||||
<!-- 收件人信息 -->
|
||||
<view class="order_submit_header_warp" @click="checkAddressShow(true,'data')" v-if="orderInfo.address && Object.keys(orderInfo.address).length !==0">
|
||||
<view class="header_areaAddress_warp">
|
||||
@@ -20,7 +21,9 @@
|
||||
<view v-else class="no_address" @click="checkAddressShow(true,'data')">
|
||||
<view class="no_address_title">
|
||||
<view>请填写地址</view>
|
||||
<up-image src="/static/common/right.png" width="14" height="14" bgColor="#f1f6ff00"></up-image>
|
||||
<view style="margin-top: 10rpx;">
|
||||
<up-image src="/static/common/right.png" width="14" height="14" bgColor="#f1f6ff00"></up-image>
|
||||
</view>
|
||||
</view>
|
||||
<view class="no_address_msg">您还未添加收货地址,请完善地址!</view>
|
||||
</view>
|
||||
@@ -28,7 +31,7 @@
|
||||
<view class="order_store_warp order_product_warp" v-for="(item,index) in orderInfo.shops" :key="item.id">
|
||||
<!-- 头部 -->
|
||||
<view class="order_product_header">
|
||||
<up-image :src="item.logo" width="22" height="22" bgColor="#f1f6ff00"></up-image>
|
||||
<up-image :src="item.logo" width="22" height="22" bgColor="#f1f6ff00" shape="circle"></up-image>
|
||||
<view class="order_product_title">{{item.name}}</view>
|
||||
</view>
|
||||
<view v-for="(addItem,addIndex) in item.addrTimes" :key="addIndex">
|
||||
@@ -44,9 +47,9 @@
|
||||
</view>
|
||||
<!-- 产品详情 -->
|
||||
<view class="order_item_content" v-for="(pItem,pIndex) in addItem.goods" :key="pItem.id">
|
||||
<up-image :src="pItem.img" width="80" height="80" bgColor="#f1f6ff00"></up-image>
|
||||
<up-image :src="pItem.img" width="80" height="80" bgColor="#f1f6ff00" @click="jumpProductInfo(pItem)"></up-image>
|
||||
<view class="content_info_right">
|
||||
<view>
|
||||
<view class="content_info_left_total" @click="jumpProductInfo(pItem)">
|
||||
<view class="content_info_title">{{pItem.title}}</view>
|
||||
<view class="content_info_tag">{{pItem.specs}}</view>
|
||||
</view>
|
||||
@@ -98,7 +101,7 @@
|
||||
<view class="order_way_warp" @click="wayShow = true;">
|
||||
<view>支付方式</view>
|
||||
<view class="order_way_right">
|
||||
{{getValue(PAYMENT_WAY_,orderInfo.paymentMethod)}}
|
||||
{{getValue(wayOption,orderInfo.paymentMethod)}}
|
||||
<up-image src="/static/common/right.png" width="20" height="20" bgColor="#f1f6ff00"></up-image>
|
||||
</view>
|
||||
</view>
|
||||
@@ -116,14 +119,13 @@
|
||||
v-model="orderInfo.paymentMethod"
|
||||
placement="column"
|
||||
>
|
||||
<view class="way_item" v-for="item in wayList" :key="item.id">
|
||||
<view class="way_item" v-for="item in wayOption" :key="item.id">
|
||||
<view class="way_item_">
|
||||
<view style="margin-top: 2rpx;"><up-image :src="item.path" width="20" height="20" bgColor="#f1f6ff00"></up-image></view>
|
||||
<view class="way_item_val">{{item.name}}</view>
|
||||
<!-- <view style="margin-top: 2rpx;"><up-image :src="item.path" width="20" height="20" bgColor="#f1f6ff00"></up-image></view> -->
|
||||
<view class="way_item_val">{{item.name}}<text v-if="item.balance"> ({{item.balance}})</text></view>
|
||||
</view>
|
||||
<up-radio
|
||||
:name="item.id"
|
||||
:disabled="item.disabled"
|
||||
:name="item.type"
|
||||
activeColor="#FF7C41"
|
||||
>
|
||||
</up-radio>
|
||||
@@ -140,6 +142,7 @@
|
||||
<view class="address_popup_warp">
|
||||
<view class="address_popup_title">收件地址</view>
|
||||
<view class="address_popup_content">
|
||||
<view class="address_popup_content_add" @click="addAdress"> + 新增地址</view>
|
||||
<Address @valueFunc="getAddressValueFunc"/>
|
||||
</view>
|
||||
<view class="popup_but" @click="addressOk">
|
||||
@@ -154,65 +157,87 @@
|
||||
|
||||
<script>
|
||||
import Address from '@/components/address.vue';
|
||||
import { PAYMENT_WAY,PAYMENT_WAY_,PRODUCT_DELIVERY_TIME,getValue } from '@/utils/enumUtils.js';
|
||||
import { getSettleList,settle } from '@/api/cart.js'
|
||||
import { PAYMENT_WAY,PAYMENT_WAY_,PRODUCT_DELIVERY_TIME,getValue,WAY_LIST } from '@/utils/enumUtils.js';
|
||||
import { getSettleList,settle,updateGoodsNum } from '@/api/cart.js';
|
||||
import { getSupportPay } from '@/api/order.js';
|
||||
import { feedback } from '@/api/payment.js';
|
||||
import { assembleAddress } from '@/utils/index.js'
|
||||
import Header from '@/components/header.vue';
|
||||
import { appWxpayFun,zfbPayFun,jumpWayOk,jumpWayError } from '@/utils/payUtils.js'
|
||||
|
||||
|
||||
export default {
|
||||
computed: {
|
||||
PAYMENT_WAY_() {
|
||||
return PAYMENT_WAY_;
|
||||
},
|
||||
PRODUCT_DELIVERY_TIME() {
|
||||
return PRODUCT_DELIVERY_TIME;
|
||||
}
|
||||
},
|
||||
},
|
||||
components: {
|
||||
Address,
|
||||
},
|
||||
onLoad(option) {
|
||||
const ids = option.ids;
|
||||
if(ids){
|
||||
this.ids = ids;
|
||||
this.getOrder();
|
||||
}
|
||||
Header,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
ids:0,
|
||||
orderInfo:{
|
||||
// coupon:2,//优惠卷
|
||||
paymentMethod:null,// 支付方式
|
||||
paymentMethod:PAYMENT_WAY.ALIPAY,// 支付方式,暂时默认用支付宝
|
||||
total:4000,// 需要支付的总金额
|
||||
address:{},// 选中的地址
|
||||
store:[],
|
||||
},
|
||||
wayList:[
|
||||
{
|
||||
disabled:false,
|
||||
id:PAYMENT_WAY.WECHAT,
|
||||
name:"微信支付",
|
||||
path:"/static/product/way_wx.png",
|
||||
},
|
||||
{
|
||||
disabled:false,
|
||||
id:PAYMENT_WAY.ALIPAY,
|
||||
name:"支付宝支付",
|
||||
path:"/static/product/way_zfb.png",
|
||||
},
|
||||
],
|
||||
wayShow:false,
|
||||
addressShow:false,// 收件地址选择
|
||||
addressType:'',// 收件地址数据类型
|
||||
addressIndex:0,// 收件地址数据类型
|
||||
shopsIndex:0,// 收件地址数据类型
|
||||
selectAddress:{},// 收件地址选择
|
||||
wayOption:[],
|
||||
// leftPath:'',
|
||||
// leftPathType:'',
|
||||
};
|
||||
},
|
||||
onLoad(option) {
|
||||
const ids = option.ids;
|
||||
console.log("ids",ids);
|
||||
if(ids && ids!=="null"){
|
||||
this.ids = ids;
|
||||
this.getOrder();
|
||||
// const idsArr = ids.split(",");
|
||||
// console.log("idsArr.length",idsArr.length);
|
||||
// if(idsArr.length >1){
|
||||
// this.leftPath = "/pages/sort/sort";
|
||||
// this.leftPathType = "switchTab"
|
||||
// }else{
|
||||
// this.leftPath = "/pages/productInfo/productInfo?id="+ids;
|
||||
// this.leftPathType = "navigateTo"
|
||||
// }
|
||||
}
|
||||
const addressShow = option.addressShow;
|
||||
if(addressShow && addressShow !=="null"){
|
||||
this.addressShow = addressShow;
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.getWayOption();
|
||||
},
|
||||
methods: {
|
||||
getValue,
|
||||
assembleAddress,
|
||||
// 增加收货地址
|
||||
addAdress(){
|
||||
const ids = this.ids;
|
||||
// addressShow = true;
|
||||
uni.navigateTo({
|
||||
url:"/pages/mine_address_add/mine_address_add?ids="+ids,
|
||||
})
|
||||
},
|
||||
async getWayOption(){
|
||||
const result = await getSupportPay();
|
||||
if(result && result.bizcode === 100){
|
||||
this.wayOption = result.data;
|
||||
}
|
||||
},
|
||||
async getOrder(){
|
||||
const ids = this.ids;
|
||||
if(!ids || ids ===0){
|
||||
@@ -253,28 +278,43 @@
|
||||
* @param {Object} addIndex 需要修改店铺的数据节点
|
||||
* @param {Object} index 需要修改的数据节点
|
||||
*/
|
||||
quantityFun(type,index,addIndex,pIndex){
|
||||
let currentQuantity = this.orderInfo.shops[index].addrTimes[addIndex].goods[pIndex].num;// 当前数量
|
||||
async quantityFun(type,index,addIndex,pIndex){
|
||||
const data = this.orderInfo.shops[index].addrTimes[addIndex].goods[pIndex];
|
||||
let currentQuantity = Number(data.num);// 当前数量
|
||||
let currentTotalPrice = Number(data.totalPrice);// 当前金额
|
||||
let currentAmount = Number(this.orderInfo.amount);// 总金额
|
||||
if(type === "minus"){
|
||||
if(currentQuantity === 1){
|
||||
this.$refs.uToastRef.show({
|
||||
type: 'error',
|
||||
message: "不能再减拉,不能小于最低购买数量~",
|
||||
});
|
||||
});x3
|
||||
}else{
|
||||
currentQuantity = currentQuantity - 1;
|
||||
currentAmount = currentAmount - data.unitPrice;
|
||||
currentTotalPrice = currentTotalPrice - data.unitPrice;
|
||||
}
|
||||
}else if(type === "add"){
|
||||
// 需要判断一下库存
|
||||
currentQuantity = currentQuantity + 1;
|
||||
currentAmount = currentAmount + data.unitPrice;
|
||||
currentTotalPrice = currentTotalPrice + data.unitPrice;
|
||||
}
|
||||
const params={
|
||||
id:data.id,
|
||||
goodsNum:currentQuantity,
|
||||
}
|
||||
const result = await updateGoodsNum(params);
|
||||
if(result && result.bizcode === 100){
|
||||
this.orderInfo.shops[index].addrTimes[addIndex].goods[pIndex].num = currentQuantity;
|
||||
this.orderInfo.shops[index].addrTimes[addIndex].goods[pIndex].totalPrice = currentTotalPrice.toFixed(2);
|
||||
this.orderInfo.amount = currentAmount.toFixed(2);
|
||||
}
|
||||
this.orderInfo.shops[index].addrTimes[addIndex].goods[pIndex].num = currentQuantity;
|
||||
},
|
||||
|
||||
// 获取备注
|
||||
getRemark(){
|
||||
const orderInfo = this.orderInfo;
|
||||
console.log("orderInfo",orderInfo);
|
||||
const remarkArr = [];
|
||||
if(orderInfo && Object.keys(orderInfo).length!==0){
|
||||
const remarObj={};
|
||||
@@ -292,7 +332,6 @@
|
||||
}
|
||||
remarkArr.push(remarObj);
|
||||
}
|
||||
console.log("remarkArr",remarkArr);
|
||||
return remarkArr;
|
||||
},
|
||||
/**
|
||||
@@ -300,6 +339,15 @@
|
||||
*/
|
||||
async goPay(){
|
||||
const orderInfo = this.orderInfo;
|
||||
|
||||
if(!orderInfo.address || Object.keys(orderInfo.address).length === 0){
|
||||
this.$refs.uToastRef.show({
|
||||
type: 'error',
|
||||
message: "请选择收货地址",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const way = orderInfo.paymentMethod;
|
||||
if(!way || way === 0){
|
||||
this.$refs.uToastRef.show({
|
||||
@@ -308,6 +356,7 @@
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const params={
|
||||
addrId:orderInfo.address.id,// 收货地址ID
|
||||
cartIds:this.ids,//结算的购物车ID,多个以逗号分割,ALL表示全选
|
||||
@@ -319,93 +368,48 @@
|
||||
// 提交订单成功,就唤起支付
|
||||
if(resp && resp.bizcode === 100){
|
||||
const item = resp.data;
|
||||
if(params.payway === PAYMENT_WAY.WECHAT){// APP微信支付
|
||||
if(item.wechat && Object.keys(item.wechat).length !==0){
|
||||
this.appWxpay(item.wechat);
|
||||
}else{
|
||||
this.$refs.uToastRef.show({
|
||||
type: 'error',
|
||||
message: "订单支付失败",
|
||||
});
|
||||
}
|
||||
}else if(params.payway === PAYMENT_WAY.ALIPAY){// 支付宝支付
|
||||
if(item.alipay && Object.keys(item.alipay).length !==0){
|
||||
this.zfbPay(item.alipay);
|
||||
}else{
|
||||
this.$refs.uToastRef.show({
|
||||
type: 'error',
|
||||
message: "订单支付失败",
|
||||
});
|
||||
}
|
||||
if(item.status === 1){
|
||||
jumpWayOk();
|
||||
return;
|
||||
}
|
||||
if(item.wechat && Object.keys(item.wechat).length !==0){
|
||||
this.appWxpay(item.wechat,item.orderId,item.orderNum);
|
||||
}else if(item.alipay && Object.keys(item.alipay).length !==0 && item.alipay){
|
||||
this.zfbPay(item.alipay,item.orderId,item.orderNum);
|
||||
}else{
|
||||
this.$refs.uToastRef.show({
|
||||
type: 'error',
|
||||
message: "订单支付失败",
|
||||
});
|
||||
setTimeout(()=>{
|
||||
jumpWayError()
|
||||
},2000)
|
||||
}
|
||||
}else{
|
||||
this.getOrder();
|
||||
}
|
||||
},
|
||||
// app 微信支付
|
||||
appWxpay(item){
|
||||
const newThis = this;
|
||||
const orderInfo = {
|
||||
"appid": item.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
|
||||
"noncestr": item.nonceStr, // 随机字符串
|
||||
"package": "Sign=WXPay", // 固定值
|
||||
"partnerid": item.partnerId, // 微信支付商户号
|
||||
"prepayid": item.prepayId, // 统一下单订单号
|
||||
"timestamp": item.timeStamp, // 时间戳(单位:秒)
|
||||
"sign": item.sign // 签名,这里用的 MD5/RSA 签名
|
||||
};
|
||||
uni.requestPayment({
|
||||
provider:"wxpay",
|
||||
orderInfo: orderInfo,
|
||||
success: function(res) {
|
||||
console.log('success:' + res);
|
||||
newThis.payFeedbackFun(item.orderId,res.orderNum,1);
|
||||
newThis.jumpWayOk();
|
||||
},
|
||||
fail: function(err) {
|
||||
console.log('fail:',err);
|
||||
this.$refs.uToastRef.show({
|
||||
type: 'error',
|
||||
message: "支付失败",
|
||||
});
|
||||
}
|
||||
});
|
||||
async appWxpay(alipay,orderId,orderNum){
|
||||
try {
|
||||
const result = await appWxpayFun(alipay,orderId,orderNum);
|
||||
console.log('支付成功', result);
|
||||
// 处理支付成功后的逻辑,如更新订单状态等
|
||||
} catch (error) {
|
||||
console.error('支付失败', error);
|
||||
// 处理支付失败后的逻辑,如提示用户等
|
||||
}
|
||||
},
|
||||
// 支付宝支付
|
||||
zfbPay(item){
|
||||
const that = this;
|
||||
uni.requestPayment({
|
||||
provider: 'alipay',
|
||||
orderInfo: item.orderStr,
|
||||
success(res) {
|
||||
console.log("res",res);
|
||||
that.payFeedbackFun(item.orderId,item.orderNum,1);
|
||||
that.jumpWayOk();
|
||||
},
|
||||
//调用失败的回调
|
||||
fail(err) {
|
||||
console.log('fail:',err);
|
||||
this.$refs.uToastRef.show({
|
||||
type: 'error',
|
||||
message: "支付失败",
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
// 跳转到支付成功页面
|
||||
jumpWayOk(){
|
||||
uni.navigateTo({
|
||||
url:"/pages/order_submit_ok/order_submit_ok",
|
||||
})
|
||||
},
|
||||
// 支付结果回调
|
||||
async payFeedbackFun(orderId,orderNum,status){
|
||||
const params = {
|
||||
orderId,
|
||||
orderNum,
|
||||
status,
|
||||
async zfbPay(alipay,orderId,orderNum){
|
||||
try {
|
||||
const result = await zfbPayFun(alipay,orderId,orderNum);
|
||||
console.log('支付成功', result);
|
||||
// 处理支付成功后的逻辑,如更新订单状态等
|
||||
} catch (error) {
|
||||
console.error('支付失败', error);
|
||||
// 处理支付失败后的逻辑,如提示用户等
|
||||
}
|
||||
console.log("params",params);
|
||||
const response = await feedback(params);
|
||||
console.log("反馈结果",response);
|
||||
},
|
||||
// 地址选中
|
||||
getAddressValueFunc(item){
|
||||
@@ -431,6 +435,12 @@
|
||||
this.addressType = type;
|
||||
this.addressIndex = addIndex;
|
||||
this.shopsIndex = index;
|
||||
},
|
||||
jumpProductInfo(item){
|
||||
console.log("item",item);
|
||||
uni.navigateTo({
|
||||
url:"/pages/productInfo/productInfo?id="+item.goodsId,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -538,12 +548,16 @@
|
||||
}
|
||||
.order_item_content{
|
||||
display: flex;
|
||||
margin-top: 20rpx;
|
||||
.content_info_right{
|
||||
margin-left: 20rpx;
|
||||
display: grid;
|
||||
width: calc(100% - 160rpx);
|
||||
}
|
||||
.content_info_left_total{
|
||||
}
|
||||
.content_info_title {
|
||||
width: 266px;
|
||||
width: 460rpx;
|
||||
}
|
||||
.content_info_tag{
|
||||
font-size: 20rpx;
|
||||
@@ -600,21 +614,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
.order_way_warp{
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: #FFFFFF;
|
||||
border-radius: 24rpx;
|
||||
margin-top: 30rpx;
|
||||
padding: 30rpx;
|
||||
font-weight: 500;
|
||||
font-size: 26rpx;
|
||||
color: #222222;
|
||||
.order_way_right{
|
||||
display: flex;
|
||||
}
|
||||
}
|
||||
|
||||
.order_pay_but{
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
@@ -637,54 +637,8 @@
|
||||
font-size: 36rpx;
|
||||
color: $app-bt-bj;
|
||||
}
|
||||
}
|
||||
|
||||
.way_popup_warp{
|
||||
padding: 30rpx;
|
||||
min-height: 800rpx;
|
||||
width: calc(100% - 60rpx);
|
||||
.way_popup_title{
|
||||
text-align: center;
|
||||
margin-bottom: 60rpx;
|
||||
}
|
||||
.way_item{
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
line-height: 82rpx;
|
||||
.way_item_{
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.way_item_val{
|
||||
font-weight: bold;
|
||||
font-size: 30rpx;
|
||||
color: #222222;
|
||||
margin-left: 20rpx;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
.popup_but{
|
||||
position: fixed;
|
||||
bottom: 64rpx;
|
||||
background: $app-bt-bj;
|
||||
border-radius: 16rpx;
|
||||
color: #FFFFFF;
|
||||
text-align: center;
|
||||
padding: 20rpx 0;
|
||||
width: calc(100% - 60rpx);
|
||||
}
|
||||
.address_popup_warp{
|
||||
padding: 30rpx;
|
||||
height: 1200rpx;
|
||||
overflow-y: hidden;
|
||||
.address_popup_title{
|
||||
text-align: center;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
.address_popup_content{
|
||||
height: calc(100% - 180rpx);
|
||||
overflow-y: auto;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user