image.png
<template>
<div class="app-container">
<el-form
ref="templateForm"
:model="formData"
:rules="rules"
label-width="90px"
class="edit-page-form"
>
<el-form-item label="模板id" prop="docTreeName" v-show="false">
<el-input v-model="formData.id" v-show="true" />
</el-form-item>
<el-form-item label="模板名稱" prop="docTreeName">
<el-input
v-model="formData.docTreeName"
placeholder="請(qǐng)輸入文書樹模板名稱"
/>
</el-form-item>
<el-form-item label="審計(jì)類型" prop="auditBizType">
<treeselect
noResultsText="暫無(wú)數(shù)據(jù)"
v-model="formData.auditBizType"
:options="auditBizTypeOptions"
:show-count="true"
placeholder="請(qǐng)選擇審計(jì)業(yè)務(wù)類型 "
clearable
:style="{ width: '100%' }"
@select="selectChange"
>
<label
:style="{
color: '#606266',
'font-family':
'Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif',
'font-weight': '400',
'font-size': '14px',
}"
slot="option-label"
slot-scope="{
node,
shouldShowCount,
count,
labelClassName,
countClassName,
}"
:class="labelClassName"
>
{{ node.label }}
</label>
</treeselect>
</el-form-item>
<el-form-item label="模板描述" prop="docTreeDesc">
<el-input
v-model="formData.docTreeDesc"
type="textarea"
placeholder="請(qǐng)輸入模板描述"
:autosize="{ minRows: 4, maxRows: 4 }"
:style="{ width: '100%' }"
></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer" style="text-align: center">
<el-button type="primary" @click="submitTemplateForm">確 定</el-button>
<el-button @click="templateCancel">取 消</el-button>
</div>
</div>
</template>
<script>
import {
addDocTemplate,
updateDocTemplate,
} from "../../../api/operation/docTemplate";
import { listTreedict, loadTreeNode } from "../../../api/system/treedict";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
name: "templateInfo",
components: {
Treeselect,
},
props: {
templateForm: {
type: Object,
required: true,
},
},
data() {
return {
formData: {
id: null,
docTreeName: null,
auditBizType: null,
docTreeDesc: null,
},
auditBizTypeOptions: [],
// 表單校驗(yàn)
rules: {
auditBizType: [
{
required: true,
message: "審計(jì)類型不能為空",
trigger: "input",
},
],
docTreeName: [
{
required: true,
message: "模板名稱不能為空",
trigger: "blur",
},
],
},
};
},
watch: {
templateForm: {
deep: true,
handler(newValue, oldValue) {
console.log("newValue", newValue);
console.log("oldValue", oldValue);
console.log("this.formData", this.formData);
this.formData = {
id: newValue.id,
docTreeName: newValue.docTreeName,
auditBizType: newValue.auditBizType,
docTreeDesc: newValue.docTreeDesc,
};
},
immediate: true,
},
},
created() {
this.getListTreeDictselect();
},
methods: {
initFormData() {
this.$refs["templateForm"].resetFields();
},
// 不要用input事件 => 值更改后發(fā)出。 因?yàn)辄c(diǎn)完編輯再點(diǎn)擊新增 會(huì)導(dǎo)致校驗(yàn)的提示語(yǔ)不會(huì)消失
// 用select即可解決 =>選擇一個(gè)選項(xiàng)后發(fā)出。
selectChange(val) {
console.log("this.fromAddBtn", this.fromAddBtn);
this.$nextTick(() => {
this.$refs.templateForm.validateField("auditBizType");
});
},
/** 文書模板提交按鈕 */
submitTemplateForm() {
console.log("this.formData.auditBizType", this.formData.auditBizType);
this.$refs["templateForm"].validate((valid) => {
console.log("valid", valid);
if (valid) {
if (this.templateForm.id != null) {
updateDocTemplate(this.templateForm).then((response) => {
this.msgSuccess("模板修改成功");
this.$emit("closeDialog");
this.$refs["templateForm"].resetFields();
});
} else {
addDocTemplate(this.templateForm).then((response) => {
this.msgSuccess("模板新增成功");
this.$emit("closeDialog");
this.$refs["templateForm"].resetFields();
});
}
}
});
},
templateCancel() {
this.$emit("closeDialog");
this.$refs["templateForm"].resetFields();
// this.$refs["templateForm"].clearValidate();
},
/** 查詢審計(jì)業(yè)務(wù)類型下拉樹結(jié)構(gòu) */
getListTreeDictselect() {
loadTreeNode("auditBizType").then((response) => {
this.auditBizTypeOptions = response.data.filter((item) => {
if (item.dictId != 1) {
return true;
}
});
});
},
},
};
</script>
<style scoped>
span {
color: #333;
text-align: left;
overflow: hidden;
text-overflow: ellipsis;
font-weight: 500;
font-size: 16px;
margin-top: 2px;
}
/deep/ .audit-notice .el-form-item .el-form-item__label {
color: #333;
text-align: left;
display: inline-block;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
position: relative;
font-weight: 500;
font-size: 16px;
}
</style>