Commit 2097745c by 胡悦

feat(insurance): 实现保险权益产品选择与管理功能

- 新增用户store中保险权益产品的状态、mutation和action,重置客户信息时自动清空
- 重构原购车方式选择组件为通用权益产品多选弹窗,支持搜索与多选功能
- 移除客户信息中购车方式相关字段,替换为保险权益产品管理逻辑
- 集成权益产品选择器到保险模块,同步选中状态到全局状态管理
- 更新保险表格组件,过滤权益产品并将选中项追加到新能源车险详情展示
1 parent f9fe7ce2
......@@ -69,6 +69,7 @@
<insurance-table
:isPreview="isPreview"
:show="show"
@equity-products-change="handleEquityProductList"
/>
</view>
</template>
......@@ -80,7 +81,9 @@
/>
<carBuyers
ref="carBuyersVisible"
@select="handleSelect($event,'carBuyersVisible')"
:productList="equityProductList"
@confirm="handleEquityProductsConfirm"
@cancel="resetFocusIndex"
@close="resetFocusIndex"
/>
</view>
......@@ -136,15 +139,15 @@ export default {
unit: '元',
},
{
placeholder: '购车方式',
key: 'carBuyers',
placeholder: '权益产品',
key: 'equityProducts',
type: 'select',
popKey: 'carBuyersVisible',
}
],
customerInfo: {},
focusIndex: -1,
insuranceList: []
equityProductList: []
}
},
watch: {
......@@ -172,9 +175,6 @@ export default {
if (popkey == 'employeeBoxVisible') {
this.customerInfo.salesUuid = item.uuid
this.customerInfo.staffName = item.staffName
} else if (popkey == 'carBuyersVisible') {
this.customerInfo.carBuyers = item.name
this.customerInfo.carPurchaseMethod = item.id
} else {
this.$refs.carBrandListVisible.close()
this.customerInfo.carModel = item.name
......@@ -183,12 +183,29 @@ export default {
this.resetFocusIndex()
this.$store.dispatch('setCustomerInfo', this.customerInfo)
},
handleEquityProductList (list) {
this.equityProductList = Array.isArray(list) ? list : []
const selectedProducts = this.$store.state.user.insuranceEquityProducts || []
const productMap = this.equityProductList.reduce((result, item) => {
result[item.itemName] = item
return result
}, {})
const availableSelectedProducts = selectedProducts
.map(item => productMap[item.itemName])
.filter(Boolean)
this.$store.dispatch('setInsuranceEquityProducts', availableSelectedProducts)
},
handleEquityProductsConfirm (list) {
this.$store.dispatch('setInsuranceEquityProducts', list)
this.resetFocusIndex()
},
showPopup (e, index) {
this.focusIndex = index
this.$refs[e].open()
},
closeAllPopup () {
this.$refs.carBrandListVisible.close()
this.$refs.carBuyersVisible.close()
this.resetFocusIndex()
},
resetFocusIndex (e) {
......
......@@ -49,8 +49,14 @@
class="range row-2"
@click="showDetail(i)"
>
<view class="text-two-line">
<rich-text :nodes="i.itemDesc"></rich-text>
<view class="description-list">
<view
v-for="(itemDesc, descIndex) in getDescriptionList(i)"
:key="`${i.id}-${descIndex}`"
class="description-item"
>
<rich-text :nodes="itemDesc"></rich-text>
</view>
</view>
</view>
<view class="cost row-3">
......@@ -123,7 +129,7 @@ export default {
watch: {
watchStatus: {
immediate: true,
handler (newval) {
handler () {
this.$refs.popupRef?.close()
this.flag = false
this.scrollTop = -1
......@@ -133,18 +139,33 @@ export default {
const storageKey = this.getStorageKey(),
insuranceList = uni.getStorageSync(storageKey)
if (insuranceList) {
insuranceList.map(e => e.cost = '')
this.insuranceList = JSON.parse(JSON.stringify(insuranceList))
const vehicleInsuranceList = insuranceList.filter(item => this.isVehicleInsurance(item))
vehicleInsuranceList.forEach(item => {
item.cost = ''
item.checked = true
item.originalItemDesc = item.itemDesc || ''
})
this.insuranceList = JSON.parse(JSON.stringify(vehicleInsuranceList))
this.applyEquityProducts()
this.flag = true
}
}
},
show (n) {
if (n) {
this.getMerchantInsuranceList()
show: {
immediate: true,
handler(n) {
if (n) {
this.getMerchantInsuranceList()
}
}
},
selectedEquityProducts: {
deep: true,
handler () {
this.applyEquityProducts()
}
}
},
computed: {
watchStatus () {
......@@ -152,11 +173,15 @@ export default {
},
total () {
return this.insuranceList.reduce((pre, cur) => {
return NP.plus(pre, NP.times(cur.cost, (this.isPreview ? cur.show : cur.checked) ? 1 : 0))
const included = this.showInsurance(cur) && (this.isPreview ? cur.show : cur.checked)
return NP.plus(pre, NP.times(cur.cost, included ? 1 : 0))
}, 0)
},
check () {
return this.isPreview ? this.insuranceList.length : this.insuranceList.filter(item => item.show).length
return this.insuranceList.filter(item => this.showInsurance(item)).length
},
selectedEquityProducts () {
return this.$store.state.user.insuranceEquityProducts || []
}
},
mounted () {
......@@ -196,26 +221,37 @@ export default {
setItemDisabled (item, index) {
const { storageKey } = this
this.insuranceList[index].show = !item.show
uni.setStorageSync(storageKey, this.insuranceList);
this.saveInsuranceConfig(storageKey)
},
/**
* 查询门店保险权益
*/
async getMerchantInsuranceList () {
try {
const { storageKey } = this,
const storageKey = this.getStorageKey(),
{ shopMerchantId } = uni.$storage.get("userInfo"),
storageInsuranceList = uni.getStorageSync(storageKey),
list = await uni.$api.userApi.getMerchantInsuranceList({
responseList = await uni.$api.userApi.getMerchantInsuranceList({
merchantId: shopMerchantId,
})
list?.map(e => {
e.cost = ''
e.checked = true
e.main = e.itemName == '交强险' ? '交强险' : '商业险'
e.show = false
e.itemDesc = e.itemDesc ? this.processHtmlString(e.itemDesc) : ''
const sourceList = Array.isArray(responseList) ? responseList : []
const normalizedList = sourceList.map(item => {
const itemDesc = item.itemDesc ? this.processHtmlString(item.itemDesc) : ''
return {
...item,
cost: '',
checked: true,
main: item.itemName == '交强险' ? '交强险' : '商业险',
show: false,
itemDesc,
originalItemDesc: itemDesc
}
})
const list = normalizedList.filter(item => this.isVehicleInsurance(item))
const equityProductList = this.dedupeEquityProducts(
normalizedList.filter(item => this.isEquityProduct(item))
)
this.$emit('equity-products-change', equityProductList)
if (!storageInsuranceList) {
uni.showLoading({
mask: true
......@@ -223,23 +259,21 @@ export default {
this.setInsuranceList(storageKey, list || [])
}
else {
let { insuranceList } = this,
combinedList = [...insuranceList, ...list]
const deduplicatedList = combinedList.reduce((acc, item) => {
const existingItem = acc.find(existing => String(existing.id) === String(item.id));
if (existingItem) {
existingItem.itemName = item.itemName || ''
existingItem.itemDesc = item.itemDesc || ''
if (this.currentItem.id == existingItem.id) this.currentItem = existingItem
} else acc.push(item)
return acc;
}, [])
let arr = []
deduplicatedList.map(e => {
let index = list.findIndex(item => String(item.id) === String(e.id))
if (index != -1) arr.push(e)
const cachedList = Array.isArray(storageInsuranceList)
? storageInsuranceList.filter(item => this.isVehicleInsurance(item))
: []
const currentList = this.insuranceList.length ? this.insuranceList : cachedList
const mergedList = list.map(item => {
const existingItem = currentList.find(existing => String(existing.id) === String(item.id))
if (!existingItem) return item
return {
...item,
cost: existingItem.cost || '',
checked: existingItem.checked !== false,
show: !!existingItem.show
}
})
this.setInsuranceList(storageKey, arr)
this.setInsuranceList(storageKey, mergedList)
}
} catch (error) {
this.flag = true
......@@ -248,10 +282,72 @@ export default {
setInsuranceList (storageKey, value) {
uni.hideLoading()
this.insuranceList = JSON.parse(JSON.stringify(value))
value.map(e => e.checked = true)
uni.setStorageSync(storageKey, value);
this.applyEquityProducts()
this.saveInsuranceConfig(storageKey)
this.flag = true
},
saveInsuranceConfig (storageKey) {
const insuranceList = this.insuranceList.map(item => {
const result = {
...item,
cost: '',
checked: true,
itemDesc: item.originalItemDesc || ''
}
delete result.originalItemDesc
return result
})
uni.setStorageSync(storageKey, insuranceList)
},
dedupeEquityProducts (list) {
const productNames = new Set()
return list.filter(item => {
const itemName = String(item.itemName || '').trim()
if (!itemName || productNames.has(itemName)) return false
productNames.add(itemName)
return true
})
},
isNewEnergyInsurance (item) {
return String(item.id) === '-10' || item.itemName === '新能源险'
},
isVehicleInsurance (item) {
return Number(item.id) < 0
},
isEquityProduct (item) {
return Number(item.id) > 0
},
getDescriptionList (item) {
if (!this.isNewEnergyInsurance(item)) {
return [item.originalItemDesc || item.itemDesc].filter(Boolean)
}
return [
item.originalItemDesc || '',
...this.selectedEquityProducts.map(product => product.itemDesc || '')
].filter(Boolean)
},
applyEquityProducts () {
const newEnergyInsurance = this.insuranceList.find(item => this.isNewEnergyInsurance(item))
if (!newEnergyInsurance) return
const itemDesc = this.buildNewEnergyDesc(
newEnergyInsurance.originalItemDesc || '',
this.selectedEquityProducts
)
this.$set(newEnergyInsurance, 'itemDesc', itemDesc)
if (String(this.currentItem.id) === String(newEnergyInsurance.id)) {
this.currentItem = newEnergyInsurance
}
},
buildNewEnergyDesc (originalItemDesc, products) {
const sections = [
originalItemDesc,
...products.map(item => item.itemDesc || '')
].filter(Boolean)
return sections.map((itemDesc, index) => {
const borderStyle = index ? 'border-top:2rpx solid #fff;' : ''
return `<div style="${borderStyle}padding:32rpx 0;">${itemDesc}</div>`
}).join('')
},
processHtmlString (htmlString) {
// 移除 `<br>` 及其变体,并用 `<div></div>` 替换
let processedString = htmlString.replace(/<\/?br\s*\/?>|\n/g, '<div></div>')
......@@ -387,9 +483,20 @@ export default {
}
}
.range {
padding: toRpx(40) toRpx(64);
padding: 0 toRpx(40);
box-sizing: border-box;
text-align: center;
.description-list {
width: 100%;
.description-item {
padding: toRpx(32) 0;
line-height: toRpx(44);
box-sizing: border-box;
&:not(:first-child) {
border-top: toRpx(4) solid #ffffff;
}
}
}
}
.cost {
&-input {
......@@ -569,4 +676,4 @@ export default {
}
}
}
</style>
\ No newline at end of file
</style>
<template>
<MessageBox
<Popup
ref="carBuyersVisible"
position="bottom"
:isFooter="false"
:title="`请选择${title}`"
:maxHeight="1000"
@close="$emit('close')"
@onCancel="handleCancel"
@onConfirm="handleConfirm"
>
<view class="select-box">
<view class="popup-title flex">
请选择{{ title }}
<view
class="select-item"
:class="{ checked: carBuyers == item.name }"
@click="handleSelect(item)"
v-for="(item, index) in carBuyersList"
:key="index"
class="popup-close flex"
@click="handleClose"
>
{{ item.name }}
<uni-icons
type="closeempty"
size="16"
></uni-icons>
</view>
</view>
</MessageBox>
<view class="popup-search">
<input
v-model="keyword"
class="input"
type="text"
placeholder="查找"
placeholder-class="placeholder"
confirm-type="search"
/>
<view
v-if="keyword"
class="clear flex"
@click="keyword = ''"
>
<uni-icons
type="closeempty"
size="16"
></uni-icons>
</view>
</view>
<scroll-view
scroll-y
class="popup-body"
>
<view
v-if="filteredProductList.length"
class="select-box"
>
<view
v-for="item in filteredProductList"
:key="item.itemName"
:class="['select-item flex', { checked: isSelected(item) }]"
@click="toggleSelect(item)"
>
<view class="sprite-icon icon-tag-checked"></view>
<view class="product-name text-hide">{{ item.itemName }}</view>
</view>
</view>
<view
v-else
class="empty flex"
>{{ productList.length ? '未找到相关权益产品' : '当前门店暂无可选权益产品' }}</view>
</scroll-view>
</Popup>
</template>
<script type="text/ecmascript-6">
import Popup from '@/components/Popup.vue'
export default {
name: 'carBuyers',
components: { Popup },
props: {
title: {
type: String,
default: '购车方式'
default: '权益产品'
},
salesPropsUuid: {
type: String,
default: ''
productList: {
type: Array,
default: () => []
}
},
data () {
return {
carBuyersList: [
{
name: '全款',
id: 1
},
{
name: '按揭',
id: 2
}
]
selectedNames: [],
keyword: ''
}
},
watch: {
watchStatus: {
immediate: true,
handler (newval) {
handler () {
this.resetSelection()
this.close()
}
},
......@@ -60,19 +97,46 @@ export default {
watchStatus () {
return this.$store.state.user.historyStatus
},
carBuyers () {
return this.$store.state.user.customerInfo.carBuyers
selectedProducts () {
return this.$store.state.user.insuranceEquityProducts || []
},
},
mounted () {
filteredProductList () {
const keyword = this.keyword.trim()
if (!keyword) return this.productList
return this.productList.filter(item => String(item.itemName || '').includes(keyword))
}
},
methods: {
open () {
this.resetSelection()
this.keyword = ''
this.$refs.carBuyersVisible.open()
},
handleSelect (item) {
this.close();
this.$emit('select', item)
resetSelection () {
this.selectedNames = this.selectedProducts.map(item => item.itemName)
},
isSelected (item) {
return this.selectedNames.includes(item.itemName)
},
toggleSelect (item) {
const index = this.selectedNames.indexOf(item.itemName)
if (index === -1) this.selectedNames.push(item.itemName)
else this.selectedNames.splice(index, 1)
},
handleConfirm () {
const selectedProducts = this.productList.filter(item => this.isSelected(item))
this.close()
this.$emit('confirm', selectedProducts)
},
handleCancel () {
this.resetSelection()
this.close()
this.$emit('cancel')
},
handleClose () {
this.resetSelection()
this.close()
this.$emit('close')
},
close () {
this.$refs?.carBuyersVisible?.close()
......@@ -82,26 +146,101 @@ export default {
</script>
<style scoped lang="scss">
.popup-title {
height: toRpx(104);
justify-content: center;
position: relative;
color: #333333;
font-size: toRpx(36);
font-weight: 500;
.popup-close {
position: absolute;
height: 100%;
top: 0;
right: 0;
padding: 0 toRpx(48);
font-weight: 400;
color: #1a1a1a;
}
}
.popup-search {
height: toRpx(80);
border-radius: toRpx(40);
background: #f5f7fa;
margin: 0 toRpx(48);
position: relative;
.input {
height: 100%;
width: 100%;
text-align: center;
color: #333;
font-size: toRpx(32);
}
.placeholder {
height: 100%;
color: #999ea8;
font-family: uniicons;
display: flex;
align-items: center;
justify-content: center;
&::after {
display: block;
content: '\e654';
margin-left: toRpx(8);
height: 100%;
display: flex;
align-items: center;
font-size: toRpx(36);
}
}
.clear {
position: absolute;
right: 0;
top: 0;
height: 100%;
padding: 0 toRpx(48);
}
}
.popup-body {
height: calc(70vh - #{toRpx(392)});
padding-top: toRpx(32);
box-sizing: border-box;
}
.select-box {
margin: toRpx(40) 0;
margin: 0 toRpx(48);
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: toRpx(32);
overflow-y: scroll;
max-height: 50vh;
padding-bottom: toRpx(60);
.select-item {
text-align: center;
height: toRpx(68);
line-height: toRpx(44);
opacity: 1;
height: toRpx(72);
border: toRpx(2) solid #dce0e6;
color: #333;
color: #333333;
font-size: toRpx(32);
border-radius: toRpx(8);
box-sizing: border-box;
justify-content: center;
position: relative;
padding: 0 toRpx(24);
&.checked {
border: toRpx(2) solid #292d33;
border-color: #2c66f7;
background: #ecf1ff;
color: #2c66f7;
.sprite-icon {
display: block;
}
}
.sprite-icon {
display: none;
position: absolute;
top: 0;
right: 0;
}
}
}
.empty {
height: 100%;
justify-content: center;
color: #808291;
font-size: toRpx(28);
}
</style>
......@@ -20,11 +20,10 @@ export default {
staffName: "",
newCarFare: '',
carModelId: '',
carBuyers: '',
carPurchaseMethod: '',
oneCarBrand: '',
oneCarBrandId: ''
},
insuranceEquityProducts: [], // 当前接待已选择的保险权益产品
historyStatus: Date.now(),
carBrands: [],
employeeList: [],
......@@ -53,6 +52,9 @@ export default {
state.customerInfo = data
state.customerKey = Date.now()
},
setInsuranceEquityProducts (state, value = []) {
state.insuranceEquityProducts = Array.isArray(value) ? value : []
},
setReceptionTrack (state, { key, value }) {
state.receptionTrack[key] = value
state.receptionKey = Date.now()
......@@ -86,13 +88,12 @@ export default {
staffName: "",
newCarFare: '',
carModelId: '',
carBuyers: '',
carPurchaseMethod: '',
oneCarBrand: '',
oneCarBrandId: ''
};
uni.$storage.set("customerInfo", JSON.stringify(info));
state.customerInfo = info
state.insuranceEquityProducts = []
state.customerKey = Date.now()
},
setCarBrandOpenStatus (state, value) {
......@@ -112,6 +113,9 @@ export default {
// uni.$logger.local.info(`当前接待客户信息: ${JSON.stringify(value)}`)
commit("setCustomerInfo", value);
},
setInsuranceEquityProducts ({ commit }, value) {
commit('setInsuranceEquityProducts', value)
},
clearCustomerInfo ({ commit }) {
commit("clearCustomerInfo");
},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!