| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032 |
- <template>
- <div>
- <el-drawer v-model="drawer" :title="props.drawerTitle" size="918" @close="handleClose">
- <div class="item-title"><span></span> 当报价信息满足以下条件时</div>
- <el-form ref="formRef" :model="formData" label-width="auto" class="demo-dynamic" :rules="formRules">
- <!-- 多组条件容器(组之间是"或者"关系) -->
- <div class="condition-container">
- <div v-for="(group, groupIndex) in formData.conditionGroups" :key="group.groupKey" class="condition-group">
- <!-- 组内条件行(行之间是"并且"关系) -->
- <el-form-item v-for="(domain, rowIndex) in group.actions" :key="domain.key"
- :prop="`conditionGroups.${groupIndex}.actions.${rowIndex}`" :error="domain.errorMsg">
- <div class="condition-row">
- <!-- 1. 条件类型选择框 -->
- <el-select v-model="domain.attrCode" placeholder="选择条件" style="width: 341px"
- @change="(val) => handleConditionChange(domain, val)" clearable>
- <el-option v-for="item in dispatchList" :key="item.attrCode" :label="item.attrName"
- :value="item.attrCode" />
- </el-select>
- <!-- 2. 运算符选择框 -->
- <el-select v-model="domain.operator" placeholder="选择运算符" style="width: 100px"
- :disabled="!domain.attrCode" clearable @change="handleOperatorChange(domain)">
- <el-option v-for="item in getOperations(domain.attrCode)" :key="item.value" :label="item.label"
- :value="item.value" />
- </el-select>
- <!-- 3. 值输入区域(动态切换) -->
- <!-- 单选按钮组 -->
- <el-radio-group v-model="domain.min" v-if="getConditionType(domain.attrCode) === 'radio'">
- <el-radio :value="item.id + ''" size="large" v-for="item in getOptions(domain.attrCode)"
- :key="item.id + ''">{{ item.name }}</el-radio>
- </el-radio-group>
- <!-- 多选下拉 -->
- <el-select v-model="domain.minArray" placeholder="选择值" multiple style="width: 341px"
- v-if="getConditionType(domain.attrCode) === 'checkbox'" :disabled="!domain.operator" clearable>
- <template #header>
- <el-checkbox v-model="domain.checkAll" :indeterminate="domain.indeterminate"
- @change="(val) => handleCheckAll(domain, val)">
- 全选
- </el-checkbox>
- </template>
- <el-option v-for="(item, index) in getOptions(domain.attrCode)" :key="index" :label="item.name"
- :value="item.idStr" />
- </el-select>
- <!-- 单选下拉 -->
- <el-select v-model="domain.minArray" placeholder="选择值" style="width: 341px" multiple
- @change="change(domain)" v-if="getConditionType(domain.attrCode) === 'select'"
- :disabled="!domain.operator" clearable>
- <template #header>
- <el-checkbox v-model="domain.checkAll" :indeterminate="domain.indeterminate"
- @change="(val) => handleCheckAll(domain, val)">
- 全选
- </el-checkbox>
- </template>
- <el-option v-for="item in getOptions(domain.attrCode)" :key="item.idStr" :label="item.name"
- :value="item.idStr" />
- </el-select>
- <!-- 数值输入 -->
- <el-input v-model="domain.min" placeholder="输入数值" type="number" style="width: 341px" v-if="
- getConditionType(domain.attrCode) === 'inputNumber' &&
- domain.operator !== '1'
- " :disabled="!domain.operator" clearable />
- <!-- 数值输入范围 -->
- <div v-if="
- getConditionType(domain.attrCode) === 'inputNumber' &&
- domain.operator == '1'
- ">
- <el-input-number v-model="domain.min" :disabled="!domain.operator"
- style="width: 160px"></el-input-number>
- 至
- <el-input-number v-model="domain.max" :disabled="!domain.operator"
- style="width: 170px"></el-input-number>
- </div>
- <!-- 标签输入 -->
- <el-input-tag v-model="domain.minArray" style="width: 341px"
- v-if="getConditionType(domain.attrCode) === 'inputTag'" :disabled="!domain.operator"
- placeholder="输入内容后按回车键隔开" />
- <!-- 日期选择 -->
- <el-date-picker v-model="domain.max" type="date" placeholder="选择日期" style="width: 341px" v-if="
- getConditionType(domain.attrCode) === 'datetime' &&
- domain.operator !== '1'
- " value-format="YYYY-MM-DD" :disabled="!domain.operator" clearable />
- <!-- 日期范围选择 -->
- <div v-if="
- getConditionType(domain.attrCode) === 'datetime' &&
- domain.operator == '1'
- ">
- <el-date-picker v-model="domain.min" :disabled="!domain.operator" type="datetime"
- format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" time-format="HH:mm:ss"
- placeholder="选择日期时间" style="width: 170px">
- </el-date-picker>
- 至
- <el-date-picker v-model="domain.max" :disabled="!domain.operator" type="datetime"
- format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" time-format="HH:mm:ss"
- placeholder="选择日期时间" style="width: 170px">
- </el-date-picker>
- </div>
- <!-- 车牌级联选择 -->
- <el-cascader :options="getOptions(domain.attrCode)" :props="cascaderProps" v-model="domain.max"
- placeholder="选择车牌" clearable v-if="getConditionType(domain.attrCode) === 'plate'" style="width: 341px"
- :disabled="!domain.operator" />
- <!-- 4. 删除行按钮 -->
- <el-button type="text" :icon="Delete" size="small" style="color: #333333"
- @click="handleRemoveRow(groupIndex, rowIndex)" v-if="group.actions.length > 1" />
- </div>
- </el-form-item>
- <div class="flex justify-between items-center">
- <!-- 组内添加并且条件按钮 -->
- <el-button type="text" @click="handleAddRow(groupIndex)" class="add-condition-btn">
- + 并且条件
- </el-button>
- <el-button v-if="groupIndex !== 0" type="text"
- @click="formData.conditionGroups = formData.conditionGroups.filter(v => v.groupKey !== group.groupKey)"
- class="add-condition-btn">
- 删除
- </el-button>
- </div>
- </div>
- </div>
- <!-- 添加或者条件组按钮 -->
- <el-form-item class="add-group-btn">
- <el-button type="primary" @click="handleAddGroup">
- + 或者条件
- </el-button>
- </el-form-item>
- </el-form>
- <!-- 执行动作区域 -->
- <!-- 执行动作区域 -->
- <div class="item-title"><span></span> 将执行以下动作</div>
- <el-form :model="formData" :rules="formRules" ref="formRef" class="action-form">
- <!-- 指定报价协议 -->
- <el-form-item prop="formdata.actionJson[0].agreementId" class="form-item">
- <span>指定报价协议:</span>
- <el-select v-model="formData.actionJson[0].agreementId" placeholder="选择报价协议" style="width: 240px" clearable>
- <el-option v-for="item in agreementList" :key="item.id" :label="item.agreementName" :value="item.id" />
- </el-select>
- </el-form-item>
- <!-- 对接人变更方式选择 -->
- <el-form-item>
- <el-checkbox-group v-model="linkTypeList" @change="handleTypeChange">
- <!-- 手动输入对接人 -->
- <el-checkbox value="manual_input" size="large" style="margin: 20px 0; display: block">
- 手动输入对接人信息:
- <el-form-item prop="actionJson.name" style="display: inline-block; margin: 0 20px">
- <el-input v-model="formData.actionJson[1].name" style="width: 327px" placeholder="变更后对接人姓名"
- :disabled="!linkTypeList.includes('manual_input')" clearable />
- </el-form-item>
- <el-form-item prop="actionJson.phone" style="display: inline-block">
- <el-input v-model="formData.actionJson[1].phone" style="width: 327px" type="number"
- placeholder="变更后对接人手机号" maxlength="11" @input="handlePhoneInput"
- :disabled="!linkTypeList.includes('manual_input')" clearable />
- </el-form-item>
- </el-checkbox>
- <!-- 选择保司账号 -->
- <el-checkbox value="select_account" size="large" style="margin: 20px 0; display: block">
- 选择已有保司账号:
- <el-form-item prop="actionJson.accountId" style="display: inline-block; margin-left: 20px">
- <el-select v-model="formData.actionJson[2].accountId" placeholder="选择变更后的保司账号" style="width: 662px"
- :disabled="!linkTypeList.includes('select_account')" clearable>
- <!-- -->
- <el-option v-for="item in accountList" :key="item.id" :label="item.username" :value="item.id" />
- </el-select>
- </el-form-item>
- </el-checkbox>
- </el-checkbox-group>
- </el-form-item>
- </el-form>
- <!-- 抽屉底部按钮 -->
- <template #footer>
- <div class="foot">
- <el-button @click="handleClose"> 取消 </el-button>
- <el-button type="primary" @click="submit"> 保存 </el-button>
- </div>
- </template>
- </el-drawer>
- </div>
- </template>
- <script lang="ts" setup>
- import { reactive, ref, type Ref, onMounted } from "vue";
- import type { FormInstance, FormRules } from "element-plus";
- import { Delete } from "@element-plus/icons-vue";
- import { ElMessage } from "element-plus";
- import api from "@/api";
- import { getDictItems } from "@/api/dict";
- // 抽屉状态
- const drawer = ref(true);
- const emit = defineEmits(["close"]);
- // 组件props
- const props = defineProps({
- companyId: {
- type: [String, Number],
- required: true,
- validator: (value: string | number) => value !== "" && value !== 0,
- },
- editData: {},
- editType: "",
- drawerTitle: {
- type: String,
- default: "规则配置",
- },
- });
- // 表单实例引用
- const formRef: Ref<FormInstance | undefined> = ref(undefined);
- // 级联选择器配置
- const cascaderProps = { multiple: true, checkStrictly: true };
- // 数据类型定义
- interface ConditionRow {
- key: number;
- min: any;
- attrType: string;
- operator: string;
- attrCode: string;
- max: any;
- errorMsg: string;
- checkAll: boolean;
- indeterminate: boolean;
- minArray?: string[];
- }
- interface ConditionGroup {
- groupKey: number;
- actions: ConditionRow[];
- }
- const linkTypeList = ref([])
- // 表单核心数据
- // 表单核心数据 - 优化actionJson结构
- const formData = ref<{
- conditionGroups: ConditionGroup[];
- actionJson: [
- {
- actionCode: "specify_agreement"; // 固定:指定报价协议
- agreementId: string; // 报价协议ID
- },
- {
- actionCode: "change_bs_account"; // 固定:变更对接人
- linkType: "manual_input" | "select_account"; // 对接人方式:手动输入/选择账号
- name: string; // 手动输入-姓名
- phone: string; // 手动输入-手机号
- accountId: string; // 选择账号-账号ID
- },
- {
- actionCode: "change_bs_account"; // 固定:变更对接人
- linkType: "manual_input" | "select_account"; // 对接人方式:手动输入/选择账号
- name: string; // 手动输入-姓名
- phone: string; // 手动输入-手机号
- accountId: string; // 选择账号-账号ID
- }
- ];
- }>({
- actionJson: [
- {
- actionCode: "specify_agreement",
- agreementId: "", // 初始为空
- },
- {
- actionCode: "change_bs_account",
- linkType: "manual_input", // 默认选中“手动输入”
- name: "",
- phone: "",
- accountId: "",
- },
- {
- actionCode: "change_bs_account",
- linkType: "select_account", // 默认选中“手动输入”
- name: "",
- phone: "",
- accountId: "",
- },
- ],
- conditionGroups: [
- {
- groupKey: Date.now(),
- actions: [
- {
- attrType: "",
- attrCode: "",
- key: Date.now(),
- min: "",
- operator: "",
- max: "",
- errorMsg: "",
- minArray: [],
- },
- ],
- },
- ],
- });
- const selectprops = {
- value: 'id',
- label: 'name',
- }
- // 下拉选项数据源
- const dispatchList = ref([]);
- const agreementList = ref([]);
- const accountList = ref([]);
- const dictionaries = ref([]);
- const dispatchId = ref(""); //调度id
- const editType = ref("");
- const handleCheckAll = (item: any, val: boolean) => {
- item.indeterminate = false
- if (val) {
- item.minArray = getOptions(item.attrCode).map((item: any) => item.idStr)
- } else {
- item.minArray = []
- }
- }
- const change = (item: any) => {
- console.log('change', item)
- if (item?.attrType == 'select') {
- if (item.minArray.length === 0) {
- item.checkAll = false
- item.indeterminate = false
- } else if (item.minArray.length === getOptions(item.attrCode).length) {
- item.checkAll = true
- item.indeterminate = false
- } else {
- item.indeterminate = true
- }
- }
- }
- const validateAgreementId = (rule: any, value: string, callback: any) => {
- if (!value) {
- return callback(new Error("请选择需要指定的报价协议"));
- }
- callback();
- };
- const validateLinkManName = (rule: any, value: string, callback: any) => {
- const linkType = formData.value.actionJson[1].linkType;
- if (linkType === "manual_input" && !value?.trim()) {
- return callback(new Error("请输入对接人姓名(手动输入模式)"));
- }
- callback();
- };
- const validateLinkManPhone = (rule: any, value: string, callback: any) => {
- const linkType = formData.value.actionJson[1].linkType;
- if (linkType !== "manual_input") {
- return callback();
- }
- if (!value) {
- return callback(new Error("请输入对接人手机号(手动输入模式)"));
- }
- if (!/^1[3-9]\d{9}$/.test(value)) {
- return callback(
- new Error("手机号格式错误,请输入11位有效号码(如13800138000)")
- );
- }
- callback();
- };
- const validateAccountId = (rule: any, value: string, callback: any) => {
- const linkType = formData.value.actionJson[1].linkType;
- if (linkType === "select_account" && !value) {
- return callback(new Error("请选择变更后的保司账号(选择账号模式)"));
- }
- callback();
- };
- // 优化后的formRules
- const formRules = reactive<FormRules>({
- // 1. 条件组校验(核心)
- conditionGroups: [
- {
- required: true,
- trigger: ["submit", "blur"], // 移除频繁的change触发,仅在提交和失焦时校验
- // validator: validateConditionGroups,
- },
- ],
- // 2. 执行动作:指定报价协议(必选)
- "actionJson[0].agreementId": [
- {
- required: true,
- trigger: ["submit", "blur"], // 下拉选择无需change触发,失焦+提交足够
- validator: validateAgreementId,
- },
- ],
- // 3. 执行动作:对接人姓名(仅手动输入时必选)
- "actionJson[1].name": [
- {
- trigger: ["submit", "blur"],
- validator: validateLinkManName,
- },
- ],
- // 4. 执行动作:对接人手机号(仅手动输入时必选+格式校验)
- "actionJson[1].phone": [
- {
- trigger: ["submit", "blur"], // 移除input触发,避免输入过程中频繁报错
- validator: validateLinkManPhone,
- },
- ],
- // 5. 执行动作:保司账号(仅选择账号时必选)
- "actionJson[1].accountId": [
- {
- trigger: ["submit", "blur"],
- validator: validateAccountId,
- },
- ],
- });
- // 工具函数:根据条件类型获取对应的运算符列表
- const getOperations = (conditionValue: string) => {
- const target = dispatchList.value.find(
- (item) => item.attrCode === conditionValue
- );
- return target?.rulesDict || [];
- };
- // 工具函数:根据条件类型获取对应的选项列表
- const getOptions = (conditionValue: string) => {
- const target = dispatchList.value.find(
- (item) => item.attrCode === conditionValue
- );
- let arr=target?.dictLabal || []
- if(conditionValue==='InsruanceProduct') arr=arr.map(v=>({...v,idStr:v.code}))
- return target?.dictLabal || [];
- };
- // 工具函数:根据条件类型获取输入组件类型
- const getConditionType = (conditionValue: string) => {
- const target = dispatchList.value.find(
- (item) => item.attrCode === conditionValue
- );
- return target?.attrType || "input";
- };
- // 条件切换时的处理
- const handleConditionChange = (domain: ConditionRow, val: string) => {
- const target = dispatchList.value.find((item: any) => item.attrCode == val)
- domain.max = null;
- domain.operator = "";
- domain.checkAll = false;
- domain.indeterminate = false
- domain.attrType = target?.attrType || "input";
- };
- // 运算符切换时重置值
- const handleOperatorChange = (domain: ConditionRow) => {
- const attrType = getConditionType(domain.attrCode);
- domain.checkAll = false;
- domain.indeterminate = false
- // 重置对应类型的值
- if (["checkbox", "inputTag", "select"].includes(attrType)) {
- domain.minArray = [];
- } else {
- domain.min = null;
- domain.max = null;
- }
- };
- // 组内添加并且条件行
- const handleAddRow = (groupIndex: number) => {
- formData.value.conditionGroups[groupIndex].actions.push({
- key: Date.now(),
- min: "",
- attrType: "",
- attrCode: "",
- operator: "",
- max: null,
- errorMsg: "",
- minArray: [],
- });
- };
- // 删除组内条件行
- const handleRemoveRow = (groupIndex: number, rowIndex: number) => {
- formData.value.conditionGroups[groupIndex].actions.splice(rowIndex, 1);
- };
- // 添加新的或者条件组
- const handleAddGroup = () => {
- formData.value.conditionGroups.push({
- groupKey: Date.now(),
- actions: [
- {
- key: Date.now(),
- min: "",
- attrType: "",
- attrCode: "",
- operator: "",
- max: null,
- errorMsg: "",
- minArray: [],
- },
- ],
- });
- };
- // 手机号输入处理
- const handlePhoneInput = () => {
- const phone = formData.value.actionJson[1].phone;
- if (phone) {
- // 截取前11位,去除非数字字符
- const filtered = phone.replace(/\D/g, "").slice(0, 11);
- formData.value.actionJson[1].phone = filtered;
- }
- };
- // 获取条件类型列表
- const getList = async () => {
- try {
- const res = await api.dispatchApi.listByParam({
- scopeApplication: 'PROTOCOL_SCHEDULING',
- companyId: props.companyId
- });
- dispatchList.value = res.data;
- } catch (error) {
- console.error("获取条件类型列表失败:", error);
- }
- };
- // 获取报价协议列表
- const getByCompanyId = async () => {
- try {
- const res = await api.dispatchApi.getByCompanyIdt(props.companyId);
- agreementList.value = res.data;
- } catch (error) {
- console.error("获取报价协议列表失败:", error);
- }
- };
- // 获取保司账号列表
- const getAccountList = async () => {
- try {
- const res = await api.dispatchApi.getAgreementAttributionByCompanyId(
- props.companyId
- );
- accountList.value = res.data;
- } catch (error) {
- console.error("获取保司账号列表失败:", error);
- }
- };
- //清空选项数据
- const handleTypeChange = (value) => {
- if (!value.includes("manual_input")) {
- formData.value.actionJson[1].name = "";
- formData.value.actionJson[1].phone = "";
- }
- if (!value.includes("select_account")) {
- formData.value.actionJson[2].accountId = "";
- }
- };
- // 提交表单
- const submit = async () => {
- const { editType } = props;
- // if (!formRef.value) return;
- // await formRef.value.validate();
- const actionJson = formData.value.actionJson;
- // const actions =formData.value.actionJson
- let actions = [
- {
- actionCode: actionJson[0].actionCode,
- actionJson: {
- agreementId: actionJson[0].agreementId,
- },
- },
- ];
- if (linkTypeList.value.includes('manual_input')) {
- const obj = {
- actionCode:
- actionJson[1].linkType == "manual_input"
- ? "change_poc"
- : "change_bs_account",
- actionJson: {
- ...(actionJson[1].linkType === "manual_input"
- ? { name: actionJson[1].name, phone: actionJson[1].phone }
- : { accountId: actionJson[1].accountId }),
- },
- }
- actions.push(obj)
- }
- if (linkTypeList.value.includes('select_account')) {
- const obj = {
- actionCode:
- actionJson[2].linkType == "manual_input"
- ? "change_poc"
- : "change_bs_account",
- actionJson: {
- ...(actionJson[2].linkType === "manual_input"
- ? { name: actionJson[2].name, phone: actionJson[2].phone }
- : { accountId: actionJson[2].accountId }),
- },
- }
- actions.push(obj)
- }
- if (!actionJson[0].agreementId) {
- ElMessage({
- message: '请选择指定报价协议!',
- type: 'error'
- })
- return
- }
- // 处理多选框额外传值
- const allActions = formData.value.conditionGroups.flatMap((group) => group.actions);
- allActions.map((item) => {
- if (["checkbox", "inputTag", "select"].includes(item.attrType)) {
- item.min = item.minArray.join(',');
- }
- return item
- })
- const submitData = {
- companyId: props.companyId + "",
- attrLinks: allActions,
- actions,
- ...(dispatchId.value && { dispatchId: dispatchId.value }), // 编辑时携带ID
- };
- const apiFunc = editType === "edit"
- ? api.dispatchApi.updateAgreementDispatch
- : api.dispatchApi.addAgreementDispatch;
- // const apiFunc = api.dispatchApi.addAgreementDispatch;
- const res = await apiFunc(submitData);
- if (res.code === 200) {
- ElMessage.success("保存成功");
- handleClose();
- } else {
- ElMessage.error("保存失败");
- }
- // try {
- // } catch (error) {
- // ElMessage.error("表单校验失败,请检查填写内容");
- // }
- };
- // 关闭抽屉
- const handleClose = () => {
- emit("close", false);
- };
- // 组件挂载时初始化数据
- // onMounted(async () => {
- // await getList();
- // await getByCompanyId();
- // await getAccountList();
- // dictionaries.value = await getDictItems({ dictCode: "dispatch_action" });
- // console.log(dictionaries.value);
- // formData.value = props.editData;
- // });
- onMounted(async () => {
- // 1. 加载基础数据(条件类型、协议列表等)
- await Promise.all([
- getList(), // 条件类型列表
- getByCompanyId(), // 报价协议列表
- getAccountList(), // 保司账号列表
- ]);
- regionLicenseNumber('0'),//车牌地区
- regionLicenseNumber('14')//车牌号
- dictionaries.value = await getDictItems({ dictCode: "dispatch_action" });
- // 2. 提取props参数
- const { editType, editData } = props;
- console.log('editData', editData)
- dispatchId.value = editData?.dispatchId || "";
- // 3. 初始化formData基础结构(固定保留actionJson默认值,仅动态处理conditionGroups)
- const baseFormData = {
- // actionJson保持初始默认结构(新增/编辑通用基础配置)
- actionJson: [
- {
- actionCode: "specify_agreement",
- agreementId: "", // 新增时为空,编辑时后续单独处理
- },
- {
- actionCode: "change_bs_account",
- linkType: "manual_input" as "manual_input" | "select_account",
- name: "",
- phone: "",
- accountId: "",
- },
- {
- actionCode: "change_bs_account",
- linkType: "select_account" as "manual_input" | "select_account",
- name: "",
- phone: "",
- accountId: "",
- },
- ],
- // 条件组:根据editType动态赋值
- conditionGroups: [] as ConditionGroup[],
- };
- let isDefaultScene = false;
- // 4. 新增场景:仅初始化conditionGroups为默认一组条件
- if (!editType || editType === "add") {
- isDefaultScene = true;
- console.log("[初始化] 进入场景:无editType或add"); // 新增日志
- // 提取原始条件组(兼容editData可能的格式)
- const rawGroups = editData?.groupedAttrLinks
- ? editData.groupedAttrLinks
- : editData?.attrLinks
- ? [editData.attrLinks]
- : [];
- console.log("[初始化] 提取到的rawGroups:", rawGroups, "长度:", rawGroups.length); // 新增日志
- // 转换rawGroups为conditionGroups
- baseFormData.conditionGroups = rawGroups.map((rawGroup: any[], groupIdx: number) => {
- const group: ConditionGroup = {
- groupKey: editData?.dispatchId || `group_${groupIdx}_${Date.now()}`,
- actions: [],
- };
- // 处理组内条件行
- if (rawGroup.length > 0) {
- group.actions = rawGroup.map((rawRow: any, rowIdx: number) => ({
- key: rawRow.id || `row_${groupIdx}_${rowIdx}_${Date.now()}`,
- attrType: rawRow.attrType || "",
- attrCode: rawRow.attrCode || "",
- operator: rawRow.operator || "",
- min: rawRow.min !== undefined ? rawRow.min : null,
- max: rawRow.max !== undefined ? rawRow.max : null,
- minArray: rawRow.minArray ? [...rawRow.minArray] : [],
- errorMsg: "",
- }));
- } else {
- // 组内无数据时,兜底1行
- group.actions.push({
- key: Date.now(),
- attrType: "",
- attrCode: "",
- operator: "",
- min: null,
- max: null,
- errorMsg: "",
- minArray: [],
- });
- }
- return group;
- });
- // 第一次兜底:如果转换后还是空,直接加1组
- if (baseFormData.conditionGroups.length === 0) {
- console.log("[初始化] rawGroups为空,第一次兜底添加1组条件"); // 新增日志
- baseFormData.conditionGroups.push({
- groupKey: Date.now(),
- actions: [
- {
- key: Date.now(),
- attrType: "",
- attrCode: "",
- operator: "",
- min: null,
- max: null,
- errorMsg: "",
- minArray: [],
- },
- ],
- });
- }
- }
- // 5. 编辑场景:从editData解析conditionGroups(保持之前的编辑逻辑)
- else if (
- editType === "edit" &&
- editData &&
- Object.keys(editData).length > 0
- ) {
- const rawGroups = editData.groupedAttrLinks
- ? editData.groupedAttrLinks
- : editData.attrLinks
- ? [editData.attrLinks]
- : [];
- baseFormData.conditionGroups = rawGroups.map(
- (rawGroup: any[], groupIdx: number) => {
- const group: ConditionGroup = {
- groupKey: editData.dispatchId || `group_${groupIdx}_${Date.now()}`,
- actions: [],
- };
- rawGroup.forEach((rawRow: any, rowIdx: number) => {
- console.log('rawRow', rawRow)
- group.actions.push({
- key: rawRow.id || `row_${groupIdx}_${rowIdx}_${Date.now()}`,
- attrType: rawRow.attrType || "",
- attrCode: rawRow.attrCode || "",
- operator: rawRow.operator || "",
- min: rawRow.min !== undefined ? rawRow.min : null,
- max: rawRow.max !== undefined ? rawRow.max : null,
- minArray: rawRow.minArray ? [...rawRow.minArray] : [],
- errorMsg: "",
- });
- });
- // 兜底:确保每组至少有一行条件
- if (group.actions.length === 0) {
- group.actions.push({
- key: Date.now(),
- attrType: "",
- attrCode: "",
- operator: "",
- min: null,
- max: null,
- errorMsg: "",
- minArray: [],
- });
- }
- console.log('group-------------', group)
- return group;
- }
- );
- // 编辑场景补充:回显actionJson(报价协议和对接人信息)
- if (editData.actions && editData.actions.length > 0) {
- // 回显报价协议
- const agreementAction = editData.actions.find(
- (action: any) => action.actionCode === "specify_agreement"
- );
- if (agreementAction?.actionJson?.agreementId) {
- baseFormData.actionJson[0].agreementId =
- agreementAction.actionJson.agreementId;
- }
- // 回显对接人信息
- const linkAction = editData.actions.find(
- (action: any) =>
- action.actionCode === "change_poc"
- );
- const linkAction1 = editData.actions.find(
- (action: any) =>
- action.actionCode === "change_bs_account"
- );
- if (linkAction?.actionJson) {
- const linkJson = linkAction.actionJson;
- if (linkJson.accountId) {
- baseFormData.actionJson[1].linkType = "select_account";
- baseFormData.actionJson[1].accountId = linkJson.accountId;
- } else {
- linkTypeList.value.push('manual_input')
- baseFormData.actionJson[1].linkType = "manual_input";
- baseFormData.actionJson[1].name = linkJson.name || "";
- baseFormData.actionJson[1].phone = linkJson.phone || "";
- }
- }
- if (linkAction1?.actionJson) {
- const linkJson = linkAction1.actionJson;
- if (linkJson.accountId) {
- linkTypeList.value.push('select_account')
- baseFormData.actionJson[2].linkType = "select_account";
- baseFormData.actionJson[2].accountId = linkJson.accountId;
- }
- }
- }
- if (baseFormData.conditionGroups.length === 0) {
- baseFormData.conditionGroups = [
- {
- groupKey: Date.now(),
- actions: [
- {
- key: Date.now(),
- attrType: "",
- attrCode: "",
- operator: "",
- min: null,
- max: null,
- errorMsg: "",
- minArray: [],
- },
- ],
- },
- ];
- }
- }
- // 6. 赋值给formData(确保响应式生效)
- formData.value = baseFormData;
- console.log(
- `[${editType}] 场景初始化完成,conditionGroups长度:`,
- formData.value.conditionGroups.length
- );
- });
- const regionLicenseNumber = (value: string) => {
- api.agreementApi.getAreaLicense(value).then((res: any) => {
- if (res.code == '200') {
- let data: any = [];
- res.data.map((val: any) => {
- data.push({
- idStr: val.license,
- name: val.license,
- })
- return val;
- })
- if (value == '14') {
- const licenseNoItem = dispatchList.value.find((item: any) => item.attrCode == 'LicenseNo');
- if (licenseNoItem) {
- licenseNoItem.dictLabal = data;
- }
- }
- if (value == '0') {
- const licenseAreaItem = dispatchList.value.find((item: any) => item.attrCode == 'LicenseArea');
- if (licenseAreaItem) {
- licenseAreaItem.dictLabal = data;
- }
- }
- } else {
- }
- });
- }
- </script>
- <style scoped lang="scss">
- .condition-container {
- margin-bottom: 16px;
- }
- .condition-group {
- width: 100%;
- padding: 24px;
- margin-bottom: 20px;
- border: 1px solid #eee;
- border-radius: 6px;
- box-sizing: border-box;
- background-color: #fff;
- position: relative;
- }
- .group-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 16px;
- padding-bottom: 8px;
- border-bottom: 1px solid #f0f0f0;
- }
- .condition-row {
- display: flex;
- align-items: center;
- gap: 8px;
- flex-wrap: wrap;
- }
- .add-condition-btn {
- margin-top: 8px;
- text-align: left;
- }
- .add-group-btn {
- text-align: left;
- }
- .item-title {
- display: flex;
- align-items: center;
- margin-bottom: 20px;
- span {
- display: inline-block;
- width: 4px;
- height: 18px;
- background: #0083ff;
- border-radius: 10px 10px 10px 10px;
- margin-right: 8px;
- }
- }
- .form-item {
- display: flex;
- align-items: center;
- span {
- font-size: 14px;
- margin-right: 10px;
- }
- }
- .foot {
- display: flex;
- justify-content: center;
- align-items: center;
- gap: 12px;
- padding-top: 10px;
- border-top: 1px solid #eee;
- }
- :deep(.main-container) {
- height: 100%;
- }
- :deep(.el-row) {
- height: 100%;
- }
- :deep(.el-drawer__header) {
- height: 48px;
- font-size: 20px;
- color: #333333;
- border-bottom: 1px solid #eeeeee;
- margin-bottom: 24px;
- padding-bottom: 20px;
- }
- :deep(.el-drawer__body) {
- padding: 0 24px;
- }
- </style>
|