You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
6.4 KiB

2 years ago
<template>
<div class="container">
2 years ago
<el-card shadow="always" class="card">
2 years ago
<template #header>
2 years ago
<p>{{ config.customModel ? config.customModel.name : "办理" }}</p>
2 years ago
</template>
<template>
2 years ago
<div class="steps">
<el-steps :space="120" finish-status="success" align-center>
2 years ago
<el-step
:title="node.name"
status="finish"
icon="el-icon-edit"
></el-step>
<el-step
v-for="nextNode in node.nextNodes"
:key="nextNode.id"
:title="nextNode.name"
icon="el-icon-right"
status="wait"
></el-step>
2 years ago
</el-steps>
</div>
<el-divider></el-divider>
2 years ago
<div class="form-container">
<template v-if="device === 'desktop'">
2 years ago
<DesktopForm
:device="device"
ref="desktopForm"
:sub-form="subConfig"
:fields="fields"
:original-form="form"
:readable="readableFields"
:file-list="fileList"
:script-content="scriptContent"
:writeable="writeableFields"
></DesktopForm>
2 years ago
</template>
<template v-else>
2 years ago
<MobileForm
:device="device"
ref="mobileForm"
:sub-form="subConfig"
:fields="fields"
:original-form="form"
:readable="readableFields"
:file-list="fileList"
:script-content="scriptContent"
:writeable="writeableFields"
></MobileForm>
2 years ago
</template>
</div>
2 years ago
</template>
2 years ago
<div class="btns" ref="btns">
2 years ago
<el-button type="primary" size="small" @click="submit('assign')"
>保存并流转 <i class="el-icon-right"></i
></el-button>
2 years ago
</div>
2 years ago
</el-card>
2 years ago
2 years ago
<assign ref="assign" :visible.sync="isShowAssign" :config="config" :result="result"></assign>
2 years ago
2 years ago
<el-backtop></el-backtop>
2 years ago
</div>
</template>
<script>
2 years ago
import DesktopForm from "./DesktopForm.vue";
import MobileForm from "./MobileForm.vue";
2 years ago
import assign from "./components/assign.vue";
import {create, fieldConfig, preConfig,} from "@/api/flow";
2 years ago
import { deepCopy } from "@/utils";
2 years ago
2 years ago
export default {
2 years ago
components: {
DesktopForm,
2 years ago
MobileForm,
assign,
2 years ago
},
2 years ago
data() {
2 years ago
return {
2 years ago
isShowAssign: false,
2 years ago
info: [],
config: {},
subConfig: new Map(),
form: {},
2 years ago
result: {},
fileList: {},
};
2 years ago
},
methods: {
2 years ago
generateForm(object, fields) {
fields.forEach((field) => {
if (field.type === "file") {
this.fileList[field.name] = [];
2 years ago
}
2 years ago
if (field.type === "relation") {
object[field.name] = [{}];
2 years ago
2 years ago
this.generateForm(
object[field.name][0],
this.subConfig.get(field.sub_custom_model_id)?.customModel?.fields
);
2 years ago
} else {
2 years ago
object[field.name] = "";
2 years ago
}
2 years ago
});
2 years ago
},
async getConfig() {
const loading = this.$loading({
lock: true,
2 years ago
text: "拼命加载中",
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.8)",
2 years ago
});
try {
2 years ago
const res = await preConfig(this.$route.query.module_id);
2 years ago
const { fields } = res?.customModel;
2 years ago
let subFormRequest = [];
2 years ago
const getSubForm = (id) => {
2 years ago
subFormRequest.push(fieldConfig(id));
};
fields.forEach((field) => {
if (field.sub_custom_model_id) {
getSubForm(field.sub_custom_model_id);
2 years ago
}
2 years ago
});
const subConfigs = await Promise.all(subFormRequest);
subConfigs.forEach((sub) => {
if (sub.customModel?.id) {
this.subConfig.set(sub.customModel?.id, sub);
2 years ago
}
2 years ago
});
2 years ago
this.config = res;
2 years ago
this.generateForm(this.form, fields);
this.form = Object.assign({}, this.form);
loading.close();
2 years ago
} catch (err) {
2 years ago
console.error(err);
this.$message.error("配置失败");
loading.close();
2 years ago
}
2 years ago
},
2 years ago
async submit(type) {
if (this.device === "desktop") {
console.log(this.$refs["desktopForm"].form);
let copyForm = deepCopy(this.$refs["desktopForm"].form);
let copyFile = deepCopy(this.$refs["desktopForm"].file);
2 years ago
for (let [key, value] of Object.entries(copyFile)) {
if (copyForm.hasOwnProperty(key)) {
2 years ago
copyForm[key] = value.map((i) => i.response?.id)?.toString();
2 years ago
}
}
2 years ago
// for (let key in copyForm) {
// if(copyForm[key] instanceof Array && copyForm[key][0]) {
// let formatObj = {}
// let subKeys = Object.keys(copyForm[key][0])
// subKeys.forEach(key => {
// formatObj[key] = []
// })
// copyForm[key].forEach(item => {
// subKeys.forEach(subKey => {
// formatObj[subKey].push(item[subKey])
// })
// })
// delete formatObj['_X_ROW_KEY']
// copyForm[key] = formatObj
//
// }
// }
try {
2 years ago
this.result = await create(copyForm, this.$route.query.module_id);
switch (type) {
case "only-submit":
this.$router.push("/flow/list");
break;
case "assign":
this.isShowAssign = true;
break;
}
} catch (err) {
console.error(err);
2 years ago
}
}
2 years ago
},
2 years ago
},
2 years ago
computed: {
device() {
2 years ago
return this.$store.state.app.device;
2 years ago
},
fields() {
2 years ago
return this.config?.customModel?.fields || [];
2 years ago
},
readableFields() {
2 years ago
return this.config?.currentNode?.readable || [];
2 years ago
},
writeableFields() {
2 years ago
return this.config?.currentNode?.writeable || [];
2 years ago
},
node() {
2 years ago
return this.config?.currentNode || {};
2 years ago
},
scriptContent() {
2 years ago
if (this.config?.customModel?.js) {
return this.config?.customModel?.js;
2 years ago
}
2 years ago
},
2 years ago
},
2 years ago
created() {
2 years ago
this.getConfig();
2 years ago
},
2 years ago
mounted() {},
};
2 years ago
</script>
<style scoped lang="scss">
::v-deep .el-card__header {
}
.container {
padding: 20px;
2 years ago
.card {
position: relative;
}
.btns {
margin-top: 10px;
position: sticky;
bottom: 20px;
}
2 years ago
}
2 years ago
.form-container {
}
2 years ago
@media (max-width: 768px) {
.container {
padding: 10px;
}
}
</style>