projectAdd.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  1. <template>
  2. <!-- 项目添加/编辑页面主容器 -->
  3. <div class="projectAdd">
  4. <!-- 项目表单,包含基本信息和方案配置 -->
  5. <el-form :model="projectAddFrom" :rules="projectAddRules" ref="ProjectAddRef">
  6. <!-- 基本信息描述 -->
  7. <el-descriptions title="基本信息">
  8. <el-descriptions-item>
  9. <!-- 保险公司选择 -->
  10. <el-form-item label="保险公司" prop="companyId">
  11. <el-select
  12. :disabled="isEdit"
  13. filterable
  14. v-model="projectAddFrom.companyId"
  15. placeholder="请选择"
  16. style="width: 40%"
  17. @change="initProduct"
  18. >
  19. <el-option v-for="item in companyOption" :key="item.id" :value="item.id" :label="item.nameSimple"></el-option>
  20. </el-select>
  21. </el-form-item>
  22. <!-- 方案类型选择 -->
  23. <el-form-item label="方案类型" prop="schemeType">
  24. <el-radio-group
  25. :disabled="isEdit"
  26. v-model="projectAddFrom.schemeType"
  27. @change="schemeTypeChange"
  28. >
  29. <el-radio :value="1">基础方案</el-radio>
  30. <el-radio :value="2">自选方案</el-radio>
  31. </el-radio-group>
  32. </el-form-item>
  33. <!-- 险种类型选择 -->
  34. <el-form-item label="险种类型" prop="productId">
  35. <el-radio-group
  36. :disabled="isEdit"
  37. v-model="projectAddFrom.productId"
  38. @change="initProduct"
  39. >
  40. <el-radio-button v-for="item in insuranceType" :key="item.value" :value="item.value">{{ item.label }}</el-radio-button>
  41. </el-radio-group>
  42. </el-form-item>
  43. <!-- 规则条件配置 -->
  44. <div style="display: flex;">
  45. <span style="width: 10%"><a style="color: red">*</a>规则条件</span>
  46. <div style="width: 60%">
  47. <!-- 规则条件容器组件 -->
  48. <rule-condition-container :rulesAttrList="rulesAttrList" @Del="handleDel"></rule-condition-container>
  49. </div>
  50. </div>
  51. <!-- 添加规则条件按钮 -->
  52. <el-button style="margin: 10px 10%" plain type="primary" icon="plus" @click="addRules">添加条件</el-button>
  53. <!-- 方案配置描述 -->
  54. <el-descriptions>
  55. <template #title>
  56. <div style="display: flex; align-items: center">
  57. <span>方案配置</span>
  58. <!-- 添加新方案按钮(非编辑模式) -->
  59. <el-button v-show="!isEdit" type="primary" icon="plus" style="margin-left: 20px;" @click="addProject">添加新方案</el-button>
  60. </div>
  61. </template>
  62. <el-descriptions-item>
  63. <!-- 方案列表 -->
  64. <div class="configuration" v-for="(item, index) in projectAddFrom.schemeList">
  65. <!-- 方案名称 -->
  66. <el-form-item label="方案名称" prop="schemeName">
  67. <el-input v-model="item.schemeName"></el-input>
  68. </el-form-item>
  69. <!-- 方案描述 -->
  70. <el-form-item label="方案描述" prop="description">
  71. <el-input type="textarea" v-model="item.description" maxlength="500"></el-input>
  72. </el-form-item>
  73. <!-- 驾意险配置 -->
  74. <div>
  75. <div style="display: flex; align-items: center; margin-bottom: 10px">
  76. <span style="margin-right: 20px">驾意险</span>
  77. <el-button link icon="plus" type="primary" @click="handleDriving(item, index)">选择驾意险</el-button>
  78. </div>
  79. <!-- 驾意险列表 -->
  80. <el-table :data="item.drivingList">
  81. <el-table-column label="名称" prop="productName">
  82. <template #default="scope">
  83. <el-button link type="primary" @click="getJYXDetail(scope.row)">{{ scope.row.productName }}</el-button>
  84. </template>
  85. </el-table-column>
  86. <!-- 客户端状态(仅自选方案显示) -->
  87. <el-table-column label="客户端状态" prop="selectedStatus" v-if="projectAddFrom.schemeType!=1">
  88. <template #default="scope">
  89. <el-select v-model="scope.row.selectedStatus">
  90. <el-option label="默认不选中" key="1" value="1"></el-option>
  91. <el-option label="默认选中" key="2" value="2"></el-option>
  92. <el-option label="强制选中" key="3" value="3"></el-option>
  93. </el-select>
  94. </template>
  95. </el-table-column>
  96. <!-- 驾意险份数 -->
  97. <el-table-column label="份数" prop="quantity">
  98. <template #default="scope">
  99. <el-input-number
  100. v-model="scope.row.quantity"
  101. style="width: 150px;"
  102. :min="1"
  103. :max="99"
  104. @change="numberChange($event, scope.row)"
  105. ></el-input-number>份
  106. </template>
  107. </el-table-column>
  108. <!-- 驾意险操作 -->
  109. <el-table-column label="操作">
  110. <template #default="scope">
  111. <el-button link type="primary" @click="drivingTypeDel(item, scope.row)">删除</el-button>
  112. </template>
  113. </el-table-column>
  114. </el-table>
  115. </div>
  116. <!-- 险种配置 -->
  117. <div>
  118. <div style="display: flex; align-items: center; margin: 10px 0">
  119. <span style="margin-right: 20px">险种</span>
  120. <el-button link icon="plus" type="primary" @click="handlePopover(item, index)">选择险种</el-button>
  121. </div>
  122. <!-- 险种列表 -->
  123. <el-table :data="item.tableData">
  124. <el-table-column label="险种" prop="kindName">
  125. <template #default="scope">
  126. <a>{{ scope.row.kindName }}</a>
  127. </template>
  128. </el-table-column>
  129. <!-- 保额选择 -->
  130. <el-table-column label="保额" prop="optionId">
  131. <template #default="scope">
  132. <!-- 自选方案支持多选保额 -->
  133. <el-select
  134. :disabled="scope.row.insuranceId == '19'"
  135. v-if="projectAddFrom.schemeType === 2"
  136. v-model="scope.row.moneyId"
  137. style="width: 150px"
  138. multiple
  139. @change="() => { scope.row.optionId = scope.row.moneyId }"
  140. >
  141. <el-option v-for="m in scope.row.options" :label="m.label" :key="m.id" :value="m.id"></el-option>
  142. </el-select>
  143. <!-- 基础方案只能选择一个保额 -->
  144. <el-select
  145. :disabled="scope.row.insuranceId == '19'"
  146. v-else
  147. v-model="scope.row.moneyId"
  148. style="width: 150px"
  149. @change="() => { scope.row.optionId = scope.row.moneyId }"
  150. >
  151. <el-option v-for="m in scope.row.options" :label="m.label" :key="m.id" :value="m.id"></el-option>
  152. </el-select>
  153. </template>
  154. </el-table-column>
  155. <!-- 险种操作 -->
  156. <el-table-column label="操作">
  157. <template #default="scope">
  158. <!-- 交强险不可删除 -->
  159. <el-button
  160. :disabled="projectAddFrom.productId == '0330'&&scope.row.id=='19' || projectAddFrom.productId == '0330034002'&&scope.row.id=='19' || projectAddFrom.productId == '0330034001'&&scope.row.id=='19'"
  161. link
  162. type="primary"
  163. @click="insuranceTypeDel(item, scope.row)"
  164. >删除</el-button>
  165. </template>
  166. </el-table-column>
  167. </el-table>
  168. </div>
  169. </div>
  170. </el-descriptions-item>
  171. </el-descriptions>
  172. </el-descriptions-item>
  173. </el-descriptions>
  174. </el-form>
  175. <!-- 底部操作按钮 -->
  176. <div class="btns">
  177. <el-button plain @click="quit">取消</el-button>
  178. <el-button type="primary" @click="save(ProjectAddRef)">保存</el-button>
  179. </div>
  180. <!-- 驾意险选择弹窗 -->
  181. <el-dialog v-model="drivingShow" title="选择驾意险" width="700">
  182. <driving ref="DrivingTypeRef" @close="handleDrivingClose"></driving>
  183. </el-dialog>
  184. <!-- 险种选择弹窗 -->
  185. <el-dialog v-model="insuranceShow" title="选择险种" width="500">
  186. <insurance ref="InsuranceTypeRef" @close="handleClose"></insurance>
  187. </el-dialog>
  188. <!-- 驾意险详情弹窗 -->
  189. <el-dialog v-model="JYXDetailShow" title="驾意险详情" width="600">
  190. <detail ref="JYXDetail"></detail>
  191. </el-dialog>
  192. <!-- 规则条件选择弹窗 -->
  193. <el-dialog v-model="ruleSelectShow" title="规则条件" width="600">
  194. <ruleSelect ref="RuleSelect" @close="handleRuleSelectClose"></ruleSelect>
  195. </el-dialog>
  196. </div>
  197. </template>
  198. <script setup lang="ts">
  199. // 导入API模块
  200. import api from "@/api";
  201. // 导入Element Plus组件和类型
  202. import { ElMessage, FormInstance, FormRules } from "element-plus";
  203. // 导入Vue Router
  204. import { useRouter, useRoute } from 'vue-router'
  205. // 导入自定义组件
  206. import insurance from '../../../../layouts/components/InsuranceType/index.vue'
  207. import driving from '../../../../layouts/components/DrivingType/index.vue'
  208. import rule from '../../../../components/ruleConditionContainer/index.vue'
  209. import detail from '../../../../layouts/components/JYXDetail/index.vue'
  210. import ruleSelect from '../../../../layouts/components/ruleSelect/index.vue'
  211. import Detail from "@/views/representative/detail.vue";
  212. // 导入Vue 3组合式API
  213. import { ref, onMounted, onBeforeMount, nextTick } from 'vue'
  214. // 路由实例
  215. const myRouter = useRouter()
  216. const myRoute = useRoute()
  217. // 表单引用
  218. const ProjectAddRef = ref<FormInstance>()
  219. // 组件引用
  220. const InsuranceTypeRef = ref(null)
  221. const DrivingTypeRef = ref(null)
  222. const JYXDetail = ref(null)
  223. const RuleSelect = ref()
  224. // 车牌地区数据
  225. const licensePlateRegion = ref();
  226. // 车牌号数据
  227. const licensePlateNumber = ref();
  228. /**
  229. * 获取车牌地区数据
  230. * @param value 地区代码
  231. */
  232. const regionLicenseRegion = (value: string) => {
  233. api.agreementApi.getAreaLicense(value).then((res: any) => {
  234. if (res.code == '200') {
  235. let data: any = [];
  236. res.data.map((val: any) => {
  237. data.push({
  238. code: val.areaNumber,
  239. name: val.license,
  240. })
  241. return val;
  242. })
  243. licensePlateRegion.value = data;
  244. }
  245. });
  246. }
  247. /**
  248. * 获取车牌号数据
  249. * @param value 地区代码
  250. */
  251. const regionLicenseNumber = (value: string) => {
  252. api.agreementApi.getAreaLicense(value).then((res: any) => {
  253. if (res.code == '200') {
  254. let data: any = [];
  255. res.data.map((val: any) => {
  256. data.push({
  257. code: val.areaNumber,
  258. name: val.license,
  259. })
  260. return val;
  261. })
  262. licensePlateNumber.value = data;
  263. }
  264. });
  265. }
  266. // 规则条件选择弹窗状态
  267. let ruleSelectShow = ref(false)
  268. /**
  269. * 处理规则条件选择关闭
  270. * @param data 选中的规则条件数据
  271. */
  272. const handleRuleSelectClose = (data) => {
  273. if(data && data.length > 0) {
  274. rulesAttrList.value = data.map(a => {
  275. // 处理车牌相关数据
  276. if (a.attrCode == 'LicenseNo') {
  277. a.dictLabal = licensePlateNumber.value;
  278. }
  279. if (a.attrCode == 'LicenseArea') {
  280. a.dictLabal = licensePlateRegion.value;
  281. }
  282. return {
  283. ...a,
  284. min: a.attrName == '能源类型'? '0':a.min?a.min: '',
  285. minArray: a.minArray&&a.minArray.length>0?a.minArray:a.attrName == '使用性质' || a.attrName == '车辆种类' || a.attrName == '能源类型'?[a.dictLabal[0].code]:[],
  286. max: a.max?a.max: ''
  287. }
  288. })
  289. }
  290. ruleSelectShow.value = false
  291. }
  292. // 是否编辑模式
  293. let isEdit = ref(false)
  294. // 项目表单数据
  295. let projectAddFrom = ref({
  296. ruleAttrs: [], // 规则属性
  297. schemeType: 1, // 方案类型:1-基础方案,2-自选方案
  298. productId: '0330', // 险种类型
  299. schemeList: [{
  300. schemeName: '', // 方案名称
  301. description: '', // 方案描述
  302. tableData: [], // 险种列表
  303. drivingList: [], // 驾意险列表
  304. schemeInsuranceList: [], // 方案险种列表
  305. drivingIntentionList: [] // 驾意险意向列表
  306. }]
  307. })
  308. // 表单验证规则
  309. let projectAddRules = ref<FormRules>({
  310. companyId: [
  311. { required: true, trigger: "change", message: "请选择保险公司" }
  312. ],
  313. schemeType: [
  314. { required: true, trigger: "change", message: "请选择方案类型" }
  315. ],
  316. productId: [
  317. { required: true, trigger: "change", message: "请选择险种类型" }
  318. ]
  319. })
  320. // 驾意险详情弹窗状态
  321. let JYXDetailShow = ref(false)
  322. /**
  323. * 查看驾意险详情
  324. * @param row 驾意险数据行
  325. */
  326. const getJYXDetail = (row) => {
  327. JYXDetailShow.value = true
  328. nextTick(() => {
  329. JYXDetail.value.initData(row.drivingIntentionId)
  330. })
  331. }
  332. /**
  333. * 处理驾意险份数变化
  334. * @param e 新的份数值
  335. * @param row 驾意险数据行
  336. */
  337. const numberChange = (e, row) => {
  338. if(typeof e != 'number') {
  339. row.quantity = 1
  340. }
  341. }
  342. /**
  343. * 初始化产品方案
  344. * @param e 产品ID
  345. */
  346. const initProduct = (e) => {
  347. // 获取规则条件中的能源类型、车辆种类、使用性质
  348. let energyType = null, vehicleType = null, carnature = null
  349. if(rulesAttrList.value && rulesAttrList.value.length > 0) {
  350. energyType = rulesAttrList.value.find(a => a.attrName === '能源类型')
  351. vehicleType = rulesAttrList.value.find(a => a.attrName === '车辆种类')
  352. carnature = rulesAttrList.value.find(a => a.attrName === '使用性质')
  353. }
  354. // 根据产品类型初始化默认险种
  355. if(e == '0330' || e == '0330034001') {
  356. // 交强险
  357. let obj = insuranceTypeList.value.filter(item => item.id == '19')
  358. if(obj) {
  359. obj.forEach(item => {
  360. item.insuranceId = item.id
  361. if(item.id == '19') {
  362. item.moneyId = item.options[0].id
  363. }
  364. })
  365. projectAddFrom.value.schemeList.forEach(item => {
  366. item.schemeName = ''
  367. item.description = ''
  368. item.drivingList = []
  369. item.tableData = [...obj]
  370. })
  371. }
  372. } else if(e == '034002') {
  373. // 商业险
  374. let obj = insuranceTypeList.value.find(item => item.id == '2')
  375. obj.insuranceId = obj.id
  376. projectAddFrom.value.schemeList.forEach(item => {
  377. item.schemeName = ''
  378. item.description = ''
  379. item.drivingList = []
  380. item.tableData = [obj]
  381. })
  382. } else if(e == '0330034002') {
  383. // 交强险+商业险
  384. let obj = insuranceTypeList.value.filter(item => item.id == '2' || item.id == '19')
  385. if(obj) {
  386. obj.forEach(item => {
  387. item.insuranceId = item.id
  388. if(item.id == '19') {
  389. item.moneyId = item.options[0].id
  390. }
  391. })
  392. projectAddFrom.value.schemeList.forEach(item => {
  393. item.schemeName = ''
  394. item.description = ''
  395. item.drivingList = []
  396. item.tableData = [...obj]
  397. })
  398. }
  399. } else {
  400. // 其他产品类型
  401. projectAddFrom.value.schemeList.forEach(item => {
  402. item.schemeName = ''
  403. item.description = ''
  404. item.drivingList = []
  405. item.tableData = []
  406. })
  407. }
  408. // 获取保险公司的方案配置
  409. if(projectAddFrom.value.companyId && projectAddFrom.value.productId && projectAddFrom.value.schemeType) {
  410. api.projectApi.getSchemeByCompany({
  411. companyId: projectAddFrom.value.companyId,
  412. productId: projectAddFrom.value.productId,
  413. schemeType: projectAddFrom.value.schemeType,
  414. energyType: energyType?.min,
  415. vehicleType: vehicleType?.minArray?.join(','),
  416. carnature: carnature?.minArray?.join(','),
  417. }).then(res => {
  418. if(res.code == 200) {
  419. if(res.data && res.data.schemeList.length > 0) {
  420. res.data.schemeList.forEach(item => {
  421. // 处理驾意险数据
  422. item.drivingList = item.drivingIntentionList
  423. // 处理险种数据
  424. item.tableData = item.schemeInsuranceList.map(sub => {
  425. let obj = insuranceTypeList.value.find(a => a.id === sub.insuranceId)
  426. return {
  427. ...sub,
  428. optionId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  429. moneyId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  430. options: obj?.options
  431. }
  432. })
  433. })
  434. projectAddFrom.value = res.data
  435. // 处理规则条件数据
  436. rulesAttrList.value = res.data.ruleAttrs.map(val => {
  437. if (val.attrCode == 'LicenseNo') {
  438. val.dictLabal = licensePlateNumber.value;
  439. }
  440. if (val.attrCode == 'LicenseArea') {
  441. val.dictLabal = licensePlateRegion.value;
  442. }
  443. return val
  444. })
  445. }
  446. }
  447. })
  448. }
  449. }
  450. // 险种列表
  451. let insuranceTypeList = ref([])
  452. /**
  453. * 初始化险种数据
  454. */
  455. const initInsurance = () => {
  456. api.projectApi.getBusinessInsurance(projectAddFrom.value.productId || '0330').then(res => {
  457. if(res.code == 200) {
  458. insuranceTypeList.value = res.data
  459. // 根据产品类型初始化默认险种
  460. if(projectAddFrom.value.productId == '0330' || projectAddFrom.value.productId == '0330034001') {
  461. let obj = insuranceTypeList.value.filter(item => item.id == '19')
  462. if(obj) {
  463. obj.forEach(item => {
  464. item.insuranceId = item.id
  465. if(item.id == '19') {
  466. item.moneyId = item.options[0].id
  467. }
  468. })
  469. projectAddFrom.value.schemeList.forEach(item => {
  470. item.drivingList = []
  471. item.tableData = [...obj]
  472. })
  473. }
  474. } else if(projectAddFrom.value.productId == '034002') {
  475. let obj = insuranceTypeList.value.find(item => item.id == '2')
  476. obj.insuranceId = obj.id
  477. projectAddFrom.value.schemeList.forEach(item => {
  478. item.drivingList = []
  479. item.tableData = [obj]
  480. })
  481. } else if(projectAddFrom.value.productId == '0330034002') {
  482. let obj = insuranceTypeList.value.filter(item => item.id == '2' || item.id == '19')
  483. if(obj) {
  484. obj.forEach(item => {
  485. item.insuranceId = item.id
  486. if(item.id == '19') {
  487. item.moneyId = item.options[0].id
  488. }
  489. })
  490. projectAddFrom.value.schemeList.forEach(item => {
  491. item.drivingList = []
  492. item.tableData = [...obj]
  493. })
  494. }
  495. } else {
  496. projectAddFrom.value.schemeList.forEach(item => {
  497. item.drivingList = []
  498. item.tableData = []
  499. })
  500. }
  501. } else {
  502. ElMessage({
  503. message: res.msg,
  504. type: 'warning'
  505. })
  506. }
  507. })
  508. }
  509. /**
  510. * 方案类型切换处理
  511. * @param e 方案类型
  512. */
  513. const schemeTypeChange = (e) => {
  514. initProduct(projectAddFrom.value.productId)
  515. }
  516. // 保险公司列表
  517. let companyOption = ref([])
  518. /**
  519. * 初始化保险公司列表
  520. */
  521. const initCompany = () => {
  522. api.projectApi.getCompanyList().then(res => {
  523. if(res.code == 200) {
  524. companyOption.value = res.data
  525. } else {
  526. ElMessage({
  527. message: res.msg,
  528. type: 'warning'
  529. })
  530. }
  531. })
  532. }
  533. /**
  534. * 添加新方案
  535. */
  536. const addProject = () => {
  537. projectAddFrom.value.schemeList.push({
  538. schemeName: '',
  539. description: '',
  540. tableData: [],
  541. drivingList: [],
  542. schemeInsuranceList: [],
  543. drivingIntentionList: []
  544. })
  545. }
  546. // 规则条件显示状态
  547. let rulesShow = ref(false)
  548. /**
  549. * 打开规则条件选择弹窗
  550. */
  551. const addRules = () => {
  552. ruleSelectShow.value = true
  553. nextTick(() => {
  554. RuleSelect.value.initEditData(rulesAttrList.value)
  555. })
  556. }
  557. // 规则条件列表
  558. let rulesAttrList = ref([])
  559. // 默认规则条件列表
  560. let defaultAttrList = ref([])
  561. /**
  562. * 取消规则条件编辑
  563. * @param data 数据
  564. */
  565. const cancelRule = (data) => {
  566. rulesShow.value = false
  567. }
  568. /**
  569. * 删除规则条件
  570. * @param index 索引
  571. */
  572. const handleDel = (index) => {
  573. // 能源类型、使用性质、车辆种类不可删除
  574. if(rulesAttrList.value[index].attrName === '能源类型' || rulesAttrList.value[index].attrName === '使用性质' || rulesAttrList.value[index].attrName === '车辆种类') {
  575. return
  576. } else {
  577. rulesAttrList.value.splice(index, 1)
  578. }
  579. }
  580. // 险种类型列表
  581. let insuranceType = ref([])
  582. /**
  583. * 初始化险种类型
  584. */
  585. const initType = () => {
  586. api.commonApi.personInfo('insurance_type').then(res => {
  587. if(res.code == 200) {
  588. insuranceType.value = res.data
  589. projectAddFrom.value.productId = insuranceType.value[0].value
  590. } else {
  591. ElMessage({
  592. message: res.msg,
  593. type: 'warning'
  594. })
  595. }
  596. })
  597. }
  598. // 险种选择弹窗状态
  599. let insuranceShow = ref(false)
  600. /**
  601. * 处理险种选择关闭
  602. * @param obj 险种数据
  603. */
  604. const handleClose = ( obj ) => {
  605. if(obj.list && obj.list.length > 0) {
  606. if(projectAddFrom.value.schemeType === 2) {
  607. // 自选方案处理多选
  608. obj.list.forEach(a => {
  609. a.optionId = []
  610. a.options.forEach(b => {
  611. if(b.checked) {
  612. a.optionId.push(b.id)
  613. }
  614. })
  615. a.moneyId = a.optionId
  616. })
  617. } else {
  618. // 基础方案处理单选
  619. obj.list.forEach(a => {
  620. a.optionId = a.options.find(b => b.checked)?.id
  621. a.moneyId = a.optionId
  622. })
  623. }
  624. projectAddFrom.value.schemeList[obj.index].tableData = obj.list
  625. }
  626. insuranceShow.value = false
  627. }
  628. /**
  629. * 删除险种
  630. * @param item 方案项
  631. * @param row 险种行数据
  632. */
  633. const insuranceTypeDel = (item, row) => {
  634. let data = item.tableData.filter(a => a.insuranceId != row.insuranceId)
  635. item.tableData = [...data]
  636. }
  637. // 驾意险选择弹窗状态
  638. let drivingShow = ref(false)
  639. /**
  640. * 打开驾意险选择弹窗
  641. * @param item 方案项
  642. * @param index 索引
  643. */
  644. const handleDriving = (item, index) => {
  645. drivingShow.value = true
  646. nextTick(() => {
  647. DrivingTypeRef.value.initEditData(item.drivingList, index, myRoute.query.companyId)
  648. })
  649. }
  650. /**
  651. * 处理驾意险选择关闭
  652. * @param obj 驾意险数据
  653. */
  654. const handleDrivingClose = ( obj ) => {
  655. if(obj.list && obj.list.length > 0) {
  656. obj.list.forEach(sub => {
  657. sub.drivingIntentionId = sub.drivingIntentionId
  658. sub.selectedStatus = sub.selectedStatus?sub.selectedStatus:'1'
  659. sub.quantity = sub.quantity?sub.quantity:'1'
  660. })
  661. projectAddFrom.value.schemeList[obj.index].drivingList = obj.list
  662. }
  663. drivingShow.value = false
  664. }
  665. /**
  666. * 删除驾意险
  667. * @param item 方案项
  668. * @param row 驾意险行数据
  669. */
  670. const drivingTypeDel = (item, row) => {
  671. let data = item.drivingList.filter(a => a.id != row.id)
  672. item.drivingList = [...data]
  673. }
  674. /**
  675. * 打开险种选择弹窗
  676. * @param item 方案项
  677. * @param index 索引
  678. */
  679. const handlePopover = (item, index) => {
  680. insuranceShow.value = true
  681. nextTick(() => {
  682. InsuranceTypeRef.value.initEditData(item.tableData, index, projectAddFrom.value.schemeType, projectAddFrom.value.productId)
  683. })
  684. }
  685. /**
  686. * 初始化规则属性
  687. */
  688. const initAttr = () => {
  689. api.agreementApi.ruleAttrGroup({ attrName: '' }).then(res => {
  690. if(res.code == 200) {
  691. // 获取车辆信息相关的规则属性
  692. let list = res.data?.VehicleInformation?.filter(e => e.attrName === '能源类型' || e.attrName === '使用性质' || e.attrName === '车辆种类')
  693. rulesAttrList.value = list?.map(a => {
  694. if (a.attrCode == 'LicenseNo') {
  695. a.dictLabal = licensePlateNumber.value;
  696. }
  697. if (a.attrCode == 'LicenseArea') {
  698. a.dictLabal = licensePlateRegion.value;
  699. }
  700. return {
  701. ...a,
  702. operator: '1',
  703. min: a.attrName == '能源类型'? '0':'',
  704. minArray: a.minArray?a.minArray:a.attrName == '使用性质' || a.attrName == '车辆种类'?[a.dictLabal[0].code]:[]
  705. }
  706. })
  707. defaultAttrList.value = [...list]
  708. } else {
  709. ElMessage({
  710. message: res.msg,
  711. type: 'warning'
  712. })
  713. }
  714. })
  715. }
  716. /**
  717. * 初始化编辑数据
  718. */
  719. const initEdit = async () => {
  720. initInsurance()
  721. await api.projectApi.getScheme(myRoute.query.id).then(res => {
  722. if(res.code == 200) {
  723. if(res.data && res.data.schemeList.length > 0) {
  724. res.data.schemeList.forEach(item => {
  725. item.drivingList = item.drivingIntentionList
  726. item.tableData = item.schemeInsuranceList.map(sub => {
  727. let obj = insuranceTypeList.value.find(a => a.id == sub.insuranceId)
  728. console.log("🚀 ~ initEdit ~ obj:", obj)
  729. return {
  730. ...sub,
  731. optionId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  732. moneyId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  733. options: obj?.options
  734. }
  735. })
  736. })
  737. projectAddFrom.value = res.data
  738. rulesAttrList.value = res.data.ruleAttrs.map(val => {
  739. if (val.attrCode == 'LicenseNo') {
  740. val.dictLabal = licensePlateNumber.value;
  741. }
  742. if (val.attrCode == 'LicenseArea') {
  743. val.dictLabal = licensePlateRegion.value;
  744. }
  745. return val
  746. })
  747. }
  748. } else {
  749. ElMessage({
  750. message: res.msg,
  751. type: 'warning'
  752. })
  753. }
  754. })
  755. }
  756. /**
  757. * 取消操作
  758. */
  759. const quit = () => {
  760. myRouter.push({
  761. path: '/quoteConfig/agreement/project',
  762. query: {
  763. id: myRoute.query.companyId
  764. }
  765. })
  766. }
  767. /**
  768. * 保存项目
  769. * @param ProjectAddRef 表单引用
  770. */
  771. const save = async (ProjectAddRef: FormInstance | undefined) => {
  772. if(!ProjectAddRef) {
  773. return
  774. }
  775. await ProjectAddRef.validate((valid) => {
  776. if(valid) {
  777. let formData = {...projectAddFrom.value}
  778. formData.ruleAttrs = [...rulesAttrList.value]
  779. // 处理方案数据
  780. formData.schemeList.forEach(item => {
  781. item.drivingIntentionList = []
  782. item.schemeInsuranceList = []
  783. // 处理驾意险数据
  784. item.drivingList.forEach(sub => {
  785. let obj = {
  786. id: sub.id,
  787. drivingIntentionId: sub.drivingIntentionId,
  788. selectedStatus: sub.selectedStatus,
  789. quantity: sub.quantity
  790. }
  791. item.drivingIntentionList.push(obj)
  792. })
  793. // 处理险种数据
  794. item.tableData.forEach(ins => {
  795. let obj = {
  796. id: ins.id,
  797. insuranceId: ins.insuranceId,
  798. optionId: projectAddFrom.value.schemeType === 1?[ins.moneyId]:projectAddFrom.value.schemeType === 2?ins.moneyId:[]
  799. }
  800. item.schemeInsuranceList.push(obj)
  801. })
  802. })
  803. // 调用保存API
  804. api.projectApi.saveScheme({...formData}).then(res => {
  805. if(res.code == 200) {
  806. ElMessage({
  807. message: res.msg,
  808. type: 'success'
  809. })
  810. myRouter.push({
  811. path: '/quoteConfig/agreement/project',
  812. query: {
  813. id: myRoute.query.companyId
  814. }
  815. })
  816. } else if(res.code != 400) {
  817. ElMessage({
  818. message: res.msg,
  819. type: 'warning'
  820. })
  821. }
  822. })
  823. } else {
  824. ElMessage({
  825. message: '请正确填写相关信息!',
  826. type: 'warning'
  827. })
  828. }
  829. })
  830. }
  831. /**
  832. * 组件挂载时执行
  833. */
  834. onBeforeMount(() => {
  835. // 初始化险种类型
  836. initType()
  837. // 初始化保险公司列表
  838. initCompany()
  839. // 初始化车牌地区数据
  840. regionLicenseRegion('0')
  841. // 初始化车牌号数据
  842. regionLicenseNumber('14')
  843. // 设置保险公司ID
  844. projectAddFrom.value.companyId = myRoute.query.companyId
  845. // 判断是否为编辑模式
  846. if(myRoute.query.id) {
  847. isEdit.value = true
  848. projectAddFrom.value.id = myRoute.query.id
  849. projectAddFrom.value.productId = myRoute.query.productId
  850. initEdit()
  851. } else {
  852. isEdit.value = false
  853. initAttr()
  854. initInsurance()
  855. }
  856. })
  857. </script>
  858. <style scoped lang="scss">
  859. .projectAdd{
  860. width: 100%;
  861. height: 100%;
  862. background: white;
  863. padding: 20px;
  864. .ruleList{
  865. width: 90%;
  866. .ruleItem{
  867. display: flex;
  868. align-items: center;
  869. justify-content: flex-start;
  870. margin: 10px 0;
  871. }
  872. }
  873. .configuration{
  874. width: 100%;
  875. background: #f0f0f0;
  876. padding: 20px 100px;
  877. margin-bottom: 10px;
  878. border-radius: 5px;
  879. }
  880. .btns{
  881. display: flex;
  882. align-items: center;
  883. justify-content: center;
  884. }
  885. }
  886. </style>