|
|
@@ -173,6 +173,7 @@
|
|
|
this.totalNum = Number(options.totalNum) || 0
|
|
|
this.type = options.type
|
|
|
this.isFirstLoad = true;
|
|
|
+
|
|
|
if (options.type == 'win') {
|
|
|
this.getKey()
|
|
|
}
|
|
|
@@ -214,7 +215,7 @@
|
|
|
getUserAddr() {
|
|
|
userAddr().then(res => {
|
|
|
if (res.code == 200) {
|
|
|
- //console.log("用户收货地址>>>>", res.data)
|
|
|
+ console.log("用户收货地址>>>>", res.data)
|
|
|
if (res.data && !this.address) {
|
|
|
this.address = res.data;
|
|
|
}
|
|
|
@@ -286,7 +287,7 @@
|
|
|
computedReward(data).then(res => {
|
|
|
if (res.code == 200) {
|
|
|
console.log("查询创建订单信息>>>>", res.data)
|
|
|
- this.orderData = res.data || {}
|
|
|
+ this.orderData = res.data||{}
|
|
|
} else {
|
|
|
uni.showToast({
|
|
|
title: res.msg,
|
|
|
@@ -301,6 +302,7 @@
|
|
|
|
|
|
// 创建订单
|
|
|
createLiveOrder() {
|
|
|
+
|
|
|
let data = {
|
|
|
cityId: this.cityId,
|
|
|
liveId: this.liveId,
|
|
|
@@ -332,32 +334,31 @@
|
|
|
},
|
|
|
// 创建抽奖订单
|
|
|
createRewardOrder() {
|
|
|
- let data = {
|
|
|
- cityId: this.cityId,
|
|
|
- liveId: this.liveId,
|
|
|
- orderKey: this.orderKey,
|
|
|
- userName: this.address.realName,
|
|
|
- userPhone: this.address.phone,
|
|
|
- userAddress: this.address.province + ' ' + this.address.city + ' ' + this.address.district + ' ' +
|
|
|
- this.address.detail,
|
|
|
- cartId: "5",
|
|
|
- productId: this.productId,
|
|
|
- totalNum: 1,
|
|
|
- couponUserId: this.couponUserId
|
|
|
- }
|
|
|
-
|
|
|
- return createReward(data).then(res => {
|
|
|
- if (res.code == 200) {
|
|
|
- this.orderList = res.order || {};
|
|
|
- return res.order || {};
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: res.msg,
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- throw new Error(res.msg);
|
|
|
- }
|
|
|
- });
|
|
|
+ let data = {
|
|
|
+ cityId: this.cityId,
|
|
|
+ liveId: this.liveId,
|
|
|
+ orderKey: this.orderKey,
|
|
|
+ userName: this.address.realName,
|
|
|
+ userPhone: this.address.phone,
|
|
|
+ userAddress: this.address.province + ' ' + this.address.city + ' ' + this.address.district + ' ' + this.address.detail,
|
|
|
+ cartId: "5",
|
|
|
+ productId: this.productId,
|
|
|
+ totalNum: this.totalNum,
|
|
|
+ couponUserId: this.couponUserId
|
|
|
+ }
|
|
|
+
|
|
|
+ return createReward(data).then(res => {
|
|
|
+ if (res.code == 200) {
|
|
|
+ this.orderList = res.order || {};
|
|
|
+ return res.order || {};
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.msg,
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ throw new Error(res.msg);
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
couponSelect(item) {
|
|
|
this.couponText = "-¥" + (item.couponPrice || 0).toFixed(2);
|
|
|
@@ -375,8 +376,7 @@
|
|
|
if (this.couponsList.length === 0 || !this.isFirstLoad) {
|
|
|
return;
|
|
|
}
|
|
|
- const availableCoupons = this.couponsList.filter(item =>
|
|
|
-
|
|
|
+ const availableCoupons = this.couponsList.filter(item =>
|
|
|
item.status === 0 && item.useMinPrice <= (this.orderData.totalPrice || 0)
|
|
|
);
|
|
|
if (availableCoupons.length === 0) {
|
|
|
@@ -386,7 +386,7 @@
|
|
|
const maxCoupon = availableCoupons[0];
|
|
|
this.couponText = "-¥" + (maxCoupon.couponPrice || 0).toFixed(2);
|
|
|
this.couponUserId = maxCoupon.id;
|
|
|
-
|
|
|
+
|
|
|
console.log('自动选择最大优惠券:', maxCoupon);
|
|
|
this.isFirstLoad = false;
|
|
|
// 重新计算订单价格
|
|
|
@@ -422,39 +422,39 @@
|
|
|
},
|
|
|
// 提交订单
|
|
|
async submitOrder() {
|
|
|
- try {
|
|
|
- if (this.orderKey == null) {
|
|
|
- uni.showToast({
|
|
|
- icon: 'none',
|
|
|
- title: '订单KEY不存在',
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- if (this.address == null) {
|
|
|
- uni.showToast({
|
|
|
- icon: 'none',
|
|
|
- title: '收货地址不能为空',
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- let orderList;
|
|
|
- if (this.type == "win") {
|
|
|
- orderList = await this.createRewardOrder(); // 中奖订单
|
|
|
- } else {
|
|
|
- orderList = await this.createLiveOrder(); // 购买订单
|
|
|
- }
|
|
|
- console.log("orderList>>", orderList)
|
|
|
- const orderListStr = encodeURIComponent(JSON.stringify(orderList));
|
|
|
- uni.navigateTo({
|
|
|
- url: `/pages_shopping/live/paymentOrder?orderList=${orderListStr}&couponUserId=${this.couponUserId}&type=${this.type}`
|
|
|
- });
|
|
|
- } catch (error) {
|
|
|
- console.error('提交订单错误:', error);
|
|
|
- uni.showToast({
|
|
|
- title: error.message || '提交订单失败',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- }
|
|
|
+ try {
|
|
|
+ if (this.orderKey == null) {
|
|
|
+ uni.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: '订单KEY不存在',
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.address == null) {
|
|
|
+ uni.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: '收货地址不能为空',
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let orderList;
|
|
|
+ if (this.type == "win") {
|
|
|
+ orderList = await this.createRewardOrder(); // 中奖订单
|
|
|
+ } else {
|
|
|
+ orderList = await this.createLiveOrder(); // 购买订单
|
|
|
+ }
|
|
|
+ console.log("orderList>>", orderList)
|
|
|
+ const orderListStr = encodeURIComponent(JSON.stringify(orderList));
|
|
|
+ uni.navigateTo({
|
|
|
+ url: `/pages_shopping/live/paymentOrder?orderList=${orderListStr}&couponUserId=${this.couponUserId}&type=${this.type}`
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ console.error('提交订单错误:', error);
|
|
|
+ uni.showToast({
|
|
|
+ title: error.message || '提交订单失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
}
|
|
|
}
|
|
|
@@ -744,3 +744,4 @@
|
|
|
line-height: 0.44 * 100rpx;
|
|
|
background-color: red;
|
|
|
}
|
|
|
+</style>
|