Forráskód Böngészése

fix: 报价配置-方案管理功能调整

wuguojie 1 éve
szülő
commit
b3ae826f3e

+ 10 - 2
src/api/modules/project.ts

@@ -1,4 +1,5 @@
 import { ApiInstance } from '../type'
+import {LocationQueryValue} from "vue-router";
 
 export interface GetSchemeList {
   pages: number,
@@ -10,11 +11,18 @@ export interface GetSchemeList {
 }
 
 const projectApi = (axiosInstance: ApiInstance) => ({
-  getBusinessInsurance: () => axiosInstance.get('/scheme/getBusinessInsurance'),
-  getScheme: () => axiosInstance.get('/scheme/getScheme'),
+  getBusinessInsurance: () => axiosInstance.get('/scheme/getBusinessInsurance'), // 险种
+  getScheme: (data: string | null | LocationQueryValue[]) => axiosInstance.get(`/scheme/getScheme?id=${data}`), // 详情
   getSchemeList: (data: GetSchemeList) => axiosInstance.post('/scheme/getSchemeList', data), // 险种
   jyxList: (data: { company: string }) => axiosInstance.post('/jyxConfig/jyxList', data), // 驾意险
   saveScheme: (data: any) => axiosInstance.post('/scheme/saveScheme', data), // 保存方案
+  deleteScheme: (data: { id: string }) => axiosInstance.post('/scheme/deleteScheme', data), // 删除
+  getSchemeByCompany: (data: {
+    companyId: string,
+    productId: string,
+    schemeType: string
+  }) => axiosInstance.get(`/scheme/getSchemeByCompany?companyId=${data.companyId}&productId=${data.productId}&schemeType=${data.schemeType}`), // 新增时如果有方案获取对应方案
+  getCompanyList:() => axiosInstance.get('/scheme/getCompanyList')
 })
 
 export default projectApi

+ 1 - 1
src/components/ruleCondition/index.vue

@@ -75,7 +75,7 @@ const close = () => {
   emits("cancel")
 }
 watch(props, () => {
-  if (props.attrIdList.length) {
+  if (props.attrIdList?.length) {
     attractivelist.value = props.attrIdList;//获取编辑数据
     const matchedid = matchDataByIds(attractivelist.value);//
     const matchedinfo=matchDataByInfos(attractivelist.value)

+ 3 - 0
src/components/ruleConditionContainer/index.vue

@@ -129,6 +129,9 @@ const change = (e: string[] | undefined, index: number) => {
   console.log(e)
   emits('selectChange', { e, index })
 }
+onMounted(() => {
+  console.log('规则数据', props.rulesAttrList)
+})
 </script>
 <!-- 样式区域 -->
 <style lang='scss' scoped>

+ 69 - 42
src/layouts/components/DrivingType/index.vue

@@ -3,15 +3,15 @@
     <el-row :gutter="20" style="height: calc(100% - 30px); border: 1px solid #ccc; margin: 5px; border-radius: 5px; padding: 5px">
       <el-col :span="12">
         <el-input v-model="searchName" placeholder="输入驾意险名称查找" style="margin-bottom: 10px">
-          <template #append>
+<!--          <template #append>
             <el-button type="primary" @click="handleSearchName">查找</el-button>
-          </template>
+          </template>-->
         </el-input>
 <!--        <el-checkbox-group v-model="item.drivingIntentionId">
           <el-checkbox style="display: block;" v-for="JYX in JYXList" :key="JYX.id" :value="JYX.id" :label="JYX.productName"></el-checkbox>
         </el-checkbox-group>-->
         <div class="insuranceLeft">
-          <div class="insuranceItem" v-for="(item, index) in JYXList" @click="handleType(item, index)">
+          <div class="insuranceItem" v-for="(item, index) in handleSearchName" @click="handleType(item, index)">
           <span class="checkIcon" :class="{ 'active': item.checked }">
             <el-icon><Select /></el-icon>
           </span>
@@ -49,31 +49,31 @@ import api from "@/api";
 import {ElMessage} from "element-plus";
 
 let searchName = ref('')
-const handleSearchName = () => {
-
-}
+const handleSearchName = computed(() => {
+  return JYXList.value.filter(a => a.productName.includes(searchName.value))
+})
 
 // 驾意险
 let JYXList = ref([])
-const initJYX = () => {
-  api.projectApi.jyxList({
-    company: '173881173559933834'
-  }).then(res => {
-    if(res.code == 200) {
-      if(res.data && res.data.len > 0) {
-        res.data.forEach(item => {
-          item.checked = false
-        })
-      }
-      JYXList.value = res.data
-    } else {
-      ElMessage({
-        message: res.msg,
-        type: 'warning'
-      })
-    }
-  })
-}
+// const initJYX = () => {
+//   api.projectApi.jyxList({
+//     company: '173881173559933834'
+//   }).then(res => {
+//     if(res.code == 200) {
+//       if(res.data && res.data.length > 0) {
+//         res.data.forEach(item => {
+//           item.checked = false
+//         })
+//       }
+//       JYXList.value = res.data
+//     } else {
+//       ElMessage({
+//         message: res.msg,
+//         type: 'warning'
+//       })
+//     }
+//   })
+// }
 
 // 选择驾意险
 let selectedList = ref([])
@@ -97,34 +97,61 @@ const handleDel = (item, index) => {
 }
 
 // 编辑
-const initEditData = (data) => {
-  JYXList.value.forEach(item => {
-    item.checked = false
+let editIndex = ref(0)
+const initEditData = (data, index) => {
+  editIndex.value = index
+  // JYXList.value.forEach(item => {
+  //   item.checked = false
+  // })
+  // let list = [...JYXList.value]
+  api.projectApi.jyxList({
+    company: '173881173559933834'
+  }).then(res => {
+    if(res.code == 200) {
+      if(res.data && res.data.length > 0) {
+        res.data.forEach(item => {
+          item.checked = false
+          item.drivingIntentionId = item.id
+          item.id = ''
+        })
+      }
+      JYXList.value = res.data
+      if(data && data.length > 0) {
+        data.forEach(item => {
+          item.checked = true
+        })
+        JYXList.value = res.data.map(a => {
+          let obj = data.find(b => b.drivingIntentionId === a.drivingIntentionId)
+          return obj || a
+        })
+        selectedList.value = JYXList.value.filter(a => a.checked)
+      }
+    } else {
+      ElMessage({
+        message: res.msg,
+        type: 'warning'
+      })
+    }
   })
-  let list = [...JYXList.value]
-  if(data && data.length > 0) {
-    data.forEach(item => {
-      item.checked = true
-    })
-    JYXList.value = list.map(a => {
-      let obj = data.find(b => b.id === a.id)
-      return obj || a
-    })
-    selectedList.value = JYXList.value.filter(a => a.checked)
-  }
 }
 
 // 取消
 const handleCancel = () => {
-  emits('close', [])
+  emits('close', {
+    list: [],
+    index: editIndex.value
+  })
 }
 // 保存
 const handleConfirm = () => {
-  emits('close', JYXList.value)
+  emits('close', {
+    list: JYXList.value,
+    index: editIndex.value
+  })
 }
 
 onMounted(() => {
-  initJYX()
+  // initJYX()
 })
 
 defineExpose({

+ 85 - 52
src/layouts/components/InsuranceType/index.vue

@@ -12,7 +12,7 @@
         </div>
       </div>
       <el-divider direction="vertical" style="height: 100%;"></el-divider>
-      <div class="insuranceRight" v-show="choiceItem.id === item.id" v-for="(item, index) in insuranceTypeList">
+      <div class="insuranceRight" v-show="choiceItem.insuranceId === item.insuranceId" v-for="(item, index) in insuranceTypeList">
         <p class="account" :class="{'active': sub.checked}" v-for="sub in item.options" @click="handleSubType(item, sub, index)">{{ sub.label }}</p>
       </div>
     </div>
@@ -52,85 +52,118 @@ const defineStyle = {
   height: `${props.height}px`
 }
 
+// 方案类型
+let insuranceType = ref(null)
+
 // 当前选择的险种
 let choiceItem = ref({})
 // 初始化险种数据
 let insuranceTypeList = ref([])
 let typeList = ref([])
-const initInsurance = () => {
-  api.projectApi.getBusinessInsurance().then(res => {
-    if(res.code == 200) {
-      if(res.data&&res.data.length>0) {
-        choiceItem.value = res.data[0]
-        res.data.forEach(item => {
-          item.checked = false
-          item.options.forEach(sub => {
-            sub.checked = false
-          })
-        })
-        insuranceTypeList.value = JSON.parse(JSON.stringify(res.data))
-        typeList.value = JSON.parse(JSON.stringify(res.data))
-      }
-    } else {
-      ElMessage({
-        message: res.msg,
-        type: 'warning'
-      })
-    }
-  })
-}
+// const initInsurance = () => {
+//   api.projectApi.getBusinessInsurance().then(res => {
+//     if(res.code == 200) {
+//       if(res.data&&res.data.length>0) {
+//         choiceItem.value = res.data[0]
+//         res.data.forEach(item => {
+//           item.checked = false
+//           item.options.forEach(sub => {
+//             sub.checked = false
+//           })
+//         })
+//         insuranceTypeList.value = JSON.parse(JSON.stringify(res.data))
+//         typeList.value = JSON.parse(JSON.stringify(res.data))
+//       }
+//     } else {
+//       ElMessage({
+//         message: res.msg,
+//         type: 'warning'
+//       })
+//     }
+//   })
+// }
 // 险种选择
 const handleType = (item, index) => {
   choiceItem.value = item
 }
 // 投保金额选择
 const handleSubType =( item, sub, index) => {
-  item.options.forEach(a => {
-    a.checked = false
-  })
-  sub.checked = true
-  item.checked = true
+  if(insuranceType.value === 1) {
+    item.options.forEach(a => {
+      a.checked = false
+    })
+    sub.checked = true
+    item.checked = true
+  } else {
+    sub.checked = !sub.checked
+    let bool = item.options.some(a => a.checked)
+    item.checked = bool
+  }
 }
 
 // 取消
 const handleCancel = () => {
-  emits('close', [])
+  emits('close', {
+    list: [],
+    index: editIndex.value
+  })
 }
 // 保存
 const handleConfirm = () => {
   let list = [...insuranceTypeList.value]
   let checkedList = list.filter(a => a.checked)
-  emits('close', checkedList)
+  emits('close', {
+    list: checkedList,
+    index: editIndex.value
+  })
 }
 
 // 修改数据
-const initEditData = (data) => {
-  insuranceTypeList.value.forEach(item => {
-    item.checked = false
-    item.options.forEach(sub => {
-      sub.checked = false
-    })
-  })
-  if(data && data.length > 0) {
-    data.forEach(item => {
-      item.checked = true
-      item.options.forEach(sub => {
-        if(item.quota === sub.value) {
-          sub.checked = true
+let editIndex = ref(0)
+const initEditData = (data, index, type) => {
+  editIndex.value = index
+  insuranceType.value = type
+  api.projectApi.getBusinessInsurance().then(res => {
+    if(res.code == 200) {
+      if(res.data&&res.data.length>0) {
+        choiceItem.value = res.data[0]
+        res.data.forEach(item => {
+          item.checked = false
+          item.insuranceId = item.id
+          item.id = ''
+          item.options.forEach(sub => {
+            sub.checked = false
+          })
+        })
+        typeList.value = JSON.parse(JSON.stringify(res.data))
+        if(data && data.length > 0) {
+          data.forEach(item => {
+            item.checked = true
+            item.options.forEach(sub => {
+              if(item.optionId === sub.id) {
+                sub.checked = true
+              }
+            })
+          })
+          insuranceTypeList.value = res.data.map(a => {
+            let obj = data.find(b => b.insuranceId === a.insuranceId)
+            return obj || a
+          })
+        } else {
+          insuranceTypeList.value = res.data
         }
+      }
+    } else {
+      ElMessage({
+        message: res.msg,
+        type: 'warning'
       })
-    })
-    let list = [...insuranceTypeList.value]
-    insuranceTypeList.value = list.map(a => {
-      let obj = data.find(b => b.id === a.id)
-      return obj || a
-    })
-  }
-
+    }
+  })
 }
 
 onMounted(() => {
-  initInsurance()
+  // initInsurance()
 })
 
 defineExpose({

+ 12 - 1
src/views/quoteConfig/insuranceCompanyAccount/modules/insuranceAccountAdd.vue

@@ -24,6 +24,14 @@
                   ></el-cascader>
                 </el-form-item>
               </el-col>
+              <el-col :span="12">
+                <el-form-item label="报价对接方式" prop="apiType">
+                  <el-select v-model="insuranceAccountForm.apiType" placeholder="请选择" clearable @change="companyChange" filterable>
+                    <el-option key="1" value="1" label="直连"></el-option>
+                    <el-option key="2" value="2" label="非直连"></el-option>
+                  </el-select>
+                </el-form-item>
+              </el-col>
               <el-col :span="12">
                 <el-form-item label="账号登录地址" prop="loginUrl">
                   <el-select v-model="insuranceAccountForm.loginUrl" placeholder="请选择" clearable>
@@ -99,7 +107,9 @@ let insuranceAccountRules = ref<FormRules>({
   password: [
     { required: true, trigger: "blur", message: "请填写密码"  }
   ],
-
+  apiType: [
+    { required: true, trigger: "change", message: "请选择报价对接方式" }
+  ]
 })
 
 // 保险公司列表
@@ -198,6 +208,7 @@ const submit = async (formRef) => {
         username: insuranceAccountForm.value.username,
         password: insuranceAccountForm.value.password,
         userAbbr: insuranceAccountForm.value.userAbbr,
+        apiType: insuranceAccountForm.value.apiType,
         fields: []
       }
       formData.userDept = typeof formData.userDept==='string'?formData.userDept:formData.userDept[formData.userDept.length-1]

+ 100 - 35
src/views/quoteConfig/project/index.vue

@@ -4,7 +4,7 @@
       <el-col :span="4">
         <el-input placeholder="请输入保险公司名称" v-model="company" prefix-icon="search" @keyup.enter="searchCompany"></el-input>
         <div class="companyList">
-          <div class="companyItem" :class="{'active': companyIndex === index}" v-for="(item, index) in companyOption" @click="companyChose(item, index)">{{ item.nameSimple }}</div>
+          <div class="companyItem" :class="{'active': companyIndex === index}" v-for="(item, index) in filterList" @click="companyChose(item, index)">{{ item.nameSimple }}</div>
         </div>
       </el-col>
       <el-col :span="20">
@@ -22,26 +22,22 @@
           <el-row :gutter="20">
             <el-col :span="4">
               <el-form-item label="方案类型">
-                <el-select v-model="projectForm.schemeType" placeholder="请选择">
-                  <el-option key="1" value="1" label="">基础方案</el-option>
-                  <el-option key="2" value="2" label="">自选方案</el-option>
+                <el-select clearable v-model="projectForm.schemeType" placeholder="请选择" @change="search">
+                  <el-option key="1" value="1" label="基础方案"></el-option>
+                  <el-option key="2" value="2" label="自选方案"></el-option>
                 </el-select>
               </el-form-item>
             </el-col>
             <el-col :span="4">
               <el-form-item label="险种">
-                <el-select v-model="projectForm.productId" placeholder="请选择">
-                  <el-option key="1" value="1" label="">单交</el-option>
-                  <el-option key="2" value="2" label="">交商</el-option>
-                  <el-option key="3" value="3" label="">交三</el-option>
-                  <el-option key="4" value="4" label="">单三</el-option>
-                  <el-option key="5" value="5" label="">单商</el-option>
+                <el-select clearable v-model="projectForm.productId" placeholder="请选择" @change="search">
+                  <el-option v-for="item in insuranceType" :key="item.value" :value="item.value" :label="item.label"></el-option>
                 </el-select>
               </el-form-item>
             </el-col>
             <el-col :span="4">
               <el-form-item>
-                <el-input prefix-icon="search" placeholder="输入规则描述查找" @keyup.enter="search" v-model="projectForm.description"></el-input>
+                <el-input clearable prefix-icon="search" placeholder="输入规则描述查找" @keyup.enter="search" v-model="projectForm.ruleDesc"></el-input>
               </el-form-item>
             </el-col>
           </el-row>
@@ -50,16 +46,20 @@
           :data="tableData"
           height="600"
         >
-          <el-table-column label="方案名称" prop="a"></el-table-column>
-          <el-table-column label="方案描述" prop="b"></el-table-column>
-          <el-table-column label="方案类型" prop="c"></el-table-column>
-          <el-table-column label="险种" prop="d"></el-table-column>
-          <el-table-column label="驾意险" prop="e"></el-table-column>
-          <el-table-column label="规则描述" prop="f"></el-table-column>
+          <el-table-column label="方案名称" prop="schemeName"></el-table-column>
+          <el-table-column label="方案描述" prop="description"></el-table-column>
+          <el-table-column label="方案类型" prop="schemeType">
+            <template #default="scope">
+              {{ scope.row.schemeType == '1'?'基础方案':scope.row.schemeType == '1'?'自选方案':'' }}
+            </template>
+          </el-table-column>
+          <el-table-column label="险种" prop="productName"></el-table-column>
+          <el-table-column label="驾意险" prop="drivingIntentionNum"></el-table-column>
+          <el-table-column label="规则描述" prop="ruleDesc"></el-table-column>
           <el-table-column label="操作">
             <template #default="scope">
-              <el-button link type="primary">编辑</el-button>
-              <el-button link type="primary">删除</el-button>
+              <el-button link type="primary" @click="handleEdit(scope.row)">编辑</el-button>
+              <el-button link type="primary" @click="handleDel(scope.row)">删除</el-button>
             </template>
           </el-table-column>
         </el-table>
@@ -81,28 +81,35 @@
 
 <script setup lang="ts">
 import api from '@/api'
-import { ElMessage } from "element-plus";
+import {ElMessage, ElMessageBox} from "element-plus";
 import { useRouter, useRoute } from 'vue-router'
 
 const myRouter = useRouter()
 const muRoute = useRoute()
 
 const searchCompany = () => {
-
+  currentPage.value = 1
+  pageSize.value = 10
+  initData()
 }
 let company = ref('')
-const search = () => {
 
+const filterList = computed(() => {
+  return companyOption.value.filter(a => a.nameSimple.includes(company.value))
+})
+
+const search = () => {
+  initData()
 }
 // 保险公司
 let companyOption = ref([])
 let companyIndex = ref(0)
 let companyId = ref('')
 const initCompany = () => {
-  api.insuranceApi.leftList('').then(res => {
+  api.projectApi.getCompanyList().then(res => {
     if(res.code == 200) {
       companyOption.value = res.data
-      companyId.value = companyOption.value[companyIndex.value].companyCode
+      companyId.value = companyOption.value[companyIndex.value].id
       initData()
     } else {
       ElMessage({
@@ -125,29 +132,43 @@ const addProject = () => {
 }
 
 let projectForm = ref({})
-let tableData = ref([{
-
-}])
+let tableData = ref([])
 // 分页数据
 let currentPage = ref(0)
 let pageSize = ref(10)
 let total = ref(0)
 const initData = () => {
-  // api.projectApi.getBusinessInsurance().then(res => {
-  //
-  // })
-  // api.projectApi.getScheme().then(res => {
-  //
-  // })
   api.projectApi.getSchemeList({
     pages: currentPage.value,
     size: pageSize.value,
     companyId: companyId.value,
     productId: projectForm.value.productId,
     schemeType: projectForm.value.schemeType,
-    description: projectForm.value.description
+    ruleDesc: projectForm.value.ruleDesc
   }).then(res => {
-
+    if(res.code == 200) {
+      tableData.value = res.data.records
+      total.value = res.data.total
+    } else {
+      ElMessage({
+        message: res.msg,
+        type: 'warning'
+      })
+    }
+  })
+}
+// 险种类型
+let insuranceType = ref([])
+const initType = () => {
+  api.commonApi.personInfo('insurance_type').then(res => {
+    if(res.code == 200) {
+      insuranceType.value = res.data
+    } else {
+      ElMessage({
+        message: res.msg,
+        type: 'warning'
+      })
+    }
   })
 }
 const handleSizeChange = (size) => {
@@ -159,8 +180,52 @@ const handleCurrentChange = (page) => {
   initData()
 }
 
+// 编辑
+const handleEdit = (row) => {
+    myRouter.push({
+      path: '/quoteConfig/agreement/project/projectAdd',
+      query: {
+        id: row.id
+      }
+    })
+}
+// 删除
+const handleDel = (row) => {
+  ElMessageBox({
+    title: '删除方案',
+    message: '确定要删除该方案吗?',
+    type: 'warning',
+    showCancelButton: true,
+    confirmButtonText: '确定',
+    cancelButtonText: '取消',
+  }).then(( action ) => {
+    if(action === 'confirm') {
+      api.projectApi.deleteScheme({
+        id: row.id
+      }).then(res => {
+        if(res.code == 200) {
+          ElMessage({
+            message: res.msg,
+            type: 'success'
+          })
+          initData()
+        } else {
+          ElMessage({
+            message: res.msg,
+            type: 'warning'
+          })
+        }
+      })
+    }
+  }).catch(( action ) => {
+
+  })
+}
+
 onMounted(() => {
+  // initData()
   initCompany()
+  initType()
 })
 
 </script>

+ 279 - 71
src/views/quoteConfig/project/modules/projectAdd.vue

@@ -1,21 +1,21 @@
 <template>
   <div class="projectAdd">
-    <el-form :model="projectAddFrom" :rules="projectAddRules" ref="projectAddRefs">
+    <el-form :model="projectAddFrom" :rules="projectAddRules" ref="ProjectAddRef">
       <el-descriptions title="基本信息">
         <el-descriptions-item>
           <el-form-item label="保险公司" prop="companyId">
-            <el-select v-model="projectAddFrom.companyId" placeholder="请选择" style="width: 40%">
-              <el-option v-for="item in companyOption" :key="item.id" :value="item.companyCode" :label="item.nameSimple"></el-option>
+            <el-select :disabled="isEdit" v-model="projectAddFrom.companyId" placeholder="请选择" style="width: 40%" @change="initProduct">
+              <el-option v-for="item in companyOption" :key="item.id" :value="item.id" :label="item.nameSimple"></el-option>
             </el-select>
           </el-form-item>
           <el-form-item label="方案类型" prop="schemeType">
-            <el-radio-group v-model="projectAddFrom.schemeType">
+            <el-radio-group :disabled="isEdit" v-model="projectAddFrom.schemeType" @change="schemeTypeChange">
               <el-radio :value="1">基础方案</el-radio>
               <el-radio :value="2">自选方案</el-radio>
             </el-radio-group>
           </el-form-item>
           <el-form-item label="险种类型" prop="productId">
-            <el-radio-group v-model="projectAddFrom.productId">
+            <el-radio-group :disabled="isEdit" v-model="projectAddFrom.productId" @change="initProduct">
               <el-radio-button v-for="item in insuranceType" :key="item.value" :value="item.value">{{ item.label }}</el-radio-button>
             </el-radio-group>
           </el-form-item>
@@ -33,14 +33,17 @@
                 <el-icon><CircleCloseFilled /></el-icon>&nbsp;
               </div>
             </div>-->
-            <rule-condition :ruleConditionVisible="false"></rule-condition>
+            <div style="width: 60%">
+              <rule-condition-container :rulesAttrList="rulesAttrList"></rule-condition-container>
+            </div>
+            <rule-condition :ruleConditionVisible="rulesShow" :attrIdList="rulesAttrList" @save="saveRule"></rule-condition>
           </div>
-          <el-button style="margin: 10px 10%" plain type="primary" icon="plus">添加条件</el-button>
+          <el-button style="margin: 10px 10%" plain type="primary" icon="plus" @click="addRules">添加条件</el-button>
           <el-descriptions>
             <template #title>
               <div style="display: flex; align-items: center">
                 <span>方案配置</span>
-                <el-button type="primary" icon="plus" style="margin-left: 20px;" @click="addProject">添加新方案</el-button>
+                <el-button v-show="!isEdit" type="primary" icon="plus" style="margin-left: 20px;" @click="addProject">添加新方案</el-button>
               </div>
             </template>
             <el-descriptions-item>
@@ -55,13 +58,6 @@
                   <div style="display: flex; align-items: center; margin-bottom: 10px">
                     <span style="margin-right: 20px">驾意险</span>
                     <el-button link icon="plus" type="primary" @click="handleDriving(item, index)">选择驾意险</el-button>
-                    <el-dialog
-                      v-model="drivingShow"
-                      title="选择驾意险"
-                      width="700"
-                    >
-                      <driving ref="DrivingTypeRef" @close="handleDrivingClose(item, $event)"></driving>
-                    </el-dialog>
                   </div>
                   <el-table
                     :data="item.drivingList"
@@ -71,7 +67,7 @@
                         <a>{{ scope.row.productName }}</a>
                       </template>
                     </el-table-column>
-                    <el-table-column label="客户端状态" prop="f">
+                    <el-table-column label="客户端状态" prop="selectedStatus">
                       <template #default="scope">
                         <el-select v-model="scope.row.selectedStatus">
                           <el-option label="默认不选中" key="1" value="1"></el-option>
@@ -102,13 +98,6 @@
                       </template>
 
                     </el-popover>-->
-                    <el-dialog
-                      v-model="insuranceShow"
-                      title="选择险种"
-                      width="500"
-                    >
-                      <insurance ref="InsuranceTypeRef" @close="handleClose(item, $event, index)" ></insurance>
-                    </el-dialog>
                   </div>
                   <el-table
                     :data="item.tableData"
@@ -118,10 +107,13 @@
                         <a>{{ scope.row.kindName }}</a>
                       </template>
                     </el-table-column>
-                    <el-table-column label="保额" prop="quota">
+                    <el-table-column label="保额" prop="optionId">
                       <template #default="scope">
-                        <el-select v-model="scope.row.quota" style="width: 150px">
-                          <el-option v-for="m in scope.row.options" :label="m.label" :key="m.value" :value="m.value"></el-option>
+                        <el-select v-if="projectAddFrom.schemeType === 2" v-model="scope.row.moneyId" style="width: 150px" multiple>
+                          <el-option v-for="m in scope.row.options" :label="m.label" :key="m.id" :value="m.id"></el-option>
+                        </el-select>
+                        <el-select v-else v-model="scope.row.moneyId" style="width: 150px" @change="">
+                          <el-option v-for="m in scope.row.options" :label="m.label" :key="m.id" :value="m.id"></el-option>
                         </el-select>
                       </template>
                     </el-table-column>
@@ -140,24 +132,44 @@
     </el-form>
     <div class="btns">
       <el-button plain @click="quit">取消</el-button>
-      <el-button type="primary" @click="save">保存</el-button>
+      <el-button type="primary" @click="save(ProjectAddRef)">保存</el-button>
     </div>
+    <el-dialog
+      v-model="drivingShow"
+      title="选择驾意险"
+      width="700"
+    >
+      <driving ref="DrivingTypeRef" @close="handleDrivingClose"></driving>
+    </el-dialog>
+    <el-dialog
+      v-model="insuranceShow"
+      title="选择险种"
+      width="500"
+    >
+      <insurance ref="InsuranceTypeRef" @close="handleClose" ></insurance>
+    </el-dialog>
   </div>
 </template>
 
 <script setup lang="ts">
 
 import api from "@/api";
-import { ElMessage } from "element-plus";
+import { ElMessage, FormInstance, FormRules } from "element-plus";
+import { useRouter, useRoute } from 'vue-router'
 import insurance from '../../../../layouts/components/InsuranceType/index.vue'
 import driving from '../../../../layouts/components/DrivingType/index.vue'
 import rule from '../../../../components/ruleConditionContainer/index.vue'
 
+const myRouter = useRouter()
+const myRoute = useRoute()
+const ProjectAddRef = ref<FormInstance>()
 const InsuranceTypeRef = ref(null)
 const DrivingTypeRef = ref(null)
 
+// 是否编辑
+let isEdit = ref(false)
 let projectAddFrom = ref({
-  rulesList: [],
+  ruleAttrs: [],
   schemeList: [{
     schemeName: '',
     description: '',
@@ -167,19 +179,99 @@ let projectAddFrom = ref({
     drivingIntentionList: []
   }]
 })
-let projectAddRules = ref({
+let projectAddRules = ref<FormRules>({
   companyId: [
     { required: true, trigger: "change", message: "请选择保险公司" }
   ],
   schemeType: [
     { required: true, trigger: "change", message: "请选择方案类型" }
+  ],
+  productId: [
+    { required: true, trigger: "change", message: "请选择险种类型" }
   ]
 })
 
+// 新增的时候初始化已有的方案
+const initProduct = () => {
+  api.projectApi.getSchemeByCompany({
+    companyId: projectAddFrom.value.companyId,
+    productId: projectAddFrom.value.productId,
+    schemeType: projectAddFrom.value.schemeType
+  }).then(res => {
+    if(res.code == 200) {
+      if(res.data && res.data.schemeList.length > 0) {
+        res.data.schemeList.forEach(item => {
+          item.drivingList = item.drivingIntentionList
+          item.tableData = item.schemeInsuranceList.map(sub => {
+            let obj = insuranceTypeList.value.find(a => a.id === sub.insuranceId)
+            return {
+              ...sub,
+              optionId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
+              moneyId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
+              options: obj.options
+            }
+          })
+        })
+        projectAddFrom.value = res.data
+        rulesAttrList.value = res.data.ruleAttrs
+      }
+    } else {
+      projectAddFrom.value.ruleAttrs = []
+      projectAddFrom.value.schemeList  = [{
+        schemeName: '',
+        description: '',
+        tableData: [],
+        drivingList: [],
+        schemeInsuranceList: [],
+        drivingIntentionList: []
+      }]
+      ElMessage({
+        message: res.msg,
+        type: 'warning'
+      })
+    }
+  })
+}
+
+// 险种
+let insuranceTypeList = ref([])
+const initInsurance = () => {
+  api.projectApi.getBusinessInsurance().then(res => {
+    if(res.code == 200) {
+      // res.data.forEach(item => {
+      //   item.options.forEach(sub => {
+      //     sub.id = sub.value
+      //   })
+      // })
+      insuranceTypeList.value = res.data
+    } else {
+      ElMessage({
+        message: res.msg,
+        type: 'warning'
+      })
+    }
+  })
+}
+
+// 方案类型切换
+const schemeTypeChange = (e) => {
+  projectAddFrom.value.ruleAttrs = []
+  projectAddFrom.value.schemeList  = [{
+    schemeName: '',
+    description: '',
+    tableData: [],
+    drivingList: [],
+    schemeInsuranceList: [],
+    drivingIntentionList: []
+  }]
+  initProduct()
+  // rulesAttrList.value = defaultAttrList.value
+}
+
 // 保险公司
 let companyOption = ref([])
 const initCompany = () => {
-  api.insuranceApi.leftList('').then(res => {
+  api.projectApi.getCompanyList().then(res => {
     if(res.code == 200) {
       companyOption.value = res.data
     } else {
@@ -203,13 +295,27 @@ const addProject = () => {
   })
 }
 
+// 规则
+let rulesShow = ref(false)
+const addRules = () => {
+  rulesShow.value = true
+}
+let rulesAttrList = ref([])
+let defaultAttrList = ref([])
+const saveRule = (data) => {
+  if(data && data.length > 0) {
+    rulesAttrList.value = data
+  }
+  rulesShow.value = false
+}
+
 // 险种类型
 let insuranceType = ref([])
 const initType = () => {
   api.commonApi.personInfo('insurance_type').then(res => {
     if(res.code == 200) {
       insuranceType.value = res.data
-      projectAddFrom.value.productId = insuranceType.value[0].id
+      projectAddFrom.value.productId = insuranceType.value[0].value
     } else {
       ElMessage({
         message: res.msg,
@@ -224,13 +330,25 @@ let insuranceShow = ref(false)
 // let insuranceList = ref([])
 // let checkInsuranceList = ref([])
 // let checkSubInsuranceList = ref([])
-const handleClose = (item, list, index ) => {
-  if(list && list.length > 0) {
-    list.forEach(a => {
-      let obj = a.options.find(b => b.checked)
-      a.quota = obj.value
-    })
-    item.tableData = list
+const handleClose = ( obj ) => {
+  if(obj.list && obj.list.length > 0) {
+    if(projectAddFrom.value.schemeType === 2) {
+      obj.list.forEach(a => {
+        a.optionId = []
+        a.options.forEach(b => {
+          if(b.checked) {
+            a.optionId.push(b.id)
+          }
+        })
+        a.moneyId = a.optionId
+      })
+    } else {
+      obj.list.forEach(a => {
+        a.optionId = a.options.find(b => b.checked)?.id
+        a.moneyId = a.optionId
+      })
+    }
+    projectAddFrom.value.schemeList[obj.index].tableData = obj.list
   }
   insuranceShow.value = false
 }
@@ -246,18 +364,18 @@ let drivingShow = ref(false)
 const handleDriving = (item, index) => {
   drivingShow.value = true
   nextTick(() => {
-    DrivingTypeRef.value[index].initEditData(item.drivingList)
+    DrivingTypeRef.value.initEditData(item.drivingList, index)
   })
 }
-const handleDrivingClose = (item, list ) => {
-  if(list && list.length > 0) {
-    let selectList = list.filter(a => a.checked)
+const handleDrivingClose = ( obj ) => {
+  if(obj.list && obj.list.length > 0) {
+    let selectList = obj.list.filter(a => a.checked)
     selectList.forEach(sub => {
-      sub.drivingIntentionId = sub.id
+      sub.drivingIntentionId = sub.drivingIntentionId
       sub.selectedStatus = sub.selectedStatus?sub.selectedStatus:'1'
       sub.quantity = sub.quantity?sub.quantity:'1'
     })
-    item.drivingList = selectList
+    projectAddFrom.value.schemeList[obj.index].drivingList = selectList
   }
   drivingShow.value = false
 }
@@ -269,41 +387,117 @@ const drivingTypeDel = (item, row) => {
 const handlePopover = (item, index) => {
   insuranceShow.value = true
   nextTick(() => {
-    InsuranceTypeRef.value[index].initEditData(item.tableData)
+    InsuranceTypeRef.value.initEditData(item.tableData, index, projectAddFrom.value.schemeType)
   })
 }
 
-// 取消
-const quit = () => {
-
+// 规则
+const initAttr = () => {
+  api.agreementApi.ruleAttrGroup({ attrName: '' }).then(res => {
+    if(res.code == 200) {
+      let list = res.data?.VehicleInformation?.filter(e => e.attrName === '能源类型' || e.attrName === '使用性质' || e.attrName === '车辆类型')
+      rulesAttrList.value = [...list]
+      defaultAttrList.value = [...list]
+    } else {
+      ElMessage({
+        message: res.msg,
+        type: 'warning'
+      })
+    }
+  })
 }
-// 保存
-const save = () => {
-  let formData = {...projectAddFrom.value}
-  formData.schemeList.forEach(item => {
-    item.drivingList.forEach(sub => {
-      let obj = {
-        drivingIntentionId: sub.id,
-        selectedStatus: sub.selectedStatus,
-        quantity: sub.quantity
-      }
-      item.drivingIntentionList.push(obj)
-    })
-    item.tableData.forEach(ins => {
-      let obj = {
-        insuranceId: ins.id,
-        optionId: ins.options.find(a => a.checked)?.value
+
+// 编辑
+const initEdit = () => {
+  api.projectApi.getScheme(myRoute.query.id).then(res => {
+    if(res.code == 200) {
+      if(res.data && res.data.schemeList.length > 0) {
+        res.data.schemeList.forEach(item => {
+          item.drivingList = item.drivingIntentionList
+          item.tableData = item.schemeInsuranceList.map(sub => {
+            let obj = insuranceTypeList.value.find(a => a.id === sub.insuranceId)
+            return {
+              ...sub,
+              optionId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
+              moneyId: res.data.schemeType===1?`${sub.optionId[0]}`:sub.optionId,
+              options: obj.options
+            }
+          })
+        })
+        projectAddFrom.value = res.data
+        rulesAttrList.value = res.data.ruleAttrs
       }
-      item.schemeInsuranceList.push(obj)
-    })
+    } else {
+      ElMessage({
+        message: res.msg,
+        type: 'warning'
+      })
+    }
   })
-  console.log(123, formData)
-  api.projectApi.saveScheme({...formData}).then(res => {
-    if(res.code == 200) {
+}
 
+// 取消
+const quit = () => {
+  myRouter.push({
+    path: '/quoteConfig/agreement/project'
+  })
+}
+// 保存
+const save = async (ProjectAddRef: FormInstance | undefined) => {
+  console.log(123, ProjectAddRef)
+  if(!ProjectAddRef) {
+    ProjectAddRef.resetFields()
+    return
+  }
+  await ProjectAddRef.validate((valid) => {
+    if(valid) {
+      let formData = {...projectAddFrom.value}
+      formData.ruleAttrs = [...rulesAttrList.value]
+      formData.schemeList.forEach(item => {
+        item.drivingIntentionList = []
+        item.schemeInsuranceList = []
+        item.drivingList.forEach(sub => {
+          let obj = {
+            id: sub.id,
+            drivingIntentionId: sub.drivingIntentionId,
+            selectedStatus: sub.selectedStatus,
+            quantity: sub.quantity
+          }
+          item.drivingIntentionList.push(obj)
+        })
+        item.tableData.forEach(ins => {
+          let obj = {
+            id: ins.id,
+            insuranceId: ins.insuranceId,
+            optionId: projectAddFrom.value.schemeType === 1?[ins.moneyId]:projectAddFrom.value.schemeType === 2?ins.moneyId:[]
+          }
+          // ins.options.forEach(sub => {
+          //   if(sub.checked) {
+          //     obj.optionId.push(sub.id)
+          //   }
+          // })
+          item.schemeInsuranceList.push(obj)
+        })
+      })
+      api.projectApi.saveScheme({...formData}).then(res => {
+        if(res.code == 200) {
+          ElMessage({
+            message: res.msg,
+            type: 'success'
+          })
+          myRouter.push({
+            path: '/quoteConfig/agreement/project'
+          })
+        } else {
+          ElMessage({
+            message: res.msg,
+            type: 'warning'
+          })
+        }
+      })
     } else {
       ElMessage({
-        message: res.msg,
+        message: '请正确填写相关信息!',
         type: 'warning'
       })
     }
@@ -311,8 +505,17 @@ const save = () => {
 }
 
 onMounted(() => {
+  initInsurance()
   initType()
   initCompany()
+  // initAttr()
+  if(myRoute.query.id) {
+    isEdit.value = true
+    initEdit()
+  } else {
+    isEdit.value = false
+    initAttr()
+  }
   // initInsurance()
 })
 
@@ -340,5 +543,10 @@ onMounted(() => {
     margin-bottom: 10px;
     border-radius: 5px;
   }
+  .btns{
+    display: flex;
+    align-items: center;
+    justify-content: center;
+  }
 }
 </style>