projectAdd.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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" filterable 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" @Del="handleDel"></rule-condition-container>
  38. </div>
  39. <rule-condition :ruleConditionVisible="rulesShow" :attrIdList="rulesAttrList" @save="saveRule" @cancel="cancelRule"></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" v-if="projectAddFrom.schemeType!=1">
  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-number v-model="scope.row.quantity" style="width: 150px;" min="1" max="99" @change="numberChange($event, scope.row)"></el-input-number>份
  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="scope.row.insuranceId == '19'" 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="scope.row.insuranceId == '19'" 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. schemeType: 1,
  179. schemeList: [{
  180. schemeName: '',
  181. description: '',
  182. tableData: [],
  183. drivingList: [],
  184. schemeInsuranceList: [],
  185. drivingIntentionList: []
  186. }]
  187. })
  188. let projectAddRules = ref<FormRules>({
  189. companyId: [
  190. { required: true, trigger: "change", message: "请选择保险公司" }
  191. ],
  192. schemeType: [
  193. { required: true, trigger: "change", message: "请选择方案类型" }
  194. ],
  195. productId: [
  196. { required: true, trigger: "change", message: "请选择险种类型" }
  197. ]
  198. })
  199. // 驾意险详情
  200. let JYXDetailShow = ref(false)
  201. const getJYXDetail = (row) => {
  202. JYXDetailShow.value = true
  203. nextTick(() => {
  204. JYXDetail.value.initData(row.drivingIntentionId)
  205. })
  206. }
  207. const numberChange = (e, row) => {
  208. if(typeof e != 'number') {
  209. // ElMessage({
  210. // message: '请输入驾意险份数!',
  211. // type: 'warning'
  212. // })
  213. row.quantity = 1
  214. }
  215. }
  216. // 新增的时候初始化已有的方案
  217. const initProduct = (e) => {
  218. if(e == '034002') {
  219. let obj = insuranceTypeList.value.find(item => item.id == '2')
  220. obj.insuranceId = obj.id
  221. projectAddFrom.value.schemeList.forEach(item => {
  222. item.drivingList = []
  223. item.tableData = [obj]
  224. })
  225. } else if(e == '0330034002') {
  226. let obj = insuranceTypeList.value.filter(item => item.id == '2' || item.id == '19')
  227. if(obj) {
  228. obj.forEach(item => {
  229. item.insuranceId = item.id
  230. if(item.id == '19') {
  231. item.moneyId = item.options[0].id
  232. }
  233. })
  234. projectAddFrom.value.schemeList.forEach(item => {
  235. item.drivingList = []
  236. item.tableData = [...obj]
  237. })
  238. }
  239. } else {
  240. projectAddFrom.value.schemeList.forEach(item => {
  241. item.drivingList = []
  242. item.tableData = []
  243. })
  244. }
  245. if(projectAddFrom.value.companyId&&projectAddFrom.value.productId&&projectAddFrom.value.schemeType) {
  246. api.projectApi.getSchemeByCompany({
  247. companyId: projectAddFrom.value.companyId,
  248. productId: projectAddFrom.value.productId,
  249. schemeType: projectAddFrom.value.schemeType
  250. }).then(res => {
  251. if(res.code == 200) {
  252. if(res.data && res.data.schemeList.length > 0) {
  253. res.data.schemeList.forEach(item => {
  254. item.drivingList = item.drivingIntentionList
  255. item.tableData = item.schemeInsuranceList.map(sub => {
  256. let obj = insuranceTypeList.value.find(a => a.id === sub.insuranceId)
  257. return {
  258. ...sub,
  259. optionId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  260. moneyId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  261. options: obj.options
  262. }
  263. })
  264. })
  265. projectAddFrom.value = res.data
  266. rulesAttrList.value = res.data.ruleAttrs
  267. }
  268. } else {
  269. projectAddFrom.value.ruleAttrs = []
  270. if(e == '0330' || e == '0330034002' || e == '0330034001') {
  271. let obj = insuranceTypeList.value.find(a => a.alias == '交强险')
  272. if(obj) {
  273. obj.insuranceId = obj.id
  274. let sub = obj.options.find(b => b.label == '投保')
  275. obj.optionId = projectAddFrom.value.schemeType==1?sub?.id:projectAddFrom.value.schemeType==2?[sub?.id]:''
  276. obj.moneyId = sub?.id
  277. }
  278. projectAddFrom.value.schemeList = [{
  279. schemeName: '',
  280. description: '',
  281. tableData: [obj],
  282. drivingList: [],
  283. schemeInsuranceList: [obj],
  284. drivingIntentionList: []
  285. }]
  286. } else {
  287. projectAddFrom.value.schemeList = [{
  288. schemeName: '',
  289. description: '',
  290. tableData: [],
  291. drivingList: [],
  292. schemeInsuranceList: [],
  293. drivingIntentionList: []
  294. }]
  295. }
  296. // ElMessage({
  297. // message: res.msg,
  298. // type: 'warning'
  299. // })
  300. }
  301. })
  302. }
  303. }
  304. // 险种
  305. let insuranceTypeList = ref([])
  306. const initInsurance = () => {
  307. api.projectApi.getBusinessInsurance().then(res => {
  308. if(res.code == 200) {
  309. // res.data.forEach(item => {
  310. // item.options.forEach(sub => {
  311. // sub.id = sub.value
  312. // })
  313. // })
  314. insuranceTypeList.value = res.data
  315. } else {
  316. ElMessage({
  317. message: res.msg,
  318. type: 'warning'
  319. })
  320. }
  321. })
  322. }
  323. // 方案类型切换
  324. const schemeTypeChange = (e) => {
  325. initProduct(projectAddFrom.value.productId)
  326. }
  327. // 保险公司
  328. let companyOption = ref([])
  329. const initCompany = () => {
  330. api.projectApi.getCompanyList().then(res => {
  331. if(res.code == 200) {
  332. companyOption.value = res.data
  333. } else {
  334. ElMessage({
  335. message: res.msg,
  336. type: 'warning'
  337. })
  338. }
  339. })
  340. }
  341. // 新增方案
  342. const addProject = () => {
  343. projectAddFrom.value.schemeList.push({
  344. schemeName: '',
  345. description: '',
  346. tableData: [],
  347. drivingList: [],
  348. schemeInsuranceList: [],
  349. drivingIntentionList: []
  350. })
  351. }
  352. // 规则
  353. let rulesShow = ref(false)
  354. const addRules = () => {
  355. rulesShow.value = true
  356. }
  357. let rulesAttrList = ref([])
  358. let defaultAttrList = ref([])
  359. const saveRule = (data) => {
  360. if(data && data.length > 0) {
  361. rulesAttrList.value = data
  362. }
  363. rulesShow.value = false
  364. }
  365. const cancelRule = (data) => {
  366. rulesShow.value = false
  367. }
  368. const handleDel = (index) => {
  369. if(rulesAttrList.value[index].attrName === '能源类型' || rulesAttrList.value[index].attrName === '使用性质' || rulesAttrList.value[index].attrName === '车辆种类') {
  370. return
  371. } else {
  372. rulesAttrList.value.splice(index, 1)
  373. }
  374. }
  375. // 险种类型
  376. let insuranceType = ref([])
  377. const initType = () => {
  378. api.commonApi.personInfo('insurance_type').then(res => {
  379. if(res.code == 200) {
  380. insuranceType.value = res.data
  381. projectAddFrom.value.productId = insuranceType.value[0].value
  382. } else {
  383. ElMessage({
  384. message: res.msg,
  385. type: 'warning'
  386. })
  387. }
  388. })
  389. }
  390. // 险种
  391. let insuranceShow = ref(false)
  392. // let insuranceList = ref([])
  393. // let checkInsuranceList = ref([])
  394. // let checkSubInsuranceList = ref([])
  395. const handleClose = ( obj ) => {
  396. if(obj.list && obj.list.length > 0) {
  397. if(projectAddFrom.value.schemeType === 2) {
  398. obj.list.forEach(a => {
  399. a.optionId = []
  400. a.options.forEach(b => {
  401. if(b.checked) {
  402. a.optionId.push(b.id)
  403. }
  404. })
  405. a.moneyId = a.optionId
  406. })
  407. } else {
  408. obj.list.forEach(a => {
  409. a.optionId = a.options.find(b => b.checked)?.id
  410. a.moneyId = a.optionId
  411. })
  412. }
  413. projectAddFrom.value.schemeList[obj.index].tableData = obj.list
  414. }
  415. insuranceShow.value = false
  416. }
  417. // 险种删除
  418. const insuranceTypeDel = (item, row) => {
  419. let data = item.tableData.filter(a => a.insuranceId != row.insuranceId)
  420. item.tableData = [...data]
  421. }
  422. // 驾意险
  423. let drivingShow = ref(false)
  424. const handleDriving = (item, index) => {
  425. drivingShow.value = true
  426. nextTick(() => {
  427. DrivingTypeRef.value.initEditData(item.drivingList, index, myRoute.query.companyId)
  428. })
  429. }
  430. const handleDrivingClose = ( obj ) => {
  431. if(obj.list && obj.list.length > 0) {
  432. // let selectList = obj.list.filter(a => a.checked)
  433. obj.list.forEach(sub => {
  434. sub.drivingIntentionId = sub.drivingIntentionId
  435. sub.selectedStatus = sub.selectedStatus?sub.selectedStatus:'1'
  436. sub.quantity = sub.quantity?sub.quantity:'1'
  437. })
  438. projectAddFrom.value.schemeList[obj.index].drivingList = obj.list
  439. }
  440. drivingShow.value = false
  441. }
  442. const drivingTypeDel = (item, row) => {
  443. let data = item.drivingList.filter(a => a.id != row.id)
  444. item.drivingList = [...data]
  445. }
  446. const handlePopover = (item, index) => {
  447. insuranceShow.value = true
  448. nextTick(() => {
  449. InsuranceTypeRef.value.initEditData(item.tableData, index, projectAddFrom.value.schemeType)
  450. })
  451. }
  452. // 规则
  453. const initAttr = () => {
  454. api.agreementApi.ruleAttrGroup({ attrName: '' }).then(res => {
  455. if(res.code == 200) {
  456. let list = res.data?.VehicleInformation?.filter(e => e.attrName === '能源类型' || e.attrName === '使用性质' || e.attrName === '车辆种类')
  457. rulesAttrList.value = [...list]
  458. defaultAttrList.value = [...list]
  459. } else {
  460. ElMessage({
  461. message: res.msg,
  462. type: 'warning'
  463. })
  464. }
  465. })
  466. }
  467. // 编辑
  468. const initEdit = () => {
  469. api.projectApi.getScheme(myRoute.query.id).then(res => {
  470. if(res.code == 200) {
  471. if(res.data && res.data.schemeList.length > 0) {
  472. res.data.schemeList.forEach(item => {
  473. item.drivingList = item.drivingIntentionList
  474. item.tableData = item.schemeInsuranceList.map(sub => {
  475. let obj = insuranceTypeList.value.find(a => a.id === sub.insuranceId)
  476. return {
  477. ...sub,
  478. optionId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  479. moneyId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  480. options: obj.options
  481. }
  482. })
  483. })
  484. projectAddFrom.value = res.data
  485. rulesAttrList.value = res.data.ruleAttrs
  486. }
  487. } else {
  488. ElMessage({
  489. message: res.msg,
  490. type: 'warning'
  491. })
  492. }
  493. })
  494. }
  495. // 取消
  496. const quit = () => {
  497. myRouter.push({
  498. path: '/quoteConfig/agreement/project'
  499. })
  500. }
  501. // 保存
  502. const save = async (ProjectAddRef: FormInstance | undefined) => {
  503. if(!ProjectAddRef) {
  504. ProjectAddRef.resetFields()
  505. return
  506. }
  507. await ProjectAddRef.validate((valid) => {
  508. if(valid) {
  509. let formData = {...projectAddFrom.value}
  510. formData.ruleAttrs = [...rulesAttrList.value]
  511. formData.schemeList.forEach(item => {
  512. item.drivingIntentionList = []
  513. item.schemeInsuranceList = []
  514. item.drivingList.forEach(sub => {
  515. let obj = {
  516. id: sub.id,
  517. drivingIntentionId: sub.drivingIntentionId,
  518. selectedStatus: sub.selectedStatus,
  519. quantity: sub.quantity
  520. }
  521. item.drivingIntentionList.push(obj)
  522. })
  523. item.tableData.forEach(ins => {
  524. let obj = {
  525. id: ins.id,
  526. insuranceId: ins.insuranceId,
  527. optionId: projectAddFrom.value.schemeType === 1?[ins.moneyId]:projectAddFrom.value.schemeType === 2?ins.moneyId:[]
  528. }
  529. // ins.options.forEach(sub => {
  530. // if(sub.checked) {
  531. // obj.optionId.push(sub.id)
  532. // }
  533. // })
  534. item.schemeInsuranceList.push(obj)
  535. })
  536. })
  537. api.projectApi.saveScheme({...formData}).then(res => {
  538. if(res.code == 200) {
  539. ElMessage({
  540. message: res.msg,
  541. type: 'success'
  542. })
  543. myRouter.push({
  544. path: '/quoteConfig/agreement/project'
  545. })
  546. } else {
  547. ElMessage({
  548. message: res.msg,
  549. type: 'warning'
  550. })
  551. }
  552. })
  553. } else {
  554. ElMessage({
  555. message: '请正确填写相关信息!',
  556. type: 'warning'
  557. })
  558. }
  559. })
  560. }
  561. onMounted(() => {
  562. initInsurance()
  563. initType()
  564. initCompany()
  565. // initAttr()
  566. if(myRoute.query.id) {
  567. isEdit.value = true
  568. projectAddFrom.value.id = myRoute.query.id
  569. initEdit()
  570. } else {
  571. isEdit.value = false
  572. initAttr()
  573. }
  574. // initInsurance()
  575. })
  576. </script>
  577. <style scoped lang="scss">
  578. .projectAdd{
  579. width: 100%;
  580. height: 100%;
  581. background: white;
  582. padding: 20px;
  583. .ruleList{
  584. width: 90%;
  585. .ruleItem{
  586. display: flex;
  587. align-items: center;
  588. justify-content: flex-start;
  589. margin: 10px 0;
  590. }
  591. }
  592. .configuration{
  593. width: 100%;
  594. background: #f0f0f0;
  595. padding: 20px 100px;
  596. margin-bottom: 10px;
  597. border-radius: 5px;
  598. }
  599. .btns{
  600. display: flex;
  601. align-items: center;
  602. justify-content: center;
  603. }
  604. }
  605. </style>