Commit c2ff94bd authored by tianhongyang's avatar tianhongyang

fix

parent 6d2e2778
......@@ -73,7 +73,7 @@ export const updateConsultingDetailApi = (data) => request({
* @returns
*/
export const getCustomFormDetailApi = () => request({
url: "/advisory/body/getAdvisoryBodyCustomForm",
url: "/advisory/body/getCustomFormTemplate",
method: "get",
params: {}
});
......@@ -84,7 +84,7 @@ export const getCustomFormDetailApi = () => request({
* @returns
*/
export const addCustomFormDataApi = (data) => request({
url: "/advisory/body/addAdvisoryBodyCustomForm",
url: "/advisory/body/editCustomFormTemplate",
method: "post",
data
});
......
......@@ -121,6 +121,8 @@ export default {
activeModuleId: "",
// 分栏计数
moduleCount: 0,
// 获取到的表单模板
formTemplate: {}
};
},
watch: {
......@@ -168,8 +170,8 @@ export default {
defaultField: {
type: "object",
fields: {
edit: { type: "enum", enum: [false], required: true, message: "请先保存分栏名称,当前不能处于编辑状态" },
subfieldModuleName: { type: "string", required: true, message: "分栏名称不能为空" },
edit: { type: "enum", enum: [true], required: true, message: "请先保存分栏名称,当前不能处于编辑状态" },
children: {
type: "array",
required: true,
......@@ -191,12 +193,60 @@ export default {
};
const validatorIns = new Schema(finllyRules);
const flag = await validatorIns.validate(_templateTemp, { first: true });
const _tempData = cloneDeep(this.subfieldModuleForm.subfieldModuleList);
const map = new Map();
const len = _tempData.length;
for (let index = 0; index < len; index++) {
const current = _tempData[index];
const children = current.children;
if (children?.length) {
for (let j = 0; j < children.length; j++) {
const child = children[j];
if (map.has(child.uid)) return this.$message.error(`第${index + 1}个分栏下的,第${j + 1}个表单元素字段名称重复`);
map.set(child.uid, child);
}
}
}
await this.submitCustomForm({
subfieldModuleList: _tempData
});
} catch (error) {
if (error?.errors?.length) {
console.dir(error);
const { errors, fields } = error;
this.errorHandle(errors);
}
}
},
async submitCustomForm(data) {
try {
console.log(data);
const params = {
jsonData: serialize(data)
};
if (this.formTemplate?.templateId) params["templateId"] = this.formTemplate.templateId;
const result = await addCustomFormDataApi(params);
} catch (error) {
console.log(error);
}
},
errorHandle(errors) {
try {
const len = errors.length;
for (let index = 0; index < len; index++) {
const current = errors[index];
let keyName = current.field.split(".");
const isModule = keyName[0] == "subfieldModuleList" ? true : false;
if (isModule) {
this.$message.error(`第${parseInt(keyName[1]) + 1}分栏,${current.message}`);
return;
}
this.$message.error(`${current.message}`);
}
} catch (error) {
}
},
cancelCreate() {
this.$set(this.subfieldModuleForm, "subfieldModuleList", cloneDeep(this.olduSbfieldModuleList));
},
......@@ -208,21 +258,33 @@ export default {
async getCustomFormDetail() {
try {
const result = await getCustomFormDetailApi();
if (result.code == 200 && result.data?.length) {
if (result.code == 200 && result.data) {
return result.data;
}
return [];
return null;
} catch (error) {
}
},
parseTemplate(templateJson) {
try {
const data = eval(`(${templateJson})`);
if (data) {
this.$set(this.subfieldModuleForm, "subfieldModuleList", data.subfieldModuleList);
}
} catch (error) {
elementMessageSingleton("error", `解析模板失败,${error.message}`);
}
},
async initModule() {
try {
// const result = await this.getCustomFormDetail();
// if (result.length) {
// // 有模板数据 进行回显
// return;
// }
const result = await this.getCustomFormDetail();
if (result) {
// 有模板数据 进行回显
this.formTemplate = result;
this.parseTemplate(result.jsonData);
return;
}
// 模块初始化
this.addSubfieldModule();
const component = cloneDeep(defaultComOptions[0]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment