diff --git a/pages.json b/pages.json index c8bb6b5..cccdb57 100644 --- a/pages.json +++ b/pages.json @@ -84,6 +84,12 @@ "style": { "navigationBarTitleText": "积分流水" } + }, + { + "path": "pages/inviteUsers/index", + "style": { + "navigationBarTitleText": "我邀请的用户" + } } ], "globalStyle": { diff --git a/pages/inviteUsers/index.vue b/pages/inviteUsers/index.vue new file mode 100644 index 0000000..eb982be --- /dev/null +++ b/pages/inviteUsers/index.vue @@ -0,0 +1,293 @@ + + + + + + diff --git a/pages/login/index.vue b/pages/login/index.vue index 552d76b..eb5f92e 100644 --- a/pages/login/index.vue +++ b/pages/login/index.vue @@ -54,14 +54,14 @@ export default { if (!loginRes.code) { throw new Error('获取微信登录code失败'); } - - const open_id = (await request('xcx/basic_login', 'post', {code: loginRes.code})).openid + + const open_id = (await request('xcx/basic_login', 'post', { code: loginRes.code })).openid // 调用登录接口,传递code和加密数据 const loginData = { code: e.detail.code, invitation_code: '', - openid: open_id + openid: open_id // iv: e.detail.iv }; @@ -69,7 +69,7 @@ export default { await wx.setStorageSync('access_token', result.token); await wx.setStorageSync('is_personal_information_complete', result.is_personal_information_complete); // if (result.is_personal_information_complete) { - wx.navigateBack(); + wx.navigateBack(); // } else { // wx.navigateTo({ // url: `/pages/my/editInfo/index`, diff --git a/pages/my/index.vue b/pages/my/index.vue index 1bdc314..5cd1518 100644 --- a/pages/my/index.vue +++ b/pages/my/index.vue @@ -262,6 +262,7 @@ export default { quickActions: [ { icon: '💳', label: '我的钱包' }, { icon: '📍', label: '地址管理', path: '/pages/address/index' }, + { icon: '🤝', label: '邀请用户', path: '/pages/inviteUsers/index' }, { icon: '🔔', label: '消息通知' }, { icon: '❓', label: '帮助中心' } ], @@ -701,6 +702,9 @@ export default { if (item.label === '当前积分') { this.navigateTo('/pages/pointsLog/index'); } + if (item.label === '总订单数') { + this.navigateTo('/pages/order/index'); + } }, toEditInfoPage() { uni.navigateTo({ diff --git a/pages/order/create.vue b/pages/order/create.vue index 903fe21..9a8bf90 100644 --- a/pages/order/create.vue +++ b/pages/order/create.vue @@ -266,29 +266,29 @@ export default { this.submitting = true; // 获取小程序的appid - if (!this.app_id) { - const accountInfo = wx.getAccountInfoSync && wx.getAccountInfoSync(); - this.app_id = accountInfo && accountInfo.miniProgram && accountInfo.miniProgram.appId - ? accountInfo.miniProgram.appId - : ''; - } + // if (!this.app_id) { + // const accountInfo = wx.getAccountInfoSync && wx.getAccountInfoSync(); + // this.app_id = accountInfo && accountInfo.miniProgram && accountInfo.miniProgram.appId + // ? accountInfo.miniProgram.appId + // : ''; + // } try { // 构建订单数据 const orderData = { - app_id: this.app_id, + // app_id: this.app_id, address_id: this.selectedAddress.id, - items: this.orderItems.map(item => ({ - cart_id: item.cart_id, - product_id: item.product_id, - sku_id: item.sku_id, - quantity: item.quantity, - price: item.price - })), - remark: this.orderRemark, - total_price: this.totalPrice, - shipping_fee: this.shippingFee, - discount_amount: this.discountAmount, - final_price: this.finalPrice + // items: this.orderItems.map(item => ({ + // cart_id: item.cart_id, + // product_id: item.product_id, + // sku_id: item.sku_id, + // quantity: item.quantity, + // price: item.price + // })), + // remark: this.orderRemark, + // total_price: this.totalPrice, + // shipping_fee: this.shippingFee, + // discount_amount: this.discountAmount, + // final_price: this.finalPrice }; // 调用创建订单接口 diff --git a/pages/order/index.vue b/pages/order/index.vue index 684d0c5..5419537 100644 --- a/pages/order/index.vue +++ b/pages/order/index.vue @@ -26,14 +26,14 @@ - 订单号:{{ order.order_no || order.no }} - {{ formatDate(order.created_at || order.date) }} + 订单号:{{ order.order_id }} + {{ formatDate(order.created_at || order.createdAt || order.date) }} {{ getStatusText(order.status) }} @@ -44,12 +44,12 @@ @@ -62,7 +62,7 @@ - {{ formatPrice(item.price || order.price) }} + {{ formatPrice(item.price || order.price || item.sku_price) }} x{{ item.quantity || order.quantity || 1 }} @@ -74,7 +74,7 @@ 共{{ getTotalQuantity(order) }}件商品 合计: - ¥{{ formatPrice(order.final_price || order.total_price || order.amount) }} + ¥{{ formatPrice(order.final_price || order.payable_amount || order.total_price || order.amount || order.total_amount) }} sum + (parseInt(item.quantity) || 1), 0); + const items = order.items || order.product_list; + if (items && Array.isArray(items)) { + return items.reduce((sum, item) => sum + (parseInt(item.quantity) || 1), 0); } return parseInt(order.quantity) || 1; }, diff --git a/pages/shopDetail/index.vue b/pages/shopDetail/index.vue index 50d84d1..a882bfa 100644 --- a/pages/shopDetail/index.vue +++ b/pages/shopDetail/index.vue @@ -42,7 +42,7 @@ ¥{{ formatPrice(currentPrice) }} ¥{{ formatPrice(originalPrice) - }} + }} 请选择规格 @@ -143,17 +143,17 @@ 前调: {{ productInfo.scent_level.top_note || '柠檬、佛手柑、粉红胡椒' - }} + }} 中调: {{ productInfo.scent_level.middle_note || '玫瑰、茉莉、牡丹' - }} + }} 后调: {{ productInfo.scent_level.base_note || '白麝香、雪松、香草' - }} + }} @@ -254,9 +254,10 @@ 购物车 + {{ cartSelectedCount }} 加入购物车 - 立即购买 + @@ -307,6 +308,7 @@ export default { activeTab: 'detail', showPurchaseModal: false, purchaseAction: 'cart', // 'cart' 或 'buy' + cartSelectedCount: 0, fragranceNotes: { top: '柠檬、佛手柑、粉红胡椒', middle: '玫瑰、茉莉、牡丹', @@ -357,6 +359,10 @@ export default { onLoad(options) { // this.productInfo = uni.getStorageSync('product_info'); this.loadProductDetail(uni.getStorageSync('product_info')); + this.fetchCartSelectedCount(); + }, + onShow() { + this.fetchCartSelectedCount(); }, methods: { @@ -483,33 +489,53 @@ export default { switchTab(tab) { this.activeTab = tab; }, - - // 打开购买弹窗 - 加入购物车 - addToCart() { - this.purchaseAction = 'cart'; - // 如果还没有选择SKU,自动选择第一个可用的 - if (!this.selectedSku && this.skuList.length > 0) { - const availableSku = this.skuList.find(sku => sku && (sku.quantity > 0 || sku.quantity === undefined)) || this.skuList[0]; - if (availableSku) { - const skuIndex = this.skuList.indexOf(availableSku); - this.selectSku(availableSku, skuIndex >= 0 ? skuIndex : 0); - } + async userIsLogin() { + const token = await uni.getStorageSync('access_token') + if (token) { + return + } else { + uni.navigateTo({ + url: '/pages/login/index' + }) } - this.showPurchaseModal = true; + }, + // 打开购买弹窗 - 加入购物车 + async addToCart() { + await this.userIsLogin().then(async (res) => { + this.purchaseAction = 'cart'; + // 如果还没有选择SKU,自动选择第一个可用的 + if (!this.selectedSku && this.skuList.length > 0) { + const availableSku = this.skuList.find(sku => sku && (sku.quantity > 0 || sku.quantity === undefined)) || this.skuList[0]; + if (availableSku) { + const skuIndex = this.skuList.indexOf(availableSku); + this.selectSku(availableSku, skuIndex >= 0 ? skuIndex : 0); + } + } + this.showPurchaseModal = true; + }).catch((err) => { + console.log(err); + }); + + }, // 打开购买弹窗 - 立即购买 - buyNow() { - this.purchaseAction = 'buy'; - // 如果还没有选择SKU,自动选择第一个可用的 - if (!this.selectedSku && this.skuList.length > 0) { - const availableSku = this.skuList.find(sku => sku && (sku.quantity > 0 || sku.quantity === undefined)) || this.skuList[0]; - if (availableSku) { - const skuIndex = this.skuList.indexOf(availableSku); - this.selectSku(availableSku, skuIndex >= 0 ? skuIndex : 0); + async buyNow() { + await this.userIsLogin().then((res) => { + this.purchaseAction = 'buy'; + // 如果还没有选择SKU,自动选择第一个可用的 + if (!this.selectedSku && this.skuList.length > 0) { + const availableSku = this.skuList.find(sku => sku && (sku.quantity > 0 || sku.quantity === undefined)) || this.skuList[0]; + if (availableSku) { + const skuIndex = this.skuList.indexOf(availableSku); + this.selectSku(availableSku, skuIndex >= 0 ? skuIndex : 0); + } } - } - this.showPurchaseModal = true; + this.showPurchaseModal = true; + }).catch((err) => { + console.log(err); + }); + }, // 关闭购买弹窗 @@ -540,6 +566,7 @@ export default { title: '已添加到购物车', icon: 'success' }); + this.fetchCartSelectedCount(); } catch (error) { console.error('添加到购物车失败:', error); uni.showToast({ @@ -574,6 +601,20 @@ export default { uni.navigateTo({ url: '/pages/shoppingCart/index' }); + }, + async fetchCartSelectedCount() { + try { + const res = await request('xcx/carts', 'GET', { page: 1, page_size: 99 }); + const list = res.list || res.data || res || []; + this.cartSelectedCount = list + .filter(item => item && item.selected === 1) + .reduce((sum, item) => { + const quantity = parseInt(item.quantity || item.count || 0, 10); + return sum + (isNaN(quantity) ? 0 : quantity); + }, 0); + } catch (error) { + console.error('获取购物车数量失败:', error); + } } } }; @@ -1223,6 +1264,7 @@ export default { color: #666; padding: 12rpx 0; box-sizing: border-box; + position: relative; } .bar-btn .iconfont { @@ -1254,4 +1296,20 @@ export default { height: 72rpx; line-height: 72rpx; } + +.cart-count { + position: absolute; + top: 6rpx; + right: 36rpx; + min-width: 32rpx; + padding: 0 8rpx; + height: 32rpx; + border-radius: 16rpx; + background-color: #ff4d4f; + color: #fff; + font-size: 20rpx; + line-height: 32rpx; + text-align: center; + box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.15); +}