Commit d656ccf5 by liimin

Merge branch 'feature/rework' of http://192.168.3.233:8090/monorepo/venus into feature/rework

2 parents 31df9f88 46720bb8
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
</view> </view>
</template> </template>
</view> </view>
<!-- 车系列表 --> <!-- 车系列表 -->
<view v-show="currentView == 'series'" class="view-content"> <view v-show="currentView == 'series'" class="view-content">
<template v-for="(item, index) in currentCarList" :key="index"> <template v-for="(item, index) in currentCarList" :key="index">
...@@ -48,12 +47,8 @@ ...@@ -48,12 +47,8 @@
</un-popup> </un-popup>
</view> </view>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { computed, ref, watch } from "vue"; import { computed, ref, watch } from "vue";
console.log('==== CarBrands 组件脚本开始执行 ====')
import { getCarBrandsListApi, getMerchantCarBrandList } from "@/api/common-api.uts"; import { getCarBrandsListApi, getMerchantCarBrandList } from "@/api/common-api.uts";
import { recordService } from "@/services/recorder/index.uts"; import { recordService } from "@/services/recorder/index.uts";
import { dispatch, state } from "@/store/index.uts"; import { dispatch, state } from "@/store/index.uts";
...@@ -71,7 +66,6 @@ const windowHeight = computed(() => { ...@@ -71,7 +66,6 @@ const windowHeight = computed(() => {
type UserInfo = UTSJSONObject type UserInfo = UTSJSONObject
const props = defineProps({ const props = defineProps({
carBrandKey: { carBrandKey: {
type: String, type: String,
...@@ -94,9 +88,7 @@ const props = defineProps({ ...@@ -94,9 +88,7 @@ const props = defineProps({
default: true default: true
} }
}); });
const emit = defineEmits(["close", "select"]); const emit = defineEmits(["close", "select"]);
const visible = ref<boolean>(false); const visible = ref<boolean>(false);
const carBrandListOff = ref<boolean>(false); const carBrandListOff = ref<boolean>(false);
const updateView = ref<number>(Date.now()); const updateView = ref<number>(Date.now());
...@@ -108,7 +100,6 @@ const currentView = ref<"brand" | "series">("brand"); ...@@ -108,7 +100,6 @@ const currentView = ref<"brand" | "series">("brand");
const selectedBrandIndex = ref<number>(-1); const selectedBrandIndex = ref<number>(-1);
// 当前车系列表(根据选中品牌动态变化) // 当前车系列表(根据选中品牌动态变化)
const currentCarList = ref<Array<any>>([]); const currentCarList = ref<Array<any>>([]);
// 动态计算 z-index,确保始终在最上层(高于 ToolBox 的 10073) // 动态计算 z-index,确保始终在最上层(高于 ToolBox 的 10073)
const dynamicZIndex = computed<number>(() => { const dynamicZIndex = computed<number>(() => {
return 10090 + (currentView.value == "series" ? 1 : 0); return 10090 + (currentView.value == "series" ? 1 : 0);
...@@ -123,7 +114,6 @@ const watchStatus = computed<boolean>(() => { ...@@ -123,7 +114,6 @@ const watchStatus = computed<boolean>(() => {
return false; return false;
} }
}); });
const carModel = computed<null|string>(() => { const carModel = computed<null|string>(() => {
const car_key = props.carModelKey; const car_key = props.carModelKey;
if (props.customBoolean) { if (props.customBoolean) {
...@@ -134,8 +124,6 @@ const carModel = computed<null|string>(() => { ...@@ -134,8 +124,6 @@ const carModel = computed<null|string>(() => {
return `${state.user.customerInfo.carModel}`; return `${state.user.customerInfo.carModel}`;
} }
}); });
const carBrand = computed<null|string>(() => { const carBrand = computed<null|string>(() => {
const car_key = props.carBrandKey; const car_key = props.carBrandKey;
if (props.customBoolean) { if (props.customBoolean) {
...@@ -146,21 +134,17 @@ const carBrand = computed<null|string>(() => { ...@@ -146,21 +134,17 @@ const carBrand = computed<null|string>(() => {
return `${state.user.customerInfo.carBrand}`; return `${state.user.customerInfo.carBrand}`;
} }
}); });
const boutiqueDefaultCarBrandId = computed<any>(() => { const boutiqueDefaultCarBrandId = computed<any>(() => {
return state.user.boutiqueDefaultCarBrandId; return state.user.boutiqueDefaultCarBrandId;
}); });
const defaultCarId = computed<any>(() => { const defaultCarId = computed<any>(() => {
const val = state.user.defaultCarId; const val = state.user.defaultCarId;
return val != null && val != 0 ? val : ""; return val != null && val != 0 ? val : "";
}); });
// 是否显示返回按钮(车系视图时显示) // 是否显示返回按钮(车系视图时显示)
const showBackButton = computed<boolean>(() => { const showBackButton = computed<boolean>(() => {
return currentView.value == "series"; return currentView.value == "series";
}); });
function close(): void { function close(): void {
visible.value = false; visible.value = false;
carBrandListOff.value = false; carBrandListOff.value = false;
...@@ -168,7 +152,6 @@ function close(): void { ...@@ -168,7 +152,6 @@ function close(): void {
selectedBrandIndex.value = -1; // 重置选中状态 selectedBrandIndex.value = -1; // 重置选中状态
currentCarList.value = []; // 清空车系列表 currentCarList.value = []; // 清空车系列表
} }
// 处理弹窗关闭事件 // 处理弹窗关闭事件
function handlePopupClose(): void { function handlePopupClose(): void {
// 如果当前是车系视图,点击返回按钮时切换到品牌视图 // 如果当前是车系视图,点击返回按钮时切换到品牌视图
...@@ -180,12 +163,10 @@ function handlePopupClose(): void { ...@@ -180,12 +163,10 @@ function handlePopupClose(): void {
emit("close"); emit("close");
} }
} }
// 处理关闭按钮点击(不触发事件,只隐藏) // 处理关闭按钮点击(不触发事件,只隐藏)
function handleHide(): void { function handleHide(): void {
visible.value = false; visible.value = false;
} }
// 处理返回按钮点击 // 处理返回按钮点击
function handleBackClick(): void { function handleBackClick(): void {
currentView.value = "brand"; currentView.value = "brand";
...@@ -222,26 +203,21 @@ function handleSelect(item: any): void { ...@@ -222,26 +203,21 @@ function handleSelect(item: any): void {
dispatch("updateViewKey"); dispatch("updateViewKey");
dispatch("setCurrentCarInfo", selectItemVal); dispatch("setCurrentCarInfo", selectItemVal);
} }
// 关闭弹窗并发出选择事件 // 关闭弹窗并发出选择事件
visible.value = false; visible.value = false;
emit("select", { ...item, ...selectItemVal }); emit("select", { ...item, ...selectItemVal });
} }
// 选择品牌(切换到车系视图) // 选择品牌(切换到车系视图)
function selectBrand(item: any, index: number): void { function selectBrand(item: any, index: number): void {
const _brandId = (item as UTSJSONObject).brandId; const _brandId = (item as UTSJSONObject).brandId;
const _carId = (item as UTSJSONObject).id; const _carId = (item as UTSJSONObject).id;
if (_brandId == null || _carId == null) { if (_brandId == null || _carId == null) {
return uni.showToast({ return uni.showToast({
title: "车型 ID 或品牌 ID 为空", title: "车型 ID 或品牌 ID 为空",
icon: "none" icon: "none"
}); });
} }
selectedBrandIndex.value = index; selectedBrandIndex.value = index;
const _brandName = (item as UTSJSONObject).name; const _brandName = (item as UTSJSONObject).name;
const _carName = (item as UTSJSONObject).name; const _carName = (item as UTSJSONObject).name;
const selectData = { const selectData = {
...@@ -251,10 +227,8 @@ function selectBrand(item: any, index: number): void { ...@@ -251,10 +227,8 @@ function selectBrand(item: any, index: number): void {
carChildsBrandId: _carId carChildsBrandId: _carId
} as UTSJSONObject; } as UTSJSONObject;
selectItem.value = selectData; selectItem.value = selectData;
const cacheKey = `${_carId}_${_brandId}_carlist`; const cacheKey = `${_carId}_${_brandId}_carlist`;
let _carList = uni.getStorageSync(cacheKey); let _carList = uni.getStorageSync(cacheKey);
// 尝试从缓存加载车系数据 // 尝试从缓存加载车系数据
if (_carList != null && _carList != "" && _carList != "null") { if (_carList != null && _carList != "" && _carList != "null") {
_carList = typeof _carList === "string" ? JSON.parse(_carList) as Array<any> : _carList as Array<any>; _carList = typeof _carList === "string" ? JSON.parse(_carList) as Array<any> : _carList as Array<any>;
...@@ -265,8 +239,8 @@ function selectBrand(item: any, index: number): void { ...@@ -265,8 +239,8 @@ function selectBrand(item: any, index: number): void {
// 从 API 获取车系数据 // 从 API 获取车系数据
getCarBrandsListApi({ brandId: _brandId, childBrandId: _carId }).then(res => { getCarBrandsListApi({ brandId: _brandId, childBrandId: _carId }).then(res => {
const typedRes = res as UTSArray<any>; const typedRes = res as UTSArray<any>;
console.error("获取车系列表成功:", typedRes);
currentCarList.value = typedRes; currentCarList.value = typedRes;
if (typedRes.length > 0) { if (typedRes.length > 0) {
uni.setStorageSync(cacheKey, typedRes); uni.setStorageSync(cacheKey, typedRes);
} }
...@@ -277,7 +251,6 @@ function selectBrand(item: any, index: number): void { ...@@ -277,7 +251,6 @@ function selectBrand(item: any, index: number): void {
}); });
} }
} }
watch(watchStatus, () => { watch(watchStatus, () => {
close(); close();
}, { immediate: true }); }, { immediate: true });
...@@ -285,22 +258,17 @@ watch(updateView, () => { ...@@ -285,22 +258,17 @@ watch(updateView, () => {
const carBrandListData = storage.get("carBrandList"); const carBrandListData = storage.get("carBrandList");
carBrandList.value = carBrandListData != null ? (carBrandListData as Array<any>) : []; carBrandList.value = carBrandListData != null ? (carBrandListData as Array<any>) : [];
}, { immediate: true, deep: true }); }, { immediate: true, deep: true });
function autoSelect(): void { function autoSelect(): void {
const boutiqueDefaultCarBrandIdVal = boutiqueDefaultCarBrandId.value; const boutiqueDefaultCarBrandIdVal = boutiqueDefaultCarBrandId.value;
let carIndex = 0; let carIndex = 0;
if (boutiqueDefaultCarBrandIdVal != null) { if (boutiqueDefaultCarBrandIdVal != null) {
carIndex = carBrandList.value.findIndex((e: any) => (e as UTSJSONObject).id == boutiqueDefaultCarBrandIdVal); carIndex = carBrandList.value.findIndex((e: any) => (e as UTSJSONObject).id == boutiqueDefaultCarBrandIdVal);
} }
if (carIndex < 0) carIndex = 0; if (carIndex < 0) carIndex = 0;
if (carBrandList.value.length > 0) { if (carBrandList.value.length > 0) {
selectBrand(carBrandList.value[carIndex], carIndex); selectBrand(carBrandList.value[carIndex], carIndex);
} }
} }
function open(): void { function open(): void {
// 先显示弹窗 // 先显示弹窗
visible.value = true; visible.value = true;
...@@ -330,9 +298,7 @@ function open(): void { ...@@ -330,9 +298,7 @@ function open(): void {
} }
const userInfo: null | UserInfo = storage.get("userInfo") as null | UTSJSONObject; const userInfo: null | UserInfo = storage.get("userInfo") as null | UTSJSONObject;
if (userInfo == null) return; if (userInfo == null) return;
const shopMerchantId = userInfo.shopMerchantId; const shopMerchantId = userInfo.shopMerchantId;
// 异步获取车品牌列表,不阻塞弹窗显示 // 异步获取车品牌列表,不阻塞弹窗显示
...@@ -370,13 +336,11 @@ function open(): void { ...@@ -370,13 +336,11 @@ function open(): void {
if (carBrandVal != null) { if (carBrandVal != null) {
const carBrandListVal = carBrandList.value; const carBrandListVal = carBrandList.value;
let foundIndex = -1; let foundIndex = -1;
carBrandListVal.forEach((element: any, index: number) => { carBrandListVal.forEach((element: any, index: number) => {
if ((element as UTSJSONObject).name == carBrandVal) { if ((element as UTSJSONObject).name == carBrandVal) {
foundIndex = index; foundIndex = index;
} }
}); });
if (foundIndex != -1 && carBrandListVal.length == 1) { if (foundIndex != -1 && carBrandListVal.length == 1) {
selectBrand(carBrandListVal[foundIndex], foundIndex); selectBrand(carBrandListVal[foundIndex], foundIndex);
} else { } else {
...@@ -384,16 +348,10 @@ function open(): void { ...@@ -384,16 +348,10 @@ function open(): void {
} }
return; return;
} }
carBrandListOff.value = true; carBrandListOff.value = true;
} }
defineExpose({ open, close, autoSelect }); defineExpose({ open, close, autoSelect });
</script> </script>
<style scoped lang='scss'> <style scoped lang='scss'>
.popup-wrapper { .popup-wrapper {
background: #ffffff; background: #ffffff;
...@@ -402,7 +360,6 @@ defineExpose({ open, close, autoSelect }); ...@@ -402,7 +360,6 @@ defineExpose({ open, close, autoSelect });
flex-direction: column; flex-direction: column;
overflow: hidden; overflow: hidden;
} }
.popup-header { .popup-header {
position: relative; position: relative;
display: flex; display: flex;
...@@ -412,13 +369,11 @@ defineExpose({ open, close, autoSelect }); ...@@ -412,13 +369,11 @@ defineExpose({ open, close, autoSelect });
flex-shrink: 0; flex-shrink: 0;
border-bottom: 1px solid #f0f0f0; border-bottom: 1px solid #f0f0f0;
} }
.popup-title { .popup-title {
font-size: 18px; font-size: 18px;
font-weight: 600; font-weight: 600;
color: #292d33; color: #292d33;
} }
.icon-back { .icon-back {
position: absolute; position: absolute;
left: 16px; left: 16px;
...@@ -430,7 +385,6 @@ defineExpose({ open, close, autoSelect }); ...@@ -430,7 +385,6 @@ defineExpose({ open, close, autoSelect });
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.icon-close-box { .icon-close-box {
position: absolute; position: absolute;
right: 16px; right: 16px;
...@@ -442,7 +396,6 @@ defineExpose({ open, close, autoSelect }); ...@@ -442,7 +396,6 @@ defineExpose({ open, close, autoSelect });
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.select-box { .select-box {
flex: 1; flex: 1;
min-height: 0; min-height: 0;
...@@ -486,7 +439,38 @@ defineExpose({ open, close, autoSelect }); ...@@ -486,7 +439,38 @@ defineExpose({ open, close, autoSelect });
background-color: rgba(22, 119, 255, 0.05); /* 淡淡的主题色背景 */ background-color: rgba(22, 119, 255, 0.05); /* 淡淡的主题色背景 */
border: 1px solid rgba(22, 119, 255, 0.3); /* 主题色描边 */ border: 1px solid rgba(22, 119, 255, 0.3); /* 主题色描边 */
} }
.view-content {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
width: 100%;
padding: 16px 24px 24px;
box-sizing: border-box;
min-height: 100%;
}
.select-item {
width: 48%; /* 给元素间留一点呼吸空间,避免 49% 可能产生的换行问题 */
margin-bottom: 12px;
height: 44px; /* 加高触控面积,显得更大气 */
background-color: #f8f9fa; /* 低调的浅灰背景 */
border-radius: 8px; /* 圆角增加现代感 */
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
border: 1px solid transparent;
transition: background-color 0.2s ease, border-color 0.2s ease;
}
/* 悬浮反馈 */
.select-item:active {
background-color: #f1f3f5;
}
/* 选中状态 */
.is-active {
background-color: rgba(22, 119, 255, 0.05); /* 淡淡的主题色背景 */
border: 1px solid rgba(22, 119, 255, 0.3); /* 主题色描边 */
}
.select-item-text { .select-item-text {
text-align: center; text-align: center;
color: #495057; /* 稳重的深灰色 */ color: #495057; /* 稳重的深灰色 */
...@@ -494,7 +478,6 @@ defineExpose({ open, close, autoSelect }); ...@@ -494,7 +478,6 @@ defineExpose({ open, close, autoSelect });
line-height: 20px; line-height: 20px;
font-weight: 500; font-weight: 500;
} }
.is-active-text { .is-active-text {
color: #1677FF; /* 选中时的文字色与边框呼应 */ color: #1677FF; /* 选中时的文字色与边框呼应 */
font-weight: 600; font-weight: 600;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!