Commit c2ff94bd authored by tianhongyang's avatar tianhongyang

fix

parent 6d2e2778
...@@ -73,7 +73,7 @@ export const updateConsultingDetailApi = (data) => request({ ...@@ -73,7 +73,7 @@ export const updateConsultingDetailApi = (data) => request({
* @returns * @returns
*/ */
export const getCustomFormDetailApi = () => request({ export const getCustomFormDetailApi = () => request({
url: "/advisory/body/getAdvisoryBodyCustomForm", url: "/advisory/body/getCustomFormTemplate",
method: "get", method: "get",
params: {} params: {}
}); });
...@@ -84,7 +84,7 @@ export const getCustomFormDetailApi = () => request({ ...@@ -84,7 +84,7 @@ export const getCustomFormDetailApi = () => request({
* @returns * @returns
*/ */
export const addCustomFormDataApi = (data) => request({ export const addCustomFormDataApi = (data) => request({
url: "/advisory/body/addAdvisoryBodyCustomForm", url: "/advisory/body/editCustomFormTemplate",
method: "post", method: "post",
data data
}); });
......
...@@ -121,6 +121,8 @@ export default { ...@@ -121,6 +121,8 @@ export default {
activeModuleId: "", activeModuleId: "",
// 分栏计数 // 分栏计数
moduleCount: 0, moduleCount: 0,
// 获取到的表单模板
formTemplate: {}
}; };
}, },
watch: { watch: {
...@@ -168,8 +170,8 @@ export default { ...@@ -168,8 +170,8 @@ export default {
defaultField: { defaultField: {
type: "object", type: "object",
fields: { fields: {
edit: { type: "enum", enum: [false], required: true, message: "请先保存分栏名称,当前不能处于编辑状态" },
subfieldModuleName: { type: "string", required: true, message: "分栏名称不能为空" }, subfieldModuleName: { type: "string", required: true, message: "分栏名称不能为空" },
edit: { type: "enum", enum: [true], required: true, message: "请先保存分栏名称,当前不能处于编辑状态" },
children: { children: {
type: "array", type: "array",
required: true, required: true,
...@@ -191,10 +193,58 @@ export default { ...@@ -191,10 +193,58 @@ export default {
}; };
const validatorIns = new Schema(finllyRules); const validatorIns = new Schema(finllyRules);
const flag = await validatorIns.validate(_templateTemp, { first: true }); 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) { } catch (error) {
if (error?.errors?.length) { if (error?.errors?.length) {
console.dir(error); 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() { cancelCreate() {
...@@ -208,21 +258,33 @@ export default { ...@@ -208,21 +258,33 @@ export default {
async getCustomFormDetail() { async getCustomFormDetail() {
try { try {
const result = await getCustomFormDetailApi(); const result = await getCustomFormDetailApi();
if (result.code == 200 && result.data?.length) { if (result.code == 200 && result.data) {
return result.data; return result.data;
} }
return []; return null;
} catch (error) { } 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() { async initModule() {
try { try {
// const result = await this.getCustomFormDetail(); const result = await this.getCustomFormDetail();
// if (result.length) { if (result) {
// // 有模板数据 进行回显 // 有模板数据 进行回显
// return; this.formTemplate = result;
// } this.parseTemplate(result.jsonData);
return;
}
// 模块初始化 // 模块初始化
this.addSubfieldModule(); this.addSubfieldModule();
const component = cloneDeep(defaultComOptions[0]); 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