el-cascader组件 回显

发布时间:2024年01月10日
<el-form-item label="支付方式" prop="payWayList">
    <el-cascader 
    	v-model="ruleForm.payWayList" 
    	:props="propsData" 
    	clearable 
    	collapse-tags 
    	collapse-tags-tooltip
        :options="options" 
        @change="handleCasChange" 
        style="width: 360px;"
      />
</el-form-item>
const propsData = reactive({
    label: 'payTypeName',
    value: 'payTypeCode',
    children: 'nodes',
    multiple: true,
});

const handleCasChange = (value: any) => {
    console.log(value, 'value')
    let arr: any = [];
    value.map((item: any) => {
        if (item.length > 1) {
            arr.push(item[1]);
        } else {
            arr.push(item[0]);
        }
    });
    ruleForm.payWayList = arr;
};
const options = ref([]);
const getDetail = async () => {
    const res: any = await payDetail({id: mchChannelId.value});
    const result = findParentTypes(options.value, res.payWayList);
    ruleForm.payWayList = result;
};
const findParentTypes = (inputArray:any, valuesToFind:any) => {
    const parentTypes:any = [];
    inputArray.forEach((item:any) => {
        if (item.nodes.length > 0) {
            item.nodes.forEach((node:any) => {
                if (valuesToFind.includes(node.payTypeCode)) {
                    parentTypes.push([item.payTypeCode, node.payTypeCode]);
                }
            });
        } else if (valuesToFind.includes(item.payTypeCode)) {
            parentTypes.push([item.payTypeCode]);
        }
    });
    return parentTypes;
};
文章来源:https://blog.csdn.net/quhongqiang/article/details/135506139
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。