projectAdd.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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. <a>{{ scope.row.productName }}</a>
  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 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 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 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. </div>
  151. </template>
  152. <script setup lang="ts">
  153. import api from "@/api";
  154. import { ElMessage, FormInstance, FormRules } from "element-plus";
  155. import { useRouter, useRoute } from 'vue-router'
  156. import insurance from '../../../../layouts/components/InsuranceType/index.vue'
  157. import driving from '../../../../layouts/components/DrivingType/index.vue'
  158. import rule from '../../../../components/ruleConditionContainer/index.vue'
  159. const myRouter = useRouter()
  160. const myRoute = useRoute()
  161. const ProjectAddRef = ref<FormInstance>()
  162. const InsuranceTypeRef = ref(null)
  163. const DrivingTypeRef = ref(null)
  164. // 是否编辑
  165. let isEdit = ref(false)
  166. let projectAddFrom = ref({
  167. ruleAttrs: [],
  168. schemeList: [{
  169. schemeName: '',
  170. description: '',
  171. tableData: [],
  172. drivingList: [],
  173. schemeInsuranceList: [],
  174. drivingIntentionList: []
  175. }]
  176. })
  177. let projectAddRules = ref<FormRules>({
  178. companyId: [
  179. { required: true, trigger: "change", message: "请选择保险公司" }
  180. ],
  181. schemeType: [
  182. { required: true, trigger: "change", message: "请选择方案类型" }
  183. ],
  184. productId: [
  185. { required: true, trigger: "change", message: "请选择险种类型" }
  186. ]
  187. })
  188. // 新增的时候初始化已有的方案
  189. const initProduct = () => {
  190. api.projectApi.getSchemeByCompany({
  191. companyId: projectAddFrom.value.companyId,
  192. productId: projectAddFrom.value.productId,
  193. schemeType: projectAddFrom.value.schemeType
  194. }).then(res => {
  195. if(res.code == 200) {
  196. if(res.data && res.data.schemeList.length > 0) {
  197. res.data.schemeList.forEach(item => {
  198. item.drivingList = item.drivingIntentionList
  199. item.tableData = item.schemeInsuranceList.map(sub => {
  200. let obj = insuranceTypeList.value.find(a => a.id === sub.insuranceId)
  201. return {
  202. ...sub,
  203. optionId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  204. moneyId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  205. options: obj.options
  206. }
  207. })
  208. })
  209. projectAddFrom.value = res.data
  210. rulesAttrList.value = res.data.ruleAttrs
  211. }
  212. } else {
  213. projectAddFrom.value.ruleAttrs = []
  214. projectAddFrom.value.schemeList = [{
  215. schemeName: '',
  216. description: '',
  217. tableData: [],
  218. drivingList: [],
  219. schemeInsuranceList: [],
  220. drivingIntentionList: []
  221. }]
  222. ElMessage({
  223. message: res.msg,
  224. type: 'warning'
  225. })
  226. }
  227. })
  228. }
  229. // 险种
  230. let insuranceTypeList = ref([])
  231. const initInsurance = () => {
  232. api.projectApi.getBusinessInsurance().then(res => {
  233. if(res.code == 200) {
  234. // res.data.forEach(item => {
  235. // item.options.forEach(sub => {
  236. // sub.id = sub.value
  237. // })
  238. // })
  239. insuranceTypeList.value = res.data
  240. } else {
  241. ElMessage({
  242. message: res.msg,
  243. type: 'warning'
  244. })
  245. }
  246. })
  247. }
  248. // 方案类型切换
  249. const schemeTypeChange = (e) => {
  250. projectAddFrom.value.ruleAttrs = []
  251. projectAddFrom.value.schemeList = [{
  252. schemeName: '',
  253. description: '',
  254. tableData: [],
  255. drivingList: [],
  256. schemeInsuranceList: [],
  257. drivingIntentionList: []
  258. }]
  259. initProduct()
  260. // rulesAttrList.value = defaultAttrList.value
  261. }
  262. // 保险公司
  263. let companyOption = ref([])
  264. const initCompany = () => {
  265. api.projectApi.getCompanyList().then(res => {
  266. if(res.code == 200) {
  267. companyOption.value = res.data
  268. } else {
  269. ElMessage({
  270. message: res.msg,
  271. type: 'warning'
  272. })
  273. }
  274. })
  275. }
  276. // 新增方案
  277. const addProject = () => {
  278. projectAddFrom.value.schemeList.push({
  279. schemeName: '',
  280. description: '',
  281. tableData: [],
  282. drivingList: [],
  283. schemeInsuranceList: [],
  284. drivingIntentionList: []
  285. })
  286. }
  287. // 规则
  288. let rulesShow = ref(false)
  289. const addRules = () => {
  290. rulesShow.value = true
  291. }
  292. let rulesAttrList = ref([])
  293. let defaultAttrList = ref([])
  294. const saveRule = (data) => {
  295. if(data && data.length > 0) {
  296. rulesAttrList.value = data
  297. }
  298. rulesShow.value = false
  299. }
  300. // 险种类型
  301. let insuranceType = ref([])
  302. const initType = () => {
  303. api.commonApi.personInfo('insurance_type').then(res => {
  304. if(res.code == 200) {
  305. insuranceType.value = res.data
  306. projectAddFrom.value.productId = insuranceType.value[0].value
  307. } else {
  308. ElMessage({
  309. message: res.msg,
  310. type: 'warning'
  311. })
  312. }
  313. })
  314. }
  315. // 险种
  316. let insuranceShow = ref(false)
  317. // let insuranceList = ref([])
  318. // let checkInsuranceList = ref([])
  319. // let checkSubInsuranceList = ref([])
  320. const handleClose = ( obj ) => {
  321. if(obj.list && obj.list.length > 0) {
  322. if(projectAddFrom.value.schemeType === 2) {
  323. obj.list.forEach(a => {
  324. a.optionId = []
  325. a.options.forEach(b => {
  326. if(b.checked) {
  327. a.optionId.push(b.id)
  328. }
  329. })
  330. a.moneyId = a.optionId
  331. })
  332. } else {
  333. obj.list.forEach(a => {
  334. a.optionId = a.options.find(b => b.checked)?.id
  335. a.moneyId = a.optionId
  336. })
  337. }
  338. projectAddFrom.value.schemeList[obj.index].tableData = obj.list
  339. }
  340. insuranceShow.value = false
  341. }
  342. // 险种删除
  343. const insuranceTypeDel = (item, row) => {
  344. let data = item.tableData.filter(a => a.id != row.id)
  345. item.tableData = [...data]
  346. }
  347. // 驾意险
  348. let drivingShow = ref(false)
  349. const handleDriving = (item, index) => {
  350. drivingShow.value = true
  351. nextTick(() => {
  352. DrivingTypeRef.value.initEditData(item.drivingList, index)
  353. })
  354. }
  355. const handleDrivingClose = ( obj ) => {
  356. if(obj.list && obj.list.length > 0) {
  357. let selectList = obj.list.filter(a => a.checked)
  358. selectList.forEach(sub => {
  359. sub.drivingIntentionId = sub.drivingIntentionId
  360. sub.selectedStatus = sub.selectedStatus?sub.selectedStatus:'1'
  361. sub.quantity = sub.quantity?sub.quantity:'1'
  362. })
  363. projectAddFrom.value.schemeList[obj.index].drivingList = selectList
  364. }
  365. drivingShow.value = false
  366. }
  367. const drivingTypeDel = (item, row) => {
  368. let data = item.drivingList.filter(a => a.id != row.id)
  369. item.drivingList = [...data]
  370. }
  371. const handlePopover = (item, index) => {
  372. insuranceShow.value = true
  373. nextTick(() => {
  374. InsuranceTypeRef.value.initEditData(item.tableData, index, projectAddFrom.value.schemeType)
  375. })
  376. }
  377. // 规则
  378. const initAttr = () => {
  379. api.agreementApi.ruleAttrGroup({ attrName: '' }).then(res => {
  380. if(res.code == 200) {
  381. let list = res.data?.VehicleInformation?.filter(e => e.attrName === '能源类型' || e.attrName === '使用性质' || e.attrName === '车辆类型')
  382. rulesAttrList.value = [...list]
  383. defaultAttrList.value = [...list]
  384. } else {
  385. ElMessage({
  386. message: res.msg,
  387. type: 'warning'
  388. })
  389. }
  390. })
  391. }
  392. // 编辑
  393. const initEdit = () => {
  394. api.projectApi.getScheme(myRoute.query.id).then(res => {
  395. if(res.code == 200) {
  396. if(res.data && res.data.schemeList.length > 0) {
  397. res.data.schemeList.forEach(item => {
  398. item.drivingList = item.drivingIntentionList
  399. item.tableData = item.schemeInsuranceList.map(sub => {
  400. let obj = insuranceTypeList.value.find(a => a.id === sub.insuranceId)
  401. return {
  402. ...sub,
  403. optionId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  404. moneyId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  405. options: obj.options
  406. }
  407. })
  408. })
  409. projectAddFrom.value = res.data
  410. rulesAttrList.value = res.data.ruleAttrs
  411. }
  412. } else {
  413. ElMessage({
  414. message: res.msg,
  415. type: 'warning'
  416. })
  417. }
  418. })
  419. }
  420. // 取消
  421. const quit = () => {
  422. myRouter.push({
  423. path: '/quoteConfig/agreement/project'
  424. })
  425. }
  426. // 保存
  427. const save = async (ProjectAddRef: FormInstance | undefined) => {
  428. if(!ProjectAddRef) {
  429. ProjectAddRef.resetFields()
  430. return
  431. }
  432. await ProjectAddRef.validate((valid) => {
  433. if(valid) {
  434. let formData = {...projectAddFrom.value}
  435. formData.ruleAttrs = [...rulesAttrList.value]
  436. formData.schemeList.forEach(item => {
  437. item.drivingIntentionList = []
  438. item.schemeInsuranceList = []
  439. item.drivingList.forEach(sub => {
  440. let obj = {
  441. id: sub.id,
  442. drivingIntentionId: sub.drivingIntentionId,
  443. selectedStatus: sub.selectedStatus,
  444. quantity: sub.quantity
  445. }
  446. item.drivingIntentionList.push(obj)
  447. })
  448. item.tableData.forEach(ins => {
  449. let obj = {
  450. id: ins.id,
  451. insuranceId: ins.insuranceId,
  452. optionId: projectAddFrom.value.schemeType === 1?[ins.moneyId]:projectAddFrom.value.schemeType === 2?ins.moneyId:[]
  453. }
  454. // ins.options.forEach(sub => {
  455. // if(sub.checked) {
  456. // obj.optionId.push(sub.id)
  457. // }
  458. // })
  459. item.schemeInsuranceList.push(obj)
  460. })
  461. })
  462. api.projectApi.saveScheme({...formData}).then(res => {
  463. if(res.code == 200) {
  464. ElMessage({
  465. message: res.msg,
  466. type: 'success'
  467. })
  468. myRouter.push({
  469. path: '/quoteConfig/agreement/project'
  470. })
  471. } else {
  472. ElMessage({
  473. message: res.msg,
  474. type: 'warning'
  475. })
  476. }
  477. })
  478. } else {
  479. ElMessage({
  480. message: '请正确填写相关信息!',
  481. type: 'warning'
  482. })
  483. }
  484. })
  485. }
  486. onMounted(() => {
  487. initInsurance()
  488. initType()
  489. initCompany()
  490. // initAttr()
  491. if(myRoute.query.id) {
  492. isEdit.value = true
  493. initEdit()
  494. } else {
  495. isEdit.value = false
  496. initAttr()
  497. }
  498. // initInsurance()
  499. })
  500. </script>
  501. <style scoped lang="scss">
  502. .projectAdd{
  503. width: 100%;
  504. height: 100%;
  505. background: white;
  506. padding: 20px;
  507. .ruleList{
  508. width: 90%;
  509. .ruleItem{
  510. display: flex;
  511. align-items: center;
  512. justify-content: flex-start;
  513. margin: 10px 0;
  514. }
  515. }
  516. .configuration{
  517. width: 100%;
  518. background: #f0f0f0;
  519. padding: 20px 100px;
  520. margin-bottom: 10px;
  521. border-radius: 5px;
  522. }
  523. .btns{
  524. display: flex;
  525. align-items: center;
  526. justify-content: center;
  527. }
  528. }
  529. </style>