Compare commits

...

2 Commits

Author SHA1 Message Date
3b8c991e1a 1 2026-04-04 18:09:09 +08:00
46bbce84aa 1 2026-04-04 17:20:53 +08:00
7 changed files with 172 additions and 72 deletions

View File

@ -94,13 +94,13 @@
"privacy": { "privacy": {
"usePrivacyCheck": true, "usePrivacyCheck": true,
"requiredPrivateInfos": ["makePhoneCall"] "requiredPrivateInfos": ["makePhoneCall"]
}
}, },
"plugins": { "plugins": {
"lifeServicePlugin": { "lifeServicePlugin": {
"version": "*", "version": "*",
"provider": "tta5a3d31e3aecfb9b11" "provider": "tta5a3d31e3aecfb9b11"
} }
}
}, },
"mp-qq" : { "mp-qq" : {

View File

@ -13,7 +13,7 @@
<view class="flex-row-start"> <view class="flex-row-start">
<text class="fs-28 price-text"> <text class="fs-28 price-text">
¥ ¥
<text class="fs-28">{{data.prices[0].original_price || 0 }}</text> <text class="fs-28">{{data.prices[0].original_price / 100 || 0 }}</text>
</text> </text>
<!-- <text class="fs-20 price-label">到手价</text> --> <!-- <text class="fs-20 price-label">到手价</text> -->
</view> </view>

View File

@ -321,6 +321,21 @@ export default {
// 立即购买 // 立即购买
addToCar(goodsData) { addToCar(goodsData) {
console.log(goodsData,'--=') console.log(goodsData,'--=')
// Parse image_list and get the first image URL
let firstImageUrl = '';
const imageList = goodsData.product.attr_key_value_map.image_list;
if (imageList) {
try {
// Try to parse as JSON if it's a string
const parsedList = typeof imageList === 'string' ? JSON.parse(imageList) : imageList;
if (Array.isArray(parsedList) && parsedList.length > 0) {
firstImageUrl = parsedList[0].url || parsedList[0] || '';
}
} catch (e) {
console.error('Error parsing image_list:', e);
}
}
uni.navigateTo({ uni.navigateTo({
url: `/pages/client/order/create`, url: `/pages/client/order/create`,
success: (res) => { success: (res) => {
@ -330,11 +345,11 @@ export default {
...this.goodsData, ...this.goodsData,
goods_id:goodsData.product.out_id, goods_id:goodsData.product.out_id,
// price_id:goodsData.prices[0].price_id, // price_id:goodsData.prices[0].price_id,
product_pic: firstImageUrl,
number:1, number:1,
goods_name: goodsData.product.product_name, goods_name: goodsData.product.product_name,
price_name: goodsData?.product.product_name, price_name: goodsData?.product.product_name,
goods_price: goodsData.product.product_type, goods_price: goodsData.sku.actual_amount / 100
product_pic:goodsData.product.product_type
}, ], }, ],
}); });
}, },

View File

@ -160,6 +160,8 @@ export default {
imgPrefix, imgPrefix,
WeChat: undefined, WeChat: undefined,
wallet: "2", wallet: "2",
orderId: "",
outOrderNo: "",
}; };
}, },
computed: { computed: {
@ -193,8 +195,41 @@ export default {
const eventChannel = this.getOpenerEventChannel(); const eventChannel = this.getOpenerEventChannel();
eventChannel.on("createOrder", (data) => { eventChannel.on("createOrder", (data) => {
this.orderData = data?.goodList || []; // Helper function to extract first image from image_list
this.payPrice = (data?.goodList || []).reduce( const extractFirstImage = (imageList) => {
if (!imageList) return '';
try {
const parsedList = typeof imageList === 'string' ? JSON.parse(imageList) : imageList;
if (Array.isArray(parsedList) && parsedList.length > 0) {
return parsedList[0].url || parsedList[0] || '';
}
} catch (e) {
console.error('Error parsing image_list:', e);
}
return '';
};
this.orderData = (data?.goodList || []).map(item => {
// Check if product_pic is actually an image_list that needs parsing
let processedItem = { ...item };
if (processedItem.product_pic) {
// If product_pic looks like an array or JSON string, try to parse it
if (typeof processedItem.product_pic === 'string' && (processedItem.product_pic.startsWith('[') || processedItem.product_pic.startsWith('{'))) {
const extractedUrl = extractFirstImage(processedItem.product_pic);
if (extractedUrl) {
processedItem.product_pic = extractedUrl;
}
} else if (Array.isArray(processedItem.product_pic)) {
const extractedUrl = extractFirstImage(processedItem.product_pic);
if (extractedUrl) {
processedItem.product_pic = extractedUrl;
}
}
}
return processedItem;
});
this.payPrice = this.orderData.reduce(
(sum, item) => (sum, item) =>
sum + sum +
Number((item.product_price || item.goods_price) * item.number || 0), Number((item.product_price || item.goods_price) * item.number || 0),
@ -222,31 +257,28 @@ export default {
id: Number(this.orderData[0].goods_id), id: Number(this.orderData[0].goods_id),
}; };
// console.log(this.orderData,'???')
createCartOrder(params) createCartOrder(params)
.then((res) => { .then((res) => {
const plugin = tt.requirePlugin("tta5a3d31e3aecfb9b11"); uni.hideLoading();
// Check if tt and requirePlugin are available
if (typeof tt !== 'undefined' && tt.requirePlugin) {
try {
const plugin = tt.requirePlugin("lifeServicePlugin");
if (plugin && plugin.createOrder) {
plugin.createOrder({ plugin.createOrder({
goodsList: [ skuList: res.data.skuList,
{ payment: res.data.payment,
quantity: 10, // 购买数量 必填 bookInfo:res.data.bookInfo,
price: 1, // 商品价格 必填
goodsName: "测试商品", // 商品名称 必填
goodsPhoto:"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.ibaotu.com%2Fgif%2F19%2F48%2F47%2F76Z888piCd6W.gif%21fwpaa50%2Ffw%2F700&refer=http%3A%2F%2Fpic.ibaotu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1644654365&t=5fc9b5fdad0a16264a9a9c09c14b3af9", // 商品图片链接 必填
goodsId: "123", // 商品ID 必填(请务必使用小程序商品)
goodsType: 2, // 商品类型 必填
},
],
payment: {
totalAmount: 10, // 订单总价 必填
},
success: (res) => { success: (res) => {
const { orderId, outOrderNo } = res; const { orderId, outOrderNo } = res;
console.log("success res", res); console.log("success res", res);
console.log("orderId", orderId, "outOrderNo", outOrderNo); console.log("orderId", orderId, "outOrderNo", outOrderNo);
this.setData({ orderId, outOrderNo }); // Update data the Vue way
this.orderId = orderId;
this.outOrderNo = outOrderNo;
uni.navigateTo({ uni.navigateTo({
url:"/pages/client/order/list", url: "/pages/client/order/list",
}); });
}, },
fail: (res) => { fail: (res) => {
@ -259,12 +291,45 @@ export default {
console.log("支付失败", errNo, errMsg, orderId, outOrderNo); console.log("支付失败", errNo, errMsg, orderId, outOrderNo);
} }
console.log(errNo, errMsg); console.log(errNo, errMsg);
uni.showToast({
title: errMsg || '支付失败',
icon: 'none'
});
}, },
}); });
} else {
console.error('Plugin or createOrder method not found');
uni.showToast({
title: '支付插件初始化失败',
icon: 'none'
});
}
} catch (error) {
console.error('Error requiring plugin:', error);
uni.showToast({
title: '支付插件加载失败',
icon: 'none'
});
}
} else {
console.log('TikTok Mini Program environment not detected');
uni.showToast({
title: '请在抖音小程序中打开',
icon: 'none'
});
}
resolve(); resolve();
}) })
.catch((err) => {}); .catch((err) => {
uni.hideLoading();
console.error('createCartOrder error:', err);
uni.showToast({
title: '创建订单失败',
icon: 'none'
});
reject(err);
});
}); });
}, },
}, },

View File

@ -1,6 +1,6 @@
<template> <template>
<view class="goods-item" > <view class="goods-item" >
<image class="goods-img" :src="data.product_pic" mode="aspectFill" /> <image class="goods-img" :src="getProductImage(data)" mode="aspectFill" />
<view class=" fs-24 app-fc-main goods-name"> <view class=" fs-24 app-fc-main goods-name">
{{ data.product.product_name || "" }} {{ data.product.product_name || "" }}
</view> </view>
@ -13,7 +13,7 @@
<text class="fs-28" style="color: #3D3D3D;"> <text class="fs-28" style="color: #3D3D3D;">
¥ ¥
<text class="fs-28">{{ <text class="fs-28">{{
data.product.product_type || 0 data.sku.actual_amount / 100 || 0
}}</text> }}</text>
</text> </text>
<!-- <text class="fs-24 origin-price"> <!-- <text class="fs-24 origin-price">
@ -65,6 +65,27 @@
// 触发购买事件,通知父组件 // 触发购买事件,通知父组件
this.$emit('addToCar', this.data); this.$emit('addToCar', this.data);
}, },
getProductImage(data) {
// Try to get product_pic first
if (data.product_pic) {
return data.product_pic;
}
// Try to parse image_list from attr_key_value_map
if (data.product?.attr_key_value_map?.image_list) {
try {
const imageList = data.product.attr_key_value_map.image_list;
const parsedList = typeof imageList === 'string' ? JSON.parse(imageList) : imageList;
if (Array.isArray(parsedList) && parsedList.length > 0) {
return parsedList[0].url || parsedList[0] || '';
}
} catch (e) {
console.error('Error parsing image_list:', e);
}
}
return '';
}
}, },
}; };
</script> </script>

View File

@ -21,7 +21,7 @@
<view class="flex-row-between" style="margin-top: 20rpx"> <view class="flex-row-between" style="margin-top: 20rpx">
<view class=""> <view class="">
<text class="app-fc-mark fs-28"></text> <text class="app-fc-mark fs-28"></text>
<text class="app-fc-mark fs-28">{{picList[0].actual_price || 0 }}</text> <text class="app-fc-mark fs-28">{{picList[0].actual_price / 100 || 0 }}</text>
<!-- <text class="fs-24 origin-price"> <!-- <text class="fs-24 origin-price">
¥{{ minPrice.price_shichang || 0 }} ¥{{ minPrice.price_shichang || 0 }}
</text> --> </text> -->
@ -410,7 +410,7 @@
number, number,
goods_name: this.details.goods_name, goods_name: this.details.goods_name,
price_name: priceInfo?.price_name, price_name: priceInfo?.price_name,
goods_price: +(+priceInfo?.actual_price * number).toFixed(2), goods_price: +((priceInfo?.actual_price / 100) * number).toFixed(2),
}, ], }, ],
}); });
}, },

View File

@ -274,8 +274,7 @@ export default {
}) })
.then((res) => { .then((res) => {
const list = res?.data || []; const list = res?.data || [];
this.goodsList = this.goodsList = list;
this.page === 1 ? list : [...this.goodsList, ...list];
this.total = res?.count || 0; this.total = res?.count || 0;
}) })
.finally(() => { .finally(() => {
@ -397,8 +396,8 @@ export default {
product_id: good.product_id, product_id: good.product_id,
product_name: good.product_name, product_name: good.product_name,
product_pic: good.product_pic, product_pic: good.product_pic,
goods_price: good.prices?.[0]?.actual_price, goods_price: good.prices?.[0]?.actual_price / 100,
product_price: good.prices?.[0]?.actual_price, product_price: good.prices?.[0]?.actual_price / 100,
original_price: good.prices?.[0]?.original_price, original_price: good.prices?.[0]?.original_price,
yunfei: good.yunfei || 0, yunfei: good.yunfei || 0,
}, },