This commit is contained in:
邓晓坤
2019-09-12 16:22:38 +08:00
parent 90ea054ae0
commit ff8a261f79
195 changed files with 65268 additions and 0 deletions

View File

@@ -0,0 +1,620 @@
<template>
<div class="calculate-premium-container pb50">
<div class="bg-white ph10 pt10">
<div class="flex justify-content-s align-items-c border-bottom pb10">
<span class="mr10">{{ saleInsuredPersonInfo.name }}</span>
<span class="mr10">{{ saleInsuredPersonInfo.sex == 0 ? '男' : '女' }}</span>
<span class="mr10">{{ saleInsuredPersonInfo.age }}</span>
<span class="mr10 flex1 van-ellipsis"> {{ saleInsuredPersonInfo.occupationName }}</span>
</div>
</div>
<div v-for="(item, index) in chooseProducts" :key="index" class="ph10 bg-white">
<div class="flex justify-content-s align-items-c border-bottom pv10">
<van-tag type="primary" v-if="item.isMainRisk == 0" class="mr5 green" plain>主险</van-tag>
<van-tag type="primary" v-else class="mr5 green" plain>附加险</van-tag>
<span class="ml5 center fs13 flex1"> {{ item.riskName }} </span>
<van-tag type="primary" v-if="item.isMainRisk == 0" plain @click="selectAddtionRisk" class="green mr8"></van-tag>
<van-icon name="search" size="20" v-if="item.documentDTOS && item.documentDTOS.length > 0" @click="seeDocument(index)" class="green mr5" />
<van-icon name="delete" size="22" @click="deleteRisk(index)" class="green" />
</div>
<!-- 险种条件-->
<div v-if="item.isRemit == 1">
<div v-for="(riskFactor, riskFactorIndex) in item.calFactorLst" :key="riskFactorIndex">
<div class="flex justify-content-s pv10 border-bottom" v-if="riskFactor.type == 1">
<div class="flex">
<span> {{ riskFactor.name + '(' + riskFactor.suffix + ')' }} </span>
<van-stepper
v-model="item.calFactorLst[riskFactorIndex].defaultValue"
:min="riskFactor.minAmt"
:max="riskFactor.maxAmt"
class="ml10"
@change="stepperChange"
@plus="plus(index, riskFactorIndex)"
@minus="minus(index, riskFactorIndex)"
@focus="focus(index, riskFactorIndex)"
input-width="100"
:integer="true"
/>
</div>
</div>
<div
class="flex justify-content-s pv10 border-bottom"
v-if="riskFactor.type == 0"
:class="{ hidden: riskFactor.code == 'payEndYear' && item.isHidden }"
>
<van-field
v-model="riskFactor.showContent"
readonly
:label="riskFactor.name"
right-icon="arrow"
placeholder="请选择"
@click="toSelect(index, riskFactorIndex, riskFactor.columns)"
/>
</div>
</div>
</div>
<!-- 豁免险条件 -->
<div v-if="item.isRemit == 0">
<div v-for="(riskFactor, riskFactorIndex) in item.calFactorLst" :key="riskFactorIndex">
<div class="flex justify-content-s pv10 border-bottom">
<div class="flex">
<van-field v-if="riskFactor.type == 0" v-model="riskFactor.showContent" readonly :label="riskFactor.name" />
<van-field v-if="riskFactor.type == 1" v-model="riskFactor.defaultValue" readonly :label="riskFactor.name + '(' + riskFactor.suffix + ')'" />
</div>
</div>
</div>
</div>
<div class="flex justify-content-s pv10 border-bottom prem">
<span style="font-weight:bold">
首期保费(
</span>
<span class="fee red" v-if="trialList && trialList.length > 0">{{ trialList[index].prem.toFixed(2) }}</span>
</div>
</div>
<van-button type="danger" class="bottom-btn" @click="nextStep" :disabled="nextStepFlag">完成</van-button>
<van-action-sheet v-model="show" cancel-text="取消" :actions="policyInfo" @select="openDocument" />
<!-- 字段选择 -->
<van-popup v-model="popupShow" position="bottom">
<van-picker show-toolbar :columns="columns" @confirm="onConfirm" @cancel="popupShow = false" />
</van-popup>
</div>
</template>
<script>
import { Tag, Icon, Dialog, ActionSheet, Popup, Picker, Stepper, Field } from 'vant'
import { trial } from '@/api/ebiz/common/common'
import { saveOrUpdateOrderInfo } from '@/api/ebiz/sale/sale'
import { saveProposal } from '@/api/ebiz/proposal/proposal.js'
export default {
name: 'calculatePremium',
components: {
[Tag.name]: Tag,
[Icon.name]: Icon,
[ActionSheet.name]: ActionSheet,
[Popup.name]: Popup,
[Picker.name]: Picker,
[Stepper.name]: Stepper,
[Field.name]: Field
},
data() {
return {
chooseProducts: [],
productIndex: '',
calFactorIndex: '',
premiumData: [], //试算
saleInsuredInfo: {},
saleInsuredPersonInfo: {}, //投保人信息
trialList: [],
popupShow: false,
columns: [],
pickerType: '',
show: false,
policyInfo: [],
currentIndex: '', //当前操作产品
trialInfos: [],
influenceAddRiskCodes: [],
influences: [],
nextStepFlag: false
}
},
mounted() {
this.init()
Array.prototype.min = function() {
var min = this[0]
var len = this.length
for (var i = 1; i < len; i++) {
if (this[i] < min) {
min = this[i]
}
}
return min
}
},
methods: {
//初始化数据
init() {
//获取投保人信息
if (localStorage.saleInsuredInfo) {
this.saleInsuredInfo = JSON.parse(localStorage.saleInsuredInfo)
}
//获取被保人信息
if (localStorage.saleInsuredPersonInfo) {
this.saleInsuredPersonInfo = JSON.parse(localStorage.saleInsuredPersonInfo)
}
//构建提交数据、渲染险种
this.chooseProducts = JSON.parse(localStorage.chooseProducts)
this.influenceAddRiskCodes
if (this.chooseProducts[0].influences && this.chooseProducts[0].influences.length > 0) {
this.influences = this.chooseProducts[0].influences
this.chooseProducts[0].influences.forEach(item => {
this.influenceAddRiskCodes.push(item.productCode)
})
}
this.mainRiskInfluenceAddRisk()
//初始化数据试算
this.getTrial()
},
//弹框选择
toSelect(index, index1, columns) {
;[this.popupShow, this.productIndex, this.calFactorIndex] = [true, index, index1]
this.columns = columns
},
//确认选择字段
onConfirm(value) {
let currentFactor = this.chooseProducts[this.productIndex].calFactorLst
let currentEle = currentFactor[this.calFactorIndex]
if (currentEle.showContent != value.text) {
//通用规则校验
if (this.payExceedInsured(currentEle, currentFactor, value.value)) {
this.popupShow = false
return false
}
if (currentEle.code == 'payEndYear' && this.ageInfluencePayEndYear(value.value, currentEle)) {
this.popupShow = false
return false
}
currentEle.showContent = value.text
let name = currentEle.code
currentEle[name] = value.value
if (currentEle.hasFlag) {
currentEle[name + 'Flag'] = value.flag
}
this.hiddenPayEndYear(currentEle)
//特殊规则:设置豁免险
this.getTrial()
}
this.popupShow = false
},
/********start 通用规则、特殊规则处理 start******/
//通用规则1交费方式为一次交情无交费期限
hiddenPayEndYear(currentEle) {
if (currentEle.code == 'payIntv') {
this.chooseProducts[this.productIndex]['isHidden'] = currentEle.payIntv == '0' ? true : false
}
},
//通用规则2交费期限不能超过保险期间
payExceedInsured(currentEle, currentFactor, currentVale) {
let payEndYearVal, insuYearVal
if (currentEle.code == 'payEndYear') {
payEndYearVal = Number(currentVale)
insuYearVal = this.getPayEndYearOrInsuYear('insuYear', currentFactor)
}
if (currentEle.code == 'insuYear') {
insuYearVal = Number(currentVale)
payEndYearVal = this.getPayEndYearOrInsuYear('payEndYear', currentFactor)
}
if (payEndYearVal > insuYearVal) {
this.$toast('交费期限不能超过保险期间')
return true
} else {
return false
}
},
getPayEndYearOrInsuYear(flag, currentFactor) {
let returnVal
currentFactor.forEach(item => {
if (item.code == flag) {
returnVal = item[flag]
}
})
return Number(returnVal)
},
//特殊规则1、交费期间跟年龄的关系
ageInfluencePayEndYear(value, currentEle) {
let age = Number(this.saleInsuredPersonInfo.age)
for (let i = 0; i < currentEle.rules.length; i++) {
if (currentEle.rules[i].payEndYear == value && age > currentEle.rules[i].maxAge) {
this.$toast('被保人人年龄不适合改该交费期限!')
return true
}
}
return false
},
//特殊规则2、主险对附加险的影响,主要是保额之间的影响 mainAddRelation0-小于1-大于2-等于3-小于等于,4-大于等于
mainRiskInfluenceAddRisk() {
if (this.productIndex == 0) {
this.chooseProducts.forEach((item, index) => {
if (this.influenceAddRiskCodes.includes(item.productCode)) {
let influences = this.getInfluencesItem(item.productCode)
let mainAddRelation = influences.amtInfluence[0].mainAddRelation
let amtTimes = influences.amtInfluence[0].amtTimes
let mainRiskAmt = this.getMainRiskAmt()
if (mainAddRelation == 3 && amtTimes == 1) {
this.setInputAddtionRiskMaxAmt(mainRiskAmt, index)
} else if (mainAddRelation == 3 && amtTimes == 0.2) {
this.setAddtionRiskMaxAmt(mainRiskAmt * amtTimes, index)
}
}
})
}
},
setAddtionRiskMaxAmt(mainRiskAmt, index) {
this.chooseProducts[index].calFactorLst.forEach(item => {
if (item.code == 'amt') {
let columnsValArr = []
item.columns.forEach(option => {
columnsValArr.push(Number(option.value))
if (Number(option.value) > mainRiskAmt * 10000) {
option.disabled = true
} else {
option.disabled = false
}
})
//主险减,附加险变化
if (mainRiskAmt * 10000 < item.amt) {
let minVal = columnsValArr.min()
item.columns.forEach(option => {
if (option.value == minVal) {
item.showContent = option.text
item.amt = option.value
}
})
}
}
})
},
setInputAddtionRiskMaxAmt(mainRiskAmt, index) {
this.chooseProducts[index].calFactorLst.forEach(item => {
if (item.type == 1) {
item.maxAmt = Math.min(mainRiskAmt, item.oldMaxAmt)
if (item.maxAmt < item.defaultValue) {
//减保额份数
item.defaultValue = item.maxAmt
}
}
})
},
getMainRiskAmt() {
let mainRiskAmt
this.chooseProducts[0].calFactorLst.forEach(item => {
if (item.type == 1) {
mainRiskAmt = item.defaultValue
}
})
return mainRiskAmt
},
getInfluencesItem(productCode) {
let currentInfluences
this.chooseProducts[0].influences.forEach(item => {
if (item.productCode == productCode) {
currentInfluences = item
}
})
return currentInfluences
},
//特殊规则3、设置豁免险
setRemitRisk() {
//1、一次性交清和交费期间单位为A时删除豁免险
let mainRiskInfo = this.getMainRiskInfo()
let mainRiskPayIntv = mainRiskInfo.payIntv.payIntv
let mainRiskPayEndYearFlag = mainRiskInfo.payEndYear.payEndYearFlag
if (mainRiskPayIntv == 0 || mainRiskPayEndYearFlag == 'A') {
//删除已选或互斥险种
for (let i = 0; i < this.chooseProducts.length; i++) {
if (this.chooseProducts[i].isRemit == 0) {
this.chooseProducts.splice(i, 1)
i--
}
}
}
//2、豁免险跟主险联动值减一
let remitIndex = this.getRemitIndex()
if (!remitIndex) return
this.chooseProducts[remitIndex].calFactorLst.forEach(item => {
if (item.code == 'payIntv') {
for (let key in mainRiskInfo.payIntv) {
item[key] = mainRiskInfo.payIntv[key]
}
}
if (item.code == 'payEndYear') {
item.hasFlag = '1'
item.payEndYearFlag = 'Y'
item.payEndYear = Number(mainRiskInfo.payEndYear.payEndYear) - 1
item.showContent = item.payEndYear + '年交'
}
if (item.code == 'insuYear') {
item.hasFlag = '1'
item.insuYearFlag = 'Y'
item.insuYear = Number(mainRiskInfo.payEndYear.payEndYear) - 1
item.showContent = item.insuYear + '年'
}
if (item.code == 'amt') {
let trialList = JSON.parse(localStorage.trialList)
item.amt = trialList[0].prem
item.defaultValue = trialList[0].prem
item.moneyUnit = 1
item.suffix = '元'
}
})
},
getRemitIndex() {
let remitIndex
this.chooseProducts.forEach((item, index) => {
if (item.isRemit == 0) {
remitIndex = index
}
})
return remitIndex
},
getMainRiskInfo() {
let mainRiskInfo = {}
this.chooseProducts[0].calFactorLst.forEach(item => {
mainRiskInfo[item.code] = item
})
return mainRiskInfo
},
/********end 通用规则、特殊规则处理 end******/
//查看文档列表
seeDocument(index) {
this.show = true
this.policyInfo = this.chooseProducts[index].documentDTOS
},
//打开文档
openDocument(item) {
localStorage.documentInfo = JSON.stringify({ documentUrl: item.url, documentType: item.type })
this.$jump({
flag: 'h5',
extra: {
url: location.origin + '/#/product/productDocument'
},
routerInfo: {
path: `/product/productDocument`
}
})
},
//删除所选产品
deleteRisk(index) {
Dialog.confirm({
title: '提示',
message: '确认删除该险种?',
cancelButtonColor: '#4FC6B3',
confirmButtonColor: '#FFFFFF',
className: 'dialog-delete'
})
.then(() => {
if (this.chooseProducts[index].isMainRisk == 0) {
this.chooseProducts = []
} else {
this.chooseProducts.splice(index, 1)
}
localStorage.chooseProducts = JSON.stringify(this.chooseProducts)
})
.catch(() => {})
},
//试算
async getTrial() {
this.setRemitRisk()
let params = this.getParams()
let resultData = await trial(params)
//试算成功,信息返显
if (resultData.result == 0) {
this.trialList = resultData.trialList
localStorage.trialList = JSON.stringify(resultData.trialList)
//设置豁免险保额
this.setRemitRisk()
this.nextStepFlag = false
} else {
this.nextStepFlag = true
this.$toast(resultData.resultMessage)
}
localStorage.chooseProducts = JSON.stringify(this.chooseProducts)
},
//获取试算参数
getParams() {
let params = {
trialInfos: []
}
this.chooseProducts.forEach(item => {
let trialInfo = {}
item.calFactorLst.forEach(factor => {
if (factor.type == 0) {
if (factor.hasFlag == '1') {
trialInfo[factor.code] = factor[factor.code]
trialInfo[factor.code + 'Flag'] = factor[factor.code + 'Flag']
} else {
trialInfo[factor.code] = factor[factor.code]
}
} else if (factor.type == 1) {
trialInfo['amt'] = Number(factor.defaultValue) * Number(factor.moneyUnit)
} else if (factor.type == 2) {
trialInfo[factor.extra] = this.saleInsuredPersonInfo[factor.code]
}
})
//通用规则1交费方式为一次交情无交费期限
if (trialInfo['payIntv'] == '0') {
trialInfo['payEndYear'] = '1'
trialInfo['payEndYearFlag'] = 'Y'
}
//责任险参数构建
if (trialInfo.duty) {
trialInfo.duty = [{ dutyCode: trialInfo.duty }]
}
//获取投被保生日、性别
let birthday, sex
if (item.isRemit == '0' && item.remitType == '0') {
;[birthday, sex] = [this.saleInsuredInfo.birthday, this.saleInsuredInfo.sex]
} else {
;[birthday, sex] = [this.saleInsuredPersonInfo.birthday, this.saleInsuredPersonInfo.sex]
}
trialInfo = Object.assign(trialInfo, {
birthday,
sex,
platformType: 'app',
productCode: item.productCode
})
params.trialInfos.push(trialInfo)
})
this.trialInfos = params.trialInfos
return params
},
//选择附加险
selectAddtionRisk() {
//存储附加险列表
let addRiskCodes = []
this.chooseProducts.forEach(item => {
if (item.isMainRisk == 1) {
addRiskCodes.push(item.productCode)
}
})
if (localStorage.oldAddRiskCodes && JSON.parse(localStorage.oldAddRiskCodes)) {
addRiskCodes = addRiskCodes.concat(JSON.parse(localStorage.oldAddRiskCodes))
}
localStorage.addRiskCodes = JSON.stringify(addRiskCodes)
this.$jump({
flag: 'h5',
extra: {
url: location.origin + '/#/common/addRiskList'
},
routerInfo: {
path: '/common/addRiskList'
}
})
},
//保额份数变化
stepperChange(value) {
let currentEle = this.chooseProducts[this.productIndex].calFactorLst[this.calFactorIndex]
currentEle.defaultValue = value
this.mainRiskInfluenceAddRisk()
currentEle['amt'] = Number(currentEle.defaultValue) * Number(currentEle.moneyUnit)
this.getTrial()
},
focus(index, index1) {
;[this.productIndex, this.calFactorIndex] = [index, index1]
},
minus(index, index1) {
;[this.productIndex, this.calFactorIndex] = [index, index1]
},
plus(index, index1) {
;[this.productIndex, this.calFactorIndex] = [index, index1]
},
//下一步
async nextStep() {
//组装险种提交数据
let [mainRiskCode, riskDTOLst] = ['', []]
this.chooseProducts.forEach((item, index) => {
if (item.isMainRisk == 0) {
mainRiskCode = item.productCode
}
let riskItem = {
isMainRisk: item.isMainRisk,
riskName: item.riskName,
riskCode: item.productCode,
mainRiskCode: mainRiskCode,
prem: this.trialList[index] && this.trialList[index].prem,
standPrem: this.trialList[index] && this.trialList[index].standPrem
}
//责任险保存参数构建
if (this.trialList[index].duty) {
riskItem['dutyLst'] = this.trialList[index].duty
}
riskItem = Object.assign(riskItem, this.trialInfos[index])
riskDTOLst.push(riskItem)
})
//建议书需要添加全部投保人信息电投只需要投保人ID
let insuredDTOItem = Object.assign(this.saleInsuredPersonInfo, { riskDTOLst: riskDTOLst })
let params = {
orderType: 'RISK_ORDER',
orderDTO: {
orderInfoDTO: {
orderNo: localStorage.orderNo
},
// appntDTO: {},
insuredDTOs: [insuredDTOItem]
}
}
let resultData
if (localStorage.isFrom == 'proposal') {
resultData = await saveProposal(params)
} else {
resultData = await saveOrUpdateOrderInfo(params)
}
if (resultData.result == 0) {
//建议书
if (localStorage.isFrom == 'proposal' && resultData.content.id) {
this.saleInsuredPersonInfo.insuredId = resultData.content.id
localStorage.saleInsuredPersonInfo = JSON.stringify(this.saleInsuredPersonInfo)
}
this.$jump({
flag: 'goBack',
extra: {
refresh: '1',
index: '-2'
},
routerInfo: {
type: 2,
index: -2,
path: '/common/selectedProduct'
}
})
} else {
this.$toast(resultData.resultMessage)
}
}
},
watch: {
chooseProducts: {
deep: true,
handler: function(newVal) {
console.log('xin', newVal)
this.chooseProducts = newVal
}
}
}
}
</script>
<style lang="scss" scoped>
.calculate-premium-container {
.border-bottom {
border-bottom: 1px solid #dadada;
}
.van-cell {
padding: 0px;
}
.prem:last-child {
border: none;
}
}
</style>