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>
相关推荐
尘中客1 小时前
放弃 Echarts?前端直接渲染后端高精度 SVG 矢量图流的踩坑记录
前端·javascript·echarts·前端开发·svg矢量图·echarts避坑
FreeBuf_2 小时前
Chrome 0Day漏洞遭野外利用
前端·chrome
小彭努力中2 小时前
199.Vue3 + OpenLayers 实现:点击 / 拖动地图播放音频
前端·vue.js·音视频·openlayers·animate
2501_916007472 小时前
网站爬虫原理,基于浏览器点击行为还原可接口请求
前端·javascript·爬虫·ios·小程序·uni-app·iphone
前端大波2 小时前
Sentry 每日错误巡检自动化:设计思路与上手实战
前端·自动化·sentry
ZC跨境爬虫3 小时前
使用Claude Code开发校园交友平台前端UI全记录(含架构、坑点、登录逻辑及算法)
前端·ui·架构
慧一居士3 小时前
Vue项目中,何时使用布局、子组件嵌套、插槽 对应的使用场景,和完整的使用示例
前端·vue.js
Можно4 小时前
uni.request 和 axios 的区别?前端请求库全面对比
前端·uni-app
M ? A4 小时前
解决 VuReact 中 ESLint 规则冲突的完整指南
前端·react.js·前端框架
Jave21085 小时前
实现全局自定义loading指令
前端·vue.js