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