el-cascader懒加载回显问题

思路:可以在编辑和修改的时候,新增一个el-input,修改弹窗展示出相应的name,鼠标聚焦的时候展示出el-cascader

javascript 复制代码
<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="供应商分类" prop="supplier_class_id">
				<el-cascader v-if="mode=='add' || classStutus==false" v-model="form.supplier_class_id" style="width: 100%;" :props="class_tree_props" clearable placeholder="请选择标签" :show-all-levels="false"></el-cascader>
				<el-input v-if="mode=='edit' && classStutus" v-model="form.supplier_class_name" @focus="supplierClassBlur"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button v-if="mode!='show'" type="primary" @click="submit()">保 存</el-button>
			<el-button @click="visible=false" >取 消</el-button>
		</template>
	</el-dialog>
</template>

<script>
	export default {
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增供应商',
				},
				visible: false,
				form: {},
				supplierClassList: [],
				class_tree_props: {
					label: 'name',
					value: 'id',
					checkStrictly: true,
					emitPath: false,
					lazy: true,
					lazyLoad: this.getClassOptions,
				},
				classStutus: true,
			}
		},
		mounted() {
			this.getContactList();
			this.getEvaluateList();
		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			supplierClassBlur(){
				this.classStutus = false;
			},
			async getClassOptions(node, resolve){
				if(node.data.id){
					let resp = await this.$API.supplier.supplierclass.json_list.get({ parent_id: node.data.id, page: 0 });
					resolve(resp.data.rows);
				} else {
					const resp = await this.$API.supplier.supplierclass.json_list.get({page: 0, parent_id: 1});
					resolve(resp.data.rows);
				}
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if (valid) {
						let res = null;
						if(this.form.id) {
							res = await this.$API.supplier.supplier.json_edit.put(this.form.id, this.form);
						} else {
							res = await this.$API.supplier.supplier.json_add.post(this.form);
						}
						if(res.code == 200){
							this.$emit('success');
							this.visible = false;
							this.$message.success("操作成功")
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				})
			},
			setData(data){
				this.form = {  ...data };
			}
		}
	}
</script>

<style>
</style>
相关推荐
东方小月8 小时前
从零开发一个 Coding Agent(四):使用状态机校验大模型事件流
前端·人工智能·后端
想做后端的前端8 小时前
WebGL实现FPS游戏
vue.js·游戏·webgl
Csvn8 小时前
🧩 ESM vs CJS 混用的 7 个「天坑」——从 TypeScript 编译到 Node 与浏览器
前端
Csvn9 小时前
🎯 Web 性能 API 集合:Performance Observer 的 5 个冷门妙用
前端
Csvn9 小时前
深入 React 闭包陷阱:从根源上理解并根治 stale closure
前端
whyfail9 小时前
前端学 Spring Boot(8):接口为什么越用越慢?
前端·spring boot·后端
用户0595401744610 小时前
LangChain 记忆测试踩坑实录:这两个坑让我排查了 4 小时
前端·css
程序员黑豆10 小时前
鸿蒙应用开发:@Monitor 装饰器使用教程
前端·harmonyos
SamChan9010 小时前
在Web应用中集成PDF多语言翻译功能:PDFTranslator API实战指南
前端·python·ai·pdf·yapi·机器翻译
kyriewen11 小时前
AI Agent 9秒删光了生产数据库——我给自己的项目做了5个紧急检查
前端·ai编程·claude