projectAdd.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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'&&scope.row.id=='19' || projectAddFrom.productId == '0330034002'&&scope.row.id=='19' || projectAddFrom.productId == '0330034001'&&scope.row.id=='19'" 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. <el-dialog
  158. v-model="ruleSelectShow"
  159. title="规则条件"
  160. width="600"
  161. >
  162. <ruleSelect ref="RuleSelect" @close="handleRuleSelectClose"></ruleSelect>
  163. </el-dialog>
  164. </div>
  165. </template>
  166. <script setup lang="ts">
  167. import api from "@/api";
  168. import { ElMessage, FormInstance, FormRules } from "element-plus";
  169. import { useRouter, useRoute } from 'vue-router'
  170. import insurance from '../../../../layouts/components/InsuranceType/index.vue'
  171. import driving from '../../../../layouts/components/DrivingType/index.vue'
  172. import rule from '../../../../components/ruleConditionContainer/index.vue'
  173. import detail from '../../../../layouts/components/JYXDetail/index.vue'
  174. import ruleSelect from '../../../../layouts/components/ruleSelect/index.vue'
  175. import Detail from "@/views/representative/detail.vue";
  176. const myRouter = useRouter()
  177. const myRoute = useRoute()
  178. const ProjectAddRef = ref<FormInstance>()
  179. const InsuranceTypeRef = ref(null)
  180. const DrivingTypeRef = ref(null)
  181. const JYXDetail = ref(null)
  182. let RuleSelect = ref()
  183. // 规则条件
  184. let ruleSelectShow = ref(false)
  185. const handleRuleSelectClose = (data) => {
  186. if(data&&data.length>0) {
  187. rulesAttrList.value = data.map(a => {
  188. return {
  189. ...a,
  190. min: a.attrName == '能源类型'? '0':'',
  191. minArray: a.attrName == '使用性质' || a.attrName == '车辆种类'?[a.dictLabal[0].code]:[]
  192. }
  193. })
  194. }
  195. ruleSelectShow.value = false
  196. }
  197. // 是否编辑
  198. let isEdit = ref(false)
  199. let projectAddFrom = ref({
  200. ruleAttrs: [],
  201. schemeType: 1,
  202. schemeList: [{
  203. schemeName: '',
  204. description: '',
  205. tableData: [],
  206. drivingList: [],
  207. schemeInsuranceList: [],
  208. drivingIntentionList: []
  209. }]
  210. })
  211. let projectAddRules = ref<FormRules>({
  212. companyId: [
  213. { required: true, trigger: "change", message: "请选择保险公司" }
  214. ],
  215. schemeType: [
  216. { required: true, trigger: "change", message: "请选择方案类型" }
  217. ],
  218. productId: [
  219. { required: true, trigger: "change", message: "请选择险种类型" }
  220. ]
  221. })
  222. // 驾意险详情
  223. let JYXDetailShow = ref(false)
  224. const getJYXDetail = (row) => {
  225. JYXDetailShow.value = true
  226. nextTick(() => {
  227. JYXDetail.value.initData(row.drivingIntentionId)
  228. })
  229. }
  230. const numberChange = (e, row) => {
  231. if(typeof e != 'number') {
  232. // ElMessage({
  233. // message: '请输入驾意险份数!',
  234. // type: 'warning'
  235. // })
  236. row.quantity = 1
  237. }
  238. }
  239. // 新增的时候初始化已有的方案
  240. const initProduct = (e) => {
  241. // energyType 能源类型
  242. // vehicleType 车辆种类
  243. // carnature 使用性质
  244. let energyType = null, vehicleType = null, carnature = null
  245. if(rulesAttrList.value && rulesAttrList.value.length > 0) {
  246. energyType = rulesAttrList.value.find(a => a.attrName === '能源类型')
  247. vehicleType = rulesAttrList.value.find(a => a.attrName === '车辆种类')
  248. carnature = rulesAttrList.value.find(a => a.attrName === '使用性质')
  249. }
  250. // initAttr()
  251. if(e == '0330' || e == '0330034001') {
  252. let obj = insuranceTypeList.value.filter(item => item.id == '19')
  253. if(obj) {
  254. obj.forEach(item => {
  255. item.insuranceId = item.id
  256. if(item.id == '19') {
  257. item.moneyId = item.options[0].id
  258. }
  259. })
  260. projectAddFrom.value.schemeList.forEach(item => {
  261. item.schemeName = ''
  262. item.description = ''
  263. item.drivingList = []
  264. item.tableData = [...obj]
  265. })
  266. }
  267. } else if(e == '034002') {
  268. let obj = insuranceTypeList.value.find(item => item.id == '2')
  269. obj.insuranceId = obj.id
  270. projectAddFrom.value.schemeList.forEach(item => {
  271. item.schemeName = ''
  272. item.description = ''
  273. item.drivingList = []
  274. item.tableData = [obj]
  275. })
  276. } else if(e == '0330034002') {
  277. let obj = insuranceTypeList.value.filter(item => item.id == '2' || item.id == '19')
  278. if(obj) {
  279. obj.forEach(item => {
  280. item.insuranceId = item.id
  281. if(item.id == '19') {
  282. item.moneyId = item.options[0].id
  283. }
  284. })
  285. projectAddFrom.value.schemeList.forEach(item => {
  286. item.schemeName = ''
  287. item.description = ''
  288. item.drivingList = []
  289. item.tableData = [...obj]
  290. })
  291. }
  292. } else {
  293. projectAddFrom.value.schemeList.forEach(item => {
  294. item.schemeName = ''
  295. item.description = ''
  296. item.drivingList = []
  297. item.tableData = []
  298. })
  299. }
  300. if(projectAddFrom.value.companyId&&projectAddFrom.value.productId&&projectAddFrom.value.schemeType) {
  301. console.log('选项123', energyType)
  302. api.projectApi.getSchemeByCompany({
  303. companyId: projectAddFrom.value.companyId,
  304. productId: projectAddFrom.value.productId,
  305. schemeType: projectAddFrom.value.schemeType,
  306. energyType: energyType.min,
  307. vehicleType: vehicleType.minArray.join(','),
  308. carnature: carnature.minArray.join(','),
  309. }).then(res => {
  310. if(res.code == 200) {
  311. if(res.data && res.data.schemeList.length > 0) {
  312. res.data.schemeList.forEach(item => {
  313. item.drivingList = item.drivingIntentionList
  314. item.tableData = item.schemeInsuranceList.map(sub => {
  315. let obj = insuranceTypeList.value.find(a => a.id === sub.insuranceId)
  316. return {
  317. ...sub,
  318. optionId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  319. moneyId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  320. options: obj.options
  321. }
  322. })
  323. })
  324. projectAddFrom.value = res.data
  325. rulesAttrList.value = res.data.ruleAttrs
  326. }
  327. } else {
  328. // projectAddFrom.value.ruleAttrs = []
  329. // if(e == '0330' || e == '0330034002' || e == '0330034001') {
  330. // let obj = insuranceTypeList.value.find(a => a.alias == '交强险')
  331. // if(obj) {
  332. // obj.insuranceId = obj.id
  333. // let sub = obj.options.find(b => b.label == '投保')
  334. // obj.optionId = projectAddFrom.value.schemeType==1?sub?.id:projectAddFrom.value.schemeType==2?[sub?.id]:''
  335. // obj.moneyId = sub?.id
  336. // }
  337. // projectAddFrom.value.schemeList = [{
  338. // schemeName: '',
  339. // description: '',
  340. // tableData: [obj],
  341. // drivingList: [],
  342. // schemeInsuranceList: [obj],
  343. // drivingIntentionList: []
  344. // }]
  345. // } else {
  346. // projectAddFrom.value.schemeList = [{
  347. // schemeName: '',
  348. // description: '',
  349. // tableData: [],
  350. // drivingList: [],
  351. // schemeInsuranceList: [],
  352. // drivingIntentionList: []
  353. // }]
  354. // }
  355. // ElMessage({
  356. // message: res.msg,
  357. // type: 'warning'
  358. // })
  359. }
  360. })
  361. }
  362. }
  363. // 险种
  364. let insuranceTypeList = ref([])
  365. const initInsurance = () => {
  366. api.projectApi.getBusinessInsurance().then(res => {
  367. if(res.code == 200) {
  368. // res.data.forEach(item => {
  369. // item.options.forEach(sub => {
  370. // sub.id = sub.value
  371. // })
  372. // })
  373. insuranceTypeList.value = res.data
  374. if(projectAddFrom.value.productId == '0330' || projectAddFrom.value.productId == '0330034001') {
  375. let obj = insuranceTypeList.value.filter(item => item.id == '19')
  376. if(obj) {
  377. obj.forEach(item => {
  378. item.insuranceId = item.id
  379. if(item.id == '19') {
  380. item.moneyId = item.options[0].id
  381. }
  382. })
  383. projectAddFrom.value.schemeList.forEach(item => {
  384. item.drivingList = []
  385. item.tableData = [...obj]
  386. })
  387. }
  388. } else if(projectAddFrom.value.productId == '034002') {
  389. let obj = insuranceTypeList.value.find(item => item.id == '2')
  390. obj.insuranceId = obj.id
  391. projectAddFrom.value.schemeList.forEach(item => {
  392. item.drivingList = []
  393. item.tableData = [obj]
  394. })
  395. } else if(projectAddFrom.value.productId == '0330034002') {
  396. let obj = insuranceTypeList.value.filter(item => item.id == '2' || item.id == '19')
  397. if(obj) {
  398. obj.forEach(item => {
  399. item.insuranceId = item.id
  400. if(item.id == '19') {
  401. item.moneyId = item.options[0].id
  402. }
  403. })
  404. projectAddFrom.value.schemeList.forEach(item => {
  405. item.drivingList = []
  406. item.tableData = [...obj]
  407. })
  408. }
  409. } else {
  410. projectAddFrom.value.schemeList.forEach(item => {
  411. item.drivingList = []
  412. item.tableData = []
  413. })
  414. }
  415. } else {
  416. ElMessage({
  417. message: res.msg,
  418. type: 'warning'
  419. })
  420. }
  421. })
  422. }
  423. // 方案类型切换
  424. const schemeTypeChange = (e) => {
  425. initProduct(projectAddFrom.value.productId)
  426. }
  427. // 保险公司
  428. let companyOption = ref([])
  429. const initCompany = () => {
  430. // api.projectApi.getCompanyList().then(res => {
  431. api.insuranceApi.leftList('').then(res => {
  432. if(res.code == 200) {
  433. companyOption.value = res.data
  434. } else {
  435. ElMessage({
  436. message: res.msg,
  437. type: 'warning'
  438. })
  439. }
  440. })
  441. }
  442. // 新增方案
  443. const addProject = () => {
  444. projectAddFrom.value.schemeList.push({
  445. schemeName: '',
  446. description: '',
  447. tableData: [],
  448. drivingList: [],
  449. schemeInsuranceList: [],
  450. drivingIntentionList: []
  451. })
  452. }
  453. // 规则
  454. let rulesShow = ref(false)
  455. const addRules = () => {
  456. ruleSelectShow.value = true
  457. nextTick(() => {
  458. RuleSelect.value.initEditData(rulesAttrList.value)
  459. })
  460. }
  461. let rulesAttrList = ref([])
  462. let defaultAttrList = ref([])
  463. // const saveRule = (data) => {
  464. // console.log(123123123, data)
  465. // if(data && data.length > 0) {
  466. // rulesAttrList.value = data
  467. // }
  468. // rulesShow.value = false
  469. // }
  470. const cancelRule = (data) => {
  471. rulesShow.value = false
  472. }
  473. const handleDel = (index) => {
  474. if(rulesAttrList.value[index].attrName === '能源类型' || rulesAttrList.value[index].attrName === '使用性质' || rulesAttrList.value[index].attrName === '车辆种类') {
  475. return
  476. } else {
  477. rulesAttrList.value.splice(index, 1)
  478. }
  479. }
  480. // 险种类型
  481. let insuranceType = ref([])
  482. const initType = () => {
  483. api.commonApi.personInfo('insurance_type').then(res => {
  484. if(res.code == 200) {
  485. insuranceType.value = res.data
  486. projectAddFrom.value.productId = insuranceType.value[0].value
  487. } else {
  488. ElMessage({
  489. message: res.msg,
  490. type: 'warning'
  491. })
  492. }
  493. })
  494. }
  495. // 险种
  496. let insuranceShow = ref(false)
  497. // let insuranceList = ref([])
  498. // let checkInsuranceList = ref([])
  499. // let checkSubInsuranceList = ref([])
  500. const handleClose = ( obj ) => {
  501. if(obj.list && obj.list.length > 0) {
  502. if(projectAddFrom.value.schemeType === 2) {
  503. obj.list.forEach(a => {
  504. a.optionId = []
  505. a.options.forEach(b => {
  506. if(b.checked) {
  507. a.optionId.push(b.id)
  508. }
  509. })
  510. a.moneyId = a.optionId
  511. })
  512. } else {
  513. obj.list.forEach(a => {
  514. a.optionId = a.options.find(b => b.checked)?.id
  515. a.moneyId = a.optionId
  516. })
  517. }
  518. projectAddFrom.value.schemeList[obj.index].tableData = obj.list
  519. }
  520. insuranceShow.value = false
  521. }
  522. // 险种删除
  523. const insuranceTypeDel = (item, row) => {
  524. let data = item.tableData.filter(a => a.insuranceId != row.insuranceId)
  525. item.tableData = [...data]
  526. }
  527. // 驾意险
  528. let drivingShow = ref(false)
  529. const handleDriving = (item, index) => {
  530. drivingShow.value = true
  531. nextTick(() => {
  532. DrivingTypeRef.value.initEditData(item.drivingList, index, myRoute.query.companyId)
  533. })
  534. }
  535. const handleDrivingClose = ( obj ) => {
  536. if(obj.list && obj.list.length > 0) {
  537. // let selectList = obj.list.filter(a => a.checked)
  538. obj.list.forEach(sub => {
  539. sub.drivingIntentionId = sub.drivingIntentionId
  540. sub.selectedStatus = sub.selectedStatus?sub.selectedStatus:'1'
  541. sub.quantity = sub.quantity?sub.quantity:'1'
  542. })
  543. projectAddFrom.value.schemeList[obj.index].drivingList = obj.list
  544. }
  545. drivingShow.value = false
  546. }
  547. const drivingTypeDel = (item, row) => {
  548. let data = item.drivingList.filter(a => a.id != row.id)
  549. item.drivingList = [...data]
  550. }
  551. const handlePopover = (item, index) => {
  552. insuranceShow.value = true
  553. nextTick(() => {
  554. InsuranceTypeRef.value.initEditData(item.tableData, index, projectAddFrom.value.schemeType)
  555. })
  556. }
  557. // 规则
  558. const initAttr = () => {
  559. api.agreementApi.ruleAttrGroup({ attrName: '' }).then(res => {
  560. if(res.code == 200) {
  561. let list = res.data?.VehicleInformation?.filter(e => e.attrName === '能源类型' || e.attrName === '使用性质' || e.attrName === '车辆种类')
  562. rulesAttrList.value = list?.map(a => {
  563. return {
  564. ...a,
  565. min: a.attrName == '能源类型'? '0':'',
  566. minArray: a.minArray?a.minArray:a.attrName == '使用性质' || a.attrName == '车辆种类'?[a.dictLabal[0].code]:[]
  567. }
  568. })
  569. defaultAttrList.value = [...list]
  570. } else {
  571. ElMessage({
  572. message: res.msg,
  573. type: 'warning'
  574. })
  575. }
  576. })
  577. }
  578. // 编辑
  579. const initEdit = () => {
  580. api.projectApi.getScheme(myRoute.query.id).then(res => {
  581. if(res.code == 200) {
  582. if(res.data && res.data.schemeList.length > 0) {
  583. res.data.schemeList.forEach(item => {
  584. item.drivingList = item.drivingIntentionList
  585. item.tableData = item.schemeInsuranceList.map(sub => {
  586. let obj = insuranceTypeList.value.find(a => a.id === sub.insuranceId)
  587. return {
  588. ...sub,
  589. optionId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  590. moneyId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
  591. options: obj.options
  592. }
  593. })
  594. })
  595. projectAddFrom.value = res.data
  596. rulesAttrList.value = res.data.ruleAttrs
  597. }
  598. } else {
  599. ElMessage({
  600. message: res.msg,
  601. type: 'warning'
  602. })
  603. }
  604. })
  605. }
  606. // 取消
  607. const quit = () => {
  608. myRouter.push({
  609. path: '/quoteConfig/agreement/project'
  610. })
  611. }
  612. // 保存
  613. const save = async (ProjectAddRef: FormInstance | undefined) => {
  614. if(!ProjectAddRef) {
  615. ProjectAddRef.resetFields()
  616. return
  617. }
  618. await ProjectAddRef.validate((valid) => {
  619. if(valid) {
  620. let formData = {...projectAddFrom.value}
  621. formData.ruleAttrs = [...rulesAttrList.value]
  622. formData.schemeList.forEach(item => {
  623. item.drivingIntentionList = []
  624. item.schemeInsuranceList = []
  625. item.drivingList.forEach(sub => {
  626. let obj = {
  627. id: sub.id,
  628. drivingIntentionId: sub.drivingIntentionId,
  629. selectedStatus: sub.selectedStatus,
  630. quantity: sub.quantity
  631. }
  632. item.drivingIntentionList.push(obj)
  633. })
  634. item.tableData.forEach(ins => {
  635. let obj = {
  636. id: ins.id,
  637. insuranceId: ins.insuranceId,
  638. optionId: projectAddFrom.value.schemeType === 1?[ins.moneyId]:projectAddFrom.value.schemeType === 2?ins.moneyId:[]
  639. }
  640. // ins.options.forEach(sub => {
  641. // if(sub.checked) {
  642. // obj.optionId.push(sub.id)
  643. // }
  644. // })
  645. item.schemeInsuranceList.push(obj)
  646. })
  647. })
  648. api.projectApi.saveScheme({...formData}).then(res => {
  649. if(res.code == 200) {
  650. ElMessage({
  651. message: res.msg,
  652. type: 'success'
  653. })
  654. myRouter.push({
  655. path: '/quoteConfig/agreement/project'
  656. })
  657. } else if(res.code != 400) {
  658. ElMessage({
  659. message: res.msg,
  660. type: 'warning'
  661. })
  662. }
  663. })
  664. } else {
  665. ElMessage({
  666. message: '请正确填写相关信息!',
  667. type: 'warning'
  668. })
  669. }
  670. })
  671. }
  672. onMounted(() => {
  673. initInsurance()
  674. initType()
  675. initCompany()
  676. projectAddFrom.value.companyId = myRoute.query.companyId
  677. // initAttr()
  678. if(myRoute.query.id) {
  679. isEdit.value = true
  680. projectAddFrom.value.id = myRoute.query.id
  681. initEdit()
  682. } else {
  683. isEdit.value = false
  684. initAttr()
  685. }
  686. // initInsurance()
  687. })
  688. </script>
  689. <style scoped lang="scss">
  690. .projectAdd{
  691. width: 100%;
  692. height: 100%;
  693. background: white;
  694. padding: 20px;
  695. .ruleList{
  696. width: 90%;
  697. .ruleItem{
  698. display: flex;
  699. align-items: center;
  700. justify-content: flex-start;
  701. margin: 10px 0;
  702. }
  703. }
  704. .configuration{
  705. width: 100%;
  706. background: #f0f0f0;
  707. padding: 20px 100px;
  708. margin-bottom: 10px;
  709. border-radius: 5px;
  710. }
  711. .btns{
  712. display: flex;
  713. align-items: center;
  714. justify-content: center;
  715. }
  716. }
  717. </style>