projectAdd.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <template>
  2. <div class="projectAdd">
  3. <el-form :model="projectAddFrom" :rules="projectAddRules" ref="ProjectAddRef">
  4. <el-descriptions title="基本信息">
  5. <el-descriptions-item>
  6. <el-form-item label="保险公司" prop="companyId">
  7. <el-select :disabled="isEdit" v-model="projectAddFrom.companyId" placeholder="请选择" style="width: 40%" @change="initProduct">
  8. <el-option v-for="item in companyOption" :key="item.id" :value="item.id" :label="item.nameSimple"></el-option>
  9. </el-select>
  10. </el-form-item>
  11. <el-form-item label="方案类型" prop="schemeType">
  12. <el-radio-group :disabled="isEdit" v-model="projectAddFrom.schemeType" @change="schemeTypeChange">
  13. <el-radio :value="1">基础方案</el-radio>
  14. <el-radio :value="2">自选方案</el-radio>
  15. </el-radio-group>
  16. </el-form-item>
  17. <el-form-item label="险种类型" prop="productId">
  18. <el-radio-group :disabled="isEdit" v-model="projectAddFrom.productId" @change="initProduct">
  19. <el-radio-button v-for="item in insuranceType" :key="item.value" :value="item.value">{{ item.label }}</el-radio-button>
  20. </el-radio-group>
  21. </el-form-item>
  22. <div style="display: flex;">
  23. <span style="width: 10%"><a style="color: red">*</a>规则条件</span>
  24. <!-- <div class="ruleList">
  25. <div class="ruleItem">
  26. <el-input placeholder="请填写" style="width: 300px"></el-input>&nbsp;
  27. <el-select style="width: 100px">
  28. <el-option key="1" value="1" label="="></el-option>
  29. <el-option key="2" value="2" label=">"></el-option>
  30. <el-option key="3" value="3" label="<"></el-option>
  31. </el-select>&nbsp;
  32. <el-input placeholder="请填写" style="width: 300px"></el-input>&nbsp;
  33. <el-icon><CircleCloseFilled /></el-icon>&nbsp;
  34. </div>
  35. </div>-->
  36. <div style="width: 60%">
  37. <rule-condition-container :rulesAttrList="rulesAttrList"></rule-condition-container>
  38. </div>
  39. <rule-condition :ruleConditionVisible="rulesShow" :attrIdList="rulesAttrList" @save="saveRule"></rule-condition>
  40. </div>
  41. <el-button style="margin: 10px 10%" plain type="primary" icon="plus" @click="addRules">添加条件</el-button>
  42. <el-descriptions>
  43. <template #title>
  44. <div style="display: flex; align-items: center">
  45. <span>方案配置</span>
  46. <el-button v-show="!isEdit" type="primary" icon="plus" style="margin-left: 20px;" @click="addProject">添加新方案</el-button>
  47. </div>
  48. </template>
  49. <el-descriptions-item>
  50. <div class="configuration" v-for="(item, index) in projectAddFrom.schemeList">
  51. <el-form-item label="方案名称" prop="schemeName">
  52. <el-input v-model="item.schemeName"></el-input>
  53. </el-form-item>
  54. <el-form-item label="方案描述" prop="description">
  55. <el-input type="textarea" v-model="item.description" maxlength="500"></el-input>
  56. </el-form-item>
  57. <div>
  58. <div style="display: flex; align-items: center; margin-bottom: 10px">
  59. <span style="margin-right: 20px">驾意险</span>
  60. <el-button link icon="plus" type="primary" @click="handleDriving(item, index)">选择驾意险</el-button>
  61. </div>
  62. <el-table
  63. :data="item.drivingList"
  64. >
  65. <el-table-column label="名称" prop="productName">
  66. <template #default="scope">
  67. <el-button link type="primary" @click="getJYXDetail(scope.row)">{{ scope.row.productName }}</el-button>
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="客户端状态" prop="selectedStatus">
  71. <template #default="scope">
  72. <el-select v-model="scope.row.selectedStatus">
  73. <el-option label="默认不选中" key="1" value="1"></el-option>
  74. <el-option label="默认选中" key="2" value="2"></el-option>
  75. <el-option label="强制选中" key="3" value="3"></el-option>
  76. </el-select>
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="份数" prop="quantity">
  80. <template #default="scope">
  81. <el-input v-model="scope.row.quantity" style="width: 100px;"></el-input>份
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="操作">
  85. <template #default="scope">
  86. <el-button link type="primary" @click="drivingTypeDel(item, scope.row)">删除</el-button>
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. </div>
  91. <div>
  92. <div style="display: flex; align-items: center; margin: 10px 0">
  93. <span style="margin-right: 20px">险种</span>
  94. <el-button link icon="plus" type="primary" @click="handlePopover(item, index)">选择险种</el-button>
  95. <!-- <el-popover placement="bottom-end" trigger="click" width="500" v-model:visible="insuranceShow" @show="handlePopover(item)">
  96. <template #reference>
  97. <el-button link icon="plus" type="primary">选择险种</el-button>
  98. </template>
  99. </el-popover>-->
  100. </div>
  101. <el-table
  102. :data="item.tableData"
  103. >
  104. <el-table-column label="险种" prop="kindName">
  105. <template #default="scope">
  106. <a>{{ scope.row.kindName }}</a>
  107. </template>
  108. </el-table-column>
  109. <el-table-column label="保额" prop="optionId">
  110. <template #default="scope">
  111. <el-select :disabled="projectAddFrom.productId == '0330' || projectAddFrom.productId == '0330034002' || projectAddFrom.productId == '0330034001'" v-if="projectAddFrom.schemeType === 2" v-model="scope.row.moneyId" style="width: 150px" multiple>
  112. <el-option v-for="m in scope.row.options" :label="m.label" :key="m.id" :value="m.id"></el-option>
  113. </el-select>
  114. <el-select :disabled="projectAddFrom.productId == '0330' || projectAddFrom.productId == '0330034002' || projectAddFrom.productId == '0330034001'" v-else v-model="scope.row.moneyId" style="width: 150px" @change="">
  115. <el-option v-for="m in scope.row.options" :label="m.label" :key="m.id" :value="m.id"></el-option>
  116. </el-select>
  117. </template>
  118. </el-table-column>
  119. <el-table-column label="操作">
  120. <template #default="scope">
  121. <el-button :disabled="projectAddFrom.productId == '0330' || projectAddFrom.productId == '0330034002' || projectAddFrom.productId == '0330034001'" link type="primary" @click="insuranceTypeDel(item, scope.row)">删除</el-button>
  122. </template>
  123. </el-table-column>
  124. </el-table>
  125. </div>
  126. </div>
  127. </el-descriptions-item>
  128. </el-descriptions>
  129. </el-descriptions-item>
  130. </el-descriptions>
  131. </el-form>
  132. <div class="btns">
  133. <el-button plain @click="quit">取消</el-button>
  134. <el-button type="primary" @click="save(ProjectAddRef)">保存</el-button>
  135. </div>
  136. <el-dialog
  137. v-model="drivingShow"
  138. title="选择驾意险"
  139. width="700"
  140. >
  141. <driving ref="DrivingTypeRef" @close="handleDrivingClose"></driving>
  142. </el-dialog>
  143. <el-dialog
  144. v-model="insuranceShow"
  145. title="选择险种"
  146. width="500"
  147. >
  148. <insurance ref="InsuranceTypeRef" @close="handleClose" ></insurance>
  149. </el-dialog>
  150. <el-dialog
  151. v-model="JYXDetailShow"
  152. title="驾意险详情"
  153. width="600"
  154. >
  155. <detail ref="JYXDetail"></detail>
  156. </el-dialog>
  157. </div>
  158. </template>
  159. <script setup lang="ts">
  160. import api from "@/api";
  161. import { ElMessage, FormInstance, FormRules } from "element-plus";
  162. import { useRouter, useRoute } from 'vue-router'
  163. import insurance from '../../../../layouts/components/InsuranceType/index.vue'
  164. import driving from '../../../../layouts/components/DrivingType/index.vue'
  165. import rule from '../../../../components/ruleConditionContainer/index.vue'
  166. import detail from '../../../../layouts/components/JYXDetail/index.vue'
  167. import Detail from "@/views/representative/detail.vue";
  168. const myRouter = useRouter()
  169. const myRoute = useRoute()
  170. const ProjectAddRef = ref<FormInstance>()
  171. const InsuranceTypeRef = ref(null)
  172. const DrivingTypeRef = ref(null)
  173. const JYXDetail = ref(null)
  174. // 是否编辑
  175. let isEdit = ref(false)
  176. let projectAddFrom = ref({
  177. ruleAttrs: [],
  178. schemeList: [{
  179. schemeName: '',
  180. description: '',
  181. tableData: [],
  182. drivingList: [],
  183. schemeInsuranceList: [],
  184. drivingIntentionList: []
  185. }]
  186. })
  187. let projectAddRules = ref<FormRules>({
  188. companyId: [
  189. { required: true, trigger: "change", message: "请选择保险公司" }
  190. ],
  191. schemeType: [
  192. { required: true, trigger: "change", message: "请选择方案类型" }
  193. ],
  194. productId: [
  195. { required: true, trigger: "change", message: "请选择险种类型" }
  196. ]
  197. })
  198. // 驾意险详情
  199. let JYXDetailShow = ref(false)
  200. const getJYXDetail = (row) => {
  201. JYXDetailShow.value = true
  202. nextTick(() => {
  203. JYXDetail.value.initData(row.drivingIntentionId)
  204. })
  205. }
  206. // 新增的时候初始化已有的方案
  207. const initProduct = (e) => {
  208. api.projectApi.getSchemeByCompany({
  209. companyId: projectAddFrom.value.companyId,
  210. productId: projectAddFrom.value.productId,
  211. schemeType: projectAddFrom.value.schemeType
  212. }).then(res => {
  213. if(res.code == 200) {
  214. if(res.data && res.data.schemeList.length > 0) {
  215. res.data.schemeList.forEach(item => {
  216. item.drivingList = item.drivingIntentionList
  217. item.tableData = item.schemeInsuranceList.map(sub => {
  218. let obj = insuranceTypeList.value.find(a => a.id === sub.insuranceId)
  219. return {
  220. ...sub,
  221. optionId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  222. moneyId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  223. options: obj.options
  224. }
  225. })
  226. })
  227. projectAddFrom.value = res.data
  228. rulesAttrList.value = res.data.ruleAttrs
  229. }
  230. } else {
  231. projectAddFrom.value.ruleAttrs = []
  232. if(e == '0330' || e == '0330034002' || e == '0330034001') {
  233. let obj = insuranceTypeList.value.find(a => a.alias == '交强险')
  234. if(obj) {
  235. obj.insuranceId = obj.id
  236. let sub = obj.options.find(b => b.label == '投保')
  237. obj.optionId = projectAddFrom.value.schemeType==1?sub?.id:projectAddFrom.value.schemeType==2?[sub?.id]:''
  238. obj.moneyId = sub?.id
  239. }
  240. projectAddFrom.value.schemeList = [{
  241. schemeName: '',
  242. description: '',
  243. tableData: [obj],
  244. drivingList: [],
  245. schemeInsuranceList: [obj],
  246. drivingIntentionList: []
  247. }]
  248. } else {
  249. projectAddFrom.value.schemeList = [{
  250. schemeName: '',
  251. description: '',
  252. tableData: [],
  253. drivingList: [],
  254. schemeInsuranceList: [],
  255. drivingIntentionList: []
  256. }]
  257. }
  258. // ElMessage({
  259. // message: res.msg,
  260. // type: 'warning'
  261. // })
  262. }
  263. })
  264. }
  265. // 险种
  266. let insuranceTypeList = ref([])
  267. const initInsurance = () => {
  268. api.projectApi.getBusinessInsurance().then(res => {
  269. if(res.code == 200) {
  270. // res.data.forEach(item => {
  271. // item.options.forEach(sub => {
  272. // sub.id = sub.value
  273. // })
  274. // })
  275. insuranceTypeList.value = res.data
  276. } else {
  277. ElMessage({
  278. message: res.msg,
  279. type: 'warning'
  280. })
  281. }
  282. })
  283. }
  284. // 方案类型切换
  285. const schemeTypeChange = (e) => {
  286. initProduct(projectAddFrom.value.productId)
  287. }
  288. // 保险公司
  289. let companyOption = ref([])
  290. const initCompany = () => {
  291. api.projectApi.getCompanyList().then(res => {
  292. if(res.code == 200) {
  293. companyOption.value = res.data
  294. } else {
  295. ElMessage({
  296. message: res.msg,
  297. type: 'warning'
  298. })
  299. }
  300. })
  301. }
  302. // 新增方案
  303. const addProject = () => {
  304. projectAddFrom.value.schemeList.push({
  305. schemeName: '',
  306. description: '',
  307. tableData: [],
  308. drivingList: [],
  309. schemeInsuranceList: [],
  310. drivingIntentionList: []
  311. })
  312. }
  313. // 规则
  314. let rulesShow = ref(false)
  315. const addRules = () => {
  316. rulesShow.value = true
  317. }
  318. let rulesAttrList = ref([])
  319. let defaultAttrList = ref([])
  320. const saveRule = (data) => {
  321. if(data && data.length > 0) {
  322. rulesAttrList.value = data
  323. }
  324. rulesShow.value = false
  325. }
  326. // 险种类型
  327. let insuranceType = ref([])
  328. const initType = () => {
  329. api.commonApi.personInfo('insurance_type').then(res => {
  330. if(res.code == 200) {
  331. insuranceType.value = res.data
  332. projectAddFrom.value.productId = insuranceType.value[0].value
  333. } else {
  334. ElMessage({
  335. message: res.msg,
  336. type: 'warning'
  337. })
  338. }
  339. })
  340. }
  341. // 险种
  342. let insuranceShow = ref(false)
  343. // let insuranceList = ref([])
  344. // let checkInsuranceList = ref([])
  345. // let checkSubInsuranceList = ref([])
  346. const handleClose = ( obj ) => {
  347. if(obj.list && obj.list.length > 0) {
  348. if(projectAddFrom.value.schemeType === 2) {
  349. obj.list.forEach(a => {
  350. a.optionId = []
  351. a.options.forEach(b => {
  352. if(b.checked) {
  353. a.optionId.push(b.id)
  354. }
  355. })
  356. a.moneyId = a.optionId
  357. })
  358. } else {
  359. obj.list.forEach(a => {
  360. a.optionId = a.options.find(b => b.checked)?.id
  361. a.moneyId = a.optionId
  362. })
  363. }
  364. projectAddFrom.value.schemeList[obj.index].tableData = obj.list
  365. }
  366. insuranceShow.value = false
  367. }
  368. // 险种删除
  369. const insuranceTypeDel = (item, row) => {
  370. let data = item.tableData.filter(a => a.id != row.id)
  371. item.tableData = [...data]
  372. }
  373. // 驾意险
  374. let drivingShow = ref(false)
  375. const handleDriving = (item, index) => {
  376. drivingShow.value = true
  377. nextTick(() => {
  378. DrivingTypeRef.value.initEditData(item.drivingList, index)
  379. })
  380. }
  381. const handleDrivingClose = ( obj ) => {
  382. if(obj.list && obj.list.length > 0) {
  383. // let selectList = obj.list.filter(a => a.checked)
  384. obj.list.forEach(sub => {
  385. sub.drivingIntentionId = sub.drivingIntentionId
  386. sub.selectedStatus = sub.selectedStatus?sub.selectedStatus:'1'
  387. sub.quantity = sub.quantity?sub.quantity:'1'
  388. })
  389. projectAddFrom.value.schemeList[obj.index].drivingList = obj.list
  390. }
  391. drivingShow.value = false
  392. }
  393. const drivingTypeDel = (item, row) => {
  394. let data = item.drivingList.filter(a => a.id != row.id)
  395. item.drivingList = [...data]
  396. }
  397. const handlePopover = (item, index) => {
  398. insuranceShow.value = true
  399. nextTick(() => {
  400. InsuranceTypeRef.value.initEditData(item.tableData, index, projectAddFrom.value.schemeType)
  401. })
  402. }
  403. // 规则
  404. const initAttr = () => {
  405. api.agreementApi.ruleAttrGroup({ attrName: '' }).then(res => {
  406. if(res.code == 200) {
  407. let list = res.data?.VehicleInformation?.filter(e => e.attrName === '能源类型' || e.attrName === '使用性质' || e.attrName === '车辆类型')
  408. rulesAttrList.value = [...list]
  409. defaultAttrList.value = [...list]
  410. } else {
  411. ElMessage({
  412. message: res.msg,
  413. type: 'warning'
  414. })
  415. }
  416. })
  417. }
  418. // 编辑
  419. const initEdit = () => {
  420. api.projectApi.getScheme(myRoute.query.id).then(res => {
  421. if(res.code == 200) {
  422. if(res.data && res.data.schemeList.length > 0) {
  423. res.data.schemeList.forEach(item => {
  424. item.drivingList = item.drivingIntentionList
  425. item.tableData = item.schemeInsuranceList.map(sub => {
  426. let obj = insuranceTypeList.value.find(a => a.id === sub.insuranceId)
  427. return {
  428. ...sub,
  429. optionId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  430. moneyId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  431. options: obj.options
  432. }
  433. })
  434. })
  435. projectAddFrom.value = res.data
  436. rulesAttrList.value = res.data.ruleAttrs
  437. }
  438. } else {
  439. ElMessage({
  440. message: res.msg,
  441. type: 'warning'
  442. })
  443. }
  444. })
  445. }
  446. // 取消
  447. const quit = () => {
  448. myRouter.push({
  449. path: '/quoteConfig/agreement/project'
  450. })
  451. }
  452. // 保存
  453. const save = async (ProjectAddRef: FormInstance | undefined) => {
  454. if(!ProjectAddRef) {
  455. ProjectAddRef.resetFields()
  456. return
  457. }
  458. await ProjectAddRef.validate((valid) => {
  459. if(valid) {
  460. let formData = {...projectAddFrom.value}
  461. formData.ruleAttrs = [...rulesAttrList.value]
  462. formData.schemeList.forEach(item => {
  463. item.drivingIntentionList = []
  464. item.schemeInsuranceList = []
  465. item.drivingList.forEach(sub => {
  466. let obj = {
  467. id: sub.id,
  468. drivingIntentionId: sub.drivingIntentionId,
  469. selectedStatus: sub.selectedStatus,
  470. quantity: sub.quantity
  471. }
  472. item.drivingIntentionList.push(obj)
  473. })
  474. item.tableData.forEach(ins => {
  475. let obj = {
  476. id: ins.id,
  477. insuranceId: ins.insuranceId,
  478. optionId: projectAddFrom.value.schemeType === 1?[ins.moneyId]:projectAddFrom.value.schemeType === 2?ins.moneyId:[]
  479. }
  480. // ins.options.forEach(sub => {
  481. // if(sub.checked) {
  482. // obj.optionId.push(sub.id)
  483. // }
  484. // })
  485. item.schemeInsuranceList.push(obj)
  486. })
  487. })
  488. api.projectApi.saveScheme({...formData}).then(res => {
  489. if(res.code == 200) {
  490. ElMessage({
  491. message: res.msg,
  492. type: 'success'
  493. })
  494. myRouter.push({
  495. path: '/quoteConfig/agreement/project'
  496. })
  497. } else {
  498. ElMessage({
  499. message: res.msg,
  500. type: 'warning'
  501. })
  502. }
  503. })
  504. } else {
  505. ElMessage({
  506. message: '请正确填写相关信息!',
  507. type: 'warning'
  508. })
  509. }
  510. })
  511. }
  512. onMounted(() => {
  513. initInsurance()
  514. initType()
  515. initCompany()
  516. // initAttr()
  517. if(myRoute.query.id) {
  518. isEdit.value = true
  519. initEdit()
  520. } else {
  521. isEdit.value = false
  522. initAttr()
  523. }
  524. // initInsurance()
  525. })
  526. </script>
  527. <style scoped lang="scss">
  528. .projectAdd{
  529. width: 100%;
  530. height: 100%;
  531. background: white;
  532. padding: 20px;
  533. .ruleList{
  534. width: 90%;
  535. .ruleItem{
  536. display: flex;
  537. align-items: center;
  538. justify-content: flex-start;
  539. margin: 10px 0;
  540. }
  541. }
  542. .configuration{
  543. width: 100%;
  544. background: #f0f0f0;
  545. padding: 20px 100px;
  546. margin-bottom: 10px;
  547. border-radius: 5px;
  548. }
  549. .btns{
  550. display: flex;
  551. align-items: center;
  552. justify-content: center;
  553. }
  554. }
  555. </style>