Commit 2097745c by 胡悦

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

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