Commit a7784bac by Sweet Zhang

产品对比

parent e477db49
...@@ -424,4 +424,21 @@ export default { ...@@ -424,4 +424,21 @@ export default {
withdrawalList(params) { withdrawalList(params) {
return request(`${scrmUrl}/scrm-api/agCffpUserFortune/withdrawal/list`, 'POST', params) return request(`${scrmUrl}/scrm-api/agCffpUserFortune/withdrawal/list`, 'POST', params)
}, },
// 产品查询
productSearch(params){
return request(`${apiURL}/insurance_product/getAppProductList`, 'POST', params)
},
// 产品PK信息查询
getProductPKInfo(params){
return request(`${apiURL}/insurance_product/getBasicProductPKInfo`, 'POST', params)
},
// 保司查询
getInsuranceCompanyList(params){
return request(`${apiURL}/insurance_product/getInsuranceCompanyList`, 'POST', params)
},
// 数据字典查询
metaQuery(params){
return request(`${apiURL}/metadata/dropOptionsQuery`,'POST',params)
}
} }
<!-- components/ComparisonButton.vue -->
<template>
<view
class="comparison-btn"
@click="showComparisonPanel = !showComparisonPanel"
v-if="selectedProducts.length > 0"
>
<text class="count">{{ selectedProducts.length }}</text>
<uni-icons type="list" size="24" color="#fff"></uni-icons>
<!-- 已选产品面板 -->
<view class="comparison-panel" v-if="showComparisonPanel">
<view class="panel-header">
<text class="panel-title">已选对比产品</text>
<button class="clear-btn" @click="clearComparison">清空</button>
</view>
<view class="product-list">
<view class="product-item" v-for="product in selectedProducts" :key="product.id">
<image
class="product-logo"
:src="product.companyLogo"
:alt="product.companyName"
></image>
<text class="product-name">{{ product.name }}</text>
<button
class="remove-btn"
@click.stop="removeFromComparison(product.id)"
>
<uni-icons type="close" size="18" color="#fff"></uni-icons>
</button>
</view>
</view>
<button
class="compare-btn"
@click="goToComparisonResult"
:disabled="selectedProducts.length < 2"
>
去对比
</button>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue';
import { useProductComparison } from '@/util/useProductComparison';
// 引入对比逻辑
const {
selectedProducts,
removeFromComparison,
clearComparison,
goToComparisonResult
} = useProductComparison();
// 控制面板显示/隐藏
const showComparisonPanel = ref(false);
</script>
<style scoped>
.comparison-btn {
position: fixed;
right: 30rpx;
bottom: 150rpx;
width: 80rpx;
height: 80rpx;
background-color: #007aff;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.2);
z-index: 999;
}
.count {
position: absolute;
top: -10rpx;
right: -10rpx;
width: 40rpx;
height: 40rpx;
background-color: #ff3b30;
color: #fff;
font-size: 22rpx;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
.comparison-panel {
position: absolute;
right: 0;
bottom: 90rpx;
width: 500rpx;
background-color: #fff;
border-radius: 15rpx;
box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.1);
padding: 15rpx;
}
.panel-header {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 15rpx;
border-bottom: 1px solid #eee;
margin-bottom: 15rpx;
}
.panel-title {
font-size: 28rpx;
font-weight: bold;
color: #333;
}
.clear-btn {
font-size: 24rpx;
color: #007aff;
background-color: transparent;
padding: 0;
}
.product-list {
max-height: 300rpx;
overflow-y: auto;
margin-bottom: 20rpx;
}
.product-item {
display: flex;
align-items: center;
padding: 10rpx 0;
border-bottom: 1px solid #f5f5f5;
}
.product-logo {
width: 50rpx;
height: 50rpx;
border-radius: 5rpx;
margin-right: 10rpx;
}
.product-name {
flex: 1;
font-size: 26rpx;
color: #333;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.remove-btn {
width: 40rpx;
height: 40rpx;
border-radius: 50%;
background-color: #ff3b30;
display: flex;
align-items: center;
justify-content: center;
padding: 0;
}
.compare-btn {
width: 100%;
background-color: #007aff;
color: #fff;
height: 80rpx;
line-height: 80rpx;
font-size: 28rpx;
border-radius: 10rpx;
}
.compare-btn:disabled {
background-color: #ccc;
}
</style>
\ No newline at end of file
...@@ -49,7 +49,7 @@ const config = { ...@@ -49,7 +49,7 @@ const config = {
stage, stage,
prod prod
} }
let env = 'dev'; let env = 'prod';
let baseURL = config[env].base_url; let baseURL = config[env].base_url;
let apiURL = config[env].api_url; let apiURL = config[env].api_url;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"name": "验证码输入框", "name": "验证码输入框",
"version": "2.0", "version": "2.0",
"dependencies": { "dependencies": {
"@dcloudio/uni-ui": "^1.5.10", "@dcloudio/uni-ui": "^1.5.11",
"@uqrcode/js": "^4.0.7", "@uqrcode/js": "^4.0.7",
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
"dayjs": "^1.11.13", "dayjs": "^1.11.13",
...@@ -27,9 +27,10 @@ ...@@ -27,9 +27,10 @@
} }
}, },
"node_modules/@dcloudio/uni-ui": { "node_modules/@dcloudio/uni-ui": {
"version": "1.5.10", "version": "1.5.11",
"resolved": "https://registry.npmmirror.com/@dcloudio/uni-ui/-/uni-ui-1.5.10.tgz", "resolved": "https://registry.npmmirror.com/@dcloudio/uni-ui/-/uni-ui-1.5.11.tgz",
"integrity": "sha512-v6ylkGSUF6hhgSerm8aVEQE9SBkKz3oNDzorkVC0KLHfulMbkacJQ92YFSQ0kCGeudupVqXuPwNTFjKJF5Qolw==" "integrity": "sha512-DBtk046ofmeFd82zRI7d89SoEwrAxYzUN3WVPm1DIBkpLPG5F5QDNkHMnZGu2wNrMEmGBjBpUh3vqEY1L3jaMw==",
"license": "Apache-2.0"
}, },
"node_modules/@uqrcode/js": { "node_modules/@uqrcode/js": {
"version": "4.0.7", "version": "4.0.7",
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
] ]
}, },
"dependencies": { "dependencies": {
"@dcloudio/uni-ui": "^1.5.10", "@dcloudio/uni-ui": "^1.5.11",
"@uqrcode/js": "^4.0.7", "@uqrcode/js": "^4.0.7",
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
"dayjs": "^1.11.13", "dayjs": "^1.11.13",
......
...@@ -575,6 +575,16 @@ ...@@ -575,6 +575,16 @@
"style": { "style": {
"navigationBarTitleText": "提现记录" "navigationBarTitleText": "提现记录"
} }
},{
"path": "compare-result/compare-result",
"style": {
"navigationBarTitleText": "对比结果"
}
},{
"path": "product-list/product-list",
"style": {
"navigationBarTitleText": "产品对比"
}
} }
] ]
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
</view> </view>
<!-- Tab对应的PDF内容(无权限时显示空状态) --> <!-- Tab对应的PDF内容(无权限时显示空状态) -->
<view class="pdf-tab-content"> <view class="pdf-tab-content" v-if="currentPdf.type==='showURL'">
<template v-if="filteredCurrentTabs.length > 0"> <template v-if="filteredCurrentTabs.length > 0">
<web-view <web-view
:src="getPdfViewerUrl(currentPdf.url)" :src="getPdfViewerUrl(currentPdf.url)"
...@@ -49,6 +49,10 @@ ...@@ -49,6 +49,10 @@
<view class="pdf-empty">暂无访问权限</view> <view class="pdf-empty">暂无访问权限</view>
</template> </template>
</view> </view>
<!-- 显示产品搜索组件 -->
<view class="pdf-tab-content" v-if="currentPdf.type==='showPage'">
<productListVue/>
</view>
</view> </view>
<!-- 错误状态 --> <!-- 错误状态 -->
...@@ -63,6 +67,7 @@ ...@@ -63,6 +67,7 @@
import { ref, computed } from 'vue'; import { ref, computed } from 'vue';
import { onLoad } from '@dcloudio/uni-app'; import { onLoad } from '@dcloudio/uni-app';
import api from "@/api/api"; import api from "@/api/api";
import productListVue from '@/myPackageA/product-list/product-list.vue';
// ========================== 类型定义 ========================== // ========================== 类型定义 ==========================
// PDF文件类型 // PDF文件类型
...@@ -70,6 +75,7 @@ interface PdfItem { ...@@ -70,6 +75,7 @@ interface PdfItem {
id: string; id: string;
title: string; title: string;
url: string; // PDF文件路径 url: string; // PDF文件路径
type:string;
} }
// 权限数据类型(与接口返回结构对齐) // 权限数据类型(与接口返回结构对齐)
...@@ -84,7 +90,6 @@ interface PermissionItem { ...@@ -84,7 +90,6 @@ interface PermissionItem {
// ========================== 基础配置 ========================== // ========================== 基础配置 ==========================
// OSS基础路径(根据实际OSS地址修改) // OSS基础路径(根据实际OSS地址修改)
const OSS_BASE_URL = 'https://csf-doc-center.oss-cn-shanghai-finance-1-pub.aliyuncs.com'; const OSS_BASE_URL = 'https://csf-doc-center.oss-cn-shanghai-finance-1-pub.aliyuncs.com';
// 接收URL参数的type(默认1:公司介绍) // 接收URL参数的type(默认1:公司介绍)
const currentType = ref<number>(1); const currentType = ref<number>(1);
// 加载状态 // 加载状态
...@@ -92,7 +97,7 @@ const loading = ref(true); ...@@ -92,7 +97,7 @@ const loading = ref(true);
// 当前激活的Tab索引 // 当前激活的Tab索引
const activeTab = ref(0); const activeTab = ref(0);
// 当前显示的PDF信息 // 当前显示的PDF信息
const currentPdf = ref<PdfItem>({ id: '', title: '', url: '' }); const currentPdf = ref<PdfItem>({ id: '', title: '', url: '', type:''});
// 接口返回的权限列表 // 接口返回的权限列表
const permissionList = ref<PermissionItem[]>([]); const permissionList = ref<PermissionItem[]>([]);
...@@ -100,24 +105,25 @@ const permissionList = ref<PermissionItem[]>([]); ...@@ -100,24 +105,25 @@ const permissionList = ref<PermissionItem[]>([]);
const companyPdf = ref<PdfItem>({ const companyPdf = ref<PdfItem>({
id: 'company', id: 'company',
title: '公司介绍', title: '公司介绍',
url: `${OSS_BASE_URL}/public/company-intro.pdf` url: `${OSS_BASE_URL}/public/company-intro.pdf`,
type:'showURL'
}); });
// 所有模块的原始Tab配置(未过滤权限) // 所有模块的原始Tab配置(未过滤权限)
const rawTabConfig = ref<Record<number, PdfItem[]>>({ const rawTabConfig = ref<Record<number, PdfItem[]>>({
2: [ // type=2:案例分享(对应权限key=cases) 2: [ // type=2:案例分享(对应权限key=cases)
{ id: 'case1', title: '规划案例', url: `${OSS_BASE_URL}/cases/planning.pdf` }, { id: 'case1', title: '规划案例', url: `${OSS_BASE_URL}/cases/planning.pdf`,type:'showURL' },
{ id: 'case2', title: '团财案例', url: `${OSS_BASE_URL}/cases/CorporateServiceDeliveryCase-GroupandPropertyInsurance.pdf` } { id: 'case2', title: '团财案例', url: `${OSS_BASE_URL}/cases/CorporateServiceDeliveryCase-GroupandPropertyInsurance.pdf`,type:'showURL' }
], ],
3: [ // type=3:产品分析(对应权限key=products) 3: [ // type=3:产品分析(对应权限key=products)
{ id: 'product2', title: '港险分析', url: `${OSS_BASE_URL}/products/hk-analysis.pdf` }, { id: 'product2', title: '港险分析', url: `${OSS_BASE_URL}/products/hk-analysis.pdf`,type:'showURL' },
{ id: 'product1', title: '港险明细', url: `${OSS_BASE_URL}/products/2025Q3-hk-detail.pdf` }, { id: 'product1', title: '港险明细', url: `${OSS_BASE_URL}/products/2025Q3-hk-detail.pdf`,type:'showURL' },
{ id: 'product3', title: '产品搜索', url: '' }, { id: 'product3', title: '产品对比', url: '',type:'showPage' },
], ],
4: [ // type=4:制度(对应权限key=policies) 4: [ // type=4:制度(对应权限key=policies)
{ id: 'policy1', title: '个险政策', url: `${OSS_BASE_URL}/policies/individual-policy.pdf` }, { id: 'policy1', title: '个险政策', url: `${OSS_BASE_URL}/policies/individual-policy.pdf`,type:'showURL' },
{ id: 'policy2', title: '家办政策', url: `${OSS_BASE_URL}/policies/group-policy.pdf` }, { id: 'policy2', title: '家办政策', url: `${OSS_BASE_URL}/policies/group-policy.pdf`,type:'showURL' },
{ id: 'policy3', title: '介绍费政策', url: `${OSS_BASE_URL}/policies/commission-policy.pdf` } { id: 'policy3', title: '介绍费政策', url: `${OSS_BASE_URL}/policies/commission-policy.pdf`,type:'showURL' }
] ]
}); });
...@@ -132,6 +138,13 @@ const typeToPermissionKey = ref<Record<number, string>>({ ...@@ -132,6 +138,13 @@ const typeToPermissionKey = ref<Record<number, string>>({
onLoad((query) => { onLoad((query) => {
// 1. 解析URL中的type参数(默认1) // 1. 解析URL中的type参数(默认1)
currentType.value = Number(query.type) || 1; currentType.value = Number(query.type) || 1;
const index = uni.getStorageSync('tabsIndex');
setTimeout(()=>{
if(index){
switchTab(index)
}
},300)
// 2. 查询用户信息和权限 // 2. 查询用户信息和权限
queryUserInfoAndPermission(); queryUserInfoAndPermission();
}); });
...@@ -182,7 +195,7 @@ const initPdfAfterPermission = () => { ...@@ -182,7 +195,7 @@ const initPdfAfterPermission = () => {
currentPdf.value = filteredTabs[0]; currentPdf.value = filteredTabs[0];
} else { } else {
// 无权限:清空当前PDF // 无权限:清空当前PDF
currentPdf.value = { id: '', title: '', url: '' }; currentPdf.value = { id: '', title: '', url: '',type:'' };
} }
} }
...@@ -232,6 +245,7 @@ const switchTab = (index: number) => { ...@@ -232,6 +245,7 @@ const switchTab = (index: number) => {
setTimeout(() => { setTimeout(() => {
activeTab.value = index; activeTab.value = index;
currentPdf.value = tabs[index]; currentPdf.value = tabs[index];
uni.setStorageSync('tabsIndex', index);
// 延迟关闭加载提示(给WebView启动时间) // 延迟关闭加载提示(给WebView启动时间)
setTimeout(() => { setTimeout(() => {
......
## 2.1.2(2025-08-19)
- 修复 传入数字 0 不显示的问题
## 2.1.1(2024-03-20)
- 优化 app下边框过窄导致不显示的bug
## 2.1.0(2021-11-19)
- 优化 组件UI,并提供设计资源,详见:[https://uniapp.dcloud.io/component/uniui/resource](https://uniapp.dcloud.io/component/uniui/resource)
- 文档迁移,详见:[https://uniapp.dcloud.io/component/uniui/uni-tag](https://uniapp.dcloud.io/component/uniui/uni-tag)
## 2.0.0(2021-11-09)
- 新增 提供组件设计资源,组件样式调整
- 移除 插槽
- 移除 type 属性的 royal 选项
## 1.1.1(2021-08-11)
- type 不是 default 时,size 为 small 字体大小显示不正确
## 1.1.0(2021-07-30)
- 组件兼容 vue3,如何创建vue3项目,详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834)
## 1.0.7(2021-06-18)
- 修复 uni-tag 在字节跳动小程序上 css 类名编译错误的 bug
## 1.0.6(2021-06-04)
- 修复 未定义 sass 变量 "$uni-color-royal" 的bug
## 1.0.5(2021-05-10)
- 修复 royal 类型无效的bug
- 修复 uni-tag 宽度不自适应的bug
- 新增 uni-tag 支持属性 custom-style 自定义样式
## 1.0.4(2021-02-05)
- 调整为uni_modules目录规范
<template>
<text class="uni-tag" v-if="showTag" :class="classes" :style="customStyle" @click="onClick">{{text}}</text>
</template>
<script>
/**
* Tag 标签
* @description 用于展示1个或多个文字标签,可点击切换选中、不选中的状态
* @tutorial https://ext.dcloud.net.cn/plugin?id=35
* @property {String} text 标签内容
* @property {String} size = [default|small|mini] 大小尺寸
* @value default 正常
* @value small 小尺寸
* @value mini 迷你尺寸
* @property {String} type = [default|primary|success|warning|error] 颜色类型
* @value default 灰色
* @value primary 蓝色
* @value success 绿色
* @value warning 黄色
* @value error 红色
* @property {Boolean} disabled = [true|false] 是否为禁用状态
* @property {Boolean} inverted = [true|false] 是否无需背景颜色(空心标签)
* @property {Boolean} circle = [true|false] 是否为圆角
* @event {Function} click 点击 Tag 触发事件
*/
export default {
name: "UniTag",
emits: ['click'],
props: {
type: {
// 标签类型default、primary、success、warning、error、royal
type: String,
default: "default"
},
size: {
// 标签大小 normal, small
type: String,
default: "normal"
},
// 标签内容
text: {
type: String,
default: ""
},
disabled: {
// 是否为禁用状态
type: [Boolean, String],
default: false
},
inverted: {
// 是否为空心
type: [Boolean, String],
default: false
},
circle: {
// 是否为圆角样式
type: [Boolean, String],
default: false
},
mark: {
// 是否为标记样式
type: [Boolean, String],
default: false
},
customStyle: {
type: String,
default: ''
}
},
computed: {
showTag() {
return !!this.text.toString()
},
classes() {
const {
type,
disabled,
inverted,
circle,
mark,
size,
isTrue
} = this
const classArr = [
'uni-tag--' + type,
'uni-tag--' + size,
isTrue(disabled) ? 'uni-tag--disabled' : '',
isTrue(inverted) ? 'uni-tag--' + type + '--inverted' : '',
isTrue(circle) ? 'uni-tag--circle' : '',
isTrue(mark) ? 'uni-tag--mark' : '',
// type === 'default' ? 'uni-tag--default' : 'uni-tag-text',
isTrue(inverted) ? 'uni-tag--inverted uni-tag-text--' + type : '',
size === 'small' ? 'uni-tag-text--small' : ''
]
// 返回类的字符串,兼容字节小程序
return classArr.join(' ')
}
},
methods: {
isTrue(value) {
return value === true || value === 'true'
},
onClick() {
if (this.isTrue(this.disabled)) return
this.$emit("click");
}
}
};
</script>
<style lang="scss" scoped>
$uni-primary: #2979ff !default;
$uni-success: #18bc37 !default;
$uni-warning: #f3a73f !default;
$uni-error: #e43d33 !default;
$uni-info: #8f939c !default;
$tag-default-pd: 4px 7px;
$tag-small-pd: 2px 5px;
$tag-mini-pd: 1px 3px;
.uni-tag {
line-height: 14px;
font-size: 12px;
font-weight: 200;
padding: $tag-default-pd;
color: #fff;
border-radius: 3px;
background-color: $uni-info;
border-width: 1rpx;
border-style: solid;
border-color: $uni-info;
/* #ifdef H5 */
cursor: pointer;
/* #endif */
// size attr
&--default {
font-size: 12px;
}
&--default--inverted {
color: $uni-info;
border-color: $uni-info;
}
&--small {
padding: $tag-small-pd;
font-size: 12px;
border-radius: 2px;
}
&--mini {
padding: $tag-mini-pd;
font-size: 12px;
border-radius: 2px;
}
// type attr
&--primary {
background-color: $uni-primary;
border-color: $uni-primary;
color: #fff;
}
&--success {
color: #fff;
background-color: $uni-success;
border-color: $uni-success;
}
&--warning {
color: #fff;
background-color: $uni-warning;
border-color: $uni-warning;
}
&--error {
color: #fff;
background-color: $uni-error;
border-color: $uni-error;
}
&--primary--inverted {
color: $uni-primary;
border-color: $uni-primary;
}
&--success--inverted {
color: $uni-success;
border-color: $uni-success;
}
&--warning--inverted {
color: $uni-warning;
border-color: $uni-warning;
}
&--error--inverted {
color: $uni-error;
border-color: $uni-error;
}
&--inverted {
background-color: #fff;
}
// other attr
&--circle {
border-radius: 15px !important;
}
&--mark {
border-top-left-radius: 0 !important;
border-bottom-left-radius: 0 !important;
border-top-right-radius: 15px !important;
border-bottom-right-radius: 15px !important;
}
&--disabled {
opacity: 0.5;
/* #ifdef H5 */
cursor: not-allowed;
/* #endif */
}
}
.uni-tag-text {
color: #fff;
font-size: 14px;
&--primary {
color: $uni-primary;
}
&--success {
color: $uni-success;
}
&--warning {
color: $uni-warning;
}
&--error {
color: $uni-error;
}
&--small {
font-size: 12px;
}
}
</style>
\ No newline at end of file
{
"id": "uni-tag",
"displayName": "uni-tag 标签",
"version": "2.1.2",
"description": "Tag 组件,用于展示1个或多个文字标签,可点击切换选中、不选中的状态。",
"keywords": [
"uni-ui",
"uniui",
"",
"tag",
"标签"
],
"repository": "https://github.com/dcloudio/uni-ui",
"engines": {
"HBuilderX": "",
"uni-app": "^4.07",
"uni-app-x": ""
},
"directories": {
"example": "../../temps/example_temps"
},
"dcloudext": {
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui",
"type": "component-vue",
"darkmode": "x",
"i18n": "x",
"widescreen": "x"
},
"uni_modules": {
"dependencies": [
"uni-scss"
],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "x",
"aliyun": "x",
"alipay": "x"
},
"client": {
"uni-app": {
"vue": {
"vue2": "√",
"vue3": "√"
},
"web": {
"safari": "√",
"chrome": "√"
},
"app": {
"vue": "√",
"nvue": "√",
"android": "√",
"ios": "√",
"harmony": "√"
},
"mp": {
"weixin": "√",
"alipay": "√",
"toutiao": "√",
"baidu": "√",
"kuaishou": "-",
"jd": "-",
"harmony": "-",
"qq": "√",
"lark": "-"
},
"quickapp": {
"huawei": "√",
"union": "√"
}
},
"uni-app-x": {
"web": {
"safari": "-",
"chrome": "-"
},
"app": {
"android": "-",
"ios": "-",
"harmony": "-"
},
"mp": {
"weixin": "-"
}
}
}
}
}
}
\ No newline at end of file
## Tag 标签
> **组件名:uni-tag**
> 代码块: `uTag`
用于展示1个或多个文字标签,可点击切换选中、不选中的状态 。
### [查看文档](https://uniapp.dcloud.io/component/uniui/uni-tag)
#### 如使用过程中有任何问题,或者您对uni-ui有一些好的建议,欢迎加入 uni-ui 交流群:871950839
// composables/useProductComparison.js
import { ref, computed } from 'vue';
import { useRouter } from 'vue-router';
export function useProductComparison() {
// 存储已选择的对比产品
const selectedProducts = ref([]);
// 最大可选产品数量
const maxCount = 3;
const router = useRouter();
// 检查是否已选择该产品
const isSelected = (productId) => {
return selectedProducts.value.some(item => item.id === productId);
};
// 添加产品到对比列表
const addToComparison = (product) => {
if (selectedProducts.value.length >= maxCount) {
uni.showToast({
title: `最多只能选择${maxCount}个产品进行对比`,
icon: 'none'
});
return false;
}
// 检查是否同险种
if (selectedProducts.value.length > 0) {
const firstType = selectedProducts.value[0].typeId;
if (product.typeId !== firstType) {
uni.showToast({
title: '只能选择同险种产品进行对比',
icon: 'none'
});
return false;
}
}
if (!isSelected(product.id)) {
selectedProducts.value.push(product);
return true;
}
return false;
};
// 从对比列表移除产品
const removeFromComparison = (productId) => {
selectedProducts.value = selectedProducts.value.filter(
item => item.id !== productId
);
};
// 清空对比列表
const clearComparison = () => {
selectedProducts.value = [];
};
// 跳转到对比结果页
const goToComparisonResult = () => {
if (selectedProducts.value.length < 2) {
uni.showToast({
title: '至少选择2个产品才能进行对比',
icon: 'none'
});
return;
}
const productIds = selectedProducts.value.map(item => item.id).join(',');
router.push({
path: '/pages/compare-result/compare-result',
query: { productIds }
});
};
return {
selectedProducts,
maxCount,
isSelected,
addToComparison,
removeFromComparison,
clearComparison,
goToComparisonResult
};
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment