Compare commits
18 Commits
41f6f612fa
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6deef6cdce | |||
| e894689918 | |||
| 26e57e4891 | |||
| 32fa3e9bd2 | |||
| 4002f91a54 | |||
| a2fadc57b8 | |||
| b251c899ca | |||
| cdf0bc5a01 | |||
| 7a490f0ffc | |||
| 34148c6084 | |||
| 9b6b76f747 | |||
| 6ea50b824f | |||
| 72e481c6c5 | |||
| 124beb0666 | |||
| 078e0bc8ab | |||
| 1739401cb8 | |||
| 3afa2e8c10 | |||
| 7d1083bf5c |
@ -2,7 +2,7 @@ import request from "../utils/request";
|
||||
import { LOGIN, GET_PHONE, USER_SHARE,USER_WALLET,RECHARGE_WALLET,USER_WXPAY,USER_TRANSACTION,USER_ADDITIONAL,MEMBER_TYPES,
|
||||
USER_RECHARGE,USER_REDEEM,USER_HolderList,USER_MEMBERSHIP,USER_BINDPETS,USER_PETBINDING,USER_DISCOUNTFEE,USER_COUPONLIST,CANCEL_PET_ORDER,
|
||||
GET_VIP_PRICE,POINTS_RECHARGE_LIST,POINTS_DONATE,POINTS_RECORDS,POINTS_RANK,OSS_STS,DONATION_SUMMARY,
|
||||
USER_DISPATCHFEE,CANCEL_MALL_ORDER,DOUY_REVIEW
|
||||
USER_DISPATCHFEE,CANCEL_MALL_ORDER,DOUY_REVIEW,CANCEL_NOMO_ORDER,LOGIN_PHONE
|
||||
} from "./url";
|
||||
// 微信登陆
|
||||
export const getCodeByWxLogin = () => {
|
||||
@ -10,7 +10,7 @@ export const getCodeByWxLogin = () => {
|
||||
tt.login({
|
||||
provider: "toutiao",
|
||||
success: function (loginRes) {
|
||||
// console.log(loginRes,'?1?')
|
||||
console.log(loginRes,'?1?')
|
||||
resolve(loginRes.code);
|
||||
},
|
||||
fail: function (err) {
|
||||
@ -23,7 +23,7 @@ export const getCodeByWxLogin = () => {
|
||||
import Store from "../store";
|
||||
|
||||
// 登录鉴权
|
||||
export const login = (nickName, avatarUrl) => {
|
||||
export const login = ( phone) => {
|
||||
return getCodeByWxLogin().then((code) => {
|
||||
// 从 vuex 中获取 referrerID(如果通过二维码扫描进入)
|
||||
const referrerID = Store.state.user?.referrerID || 0;
|
||||
@ -32,17 +32,11 @@ export const login = (nickName, avatarUrl) => {
|
||||
url: LOGIN,
|
||||
method: "POST",
|
||||
data: {
|
||||
nickName:nickName,
|
||||
avatarUrl:avatarUrl,
|
||||
code: code,
|
||||
source:'douyin',
|
||||
referrerID:0,
|
||||
referrerType:'douyin'
|
||||
// // yaoqing_code: inviteCode || null,
|
||||
// phone: phone || null,
|
||||
// source: "wechat",
|
||||
// referrerID: Number(referrerID) || 0,
|
||||
// referrerType: "wechat"
|
||||
phone: phone || null,
|
||||
source: 'douyin',
|
||||
referrerID: 0,
|
||||
referrerType: 'douyin'
|
||||
},
|
||||
}).then((res) => {
|
||||
// 登录接口使用完 referrerID 后,清除一次,避免重复使用
|
||||
@ -54,12 +48,13 @@ export const login = (nickName, avatarUrl) => {
|
||||
});
|
||||
};
|
||||
// 获取手机号
|
||||
export const getPhone = (code) => {
|
||||
export const getPhone = (phoneCode, loginCode) => {
|
||||
return request({
|
||||
url: GET_PHONE,
|
||||
method: "POST",
|
||||
data: {
|
||||
code: code
|
||||
code: phoneCode,
|
||||
loginCode: loginCode
|
||||
},
|
||||
});
|
||||
};
|
||||
@ -74,6 +69,18 @@ export const userShare = (id) => {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
export const login_phone = (phone) => {
|
||||
return request({
|
||||
url: LOGIN_PHONE,
|
||||
method: "POST",
|
||||
data: {
|
||||
phone
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// 用户钱包
|
||||
export const userWllet = (id) => {
|
||||
return request({
|
||||
@ -164,10 +171,11 @@ export const getDonationSummary = () => {
|
||||
};
|
||||
|
||||
// 抖音审核
|
||||
export const getdouyReview = () => {
|
||||
export const getdouyReview = (data) => {
|
||||
return request({
|
||||
url: DOUY_REVIEW,
|
||||
method: "GET"
|
||||
method: "POST",
|
||||
data,
|
||||
});
|
||||
};
|
||||
|
||||
@ -225,6 +233,15 @@ export const cancelPetOrderMall = (data) => {
|
||||
});
|
||||
};
|
||||
|
||||
// 未支付取消商城订单
|
||||
export const cancelUnpaid = (data) => {
|
||||
return request({
|
||||
url: CANCEL_NOMO_ORDER,
|
||||
method: "POST",
|
||||
data: data
|
||||
});
|
||||
};
|
||||
|
||||
// 绑定宠物列表
|
||||
export const bindPets = (data) => {
|
||||
return request({
|
||||
|
||||
@ -115,12 +115,12 @@ export const updateCartSelect = ({ is_select,cart_id }) => {
|
||||
};
|
||||
|
||||
// 删除购物车
|
||||
export const deleteCart = ({ cart_id }) => {
|
||||
export const deleteCart = ({ id }) => {
|
||||
return request({
|
||||
url: DELETE_CART,
|
||||
method: "post",
|
||||
data: {
|
||||
cart_id,
|
||||
id,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@ -56,8 +56,13 @@ export const CANCEL_PET_ORDER = '/order/pet/cancel'
|
||||
// 抖音审核接口
|
||||
export const DOUY_REVIEW = '/douyin/goods/order/appointment'
|
||||
|
||||
// 抖音未支付订单取消接口
|
||||
export const CANCEL_NOMO_ORDER = '/douyin/goods/order/cancel'
|
||||
|
||||
export const LOGIN_PHONE = '/api/v1/auth/login'
|
||||
|
||||
// 取消商城接口
|
||||
export const CANCEL_MALL_ORDER = '/douyin/goods/order/cancel'
|
||||
export const CANCEL_MALL_ORDER = '/douyin/goods/order/refund'
|
||||
|
||||
// 卡包列表接口
|
||||
export const USER_HolderList = '/membership/instances'
|
||||
@ -198,7 +203,7 @@ export const GET_GOODS_CATEGORY = "/product/type/list";
|
||||
// 商品列表
|
||||
export const GET_GOODS_LIST = "/douyin/goods/product/online/query";
|
||||
// 商品详情
|
||||
export const GET_GOODS_DETAIL = "/product/detail";
|
||||
export const GET_GOODS_DETAIL = "/douyin/goods/product/detail";
|
||||
|
||||
// 获取优惠券列表
|
||||
export const GET_COUPON_LIST = "/app/coupon/coupon_list";
|
||||
@ -227,7 +232,7 @@ export const UPDATE_CART_NUM = "/cart/update";
|
||||
// 选择购物车商品
|
||||
export const UPDATE_CART_SELECT = "/cart/select/all";
|
||||
// 删除购物车
|
||||
export const DELETE_CART = "/product/cart/delete";
|
||||
export const DELETE_CART = "/douyin/goods/order/refund";
|
||||
|
||||
// 创建订单
|
||||
export const CREATE_ORDER_NEW = "/product/order/create";
|
||||
@ -238,7 +243,7 @@ export const PAY_ORDER_NEW = "/ttpay/jsapi";
|
||||
// 订单列表
|
||||
export const SHOP_ORDER_LIST = "/douyin/goods/order/list";
|
||||
// 订单详情
|
||||
export const SHOP_ORDER_DETAILS = "/product/order/show";
|
||||
export const SHOP_ORDER_DETAILS = "/douyin/goods/order/show";
|
||||
// 取消订单
|
||||
export const SHOP_ORDER_CANCEL = '/app/order/order_quxiao'
|
||||
// 提醒发货
|
||||
|
||||
@ -3,8 +3,8 @@ export default {
|
||||
appName: "Wagoo",
|
||||
appShareName: "Wagoo",
|
||||
appId: "wx00e2dcdc7c02b23a",
|
||||
apiBaseUrl: "https://api.wagoo.me/api/v1", // 服务端测试地址
|
||||
// apiBaseUrl: "https://api.wagoo.pet/api/v1", // 服务端生产地址
|
||||
// apiBaseUrl: "https://api.wagoo.me/api/v1", // 服务端测试地址
|
||||
apiBaseUrl: "https://api.wagoo.pet/api/v1", // 服务端生产地址
|
||||
// apiBaseUrl: "http:192.168.30.79", //本地接口
|
||||
tencentMapKey: "WSBBZ-7OXK4-46QUC-KFB7B-4N3W7-M2BXM",
|
||||
tencentSecret: "vb7D0PGj7xUvmOLuJz2Jd7ykTMpjiWRJ",
|
||||
|
||||
@ -96,7 +96,7 @@
|
||||
</view> -->
|
||||
</view>
|
||||
<view class="payBtn" @click.stop="writeOff">
|
||||
核销
|
||||
预约
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@ -147,6 +147,12 @@ export default {
|
||||
components: {
|
||||
InfoCell,
|
||||
},
|
||||
props: {
|
||||
orderId: {
|
||||
type: [String, Number],
|
||||
default: null
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
imgPrefix,
|
||||
@ -156,7 +162,7 @@ export default {
|
||||
ORDER_TYPE_RESERVATION,
|
||||
ORDER_TYPE_SITE,
|
||||
orderType: ORDER_TYPE_RESERVATION,
|
||||
selectedPetType: PET_TYPE_CAT, // 默认选中“猫”
|
||||
selectedPetType: PET_TYPE_CAT, // 默认选中"猫"
|
||||
petInfo: {}, // 兼容下游,取 selectedPets[0]
|
||||
selectedPets: [], // 多选宠物列表
|
||||
parkState: "",
|
||||
@ -168,11 +174,24 @@ export default {
|
||||
address: null,
|
||||
catHtmlData: "",
|
||||
dogHtmlData: "",
|
||||
tip: ''
|
||||
tip: '',
|
||||
localOrderId: null, // 本地存储的 orderId
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.initData();
|
||||
// 如果有传入的 orderId,保存到本地
|
||||
if (this.orderId) {
|
||||
this.localOrderId = this.orderId;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
// 监听 orderId 变化
|
||||
orderId(newVal) {
|
||||
if (newVal) {
|
||||
this.localOrderId = newVal;
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
// 展示价格:discount_price 数组相加的总和
|
||||
@ -186,26 +205,87 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 用于接收从父页面传递的数据
|
||||
onShowFun(orderId) {
|
||||
if (orderId) {
|
||||
this.localOrderId = orderId;
|
||||
}
|
||||
},
|
||||
// 核销按钮点击处理
|
||||
async writeOff () {
|
||||
const data = {
|
||||
goods_order_id:1, //抖音商品订单id(整数)
|
||||
order_date:'2026-03-01', //预约日期(‘2026-03-01’格式)
|
||||
period_id:1, //预约时间段id(整数)
|
||||
address_id:1, //地址id(整数)
|
||||
recipient_name:'用户姓名', //用户姓名
|
||||
phone:123, //用户手机
|
||||
park_desc:123, //停车描述
|
||||
note:'哈哈' // 备注
|
||||
// 校验必填项
|
||||
if (Object.keys(this.reservationTime).length === 0) {
|
||||
uni.showToast({
|
||||
title: "请选择预约时间",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!this.address) {
|
||||
uni.showToast({
|
||||
title: "请选择服务地址",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!this.parkState) {
|
||||
uni.showToast({
|
||||
title: "请选择停车状况",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!this.localOrderId) {
|
||||
uni.showToast({
|
||||
title: "订单ID缺失",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const data = {
|
||||
goods_order_id: Number(this.localOrderId), //抖音商品订单id(整数)
|
||||
order_date: this.reservationTime.date, //预约日期('2026-03-01'格式)
|
||||
period_id: Number(this.reservationTime.id), //预约时间段id(整数)
|
||||
address_id: Number(this.address.id), //地址id(整数)
|
||||
recipient_name: this.address.name || '用户姓名', //用户姓名
|
||||
phone: this.address.phone || '', //用户手机
|
||||
park_desc: this.parkState || '', //停车描述
|
||||
note: this.otherParkState || '' // 备注
|
||||
};
|
||||
|
||||
uni.showLoading({
|
||||
title: "处理中",
|
||||
mask: true,
|
||||
});
|
||||
|
||||
getdouyReview(data).then((res) => {
|
||||
uni.hideLoading();
|
||||
if (res.code == 0) {
|
||||
uni.showToast({
|
||||
title: "预约成功",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
});
|
||||
// 预约成功后清空数据并跳转
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({
|
||||
url: "/pages/client/index/index?activePageId=homePage",
|
||||
});
|
||||
}, 1500);
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.msg || "预约失败",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
}).catch((err) => {
|
||||
uni.hideLoading();
|
||||
console.error("预约失败:", err);
|
||||
uni.showToast({
|
||||
title: "预约失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
getPetShortName(pet) {
|
||||
|
||||
@ -322,7 +322,7 @@
|
||||
"style": {
|
||||
"navigationBarTitleText": "商城订单",
|
||||
"usingComponents": {
|
||||
"pay-button-sdk": "tta5a3d31e3aecfb9b11://pay-button"
|
||||
"pay-button": "tta5a3d31e3aecfb9b11://pay-button"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -1,17 +1,28 @@
|
||||
<template>
|
||||
<view class="loginContainer">
|
||||
<view class="body">
|
||||
<image class="login-ground-img" :src="`${imgPrefix}loginGroundImg.png`" mode="widthFix" />
|
||||
<image
|
||||
class="login-ground-img"
|
||||
:src="`${imgPrefix}loginGroundImg.png`"
|
||||
mode="widthFix"
|
||||
/>
|
||||
<view class="btnConent">
|
||||
<button v-show="!checked" class="loginBtn" @click="unCheckAndGetPhoneNumber">
|
||||
<button
|
||||
v-show="!checked"
|
||||
class="loginBtn"
|
||||
@click="unCheckAndGetPhoneNumber"
|
||||
>
|
||||
抖音用户信息授权登录
|
||||
</button>
|
||||
<button v-show="checked" class="loginBtn" @tap="getPhoneNumber" >
|
||||
抖音用户信息授权登录
|
||||
<button
|
||||
v-show="checked"
|
||||
class="loginBtn"
|
||||
open-type="getPhoneNumber"
|
||||
@getphonenumber="getPhoneNumber"
|
||||
>
|
||||
抖音用户信息授权登录
|
||||
</button>
|
||||
<view class="notLoginBtn" @click="goBack">
|
||||
暂不登录
|
||||
</view>
|
||||
<view class="notLoginBtn" @click="goBack"> 暂不登录 </view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@ -19,7 +30,11 @@
|
||||
<view class="radioWrapper">
|
||||
<view class="checkbox-wrapper" @click.stop="changeChecked">
|
||||
<view class="checkbox" :class="{ 'checkbox-checked': checked }">
|
||||
<image v-if="checked" class="check-icon" :src="require('@/static/images/y.png')" />
|
||||
<image
|
||||
v-if="checked"
|
||||
class="check-icon"
|
||||
:src="require('@/static/images/y.png')"
|
||||
/>
|
||||
</view>
|
||||
<!-- <view v-if="uncheckMessageDialog" class="tooltip">
|
||||
<view class="tooltip-content">请先勾选,同意后再进行登录</view>
|
||||
@ -28,7 +43,9 @@
|
||||
</view>
|
||||
<text class="radioText">
|
||||
请阅读并同意
|
||||
<text class="color" @click.stop="ptfwxy">《帮宠到家平台服务协议》</text>
|
||||
<text class="color" @click.stop="ptfwxy"
|
||||
>《帮宠到家平台服务协议》</text
|
||||
>
|
||||
<text class="color" @click.stop="ysxy">《隐私协议》</text>
|
||||
</text>
|
||||
</view>
|
||||
@ -54,6 +71,16 @@ export default {
|
||||
},
|
||||
onLoad(options) {
|
||||
this.yaoqing_code = options.yaoqing_code
|
||||
tt.login({
|
||||
provider: "toutiao",
|
||||
success: function (loginRes) {
|
||||
|
||||
console.log('获取 login code 成功:', loginRes);
|
||||
},
|
||||
fail: function (err) {
|
||||
console.log('获取 login code 失败:', err);
|
||||
},
|
||||
});
|
||||
},
|
||||
mounted() { },
|
||||
methods: {
|
||||
@ -81,14 +108,14 @@ export default {
|
||||
duration: 2000
|
||||
});
|
||||
},
|
||||
getmembeInfo(nickName,avatarUrl) {
|
||||
getmembeInfo(phone) {
|
||||
const inviteCode = this.yaoqing_code ? this.yaoqing_code : getApp().globalData.inviteCode
|
||||
uni.showLoading({
|
||||
title: "登录中...",
|
||||
icon: "none",
|
||||
mask: true,
|
||||
});
|
||||
login(nickName,avatarUrl).then((res) => {
|
||||
login(phone).then((res) => {
|
||||
uni.hideLoading()
|
||||
this.$store.dispatch("user/setToken", res?.data?.token || "");
|
||||
this.$store.dispatch("user/setUserInfo", res?.data || {});
|
||||
@ -143,77 +170,128 @@ export default {
|
||||
// });
|
||||
// }),
|
||||
async getPhoneNumber(e) {
|
||||
// console.log(e,'?')
|
||||
// return
|
||||
// 检查是否有 code
|
||||
// if (!e.detail.code) {
|
||||
console.log('获取手机号事件:', e);
|
||||
this.getmembeInfo(e.detail.code)
|
||||
|
||||
// // 检查是否有 code
|
||||
// if (!e.detail || !e.detail.code) {
|
||||
// uni.showToast({
|
||||
// title: "获取手机号失败,请重试",
|
||||
// title: "用户取消授权或获取手机号失败",
|
||||
// icon: "none",
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
|
||||
// uni.showLoading({
|
||||
// title: "获取手机号中...",
|
||||
// title: "登录中...",
|
||||
// icon: "none",
|
||||
// mask: true,
|
||||
// });
|
||||
|
||||
try {
|
||||
let that = this
|
||||
tt.getUserProfile({
|
||||
// try {
|
||||
// const that = this;
|
||||
// let loginCode = null;
|
||||
|
||||
success(res) {
|
||||
console.log(res,'???')
|
||||
// this.nickName = res.res.userInfo.nickName
|
||||
// this.avatarUrl = res.userInfo.avatarUrl
|
||||
that.getmembeInfo(res.userInfo.nickName,res.userInfo.avatarUrl)
|
||||
// console.log(res,'--=')
|
||||
},
|
||||
fail(res) {
|
||||
console.log("getUserProfile 调用失败", res);
|
||||
},
|
||||
// // 先获取 login code
|
||||
// try {
|
||||
// loginCode = await new Promise((resolve, reject) => {
|
||||
// tt.login({
|
||||
// provider: "toutiao",
|
||||
// success: function (loginRes) {
|
||||
// console.log('获取 login code 成功:', loginRes);
|
||||
// resolve(loginRes.code);
|
||||
// },
|
||||
// fail: function (err) {
|
||||
// console.log('获取 login code 失败:', err);
|
||||
// reject(err);
|
||||
// },
|
||||
// });
|
||||
// });
|
||||
// } catch (loginErr) {
|
||||
// throw new Error('获取登录凭证失败');
|
||||
// }
|
||||
|
||||
});
|
||||
// // 拿着 phone code 和 login code 获取手机号
|
||||
// let phone = null;
|
||||
// try {
|
||||
// const codeRes = await getPhone(e.detail.code, loginCode);
|
||||
// phone = codeRes?.data?.phoneNumber || "";
|
||||
// console.log('获取手机号成功:', phone);
|
||||
// } catch (phoneErr) {
|
||||
// console.error('获取手机号失败:', phoneErr);
|
||||
// throw new Error('获取手机号失败');
|
||||
// }
|
||||
|
||||
// if (!phone) {
|
||||
// throw new Error('获取手机号失败,请重试');
|
||||
// }
|
||||
|
||||
// const inviteCode = this.yaoqing_code ? this.yaoqing_code : getApp().globalData.inviteCode
|
||||
// console.log('获取到邀请码----->', inviteCode)
|
||||
// 手机号登录
|
||||
// 获取用户信息
|
||||
// tt.getUserProfile({
|
||||
// success: async (profileRes) => {
|
||||
// console.log('获取用户信息成功:', profileRes);
|
||||
// const nickName = profileRes.userInfo?.nickName || '';
|
||||
// const avatarUrl = profileRes.userInfo?.avatarUrl || '';
|
||||
|
||||
// 拿着code获取手机号
|
||||
// const codeRes = await getPhone(e.detail.code);
|
||||
// const phone = codeRes?.data?.phoneNumber || "";
|
||||
// try {
|
||||
// const inviteCode = that.yaoqing_code ? that.yaoqing_code : getApp().globalData.inviteCode;
|
||||
|
||||
// if (!phone) {
|
||||
// uni.hideLoading();
|
||||
// uni.showToast({
|
||||
// title: "获取手机号失败,请重试",
|
||||
// icon: "none",
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
// // 登录
|
||||
// const loginRes = await login(nickName, avatarUrl, phone);
|
||||
// uni.hideLoading();
|
||||
|
||||
// that.$store.dispatch("user/setToken", loginRes?.data?.token || "");
|
||||
// that.$store.dispatch("user/setUserInfo", loginRes?.data || {});
|
||||
|
||||
} catch (error) {
|
||||
uni.hideLoading();
|
||||
console.error("获取手机号失败:", error);
|
||||
// 检查是否是 access_token 相关错误
|
||||
const errorMsg = error?.message || error || "";
|
||||
if (errorMsg.includes("access_token") || errorMsg.includes("invalid credential")) {
|
||||
uni.showToast({
|
||||
title: "服务暂时不可用,请稍后重试",
|
||||
icon: "none",
|
||||
duration: 3000,
|
||||
});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: errorMsg || "获取手机号失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
}
|
||||
// var pages = getCurrentPages();
|
||||
// if (inviteCode) {
|
||||
// uni.reLaunch({
|
||||
// url: "/pages/client/index/index",
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
// if (pages.length === 1) {
|
||||
// uni.reLaunch({
|
||||
// url: "/pages/client/index/index",
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
// uni.navigateBack();
|
||||
// } catch (loginErr) {
|
||||
// uni.hideLoading();
|
||||
// console.error('登录失败:', loginErr);
|
||||
// uni.showToast({
|
||||
// title: loginErr || "登录失败,请重试",
|
||||
// icon: "none",
|
||||
// });
|
||||
// }
|
||||
// },
|
||||
// fail: (profileErr) => {
|
||||
// uni.hideLoading();
|
||||
// console.log("getUserProfile 调用失败", profileErr);
|
||||
// uni.showToast({
|
||||
// title: "获取用户信息失败",
|
||||
// icon: "none",
|
||||
// });
|
||||
// },
|
||||
// });
|
||||
// } catch (error) {
|
||||
// uni.hideLoading();
|
||||
// console.error("获取手机号失败:", error);
|
||||
// const errorMsg = error?.message || error || "";
|
||||
// if (errorMsg.includes("access_token") || errorMsg.includes("invalid credential")) {
|
||||
// uni.showToast({
|
||||
// title: "服务暂时不可用,请稍后重试",
|
||||
// icon: "none",
|
||||
// duration: 3000,
|
||||
// });
|
||||
// } else {
|
||||
// uni.showToast({
|
||||
// title: errorMsg || "获取手机号失败,请重试",
|
||||
// icon: "none",
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
},
|
||||
loginAction() {
|
||||
if (!this.checked) {
|
||||
@ -300,8 +378,8 @@ export default {
|
||||
|
||||
.notLoginBtn {
|
||||
background-color: #fff;
|
||||
color: #FF19A0;
|
||||
border: 1rpx solid #FF19A0;
|
||||
color: #ff19a0;
|
||||
border: 1rpx solid #ff19a0;
|
||||
border-radius: 300rpx;
|
||||
padding: 26rpx 0rpx;
|
||||
text-align: center;
|
||||
@ -333,13 +411,13 @@ export default {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #FFFFFF;
|
||||
background: #ffffff;
|
||||
transition: all 0.3s ease;
|
||||
flex-shrink: 0;
|
||||
|
||||
&.checkbox-checked {
|
||||
border-color: #FF19A0;
|
||||
background: #FF19A0;
|
||||
border-color: #ff19a0;
|
||||
background: #ff19a0;
|
||||
}
|
||||
|
||||
.check-icon {
|
||||
@ -362,7 +440,7 @@ export default {
|
||||
|
||||
.tooltip-content {
|
||||
font-size: 24rpx;
|
||||
color: #FFFFFF;
|
||||
color: #ffffff;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
@ -385,7 +463,7 @@ export default {
|
||||
color: #9b939a;
|
||||
|
||||
.color {
|
||||
color: #FF19A0;
|
||||
color: #ff19a0;
|
||||
font-size: 22rpx;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,196 +1,146 @@
|
||||
<template>
|
||||
<view class="flex-row-start goods-item" @click.stop="$emit('clickCard', data)">
|
||||
<image class="goods-img" :src="data.product_pic" mode="aspectFill" />
|
||||
<view class="goods-content">
|
||||
<view class="text-multi-ellipse fs-28 app-fc-main app-font-bold goods-name">
|
||||
{{ data.product_name || "" }}
|
||||
</view>
|
||||
<!-- <view class="flex-row-start label">
|
||||
<image class="hot-icon" :src="`${imgPrefix}mall-hot.png`"></image>
|
||||
<view class="fs-20 app-fc-main label-name">{{data.sales}}人买过</view>
|
||||
</view> -->
|
||||
<view class="price-row">
|
||||
<view class="flex-row-start">
|
||||
<text class="fs-28 price-text">
|
||||
¥
|
||||
<text class="fs-28">{{data.prices[0].original_price / 100 || 0 }}</text>
|
||||
</text>
|
||||
<!-- <text class="fs-20 price-label">到手价</text> -->
|
||||
</view>
|
||||
<text class="fs-24 origin-price" v-if="minPrice.price_shichang">
|
||||
¥{{ minPrice.price_shichang || 0 }}
|
||||
</text>
|
||||
</view>
|
||||
<view class="buy-now-btn-wrapper" @click.stop="handleBuyNow">
|
||||
<text class="buy-now-btn">立即购买</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="goods-item" >
|
||||
<image @click.stop="handleBuyNow" class="goods-img" :src="data.product_pic" mode="aspectFill" />
|
||||
<view class="fs-24 app-fc-main goods-name">
|
||||
{{ data.product_name || "" }}
|
||||
</view>
|
||||
<view class="flex-row-start label">
|
||||
<image class="hot-icon" :src="`${imgPrefix}mall-hot.png`"></image>
|
||||
<view class="fs-20 app-fc-main label-name">32人买过</view>
|
||||
</view>
|
||||
<view class="flex-row-between" style="margin-top: 12rpx; align-items: baseline;">
|
||||
<view class="price-wrapper">
|
||||
<text class="fs-28" style="color: #FF19A0;">
|
||||
¥
|
||||
<text class="fs-28">{{
|
||||
data.prices[0].original_price / 100 || 0
|
||||
}}</text>
|
||||
</text>
|
||||
</view>
|
||||
<view class="buy-now-btn" @click.stop="handleBuyNow">
|
||||
立即购买
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { imgPrefix } from '@/utils/common';
|
||||
import {
|
||||
imgPrefix
|
||||
} from '@/utils/common';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
index: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
data: {
|
||||
type: Object,
|
||||
default: () => {},
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
imgPrefix,
|
||||
isAnimating: false,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
// minPrice() {
|
||||
// let minPrice = {};
|
||||
// let minPriceValue = 0;
|
||||
// this.data.price_list.map((v) => {
|
||||
// if (!minPriceValue || minPriceValue > +v.price) {
|
||||
// minPriceValue = +v.price;
|
||||
// minPrice = { ...v };
|
||||
// }
|
||||
// });
|
||||
// return minPrice;
|
||||
// },
|
||||
labelList() {
|
||||
return this.data.label.split(",").filter((v) => !!v);
|
||||
},
|
||||
},
|
||||
mounted() {},
|
||||
methods: {
|
||||
// 触发添加购物车动画
|
||||
triggerAddCartAnimation() {
|
||||
this.isAnimating = true;
|
||||
setTimeout(() => {
|
||||
this.isAnimating = false;
|
||||
}, 600);
|
||||
},
|
||||
// 立即购买
|
||||
handleBuyNow() {
|
||||
this.$emit('buyNow', this.data);
|
||||
},
|
||||
},
|
||||
};
|
||||
export default {
|
||||
props: {
|
||||
index: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
data: {
|
||||
type: Object,
|
||||
default: () => {},
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
imgPrefix,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
labelList() {
|
||||
return (this.data?.label || "").split(",").filter((v) => !!v);
|
||||
},
|
||||
},
|
||||
mounted() {},
|
||||
methods: {
|
||||
handleBuyNow() {
|
||||
// 触发购买事件,通知父组件
|
||||
this.$emit('addToCar', this.data);
|
||||
},
|
||||
triggerAddCartAnimation() {
|
||||
// 保留方法以兼容父组件调用
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.goods-item {
|
||||
background: #fff;
|
||||
border-radius: 40rpx;
|
||||
width: 100%;
|
||||
padding: 20rpx;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 20rpx;
|
||||
position: relative;
|
||||
border-bottom: 1rpx solid #F5F5F5;
|
||||
.goods-item {
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 20rpx;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 22rpx;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
|
||||
.goods-img {
|
||||
border-radius: 20rpx;
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
}
|
||||
.goods-img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
height: 260rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.goods-content {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
margin-left: 20rpx;
|
||||
}
|
||||
.goods-name {
|
||||
margin: 16rpx 0 12rpx 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
word-wrap: break-word;
|
||||
word-break: break-all;
|
||||
font-size: 24rpx;
|
||||
color: #3D3D3D;
|
||||
}
|
||||
|
||||
.goods-name {
|
||||
margin: 0 0 12rpx;
|
||||
}
|
||||
.label {
|
||||
background-color: #ffecf3;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
border-radius: 4rpx;
|
||||
padding: 4rpx 8rpx;
|
||||
|
||||
.label {
|
||||
background-color: #ffecf3;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
border-radius: 4rpx;
|
||||
margin-bottom: 12rpx;
|
||||
.hot-icon {
|
||||
width: 28rpx;
|
||||
height: 28rpx;
|
||||
}
|
||||
|
||||
.hot-icon {
|
||||
width: 28rpx;
|
||||
height: 28rpx;
|
||||
margin-right: 6rpx;
|
||||
}
|
||||
.label-name {
|
||||
padding-left: 4rpx;
|
||||
color: #FF19A0;
|
||||
font-size: 20rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.label-name {
|
||||
padding: 4rpx 8rpx;
|
||||
color: #FF19A0;
|
||||
}
|
||||
}
|
||||
.flex-row-between {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.price-row {
|
||||
margin-top: 12rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.flex-row-start {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.price-text {
|
||||
color: #3D3D3D;
|
||||
}
|
||||
.price-wrapper {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.price-label {
|
||||
color: #999;
|
||||
margin-left: 8rpx;
|
||||
}
|
||||
|
||||
.origin-price {
|
||||
color: #999;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
|
||||
.add-cart-icon {
|
||||
width: 44rpx;
|
||||
height: 44rpx;
|
||||
position: absolute;
|
||||
bottom: 20rpx;
|
||||
right: 20rpx;
|
||||
transition: transform 0.3s ease;
|
||||
|
||||
&.add-cart-icon-animate {
|
||||
animation: addCartBounce 0.6s ease;
|
||||
}
|
||||
}
|
||||
|
||||
.buy-now-btn-wrapper {
|
||||
margin-top: 16rpx;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
|
||||
.buy-now-btn {
|
||||
background: linear-gradient(90deg, #FF19A0, #FF4DB8);
|
||||
color: #FFFFFF;
|
||||
font-size: 24rpx;
|
||||
padding: 12rpx 32rpx;
|
||||
border-radius: 24rpx;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes addCartBounce {
|
||||
0% {
|
||||
transform: scale(1) rotate(0deg);
|
||||
}
|
||||
25% {
|
||||
transform: scale(1.2) rotate(-10deg);
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.3) rotate(10deg);
|
||||
}
|
||||
75% {
|
||||
transform: scale(1.1) rotate(-5deg);
|
||||
}
|
||||
100% {
|
||||
transform: scale(1) rotate(0deg);
|
||||
}
|
||||
}
|
||||
.buy-now-btn {
|
||||
background: #FF19A0;
|
||||
color: #fff;
|
||||
font-size: 20rpx;
|
||||
padding: 10rpx 20rpx;
|
||||
border-radius: 30rpx;
|
||||
font-weight: 500;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -70,8 +70,14 @@
|
||||
<scroll-view class="category-right" scroll-y :refresher-enabled="true"
|
||||
:refresher-triggered="refreshTriggered" @refresherrefresh="onRefresh" @scrolltolower="onLoadMore">
|
||||
<view class="goods-list">
|
||||
<good-item v-for="good in goodsList" :key="good.product_id" :ref="`goodItem_${good.product_id}`"
|
||||
:data="good" @addToCar="addToCar" @clickCard="jumpToDetail" />
|
||||
<view class="goods-list-item left">
|
||||
<good-item v-for="(good, i) in leftColumnGoods" :key="2 * i" :ref="`goodItem_${good.product_id}`"
|
||||
:data="good" @addToCar="addToCar" />
|
||||
</view>
|
||||
<view class="goods-list-item right">
|
||||
<good-item v-for="(good, i) in rightColumnGoods" :key="2 * i + 1" :ref="`goodItem_${good.product_id}`"
|
||||
:data="good" @addToCar="addToCar" />
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
@ -109,6 +115,7 @@ import CategoryModal from "./components/CategoryModal.vue";
|
||||
import {
|
||||
getGoodsListData
|
||||
} from "../../../api/shop";
|
||||
import { getCategoryGoodsWithCache } from "@/utils/goodsCache";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@ -152,6 +159,8 @@ export default {
|
||||
total: 0,
|
||||
page: 1,
|
||||
size: 10,
|
||||
nextCursor: '',
|
||||
hasMore: true,
|
||||
refreshTriggered: false,
|
||||
isLoading: false,
|
||||
petOrderId: '',
|
||||
@ -179,6 +188,12 @@ export default {
|
||||
) || {}
|
||||
);
|
||||
},
|
||||
leftColumnGoods() {
|
||||
return this.goodsList.filter((v, i) => i % 2 === 0);
|
||||
},
|
||||
rightColumnGoods() {
|
||||
return this.goodsList.filter((v, i) => i % 2 === 1);
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.getCategoryList();
|
||||
@ -195,6 +210,10 @@ export default {
|
||||
},
|
||||
onShow() {
|
||||
this.getCartListData();
|
||||
// 页面显示时检查是否需要刷新商品数据
|
||||
if (this.selectCategoryId) {
|
||||
this.getShopList(false);
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
selectCategoryId(val) {
|
||||
@ -224,27 +243,70 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
changeCateg(item) {
|
||||
changeCateg(item) {
|
||||
this.changeId = item.id
|
||||
this.selectCategoryId = item.id;
|
||||
this.page = 1; // 切换分类时重置分页
|
||||
this.nextCursor = '';
|
||||
this.hasMore = true;
|
||||
this.goodsList = []; // 清空当前商品列表
|
||||
this.showAllCategory = false;
|
||||
// console.log(item,'--')
|
||||
|
||||
this.getShopList(true); // 切换分类时强制刷新
|
||||
},
|
||||
// 商品列表
|
||||
getShopList() {
|
||||
getGoodsListData({
|
||||
getShopList(forceRefresh = false) {
|
||||
// 如果不是第一页且没有更多数据,直接返回
|
||||
if (this.page > 1 && !this.hasMore) {
|
||||
return;
|
||||
}
|
||||
|
||||
const params = {
|
||||
type: this.changeId,
|
||||
p: this.page,
|
||||
num: this.size,
|
||||
keyword: "",
|
||||
is_tui: 0,
|
||||
})
|
||||
cursor: this.nextCursor,
|
||||
};
|
||||
|
||||
// 第一页使用缓存,后续页直接请求
|
||||
if (this.page > 1) {
|
||||
getGoodsListData(params)
|
||||
.then((res) => {
|
||||
const list = res?.data.data?.products || res?.data || [];
|
||||
const hasMore = res?.data.data?.has_more;
|
||||
const nextCursor = res?.data.data?.next_cursor || '';
|
||||
|
||||
this.goodsList = [...this.goodsList, ...list];
|
||||
this.hasMore = hasMore;
|
||||
this.nextCursor = nextCursor;
|
||||
this.total = res?.count || 0;
|
||||
})
|
||||
.finally(() => {
|
||||
this.isLoading = false;
|
||||
this.refreshTriggered = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 第一页使用缓存
|
||||
getCategoryGoodsWithCache(params, forceRefresh)
|
||||
.then((res) => {
|
||||
const list = res?.data || [];
|
||||
this.goodsList =
|
||||
this.page === 1 ? list : [...this.goodsList, ...list];
|
||||
this.total = res?.count || 0;
|
||||
const list = res?.data?.products || res?.data || [];
|
||||
const hasMore = res?.data?.has_more;
|
||||
const nextCursor = res?.data?.next_cursor || '';
|
||||
|
||||
// 只有当数据有变化时才更新商品列表,避免不必要的刷新
|
||||
if (res.hasChanged !== false || this.goodsList.length === 0) {
|
||||
this.goodsList = list;
|
||||
}
|
||||
|
||||
this.hasMore = hasMore;
|
||||
this.nextCursor = nextCursor;
|
||||
this.total = res?.count || list.length || 0;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('获取商品列表失败', err);
|
||||
})
|
||||
.finally(() => {
|
||||
this.isLoading = false;
|
||||
@ -349,15 +411,17 @@ export default {
|
||||
url: `/pages/client/shop/details?product_id=${details.product_id}&petOrderId=${this.petOrderId}&petOrderAddressId=${this.petOrderAddressId}`,
|
||||
});
|
||||
},
|
||||
onRefresh() {
|
||||
onRefresh() {
|
||||
this.refreshTriggered = true;
|
||||
this.page = 1;
|
||||
this.size = 10;
|
||||
this.total = 0;
|
||||
this.getShopList();
|
||||
this.nextCursor = '';
|
||||
this.hasMore = true;
|
||||
this.getShopList(true); // 下拉刷新时强制刷新
|
||||
},
|
||||
onLoadMore() {
|
||||
if (!this.isLoading && this.total > this.goodsList.length) {
|
||||
if (!this.isLoading && this.hasMore) {
|
||||
this.page++;
|
||||
this.getShopList();
|
||||
}
|
||||
@ -385,7 +449,7 @@ export default {
|
||||
height: 100%;
|
||||
align-items: stretch;
|
||||
position: relative;
|
||||
padding-top: calc(var(--status-bar-height, 0px) + 88rpx + 20rpx);
|
||||
padding-top: 0;
|
||||
|
||||
.custom-navbar {
|
||||
position: fixed;
|
||||
@ -394,7 +458,7 @@ export default {
|
||||
right: 0;
|
||||
z-index: 999;
|
||||
background: #ff19a0;
|
||||
border-radius: 0px 0px 16px 16px;
|
||||
border-radius: 0px;
|
||||
|
||||
.status-bar {
|
||||
background: #ff19a0;
|
||||
@ -589,6 +653,24 @@ export default {
|
||||
.category-right {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
|
||||
.goods-list {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-start;
|
||||
margin-top: 20rpx;
|
||||
padding: 0 20rpx 120rpx;
|
||||
|
||||
.goods-list-item {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
&.left {
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
<!-- 可拖动联系客服组件 -->
|
||||
<DraggableContact ref="draggableContact" :onClick="handleContactClick" />
|
||||
|
||||
<scroll-view class="homeContainer" scroll-y :show-scrollbar="false" :enhanced="true">
|
||||
<scroll-view class="homeContainer" scroll-y :show-scrollbar="false" :enhanced="true" @scrolltolower="onLoadMore" :refresher-enabled="true" :refresher-triggered="refreshTriggered" @refresherrefresh="onRefresh">
|
||||
<view class="swiperWrapper">
|
||||
<swiper indicator-dots="true" autoplay="true" interval="3000" duration="500" circular="true"
|
||||
class="swiper">
|
||||
@ -48,6 +48,9 @@
|
||||
<view class="loginBtn" @click="toLogin" v-if="!userInfo.userID">
|
||||
注册/登陆
|
||||
</view>
|
||||
<view class="logoutBtn" @click="logout" v-if="userInfo.userID">
|
||||
退出登录
|
||||
</view>
|
||||
|
||||
</view>
|
||||
<view class="shadowBackground" />
|
||||
@ -59,11 +62,11 @@
|
||||
</view> -->
|
||||
<view class="goods-list">
|
||||
<view class="goods-list-item left">
|
||||
<good-item v-for="(good, i) in leftColumnGoods" :index="2 * i" :key="2 * i" :data="good"
|
||||
<good-item v-for="(good, i) in leftColumnGoods" :index="2 * i" :key="2 * i" :data="good" :isHome="true"
|
||||
@addToCar="addToCar" />
|
||||
</view>
|
||||
<view class="goods-list-item right">
|
||||
<good-item v-for="(good, i) in rightColumnGoods" :index="2 * i + 1" :key="2 * i + 1" :data="good"
|
||||
<good-item v-for="(good, i) in rightColumnGoods" :index="2 * i + 1" :key="2 * i + 1" :data="good" :isHome="true"
|
||||
@addToCar="addToCar" />
|
||||
</view>
|
||||
</view>
|
||||
@ -85,6 +88,9 @@ import {
|
||||
import {
|
||||
userWllet
|
||||
} from "../../../api/login";
|
||||
import {
|
||||
loginOut,
|
||||
} from "../../../api/user";
|
||||
import WeChatCopyModal from "@/components/WeChatCopyModal.vue";
|
||||
import GoodItem from "../shop/components/GoodItem.vue";
|
||||
import DraggableContact from "@/components/DraggableContact.vue";
|
||||
@ -92,6 +98,7 @@ import {
|
||||
getGoodsClassify,
|
||||
getGoodsListData
|
||||
} from "@/api/shop";
|
||||
import { getHomeGoodsWithCache } from "@/utils/goodsCache";
|
||||
|
||||
export default {
|
||||
name: "HomePage",
|
||||
@ -107,6 +114,8 @@ export default {
|
||||
goodsList: [], // 商品列表
|
||||
goodsTotal: 0, // 商品总数
|
||||
goodPage: 1, // 当前页码
|
||||
nextCursor: '', // 下一页游标
|
||||
hasMore: true, // 是否还有更多数据
|
||||
isLoadingGoods: false, // 是否正在加载商品
|
||||
refreshTriggered: false, // 刷新是否已触发
|
||||
cartCount: 0, // 购物车数量
|
||||
@ -171,22 +180,68 @@ export default {
|
||||
return this.cartCount > 9 ? "9+" : this.cartCount;
|
||||
}
|
||||
},
|
||||
created() {
|
||||
created() {
|
||||
this.goodPage = 1;
|
||||
this.nextCursor = '';
|
||||
this.hasMore = true;
|
||||
this.goodsList = [];
|
||||
this.getGoodsList()
|
||||
},
|
||||
onShow() {
|
||||
// 页面显示时检查是否需要刷新商品数据
|
||||
this.getGoodsList(false);
|
||||
},
|
||||
methods: {
|
||||
getGoodsList() {
|
||||
getGoodsList(forceRefresh = false) {
|
||||
if (this.isLoadingGoods) return;
|
||||
if (!this.hasMore && this.goodPage > 1) return;
|
||||
this.isLoadingGoods = true;
|
||||
const params = {
|
||||
type: 0
|
||||
type: 0,
|
||||
cursor: this.nextCursor
|
||||
}
|
||||
getGoodsListData(params)
|
||||
|
||||
// 加载更多时直接请求,不使用缓存
|
||||
if (this.goodPage > 1) {
|
||||
getGoodsListData(params)
|
||||
.then((res) => {
|
||||
const list = res?.data.data?.products || res?.data || [];
|
||||
const hasMore = res?.data.data?.has_more;
|
||||
const nextCursor = res?.data.data?.next_cursor || '';
|
||||
|
||||
this.goodsList = [...this.goodsList, ...list];
|
||||
this.hasMore = hasMore;
|
||||
this.nextCursor = nextCursor;
|
||||
this.goodsTotal = res?.count || 0;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('获取商品列表失败', err);
|
||||
})
|
||||
.finally(() => {
|
||||
this.isLoadingGoods = false;
|
||||
this.refreshTriggered = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 第一页使用缓存
|
||||
getHomeGoodsWithCache(params, forceRefresh)
|
||||
.then((res) => {
|
||||
const list = res?.data.data.products || [];
|
||||
this.goodsList = list;
|
||||
console.log(this.goodsList,'???')
|
||||
this.goodsTotal = res?.count || 0;
|
||||
const list = res?.data.data?.products || res?.data.data || [];
|
||||
const hasMore = res?.data.data?.has_more;
|
||||
const nextCursor = res?.data.data?.next_cursor || '';
|
||||
|
||||
// 只有当数据有变化时才更新商品列表,避免不必要的刷新
|
||||
if (res.hasChanged !== false || this.goodsList.length === 0) {
|
||||
this.goodsList = list;
|
||||
}
|
||||
|
||||
this.hasMore = hasMore;
|
||||
this.nextCursor = nextCursor;
|
||||
this.goodsTotal = res?.count || list.length || 0;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('获取商品列表失败', err);
|
||||
})
|
||||
.finally(() => {
|
||||
this.isLoadingGoods = false;
|
||||
@ -198,6 +253,17 @@ export default {
|
||||
url: "/pages/client/auth/index",
|
||||
});
|
||||
},
|
||||
logout() {
|
||||
loginOut();
|
||||
// 清除Vuex中的用户状态
|
||||
this.$store.dispatch('user/deleteToken');
|
||||
this.$store.dispatch('user/clearUserInfo');
|
||||
// 清除本地缓存
|
||||
uni.clearStorageSync();
|
||||
uni.reLaunch({
|
||||
url: "/pages/client/auth/index",
|
||||
});
|
||||
},
|
||||
// 统一的 token 检查方法,未登录时弹窗让用户自主选择
|
||||
async checkTokenAndExecute(callback) {
|
||||
const token = uni.getStorageSync('token');
|
||||
@ -335,24 +401,23 @@ export default {
|
||||
console.error('Error parsing image_list:', e);
|
||||
}
|
||||
}
|
||||
|
||||
uni.navigateTo({
|
||||
url: `/pages/client/order/create`,
|
||||
success: (res) => {
|
||||
// 通过eventChannel向被打开页面传送数据
|
||||
res.eventChannel.emit("createOrder", {
|
||||
goodList: [{
|
||||
...this.goodsData,
|
||||
goods_id:goodsData.product.out_id,
|
||||
// price_id:goodsData.prices[0].price_id,
|
||||
product_pic: firstImageUrl,
|
||||
number:1,
|
||||
goods_name: goodsData.product.product_name,
|
||||
price_name: goodsData?.product.product_name,
|
||||
goods_price: goodsData.sku.actual_amount / 100
|
||||
}, ],
|
||||
});
|
||||
},
|
||||
url: `/pages/client/order/create?product_id=${goodsData.product.product_id}`,
|
||||
// success: (res) => {
|
||||
// // 通过eventChannel向被打开页面传送数据
|
||||
// res.eventChannel.emit("createOrder", {
|
||||
// goodList: [{
|
||||
// ...this.goodsData,
|
||||
// goods_id:goodsData.product.out_id,
|
||||
// // price_id:goodsData.prices[0].price_id,
|
||||
// product_pic: firstImageUrl,
|
||||
// number:1,
|
||||
// goods_name: goodsData.product.product_name,
|
||||
// price_name: goodsData?.product.product_name,
|
||||
// goods_price: goodsData.sku.actual_amount / 100
|
||||
// }, ],
|
||||
// });
|
||||
// },
|
||||
});
|
||||
|
||||
},
|
||||
@ -376,6 +441,19 @@ export default {
|
||||
});
|
||||
}
|
||||
},
|
||||
onLoadMore() {
|
||||
if (!this.isLoadingGoods && this.hasMore) {
|
||||
this.goodPage++;
|
||||
this.getGoodsList();
|
||||
}
|
||||
},
|
||||
onRefresh() {
|
||||
this.refreshTriggered = true;
|
||||
this.goodPage = 1;
|
||||
this.nextCursor = '';
|
||||
this.hasMore = true;
|
||||
this.getGoodsList(true);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@ -384,6 +462,7 @@ export default {
|
||||
.home-page {
|
||||
height: 100vh;
|
||||
background-color: #ffecf3;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
.recommand-goods-wrapper {
|
||||
@ -396,7 +475,8 @@ export default {
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-start;
|
||||
margin-top: 40rpx;
|
||||
margin-top: 50rpx;
|
||||
padding: 0 20rpx;
|
||||
|
||||
.goods-list-item {
|
||||
flex: 1;
|
||||
@ -442,10 +522,13 @@ export default {
|
||||
|
||||
.swiperWrapper {
|
||||
position: relative;
|
||||
margin-top: -88rpx;
|
||||
|
||||
.swiper {
|
||||
height: 552rpx;
|
||||
width: 100%;
|
||||
padding-top: 88rpx;
|
||||
box-sizing: content-box;
|
||||
|
||||
.swiper-img {
|
||||
width: 100%;
|
||||
@ -587,6 +670,16 @@ export default {
|
||||
margin-left: 8rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.logoutBtn {
|
||||
background: #FF19A0;
|
||||
border-radius: 218px;
|
||||
color: #fff;
|
||||
font-size: 23rpx;
|
||||
padding: 16rpx 24rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.shadowBackground {
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
<reservation
|
||||
v-show="activePageId === 'reservationPage'"
|
||||
ref="reservationPage"
|
||||
:orderId="orderId"
|
||||
/>
|
||||
</view>
|
||||
<tab-bar
|
||||
@ -60,6 +61,7 @@ export default {
|
||||
path: "/pages/client/index/index",
|
||||
},
|
||||
getUserInfoPromise: null, // 用于防止重复调用 getUserInfo
|
||||
orderId: null, // 存储从订单页面传递过来的 orderId
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
@ -165,12 +167,17 @@ export default {
|
||||
this.$store.dispatch('user/setReferrerID', Number(option.referrerID) || 0);
|
||||
}
|
||||
|
||||
// 处理从订单页面传递的 orderId
|
||||
if (option?.orderId) {
|
||||
this.orderId = option.orderId;
|
||||
}
|
||||
|
||||
// 处理页面跳转参数
|
||||
if (option?.activePageId) {
|
||||
const targetPageId = option.activePageId;
|
||||
// 如果目标页面与当前页面不同,触发切换
|
||||
if (this.activePageId !== targetPageId) {
|
||||
this.handleTabChange([targetPageId]);
|
||||
this.handleTabChange([targetPageId], option.orderId);
|
||||
} else {
|
||||
this.activePageId = targetPageId;
|
||||
}
|
||||
|
||||
@ -14,12 +14,18 @@
|
||||
{{ userInfo.userID && userInfo.username ? userInfo.username : '嗨,你好呀' }}
|
||||
</view>
|
||||
</view>
|
||||
<view class="userPhone" v-if="userInfo.phone">
|
||||
{{ userInfo.phone }}
|
||||
</view>
|
||||
<!-- <view class="vipWrapper">
|
||||
<image class="lableImg" :src="`${imgPrefix}home-vipLabel.png`" mode=""></image>
|
||||
v{{ userInfo.vipLevel || 1 }}会员
|
||||
</view> -->
|
||||
</view>
|
||||
</view>
|
||||
<view class="logoutBtn" @click="showLogoutModal = true">
|
||||
退出登录
|
||||
</view>
|
||||
<!-- <view class="userRight">
|
||||
<view class="userRgihtItemView" @click="jumpTo('/pages/client/recharge/index?tab=points')">
|
||||
<view class="num">
|
||||
@ -300,6 +306,10 @@ components: {
|
||||
logout() {
|
||||
loginOut();
|
||||
this.showLogoutModal = false;
|
||||
// 清除Vuex中的用户状态
|
||||
this.$store.dispatch('user/deleteToken');
|
||||
this.$store.dispatch('user/clearUserInfo');
|
||||
// 清除本地缓存
|
||||
uni.clearStorageSync();
|
||||
uni.reLaunch({
|
||||
url: "/pages/client/auth/index",
|
||||
@ -330,13 +340,17 @@ title: '请添加客服号',
|
||||
overflow-y: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
height: calc(100vh - #{$app_tabbar_height + 26});
|
||||
padding-top: 0;
|
||||
|
||||
.mineGroundImgView {
|
||||
position: relative;
|
||||
margin-top: -88rpx;
|
||||
|
||||
.groundImg {
|
||||
width: 100%;
|
||||
height: 552rpx;
|
||||
padding-top: 88rpx;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
}
|
||||
|
||||
@ -386,6 +400,21 @@ title: '请添加客服号',
|
||||
font-size: 28rpx;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.userPhone {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.logoutBtn {
|
||||
background: #FF19A0;
|
||||
color: #fff;
|
||||
padding: 16rpx 32rpx;
|
||||
border-radius: 50rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.userRight {
|
||||
@ -460,7 +489,7 @@ title: '请添加客服号',
|
||||
width: calc(100vw - 40rpx);
|
||||
background-color: #fff;
|
||||
margin: auto;
|
||||
margin-top: 20rpx;
|
||||
margin-top:46rpx;
|
||||
border-radius: 16rpx;
|
||||
margin-bottom: 26rpx;
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<view class="edit-content">
|
||||
<view class="flex-row-between edit-cell">
|
||||
<text class="title">头像</text>
|
||||
<button class="flex-row-end user-avator" open-type="chooseAvatar" @chooseavatar="chooseavatar">
|
||||
<button class="flex-row-end user-avator" @click="chooseavatar">
|
||||
<image class="avator-icon" :src="userInfo.head_pic_url" />
|
||||
<!-- <image class="arrow-icon" :src="`${imgPrefix}right-arrow.png`" /> -->
|
||||
</button>
|
||||
@ -174,30 +174,41 @@ export default {
|
||||
});
|
||||
},
|
||||
// 更新头像
|
||||
async chooseavatar(e) {
|
||||
const {
|
||||
avatarUrl
|
||||
} = e.detail;
|
||||
chooseavatar() {
|
||||
let that = this;
|
||||
|
||||
uni.showLoading({
|
||||
title: "上传中..."
|
||||
});
|
||||
|
||||
try {
|
||||
const { url, objectKey } = await uploadImageToOSS_PUT(avatarUrl);
|
||||
console.log(url, objectKey, 'url, objectKey')
|
||||
this.userInfo.head_pic_url = url; // 同时更新 head_pic_url,因为模板使用的是这个字段
|
||||
this.userInfo.head_pic = objectKey;
|
||||
this.$forceUpdate();
|
||||
uni.hideLoading();
|
||||
} catch (error) {
|
||||
console.error('头像上传失败:', error);
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: error?.message || "头像上传失败",
|
||||
icon: "none"
|
||||
});
|
||||
}
|
||||
uni.chooseImage({
|
||||
count: 1, // 只选一张图片
|
||||
sourceType: ['album', 'camera'], // 来源:相册、相机
|
||||
success: async function(res) {
|
||||
try {
|
||||
const { url, objectKey } = await uploadImageToOSS_PUT(res.tempFilePaths[0]);
|
||||
that.userInfo.head_pic_url = url; // 同时更新 head_pic_url,因为模板使用的是这个字段
|
||||
that.userInfo.head_pic = objectKey;
|
||||
that.$forceUpdate();
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: "上传成功",
|
||||
icon: "success",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('头像上传失败:', error);
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: error?.message || "头像上传失败",
|
||||
icon: "none"
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: function(err) {
|
||||
console.log('选择图片失败:', err.errMsg);
|
||||
uni.hideLoading();
|
||||
}
|
||||
});
|
||||
},
|
||||
onChange(value, key) {
|
||||
this.userInfo[key] = value;
|
||||
|
||||
@ -5,14 +5,11 @@
|
||||
<view class="good-content" @click="$emit('clickGoodInfo', data[0])">
|
||||
<view class="goods-row-first">
|
||||
<view class="goods-name">{{ data[0].goods_name || "" }}</view>
|
||||
<text class="goods-price">¥{{ data[0].goods_price || actual_price }}</text>
|
||||
</view>
|
||||
<view class="goods-row-second">
|
||||
<view class="goods-spec">
|
||||
{{ data[0].shuxing_name || "" }}{{ data[0].shuxing_name && data[0].price_name ? ";" : "" }}{{ data[0].price_name || "" }}
|
||||
<view class="fs-28 app-fc-main goods-price">
|
||||
¥{{ data[0].goods_price || data[0].product_actual_price }}
|
||||
</view>
|
||||
<text class="goods-count">共{{ data[0].number || 1 }}件</text>
|
||||
</view>
|
||||
<view class="fs-24 app-fc-normal">共{{ data[0].number || 1 }}件</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@ -24,7 +21,7 @@
|
||||
<view class="good-info-right">
|
||||
<text class="good-total-price">¥{{ actual_price }}</text>
|
||||
<text class="fs-24 app-fc-normal good-num">
|
||||
共1件
|
||||
共{{ totalCount }}件
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
@ -56,6 +53,11 @@
|
||||
return sum + price * number;
|
||||
}, 0).toFixed(2);
|
||||
},
|
||||
totalCount() {
|
||||
return this.data.reduce((sum, item) => {
|
||||
return sum + parseInt(item.number || 1);
|
||||
}, 0);
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
console.log(this.data,'--')
|
||||
@ -76,68 +78,43 @@
|
||||
|
||||
&.good-info {
|
||||
padding-top: 20rpx;
|
||||
align-items: center;
|
||||
align-items: flex-start;
|
||||
|
||||
.good-icon {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
border-radius: 8rpx;
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #f5f5f5;
|
||||
margin-right: 20rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.good-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
height: 160rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100rpx;
|
||||
justify-content: space-between;
|
||||
|
||||
.goods-row-first {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8rpx;
|
||||
align-items: flex-start;
|
||||
width: 100%;
|
||||
|
||||
.goods-name {
|
||||
flex: 1;
|
||||
font-size: 28rpx;
|
||||
color: #3D3D3D;
|
||||
line-height: 40rpx;
|
||||
margin-right: 16rpx;
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.goods-price {
|
||||
flex-shrink: 0;
|
||||
font-size: 28rpx;
|
||||
color: #3D3D3D;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.goods-row-second {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.goods-spec {
|
||||
flex: 1;
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
margin-right: 20rpx;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.goods-count {
|
||||
flex-shrink: 0;
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,21 +1,30 @@
|
||||
<template>
|
||||
<view class="order-item">
|
||||
<view class="flex-row-between order-title" @click="jumpToDetails">
|
||||
<text class="fs-24 app-fc-normal">
|
||||
订单编号:{{ data.order_no || "-" }}
|
||||
</text>
|
||||
<!-- 待支付状态:显示倒计时横幅 -->
|
||||
<view v-if="data.status === SHOP_ORDER_UNPAY && !data.tui_status && countDownTime > 0"
|
||||
class="order-status-banner">
|
||||
<view class="status-banner-left">
|
||||
<text class="status-text">等待付款</text>
|
||||
</view>
|
||||
<view class="status-banner-right">
|
||||
<text class="countdown-text">{{ formatCountdown(countDownTime) }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 其他状态:显示原有样式 -->
|
||||
<view v-else-if="
|
||||
<view class="order-item">
|
||||
<view class="flex-row-between order-title" @click="jumpToDetails">
|
||||
<text class="fs-24 app-fc-normal">
|
||||
订单编号:{{ data.order_no || "-" }}
|
||||
</text>
|
||||
<!-- 待支付状态:显示倒计时横幅 -->
|
||||
<view
|
||||
v-if="
|
||||
data.status === SHOP_ORDER_UNPAY &&
|
||||
!data.tui_status &&
|
||||
countDownTime > 0
|
||||
"
|
||||
class="order-status-banner"
|
||||
>
|
||||
<view class="status-banner-left">
|
||||
<text class="status-text">等待付款</text>
|
||||
</view>
|
||||
<view class="status-banner-right">
|
||||
<text class="countdown-text">{{
|
||||
formatCountdown(countDownTime)
|
||||
}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 其他状态:显示原有样式 -->
|
||||
<view
|
||||
v-else-if="
|
||||
([
|
||||
SHOP_ORDER_CANCEL,
|
||||
SHOP_ORDER_UNPAY,
|
||||
@ -26,428 +35,548 @@
|
||||
].includes(data.status) &&
|
||||
!data.tui_status) ||
|
||||
[SHOP_ORDER_AFTERSALE_REJECT].includes(data.tui_status)
|
||||
" class="flex-center fs-24 order-btn" :class="[
|
||||
"
|
||||
class="flex-center fs-24 order-btn"
|
||||
:class="[
|
||||
![SHOP_ORDER_DONE, SHOP_ORDER_CANCEL, SHOP_ORDER_UNREMARK].includes(
|
||||
data.status
|
||||
)
|
||||
? 'app-fc-mark confirm'
|
||||
: 'cancel',
|
||||
]">
|
||||
{{ orderStatus }}
|
||||
</view>
|
||||
<view v-if="
|
||||
]"
|
||||
>
|
||||
{{ orderStatus }}
|
||||
</view>
|
||||
<view
|
||||
v-if="
|
||||
[SHOP_ORDER_AFTERSALE, SHOP_ORDER_AFTERSALE_DONE].includes(
|
||||
data.tui_status
|
||||
)
|
||||
" class="flex-center fs-24 order-btn cancel">
|
||||
{{ refundOrderStatus }}
|
||||
</view>
|
||||
</view>
|
||||
<view class="order-content" :class="{ 'split-border': showStatusBtn }" @click="jumpToDetails">
|
||||
<good-info :data="data" :actual_price="data.actual_price" />
|
||||
<view v-if="data.type && data.type !== 1" class="fs-24 app-fc-mark order-type">
|
||||
随车订单
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="showStatusBtn" class="order-btns">
|
||||
<!-- 待支付 -->
|
||||
<template v-if="[SHOP_ORDER_UNPAY].includes(data.status)">
|
||||
<view class="flex-center fs-24 app-fc-main cancel-order-btn" @click.stop="$emit('cancelOrder', data)">
|
||||
取消订单
|
||||
</view>
|
||||
<view class="order-btns-right">
|
||||
<!-- <view class="flex-center fs-24 app-fc-main status-btn" @click.stop="$emit('concactService', data)">
|
||||
"
|
||||
class="flex-center fs-24 order-btn cancel"
|
||||
>
|
||||
{{ refundOrderStatus }}
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
class="order-content"
|
||||
:class="{ 'split-border': showStatusBtn }"
|
||||
@click="jumpToDetails"
|
||||
>
|
||||
<good-info :data="data.items" :actual_price="data.actual_price" />
|
||||
<view
|
||||
v-if="data.type && data.type !== 1"
|
||||
class="fs-24 app-fc-mark order-type"
|
||||
>
|
||||
随车订单
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="showStatusBtn" class="order-btns">
|
||||
<!-- 待支付 -->
|
||||
<template v-if="[SHOP_ORDER_UNPAY].includes(data.status)">
|
||||
<view
|
||||
class="flex-center fs-24 app-fc-main cancel-order-btn"
|
||||
@click.stop="$emit('cancelOrder', data)"
|
||||
>
|
||||
取消订单
|
||||
</view>
|
||||
<view class="order-btns-right">
|
||||
<!-- <view class="flex-center fs-24 app-fc-main status-btn" @click.stop="$emit('concactService', data)">
|
||||
联系客服
|
||||
</view> -->
|
||||
<view class="flex-center fs-24 app-fc-white status-btn confirm" @click.stop="$emit('pay', data)">
|
||||
立即支付
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<view
|
||||
class="flex-center fs-24 app-fc-white status-btn confirm"
|
||||
@click.stop="$emit('pay', data)"
|
||||
>
|
||||
立即支付
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<!-- 待预约 -->
|
||||
<template v-if="[SHOP_ORDER_UNSLIVER].includes(data.status)">
|
||||
<view class="order-btns-right">
|
||||
<view class="flex-center fs-24 app-fc-main status-btn" @click.stop="$emit('refund', data)">
|
||||
申请退款
|
||||
</view>
|
||||
<view class="flex-center fs-24 app-fc-white status-btn confirm"
|
||||
@click.stop="jumpToReservation">
|
||||
立即预约
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<!-- 待预约 -->
|
||||
<template v-if="[SHOP_ORDER_UNSLIVER].includes(data.status)">
|
||||
<view class="order-btns-right">
|
||||
<!-- <view
|
||||
class="flex-center fs-24 app-fc-main status-btn"
|
||||
@click.stop="remindRefund(data.order_id)"
|
||||
>
|
||||
申请退款
|
||||
</view> -->
|
||||
<view
|
||||
class="flex-center fs-24 app-fc-white status-btn confirm"
|
||||
@click.stop="jumpToReservation(data.order_id)"
|
||||
>
|
||||
立即预约
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<!-- 待收货 -->
|
||||
<template v-if="[SHOP_ORDER_UNRECEIVE].includes(data.status)">
|
||||
<!-- <view class="flex-center fs-24 app-fc-main status-btn" @click.stop="$emit('concactService', data)">
|
||||
<!-- 待收货 -->
|
||||
<template v-if="[SHOP_ORDER_UNRECEIVE].includes(data.status)">
|
||||
<!-- <view class="flex-center fs-24 app-fc-main status-btn" @click.stop="$emit('concactService', data)">
|
||||
联系客服
|
||||
</view> -->
|
||||
|
||||
<view class="flex-center fs-24 app-fc-main status-btn" @click.stop="$emit('afterSale', data)">
|
||||
申请售后
|
||||
</view>
|
||||
<!-- 随车订单不显示物流 -->
|
||||
<!-- <view v-if="data.pay_type !== pay_type_BYCAR" class="flex-center fs-24 app-fc-main status-btn"
|
||||
<!-- <view
|
||||
class="flex-center fs-24 app-fc-main status-btn"
|
||||
@click.stop="$emit('afterSale', data)"
|
||||
>
|
||||
申请售后
|
||||
</view> -->
|
||||
<!-- 随车订单不显示物流 -->
|
||||
<!-- <view v-if="data.pay_type !== pay_type_BYCAR" class="flex-center fs-24 app-fc-main status-btn"
|
||||
@click.stop="$emit('checkSliver', data)">
|
||||
查看物流
|
||||
</view> -->
|
||||
<view class="flex-center fs-24 app-fc-white status-btn confirm"
|
||||
@click.stop="$emit('confirmSliver', data)">
|
||||
确认收货
|
||||
</view>
|
||||
</template>
|
||||
<!-- <view
|
||||
class="flex-center fs-24 app-fc-white status-btn confirm"
|
||||
@click.stop="$emit('confirmSliver', data)"
|
||||
>
|
||||
确认收货
|
||||
</view> -->
|
||||
</template>
|
||||
|
||||
<!-- 已签收未评价 -->
|
||||
<template v-if="[SHOP_ORDER_UNREMARK].includes(data.status)">
|
||||
<!-- <view class="flex-center fs-24 app-fc-main status-btn" @click.stop="$emit('concactService', data)">
|
||||
<!-- 已签收未评价 -->
|
||||
<template v-if="[SHOP_ORDER_UNREMARK].includes(data.status)">
|
||||
<!-- <view class="flex-center fs-24 app-fc-main status-btn" @click.stop="$emit('concactService', data)">
|
||||
联系客服
|
||||
</view> -->
|
||||
<view class="flex-center fs-24 app-fc-white status-btn confirm" @click.stop="$emit('remark', data)">
|
||||
立即评价
|
||||
</view>
|
||||
</template>
|
||||
<view
|
||||
class="flex-center fs-24 app-fc-white status-btn confirm"
|
||||
@click.stop="$emit('remark', data)"
|
||||
>
|
||||
立即评价
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<!-- 已完成 -->
|
||||
<template v-if="[SHOP_ORDER_DONE].includes(data.status)">
|
||||
<!-- <view class="flex-center fs-24 app-fc-main status-btn" @click.stop="$emit('concactService', data)">
|
||||
<!-- 已完成 -->
|
||||
<template v-if="[SHOP_ORDER_DONE].includes(data.status)">
|
||||
<!-- <view class="flex-center fs-24 app-fc-main status-btn" @click.stop="$emit('concactService', data)">
|
||||
联系客服
|
||||
</view> -->
|
||||
<view class="flex-center fs-24 app-fc-white status-btn confirm "
|
||||
style="visibility: hidden;"
|
||||
>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
<template v-if="[SHOP_ORDER_DONE].includes(data.status)">
|
||||
<!-- <view class="flex-center fs-24 app-fc-main status-btn" @click.stop="$emit('concactService', data)">
|
||||
<view
|
||||
class="flex-center fs-24 app-fc-white status-btn confirm"
|
||||
style="visibility: hidden"
|
||||
>
|
||||
</view>
|
||||
</template>
|
||||
<template v-if="[SHOP_ORDER_DONE].includes(data.status)">
|
||||
<!-- <view class="flex-center fs-24 app-fc-main status-btn" @click.stop="$emit('concactService', data)">
|
||||
联系客服
|
||||
</view> -->
|
||||
<view class="flex-center fs-24 app-fc-white status-btn confirm"
|
||||
@click.stop="$emit('remarkDetails', data)">
|
||||
查看评价
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
class="flex-center fs-24 app-fc-white status-btn confirm"
|
||||
@click.stop="$emit('remarkDetails', data)"
|
||||
>
|
||||
查看评价
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import PopUpModal from "@/components/PopUpModal.vue";
|
||||
import GoodInfo from "./GoodInfo.vue";
|
||||
import {
|
||||
SHOP_ORDER_STATUS,
|
||||
SHOP_ORDER_UNPAY,
|
||||
SHOP_ORDER_UNSLIVER,
|
||||
SHOP_ORDER_UNRECEIVE,
|
||||
SHOP_ORDER_DONE,
|
||||
SHOP_ORDER_CANCEL,
|
||||
SHOP_ORDER_AFTERSALE,
|
||||
SHOP_ORDER_AFTERSALE_DONE,
|
||||
SHOP_ORDER_AFTERSALE_REJECT,
|
||||
SHOP_ORDER_AFTERSALE_STATUS,
|
||||
SHOP_ORDER_UNREMARK,
|
||||
pay_type_ADDRESS,
|
||||
pay_type_BYCAR,
|
||||
pay_type_BYPET
|
||||
} from "@/constants/app.business";
|
||||
import PopUpModal from "@/components/PopUpModal.vue";
|
||||
import GoodInfo from "./GoodInfo.vue";
|
||||
import { walletTransaction, cancelPetOrderMall } from "../../../../api/login";
|
||||
|
||||
export default {
|
||||
props: {
|
||||
data: {
|
||||
type: Object,
|
||||
default: () => {},
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
pay_type_ADDRESS,
|
||||
pay_type_BYCAR,
|
||||
pay_type_BYPET,
|
||||
SHOP_ORDER_STATUS,
|
||||
SHOP_ORDER_UNPAY,
|
||||
SHOP_ORDER_UNSLIVER,
|
||||
SHOP_ORDER_UNRECEIVE,
|
||||
SHOP_ORDER_DONE,
|
||||
SHOP_ORDER_CANCEL,
|
||||
SHOP_ORDER_AFTERSALE,
|
||||
SHOP_ORDER_AFTERSALE_DONE,
|
||||
SHOP_ORDER_AFTERSALE_REJECT,
|
||||
SHOP_ORDER_UNREMARK,
|
||||
showCancelModal: false,
|
||||
countDownTime: 0,
|
||||
countDownTimer: null,
|
||||
};
|
||||
},
|
||||
components: {
|
||||
GoodInfo,
|
||||
PopUpModal
|
||||
},
|
||||
options: {
|
||||
styleIsolation: "shared",
|
||||
},
|
||||
computed: {
|
||||
// 抖音退款组件需要的订单ID
|
||||
orderId() {
|
||||
return this.data.order_id || this.data.order_no || "";
|
||||
},
|
||||
// 抖音退款组件需要的订单状态(1=待核销/待发货,2=已核销/已发货)
|
||||
orderStatusForSDK() {
|
||||
// 根据你的业务状态映射到抖音SDK需要的状态
|
||||
// SHOP_ORDER_UNSLIVER = 待发货 -> 映射为 1
|
||||
if (this.data.status === SHOP_ORDER_UNSLIVER) {
|
||||
return 1;
|
||||
}
|
||||
// SHOP_ORDER_UNRECEIVE = 待收货 -> 映射为 2
|
||||
if (this.data.status === SHOP_ORDER_UNRECEIVE) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
},
|
||||
// 订单总金额(单位:分)
|
||||
orderTotalAmount() {
|
||||
const price = this.data.actual_price || 0;
|
||||
// 转换为分
|
||||
return Math.round(parseFloat(price) * 100);
|
||||
},
|
||||
// UniApp 需要传入的退款参数对象
|
||||
refundParams() {
|
||||
return {
|
||||
reasonCode: [410],
|
||||
note: '用户申请退款',
|
||||
applySource: 101,
|
||||
afterSaleType: 3,
|
||||
needRefundPackFee: true
|
||||
}
|
||||
},
|
||||
orderStatus() {
|
||||
return SHOP_ORDER_STATUS[this.data.status] || "";
|
||||
},
|
||||
refundOrderStatus() {
|
||||
return SHOP_ORDER_AFTERSALE_STATUS[this.data.tui_status] || "";
|
||||
},
|
||||
showStatusBtn() {
|
||||
return (
|
||||
([
|
||||
SHOP_ORDER_UNPAY,
|
||||
SHOP_ORDER_UNSLIVER,
|
||||
SHOP_ORDER_UNRECEIVE,
|
||||
SHOP_ORDER_DONE,
|
||||
SHOP_ORDER_UNREMARK,
|
||||
].includes(this.data.status) &&
|
||||
!this.data.tui_status) || [SHOP_ORDER_AFTERSALE_REJECT].includes(this.data.tui_status)
|
||||
);
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
showCancelModal(val) {
|
||||
this.$emit("disableScroll", val);
|
||||
},
|
||||
'data.daojishi'(newVal) {
|
||||
if (this.data.status === this.SHOP_ORDER_UNPAY && newVal) {
|
||||
this.countDownTime = newVal;
|
||||
this.startCountDown();
|
||||
}
|
||||
},
|
||||
'data.status'(newVal) {
|
||||
if (newVal === this.SHOP_ORDER_UNPAY && this.data.daojishi) {
|
||||
this.countDownTime = this.data.daojishi;
|
||||
this.startCountDown();
|
||||
} else {
|
||||
this.stopCountDown();
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
// console.log(this.data,'--=')
|
||||
if (this.data.status === SHOP_ORDER_UNPAY && this.data.daojishi) {
|
||||
this.countDownTime = this.data.daojishi;
|
||||
this.startCountDown();
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.stopCountDown();
|
||||
},
|
||||
methods: {
|
||||
// 退款回调(组件触发)
|
||||
handleRefund(event) {
|
||||
const { status, result, outOrderNo } = event.detail
|
||||
console.log('退款回调:', { status, result, outOrderNo })
|
||||
import {
|
||||
SHOP_ORDER_STATUS,
|
||||
SHOP_ORDER_UNPAY,
|
||||
SHOP_ORDER_UNSLIVER,
|
||||
SHOP_ORDER_UNRECEIVE,
|
||||
SHOP_ORDER_DONE,
|
||||
SHOP_ORDER_CANCEL,
|
||||
SHOP_ORDER_AFTERSALE,
|
||||
SHOP_ORDER_AFTERSALE_DONE,
|
||||
SHOP_ORDER_AFTERSALE_REJECT,
|
||||
SHOP_ORDER_AFTERSALE_STATUS,
|
||||
SHOP_ORDER_UNREMARK,
|
||||
pay_type_ADDRESS,
|
||||
pay_type_BYCAR,
|
||||
pay_type_BYPET,
|
||||
} from "@/constants/app.business";
|
||||
|
||||
if (status === 'success') {
|
||||
uni.showToast({
|
||||
title: '退款申请已提交',
|
||||
icon: 'success'
|
||||
})
|
||||
this.$emit('refund', this.data)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: result?.errMsg || '退款失败,请稍后重试',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
export default {
|
||||
props: {
|
||||
data: {
|
||||
type: Object,
|
||||
default: () => {},
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
pay_type_ADDRESS,
|
||||
pay_type_BYCAR,
|
||||
pay_type_BYPET,
|
||||
SHOP_ORDER_STATUS,
|
||||
SHOP_ORDER_UNPAY,
|
||||
SHOP_ORDER_UNSLIVER,
|
||||
SHOP_ORDER_UNRECEIVE,
|
||||
SHOP_ORDER_DONE,
|
||||
SHOP_ORDER_CANCEL,
|
||||
SHOP_ORDER_AFTERSALE,
|
||||
SHOP_ORDER_AFTERSALE_DONE,
|
||||
SHOP_ORDER_AFTERSALE_REJECT,
|
||||
SHOP_ORDER_UNREMARK,
|
||||
showCancelModal: false,
|
||||
countDownTime: 0,
|
||||
countDownTimer: null,
|
||||
};
|
||||
},
|
||||
components: {
|
||||
GoodInfo,
|
||||
PopUpModal,
|
||||
},
|
||||
options: {
|
||||
styleIsolation: "shared",
|
||||
},
|
||||
computed: {
|
||||
// 抖音退款组件需要的订单ID
|
||||
orderId() {
|
||||
return this.data.order_id || this.data.order_no || "";
|
||||
},
|
||||
// 抖音退款组件需要的订单状态(1=待核销/待发货,2=已核销/已发货)
|
||||
orderStatusForSDK() {
|
||||
// 根据你的业务状态映射到抖音SDK需要的状态
|
||||
// SHOP_ORDER_UNSLIVER = 待发货 -> 映射为 1
|
||||
if (this.data.status === SHOP_ORDER_UNSLIVER) {
|
||||
return 1;
|
||||
}
|
||||
// SHOP_ORDER_UNRECEIVE = 待收货 -> 映射为 2
|
||||
if (this.data.status === SHOP_ORDER_UNRECEIVE) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
},
|
||||
// 订单总金额(单位:分)
|
||||
orderTotalAmount() {
|
||||
const price = this.data.actual_price || 0;
|
||||
// 转换为分
|
||||
return Math.round(parseFloat(price) * 100);
|
||||
},
|
||||
// UniApp 需要传入的退款参数对象
|
||||
refundParams() {
|
||||
return {
|
||||
reasonCode: [410],
|
||||
note: "用户申请退款",
|
||||
applySource: 101,
|
||||
afterSaleType: 3,
|
||||
needRefundPackFee: true,
|
||||
};
|
||||
},
|
||||
orderStatus() {
|
||||
return SHOP_ORDER_STATUS[this.data.status] || "";
|
||||
},
|
||||
refundOrderStatus() {
|
||||
return SHOP_ORDER_AFTERSALE_STATUS[this.data.tui_status] || "";
|
||||
},
|
||||
showStatusBtn() {
|
||||
return (
|
||||
([
|
||||
SHOP_ORDER_UNPAY,
|
||||
SHOP_ORDER_UNSLIVER,
|
||||
SHOP_ORDER_UNRECEIVE,
|
||||
SHOP_ORDER_DONE,
|
||||
SHOP_ORDER_UNREMARK,
|
||||
].includes(this.data.status) &&
|
||||
!this.data.tui_status) ||
|
||||
[SHOP_ORDER_AFTERSALE_REJECT].includes(this.data.tui_status)
|
||||
);
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
showCancelModal(val) {
|
||||
this.$emit("disableScroll", val);
|
||||
},
|
||||
"data.daojishi"(newVal) {
|
||||
if (this.data.status === this.SHOP_ORDER_UNPAY && newVal) {
|
||||
this.countDownTime = newVal;
|
||||
this.startCountDown();
|
||||
}
|
||||
},
|
||||
"data.status"(newVal) {
|
||||
if (newVal === this.SHOP_ORDER_UNPAY && this.data.daojishi) {
|
||||
this.countDownTime = this.data.daojishi;
|
||||
this.startCountDown();
|
||||
} else {
|
||||
this.stopCountDown();
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
// console.log(this.data,'--=')
|
||||
if (this.data.status === SHOP_ORDER_UNPAY && this.data.daojishi) {
|
||||
this.countDownTime = this.data.daojishi;
|
||||
this.startCountDown();
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.stopCountDown();
|
||||
},
|
||||
methods: {
|
||||
remindRefund(id) {
|
||||
const data = {
|
||||
id: Number(id),
|
||||
};
|
||||
uni.showLoading({
|
||||
icon: "none",
|
||||
title: "处理中",
|
||||
mask: true,
|
||||
});
|
||||
cancelPetOrderMall(data)
|
||||
.then((res) => {
|
||||
uni.hideLoading();
|
||||
const plugin = tt.requirePlugin("lifeServicePlugin");
|
||||
let res1 = {
|
||||
code: 0,
|
||||
result: "success",
|
||||
msg: "success",
|
||||
data: {
|
||||
outOrderNo: "DYG177556196373493862814838179",
|
||||
refundInfo: {
|
||||
reason: ["计划有变,暂时不需要了"]
|
||||
},
|
||||
// refundInfo: {
|
||||
// reason:["计划有变,暂时不需要了"],
|
||||
// reasonCode:[401],
|
||||
// },
|
||||
itemOrderList:[
|
||||
{
|
||||
"itemOrderId": "1093391915337944382",
|
||||
"refundAmount": 9000
|
||||
}],
|
||||
// goodsList: [
|
||||
// { goodsId: "7625832097692813354", goodsType: 1, quantity: 1 },
|
||||
// ],
|
||||
},
|
||||
};
|
||||
// console.log('applyRefund options', JSON.stringify(options))
|
||||
console.log(res1.data,'??')
|
||||
plugin.applyRefund({
|
||||
itemOrderList:res1.data.itemOrderList,
|
||||
// goodsList: res1.data.goodsList,
|
||||
outOrderNo: res1.data.outOrderNo,
|
||||
refundInfo: res1.data.refundInfo,
|
||||
success: (res) => {
|
||||
uni.showToast({
|
||||
title: "退款申请已提交",
|
||||
icon: "success",
|
||||
});
|
||||
this.$emit("refund", this.data);
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("退款失败:", err);
|
||||
// 处理session过期错误
|
||||
if (err && err.errMsg && err.errMsg.includes("session已过期")) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "会话已过期,请重新登录后再试",
|
||||
showCancel: false,
|
||||
confirmText: "确定",
|
||||
success: () => {
|
||||
// 清除当前用户信息并跳转到登录页
|
||||
this.$store.dispatch("user/deleteToken");
|
||||
this.$store.dispatch("user/clearUserInfo");
|
||||
uni.clearStorageSync();
|
||||
uni.reLaunch({
|
||||
url: "/pages/client/auth/index",
|
||||
});
|
||||
},
|
||||
});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: err?.errMsg || err?.msg || "退款失败,请重试",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
uni.hideLoading();
|
||||
console.error("获取退款信息失败:", err);
|
||||
uni.showToast({
|
||||
title: err?.msg || "获取退款信息失败",
|
||||
icon: "none",
|
||||
});
|
||||
});
|
||||
},
|
||||
// 退款回调(组件触发)
|
||||
handleRefund(event) {
|
||||
const { status, result, outOrderNo } = event.detail;
|
||||
console.log("退款回调:", { status, result, outOrderNo });
|
||||
|
||||
// 错误处理
|
||||
handleError(event) {
|
||||
console.error('退款组件报错:', event.detail)
|
||||
uni.showToast({
|
||||
title: '组件加载失败,请稍后重试',
|
||||
icon: 'none'
|
||||
})
|
||||
},
|
||||
if (status === "success") {
|
||||
uni.showToast({
|
||||
title: "退款申请已提交",
|
||||
icon: "success",
|
||||
});
|
||||
this.$emit("refund", this.data);
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: result?.errMsg || "退款失败,请稍后重试",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
startCountDown() {
|
||||
this.stopCountDown();
|
||||
if (this.countDownTime > 0) {
|
||||
this.countDownTimer = setInterval(() => {
|
||||
if (this.countDownTime > 0) {
|
||||
this.countDownTime--;
|
||||
} else {
|
||||
this.stopCountDown();
|
||||
// 倒计时结束,可以触发刷新
|
||||
this.$emit('countdownEnd', this.data);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
},
|
||||
stopCountDown() {
|
||||
if (this.countDownTimer) {
|
||||
clearInterval(this.countDownTimer);
|
||||
this.countDownTimer = null;
|
||||
}
|
||||
},
|
||||
formatCountdown(seconds) {
|
||||
const hour = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds - hour * 3600) / 60);
|
||||
return `${hour}小时${minutes}分钟`;
|
||||
},
|
||||
orderCancel() {
|
||||
this.showCancelModal = false;
|
||||
},
|
||||
cancel() {
|
||||
this.showCancelModal = false;
|
||||
},
|
||||
jumpToDetails() {
|
||||
this.$emit('jumpToDetails', this.data)
|
||||
},
|
||||
jumpToReservation() {
|
||||
uni.reLaunch({
|
||||
url: '/pages/client/index/index?activePageId=reservationPage'
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
// 错误处理
|
||||
handleError(event) {
|
||||
console.error("退款组件报错:", event.detail);
|
||||
uni.showToast({
|
||||
title: "组件加载失败,请稍后重试",
|
||||
icon: "none",
|
||||
});
|
||||
},
|
||||
|
||||
startCountDown() {
|
||||
this.stopCountDown();
|
||||
if (this.countDownTime > 0) {
|
||||
this.countDownTimer = setInterval(() => {
|
||||
if (this.countDownTime > 0) {
|
||||
this.countDownTime--;
|
||||
} else {
|
||||
this.stopCountDown();
|
||||
// 倒计时结束,可以触发刷新
|
||||
this.$emit("countdownEnd", this.data);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
},
|
||||
stopCountDown() {
|
||||
if (this.countDownTimer) {
|
||||
clearInterval(this.countDownTimer);
|
||||
this.countDownTimer = null;
|
||||
}
|
||||
},
|
||||
formatCountdown(seconds) {
|
||||
const hour = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor((seconds - hour * 3600) / 60);
|
||||
return `${hour}小时${minutes}分钟`;
|
||||
},
|
||||
orderCancel() {
|
||||
this.showCancelModal = false;
|
||||
},
|
||||
cancel() {
|
||||
this.showCancelModal = false;
|
||||
},
|
||||
jumpToDetails() {
|
||||
this.$emit("jumpToDetails", this.data);
|
||||
},
|
||||
jumpToReservation(orderId) {
|
||||
uni.reLaunch({
|
||||
url: `/pages/client/index/index?activePageId=reservationPage&orderId=${orderId}`,
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.order-item {
|
||||
width: calc(100vw - 40rpx);
|
||||
background: #fff;
|
||||
margin: 20rpx;
|
||||
border-radius: 30rpx;
|
||||
box-sizing: border-box;
|
||||
padding: 20rpx;
|
||||
margin-bottom: 0;
|
||||
.order-item {
|
||||
width: calc(100vw - 40rpx);
|
||||
background: #fff;
|
||||
margin: 20rpx;
|
||||
border-radius: 30rpx;
|
||||
box-sizing: border-box;
|
||||
padding: 20rpx;
|
||||
margin-bottom: 0;
|
||||
|
||||
.order-title {
|
||||
padding-bottom: 20rpx;
|
||||
border-bottom: 1rpx solid #ececec;
|
||||
.order-title {
|
||||
padding-bottom: 20rpx;
|
||||
border-bottom: 1rpx solid #ececec;
|
||||
|
||||
.order-btn {
|
||||
width: 104rpx;
|
||||
height: 48rpx;
|
||||
border-radius: 48rpx;
|
||||
.order-btn {
|
||||
width: 104rpx;
|
||||
height: 48rpx;
|
||||
border-radius: 48rpx;
|
||||
|
||||
&.confirm {
|
||||
background: #fef6ff;
|
||||
}
|
||||
&.confirm {
|
||||
background: #fef6ff;
|
||||
}
|
||||
|
||||
&.cancel {
|
||||
background: #f7f7f7;
|
||||
color: #afa5ae;
|
||||
}
|
||||
}
|
||||
&.cancel {
|
||||
background: #f7f7f7;
|
||||
color: #afa5ae;
|
||||
}
|
||||
}
|
||||
|
||||
.order-status-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-radius: 48rpx;
|
||||
overflow: hidden;
|
||||
.order-status-banner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-radius: 48rpx;
|
||||
overflow: hidden;
|
||||
|
||||
.status-banner-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
background: #FF19A0;
|
||||
padding: 8rpx;
|
||||
flex-shrink: 0;
|
||||
border-radius: 10px 0px 10px 10px;
|
||||
.status-banner-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
background: #ff19a0;
|
||||
padding: 8rpx;
|
||||
flex-shrink: 0;
|
||||
border-radius: 10px 0px 10px 10px;
|
||||
|
||||
.status-text {
|
||||
font-size: 20rpx;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
}
|
||||
.status-text {
|
||||
font-size: 20rpx;
|
||||
color: #ffffff;
|
||||
}
|
||||
}
|
||||
|
||||
.status-banner-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
background: #FFF0F8;
|
||||
padding: 8rpx;
|
||||
flex-shrink: 0;
|
||||
.status-banner-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
background: #fff0f8;
|
||||
padding: 8rpx;
|
||||
flex-shrink: 0;
|
||||
|
||||
.countdown-text {
|
||||
font-size: 20rpx;
|
||||
color: #ff19a0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.order-btns {
|
||||
padding-top: 20rpx;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
|
||||
.countdown-text {
|
||||
font-size: 20rpx;
|
||||
color: #FF19A0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.cancel-order-btn {
|
||||
font-size: 24rpx;
|
||||
color: #9b939a;
|
||||
padding: 16rpx 0;
|
||||
}
|
||||
|
||||
.order-btns-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.order-btns {
|
||||
padding-top: 20rpx;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
.status-btn {
|
||||
width: 70px;
|
||||
height: 34px;
|
||||
// padding: 16rpx 20rpx;
|
||||
border-radius: 64rpx;
|
||||
border: 1px solid #ff19a0;
|
||||
margin-left: 20rpx;
|
||||
|
||||
.cancel-order-btn {
|
||||
font-size: 24rpx;
|
||||
color: #9B939A;
|
||||
padding: 16rpx 0;
|
||||
}
|
||||
&.confirm {
|
||||
color: $app_color_main;
|
||||
border: 1px solid $app_color_main;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.order-btns-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.status-btn {
|
||||
width: 70px;
|
||||
height: 34px;
|
||||
// padding: 16rpx 20rpx;
|
||||
border-radius: 64rpx;
|
||||
border: 1px solid #FF19A0;;
|
||||
margin-left: 20rpx;
|
||||
|
||||
&.confirm {
|
||||
color: $app_color_main;
|
||||
border: 1px solid $app_color_main;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
::v-deep {
|
||||
.good-info-multi {
|
||||
padding-top: 20rpx;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
::v-deep {
|
||||
.good-info-multi {
|
||||
padding-top: 20rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,7 @@
|
||||
class="flex-column-start news-item">
|
||||
<order-item :data="data" @disableScroll="disableScrollAction" @cancelOrder="cancelOrderAction"
|
||||
@refund="handleRefundFromItem" @concactService="jumpToWeChat" @confirmSliver="confirmSliver" @remindSilver="remindSliver" @pay="pay"
|
||||
@afterSale="afterSale" @checkSliver="checkSliver" @remark="remark" @remarkDetails="remarkDetails"
|
||||
@checkSliver="checkSliver" @remark="remark" @remarkDetails="remarkDetails"
|
||||
@jumpToDetails="jumpToDetails" />
|
||||
</view>
|
||||
<uni-load-more v-if="isLoading || (!isLoading && total && total === list.length)"
|
||||
@ -101,7 +101,7 @@ import ContactModal from "@/components/ContactModal.vue";
|
||||
import SliverInfo from "./components/SliverInfo.vue";
|
||||
import WeChatCopyModal from "@/components/WeChatCopyModal.vue";
|
||||
import DraggableContact from "@/components/DraggableContact.vue";
|
||||
import { walletTransaction, cancelPetOrderRefund, cancelPetOrderMall } from "../../../api/login";
|
||||
import { walletTransaction, cancelPetOrderRefund, cancelPetOrderMall,cancelUnpaid } from "../../../api/login";
|
||||
|
||||
|
||||
import {
|
||||
@ -250,14 +250,14 @@ export default {
|
||||
mask: true,
|
||||
});
|
||||
const data = {
|
||||
id: this.orderInfo.order_id,
|
||||
id: Number(this.orderInfo.order_id),
|
||||
// business_type:1
|
||||
}
|
||||
|
||||
// 判断是取消订单还是退款
|
||||
const apiPromise = this.cancelModalContent.includes('退款')
|
||||
? cancelPetOrderRefund(data)
|
||||
: cancelPetOrderMall(data);
|
||||
? cancelUnpaid(data)
|
||||
: cancelUnpaid(data);
|
||||
|
||||
apiPromise.then((res) => {
|
||||
uni.hideLoading();
|
||||
@ -303,23 +303,26 @@ export default {
|
||||
},
|
||||
// 支付
|
||||
pay(data) {
|
||||
uni.showLoading({
|
||||
icon: "none",
|
||||
title: "支付中",
|
||||
mask: true,
|
||||
});
|
||||
uni.showLoading({
|
||||
icon: "none",
|
||||
title: "支付中",
|
||||
mask: true,
|
||||
});
|
||||
console.log(data,'-?')
|
||||
|
||||
const plugin = tt.requirePlugin('tta5a3d31e3aecfb9b11');
|
||||
const plugin = tt.requirePlugin('lifeServicePlugin');
|
||||
// 先隐藏loading,让插件显示自己的弹窗
|
||||
uni.hideLoading();
|
||||
plugin.continueToPay({
|
||||
orderId: "orderId", // 内部订单号
|
||||
outOrderNo: "outOrderNo", // 外部订单号 2个订单号必填一个
|
||||
orderId:data.douyin_order_id, // 内部订单号
|
||||
// outOrderNo: "outOrderNo", // 外部订单号 2个订单号必填一个
|
||||
success: (res) => {
|
||||
const { orderId, outOrderNo } = res;
|
||||
console.log("success res", res);
|
||||
console.log("orderId", orderId, "outOrderNo", outOrderNo);
|
||||
this.reloadData();
|
||||
},
|
||||
fail: (res) => {
|
||||
uni.hideLoading();
|
||||
const { orderId, outOrderNo, errNo, errMsg, errLogId } = res;
|
||||
if (errLogId) {
|
||||
console.log("查询订单信息失败", errNo, errMsg, errLogId);
|
||||
@ -327,6 +330,11 @@ plugin.continueToPay({
|
||||
if (orderId || outOrderNo) {
|
||||
console.log("支付失败", errNo, errMsg, orderId, outOrderNo);
|
||||
}
|
||||
// 隐藏抖音的报错信息,显示自定义中文提示
|
||||
uni.showToast({
|
||||
title: "支付失败",
|
||||
icon: "none",
|
||||
});
|
||||
},
|
||||
});
|
||||
// payOrder({
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<view class="goods-item" >
|
||||
<image class="goods-img" :src="getProductImage(data)" mode="aspectFill" />
|
||||
<view class="goods-item" :class="{ 'goods-item-home': isHome }">
|
||||
<image @click.stop="handleBuyNow" class="goods-img" :src="getProductImage(data)" mode="aspectFill" />
|
||||
<view class=" fs-24 app-fc-main goods-name">
|
||||
{{ data.product.product_name || "" }}
|
||||
</view>
|
||||
@ -34,7 +34,7 @@
|
||||
} from '@/utils/common';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
props: {
|
||||
index: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
@ -43,6 +43,10 @@
|
||||
type: Object,
|
||||
default: () => {},
|
||||
},
|
||||
isHome: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@ -70,7 +74,6 @@
|
||||
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 {
|
||||
@ -94,7 +97,7 @@
|
||||
.goods-item {
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 20rpx;
|
||||
padding: 2rpx;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 22rpx;
|
||||
position: relative;
|
||||
@ -102,15 +105,24 @@
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
|
||||
&.goods-item-home {
|
||||
padding: 20rpx;
|
||||
}
|
||||
|
||||
.goods-img {
|
||||
display: block;
|
||||
// width: 260rpx;
|
||||
height: 260rpx;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
height: 320rpx;
|
||||
// max-width: 100%;
|
||||
border-radius: 16rpx;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
&.goods-item-home .goods-img {
|
||||
height: 145px;
|
||||
}
|
||||
|
||||
.goods-name {
|
||||
margin: 20rpx 0;
|
||||
// overflow: hidden;
|
||||
|
||||
@ -170,6 +170,8 @@ export default {
|
||||
total: 0,
|
||||
page: 1,
|
||||
size: 10,
|
||||
nextCursor: '',
|
||||
hasMore: true,
|
||||
showModal: false,
|
||||
addGoodInfo: null,
|
||||
showContactModal: false,
|
||||
@ -263,6 +265,9 @@ export default {
|
||||
initData() {
|
||||
this.getCategoryList();
|
||||
this.page = 1;
|
||||
this.nextCursor = '';
|
||||
this.hasMore = true;
|
||||
this.goodsList = [];
|
||||
this.getGoodsList();
|
||||
this.getCartListData();
|
||||
},
|
||||
@ -281,13 +286,25 @@ export default {
|
||||
// 商品列表
|
||||
getGoodsList() {
|
||||
if (this.isLoading) return;
|
||||
if (!this.hasMore && this.page > 1) return;
|
||||
this.isLoading = true;
|
||||
getGoodsListData({
|
||||
type: this.selectCategoryId ? this.selectCategoryId : 0,
|
||||
cursor: this.nextCursor,
|
||||
})
|
||||
.then((res) => {
|
||||
const list = res?.data.data.products || [];
|
||||
this.goodsList = list;
|
||||
const hasMore = res?.data.data.has_more;
|
||||
const nextCursor = res?.data.data.next_cursor || '';
|
||||
|
||||
if (this.page === 1) {
|
||||
this.goodsList = list;
|
||||
} else {
|
||||
this.goodsList = [...this.goodsList, ...list];
|
||||
}
|
||||
|
||||
this.hasMore = hasMore;
|
||||
this.nextCursor = nextCursor;
|
||||
this.total = res?.count || 0;
|
||||
})
|
||||
.finally(() => {
|
||||
@ -300,10 +317,12 @@ export default {
|
||||
this.page = 1;
|
||||
this.size = 10;
|
||||
this.total = 0;
|
||||
this.nextCursor = '';
|
||||
this.hasMore = true;
|
||||
this.getGoodsList();
|
||||
},
|
||||
onLoadMore() {
|
||||
if (!this.isLoading && this.total > this.goodsList.length) {
|
||||
if (!this.isLoading && this.hasMore) {
|
||||
this.page++;
|
||||
this.getGoodsList();
|
||||
}
|
||||
@ -378,20 +397,20 @@ export default {
|
||||
}
|
||||
|
||||
uni.navigateTo({
|
||||
url: `/pages/client/order/create`,
|
||||
success: (res) => {
|
||||
// 通过eventChannel向被打开页面传送数据
|
||||
res.eventChannel.emit("createOrder", {
|
||||
goodList: [{
|
||||
goods_id:goodsData.product.out_id,
|
||||
product_pic: firstImageUrl,
|
||||
number:1,
|
||||
goods_name: goodsData.product.product_name,
|
||||
price_name: goodsData?.product.product_name,
|
||||
goods_price: goodsData.sku.actual_amount / 100
|
||||
}, ],
|
||||
});
|
||||
},
|
||||
url: `/pages/client/order/create?product_id=${goodsData.product.product_id}`,
|
||||
// success: (res) => {
|
||||
// // 通过eventChannel向被打开页面传送数据
|
||||
// res.eventChannel.emit("createOrder", {
|
||||
// goodList: [{
|
||||
// goods_id:goodsData.product.out_id,
|
||||
// product_pic: firstImageUrl,
|
||||
// number:1,
|
||||
// goods_name: goodsData.product.product_name,
|
||||
// price_name: goodsData?.product.product_name,
|
||||
// goods_price: goodsData.sku.actual_amount / 100
|
||||
// }, ],
|
||||
// });
|
||||
// },
|
||||
});
|
||||
},
|
||||
// 购物车列表
|
||||
@ -419,31 +438,31 @@ export default {
|
||||
// 立即购买
|
||||
handleBuyNow(good) {
|
||||
uni.navigateTo({
|
||||
url: `/pages/client/order/create`,
|
||||
success: (res) => {
|
||||
// 通过 eventChannel 向被打开页面传送数据
|
||||
res.eventChannel.emit("createOrder", {
|
||||
goodList: [
|
||||
{
|
||||
goods_id: good.product_id,
|
||||
item_type: good.type,
|
||||
price_id: good.prices?.[0]?.price_id,
|
||||
price_desc: good.prices?.[0]?.price_desc,
|
||||
item_name: good.product_name,
|
||||
item_price: good.prices?.[0]?.actual_price,
|
||||
item_pic: good.product_pic,
|
||||
number: 1,
|
||||
product_id: good.product_id,
|
||||
product_name: good.product_name,
|
||||
product_pic: good.product_pic,
|
||||
goods_price: good.prices?.[0]?.actual_price / 100,
|
||||
product_price: good.prices?.[0]?.actual_price / 100,
|
||||
original_price: good.prices?.[0]?.original_price,
|
||||
yunfei: good.yunfei || 0,
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
url: `/pages/client/order/create?product_id=${good.product.product_id}`,
|
||||
// success: (res) => {
|
||||
// // 通过 eventChannel 向被打开页面传送数据
|
||||
// res.eventChannel.emit("createOrder", {
|
||||
// goodList: [
|
||||
// {
|
||||
// goods_id: good.product_id,
|
||||
// item_type: good.type,
|
||||
// price_id: good.prices?.[0]?.price_id,
|
||||
// price_desc: good.prices?.[0]?.price_desc,
|
||||
// item_name: good.product_name,
|
||||
// item_price: good.prices?.[0]?.actual_price,
|
||||
// item_pic: good.product_pic,
|
||||
// number: 1,
|
||||
// product_id: good.product_id,
|
||||
// product_name: good.product_name,
|
||||
// product_pic: good.product_pic,
|
||||
// goods_price: good.prices?.[0]?.actual_price / 100,
|
||||
// product_price: good.prices?.[0]?.actual_price / 100,
|
||||
// original_price: good.prices?.[0]?.original_price,
|
||||
// yunfei: good.yunfei || 0,
|
||||
// },
|
||||
// ],
|
||||
// });
|
||||
// },
|
||||
});
|
||||
},
|
||||
},
|
||||
@ -476,7 +495,7 @@ export default {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 32rpx;
|
||||
height: 88rpx;
|
||||
height: 80rpx;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 20px;
|
||||
|
||||
@ -643,7 +662,6 @@ export default {
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-start;
|
||||
margin-top: 40rpx;
|
||||
padding: 0 20rpx;
|
||||
|
||||
.goods-list-item {
|
||||
|
||||
335
src/utils/goodsCache.js
Normal file
335
src/utils/goodsCache.js
Normal file
@ -0,0 +1,335 @@
|
||||
/**
|
||||
* 商品数据缓存工具
|
||||
* 用于首页和分类页的商品列表缓存,避免重复请求相同数据
|
||||
*/
|
||||
|
||||
import { getGoodsListData } from '@/api/shop'
|
||||
|
||||
// 缓存存储对象
|
||||
const goodsCache = {
|
||||
// 首页商品缓存
|
||||
home: null,
|
||||
// 分类页商品缓存,key为分类ID
|
||||
category: {}
|
||||
}
|
||||
|
||||
// 缓存过期时间(5分钟,单位:毫秒)
|
||||
const CACHE_EXPIRE_TIME = 5 * 60 * 1000
|
||||
|
||||
/**
|
||||
* 计算数据的哈希值,用于判断数据是否有变化
|
||||
* @param {Array} data - 商品数据列表
|
||||
* @returns {string} 数据哈希值
|
||||
*/
|
||||
function calculateDataHash(data) {
|
||||
if (!data || !Array.isArray(data) || data.length === 0) {
|
||||
return 'empty'
|
||||
}
|
||||
|
||||
// 使用商品ID、价格、更新时间等关键信息计算哈希
|
||||
const keyData = data.map(item => {
|
||||
const product = item.product || item
|
||||
return `${product.product_id || product.id}-${product.updated_at || Date.now()}-${item.sku?.actual_amount || product.price || 0}`
|
||||
}).join('|')
|
||||
|
||||
// 简单的字符串哈希函数
|
||||
let hash = 0
|
||||
for (let i = 0; i < keyData.length; i++) {
|
||||
const char = keyData.charCodeAt(i)
|
||||
hash = ((hash << 5) - hash) + char
|
||||
hash = hash & hash // 转换为32位整数
|
||||
}
|
||||
return hash.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取缓存的首页商品数据
|
||||
* @returns {Object|null} 缓存的商品数据,包含数据、哈希值和时间戳
|
||||
*/
|
||||
export function getHomeGoodsCache() {
|
||||
return goodsCache.home
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置首页商品缓存
|
||||
* @param {Array} data - 商品数据列表
|
||||
*/
|
||||
export function setHomeGoodsCache(data) {
|
||||
goodsCache.home = {
|
||||
data,
|
||||
hash: calculateDataHash(data),
|
||||
timestamp: Date.now()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定分类的商品缓存
|
||||
* @param {Number|String} categoryId - 分类ID
|
||||
* @returns {Object|null} 缓存的商品数据
|
||||
*/
|
||||
export function getCategoryGoodsCache(categoryId) {
|
||||
return goodsCache.category[categoryId] || null
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置指定分类的商品缓存
|
||||
* @param {Number|String} categoryId - 分类ID
|
||||
* @param {Array} data - 商品数据列表
|
||||
*/
|
||||
export function setCategoryGoodsCache(categoryId, data) {
|
||||
goodsCache.category[categoryId] = {
|
||||
data,
|
||||
hash: calculateDataHash(data),
|
||||
timestamp: Date.now()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查缓存是否有效
|
||||
* @param {Object} cache - 缓存对象
|
||||
* @returns {Boolean} 缓存是否有效
|
||||
*/
|
||||
function isCacheValid(cache) {
|
||||
if (!cache) return false
|
||||
|
||||
const now = Date.now()
|
||||
// 检查缓存是否过期
|
||||
if (now - cache.timestamp > CACHE_EXPIRE_TIME) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取首页商品数据(带缓存)
|
||||
* @param {Object} params - 请求参数
|
||||
* @param {Boolean} forceRefresh - 是否强制刷新
|
||||
* @returns {Promise} 商品数据
|
||||
*/
|
||||
export function getHomeGoodsWithCache(params, forceRefresh = false) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const cache = getHomeGoodsCache()
|
||||
|
||||
// 如果有有效缓存且不强制刷新,先返回缓存数据
|
||||
if (!forceRefresh && isCacheValid(cache)) {
|
||||
// 先从缓存返回数据
|
||||
resolve({
|
||||
data: { data: { products: cache.data } },
|
||||
fromCache: true
|
||||
})
|
||||
}
|
||||
|
||||
// 无论是否有缓存,都请求最新数据进行对比
|
||||
getGoodsListData(params).then(res => {
|
||||
const newData = res?.data.data?.products || res?.data.data || []
|
||||
const hasMore = res?.data.data?.has_more
|
||||
const nextCursor = res?.data.data?.next_cursor || ''
|
||||
const newHash = calculateDataHash(newData)
|
||||
|
||||
// 检查数据是否有变化
|
||||
const hasChanged = !cache || cache.hash !== newHash
|
||||
|
||||
if (hasChanged || forceRefresh) {
|
||||
// 更新缓存
|
||||
setHomeGoodsCache(newData)
|
||||
|
||||
// 如果没有缓存或者数据有变化,返回最新数据
|
||||
if (!cache || forceRefresh) {
|
||||
resolve({
|
||||
...res,
|
||||
data: {
|
||||
...res.data,
|
||||
data: {
|
||||
...res.data.data,
|
||||
products: newData,
|
||||
has_more: hasMore,
|
||||
next_cursor: nextCursor
|
||||
}
|
||||
},
|
||||
fromCache: false,
|
||||
hasChanged: true
|
||||
})
|
||||
} else {
|
||||
// 如果已有缓存但数据有变化,通知更新
|
||||
resolve({
|
||||
...res,
|
||||
data: {
|
||||
...res.data,
|
||||
data: {
|
||||
...res.data.data,
|
||||
products: newData,
|
||||
has_more: hasMore,
|
||||
next_cursor: nextCursor
|
||||
}
|
||||
},
|
||||
fromCache: false,
|
||||
hasChanged: true
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// 数据没有变化,更新缓存时间戳
|
||||
cache.timestamp = Date.now()
|
||||
resolve({
|
||||
data: {
|
||||
data: {
|
||||
products: cache.data,
|
||||
has_more: hasMore,
|
||||
next_cursor: nextCursor
|
||||
}
|
||||
},
|
||||
fromCache: true,
|
||||
hasChanged: false
|
||||
})
|
||||
}
|
||||
}).catch(err => {
|
||||
// 如果请求失败但有缓存,返回缓存
|
||||
if (cache) {
|
||||
resolve({
|
||||
data: {
|
||||
data: {
|
||||
products: cache.data,
|
||||
has_more: false,
|
||||
next_cursor: ''
|
||||
}
|
||||
},
|
||||
fromCache: true,
|
||||
error: err
|
||||
})
|
||||
} else {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类页商品数据(带缓存)
|
||||
* @param {Object} params - 请求参数
|
||||
* @param {Boolean} forceRefresh - 是否强制刷新
|
||||
* @returns {Promise} 商品数据
|
||||
*/
|
||||
export function getCategoryGoodsWithCache(params, forceRefresh = false) {
|
||||
const categoryId = params.type || params.category_id || ''
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const cache = getCategoryGoodsCache(categoryId)
|
||||
|
||||
// 如果有有效缓存且不强制刷新,先返回缓存数据
|
||||
if (!forceRefresh && isCacheValid(cache)) {
|
||||
resolve({
|
||||
data: cache.data,
|
||||
count: cache.data.length,
|
||||
fromCache: true
|
||||
})
|
||||
}
|
||||
|
||||
// 无论是否有缓存,都请求最新数据进行对比
|
||||
getGoodsListData(params).then(res => {
|
||||
const newData = res?.data.data?.products || res?.data || []
|
||||
const hasMore = res?.data.data?.has_more
|
||||
const nextCursor = res?.data.data?.next_cursor || ''
|
||||
const newHash = calculateDataHash(newData)
|
||||
|
||||
// 检查数据是否有变化
|
||||
const hasChanged = !cache || cache.hash !== newHash
|
||||
|
||||
if (hasChanged || forceRefresh) {
|
||||
// 更新缓存
|
||||
setCategoryGoodsCache(categoryId, newData)
|
||||
|
||||
if (!cache || forceRefresh) {
|
||||
resolve({
|
||||
...res,
|
||||
data: {
|
||||
...res.data,
|
||||
data: {
|
||||
...res.data.data,
|
||||
products: newData,
|
||||
has_more: hasMore,
|
||||
next_cursor: nextCursor
|
||||
}
|
||||
},
|
||||
fromCache: false,
|
||||
hasChanged: true
|
||||
})
|
||||
} else {
|
||||
resolve({
|
||||
...res,
|
||||
data: {
|
||||
...res.data,
|
||||
data: {
|
||||
...res.data.data,
|
||||
products: newData,
|
||||
has_more: hasMore,
|
||||
next_cursor: nextCursor
|
||||
}
|
||||
},
|
||||
fromCache: false,
|
||||
hasChanged: true
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// 数据没有变化,更新缓存时间戳
|
||||
cache.timestamp = Date.now()
|
||||
resolve({
|
||||
data: newData,
|
||||
data: {
|
||||
products: cache.data,
|
||||
has_more: hasMore,
|
||||
next_cursor: nextCursor
|
||||
},
|
||||
count: cache.data.length,
|
||||
fromCache: true,
|
||||
hasChanged: false
|
||||
})
|
||||
}
|
||||
}).catch(err => {
|
||||
// 如果请求失败但有缓存,返回缓存
|
||||
if (cache) {
|
||||
resolve({
|
||||
data: cache.data,
|
||||
data: {
|
||||
products: cache.data,
|
||||
has_more: false,
|
||||
next_cursor: ''
|
||||
},
|
||||
count: cache.data.length,
|
||||
fromCache: true,
|
||||
error: err
|
||||
})
|
||||
} else {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有商品缓存
|
||||
*/
|
||||
export function clearGoodsCache() {
|
||||
goodsCache.home = null
|
||||
goodsCache.category = {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除指定分类的商品缓存
|
||||
* @param {Number|String} categoryId - 分类ID
|
||||
*/
|
||||
export function clearCategoryGoodsCache(categoryId) {
|
||||
if (goodsCache.category[categoryId]) {
|
||||
delete goodsCache.category[categoryId]
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
getHomeGoodsCache,
|
||||
setHomeGoodsCache,
|
||||
getCategoryGoodsCache,
|
||||
setCategoryGoodsCache,
|
||||
getHomeGoodsWithCache,
|
||||
getCategoryGoodsWithCache,
|
||||
clearGoodsCache,
|
||||
clearCategoryGoodsCache
|
||||
}
|
||||
Reference in New Issue
Block a user