美文网首页
table表格默认展示所有联动下拉,支持增删改,第1列数据联动后

table表格默认展示所有联动下拉,支持增删改,第1列数据联动后

作者: 瓩千瓦 | 来源:发表于2023-04-12 09:53 被阅读0次

示例图片

需求

  • 已经选择了得ECUname,其余下拉框不再显示
  • 默认将软件产品中所有SWK1和SWK2存在值得TRCname全部显示,SWK1和SWK2默认显示一个任意值
  • SWK1、SWK2软件产品中ECUname对应得SWK1、SWK2得所有值
<template>
    <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column label="" width="50">
            <template slot-scope="scope">
                <i class="el-icon-circle-plus" @click="addRow(scope.row)" v-if="scope.$index === 0"></i>
                <i class="el-icon-remove" @click="deleteRow(scope.$index)" v-else></i>
            </template>
        </el-table-column>
        <el-table-column prop="ecuName" label="ECUname">
            <template slot-scope="scope">
                <el-select
                    :ref="scope.row.params" v-model="ecuForm[scope.row.params]"
                    placeholder="ECUname" :clearable="false"
                    @change="handleSupplier"
                    @visible-change="handleFilter(ecuForm[scope.row.params])">
                    <template v-for="(val, idx) in ecu_arr">
                        <el-option
                            :label="val.ecuName"
                            :value="val.ecuName"
                            :key="idx"
                            v-if="val.perms != 1"
                            @click.native="clearSwk(scope.$index)">
                        </el-option>
                    </template>
                </el-select>
                <span class="font_12 Danger" v-if="!ecuForm[scope.row.params]">请输入ECUname</span>
            </template>
        </el-table-column>
        <el-table-column prop="swk1" label="SWK1">
            <template slot-scope="scope">
                <el-select v-model="scope.row.swk1" placeholder="SWK1" :clearable="false">
                    <template v-if="ecuForm[scope.row.params]">
                        <el-option
                            v-for="(item, idx) in ecu_swk_obj[ecuForm[scope.row.params]].swk1Arr"
                            :key="idx"
                            :label="item.swPartNumber + item.swPartVersion" :value="item.swPartNumber + item.swPartVersion">
                        </el-option>
                    </template>
                </el-select>
                <span class="font_12 Danger" v-if="!scope.row.swk1">请输入SWK1</span>
            </template>
        </el-table-column>
        <el-table-column prop="swk2" label="SWK2">
            <template slot-scope="scope">
                <el-select v-model="scope.row.swk2" placeholder="SWK2" :clearable="false">
                    <template v-if="ecuForm[scope.row.params]">
                        <el-option
                            v-for="(item, idx) in ecu_swk_obj[ecuForm[scope.row.params]].swk2Arr || []"
                            :key="idx"
                            :label="item.swPartNumber + item.swPartVersion" :value="item.swPartNumber + item.swPartVersion">
                        </el-option>
                    </template>
                </el-select>
                <span class="font_12 Danger" v-if="!scope.row.swk2">请输入SWK2</span>
            </template>
        </el-table-column>
    </el-table>
</template>
export default {
    data () {
        return {
            tableData: [],
            ecu_arr: [],
            ecu_swk_obj: {},
            ecuForm: {},
            perms: 0
        }
    },
    mounted () {
        this.getParamsList()
    },
    methods: {
        getParamsList () {
            const data = [{"ecuName":"ADSC1303","partInfoList":[{"swPartNumber":"8895172642","swPartVersion":"A","swPartType":"SWK2","ecuName":null},{"swPartNumber":"8895172635","swPartVersion":"A","swPartType":"SWK1","ecuName":null},{"swPartNumber":"8895704476","swPartVersion":"B","swPartType":"SWK1","ecuName":null},{"swPartNumber":"8895704477","swPartVersion":"B","swPartType":"SWK2","ecuName":null},{"swPartNumber":"8895704476","swPartVersion":"A","swPartType":"SWK1","ecuName":null},{"swPartNumber":"8895704477","swPartVersion":"A","swPartType":"SWK2","ecuName":null}]},{"ecuName":"TCAM","partInfoList":[{"swPartNumber":"8895254274","swPartVersion":"A","swPartType":"SWK1","ecuName":null},{"swPartNumber":"8895254278","swPartVersion":"A","swPartType":"SWK2","ecuName":null},{"swPartNumber":"8895916007","swPartVersion":"A","swPartType":"SWK1","ecuName":null},{"swPartNumber":"8895916008","swPartVersion":"A","swPartType":"SWK2","ecuName":null}]},{"ecuName":"ADMC1301","partInfoList":[{"swPartNumber":"8895172621","swPartVersion":"A","swPartType":"SWK1","ecuName":null},{"swPartNumber":"8895172629","swPartVersion":"D","swPartType":"SWK2","ecuName":null},{"swPartNumber":"8895704529","swPartVersion":"A","swPartType":"SWK1","ecuName":null},{"swPartNumber":"8895704530","swPartVersion":"A","swPartType":"SWK2","ecuName":null},{"swPartNumber":"8895172629","swPartVersion":"A","swPartType":"SWK2","ecuName":null},{"swPartNumber":"8895172622","swPartVersion":"A","swPartType":"SWK1","ecuName":null},{"swPartNumber":"8895172623","swPartVersion":"A","swPartType":"SWK1","ecuName":null}]},{"ecuName":"DHU1202","partInfoList":[{"swPartNumber":"8895239040","swPartVersion":"A","swPartType":"SWK1","ecuName":null},{"swPartNumber":"8895239042","swPartVersion":"A","swPartType":"SWK2","ecuName":null}]}]
            const obj = {}
            const ecu_obj = {}
            const ecuArr = []
            const arr = []
            res.data.map((val, idx) => {
                this.perms += 1
                const sw1 = []
                const sw2 = []
                ecuArr.push({ ecuName: val.ecuName, perms: 1 })
                val.partInfoList.map(item => {
                    if (item.swPartType == 'SWK1') {
                        sw1.push(item)
                    }
                    if (item.swPartType == 'SWK2') {
                        sw2.push(item)
                    }
                })
                const temp = {
                    swk1Arr: sw1,
                    swk2Arr: sw2
                }
                obj[val.ecuName] = temp
                const params = 'ecuD' + this.perms + 'A'
                arr.push({
                    params,
                    type: idx == 0 ? 'add' : 'reduce',
                    ecuName: val.ecuName,
                    swk1: sw1.length ? (sw1[0].swPartNumber + sw1[0].swPartVersion) : '',
                    swk2: sw2.length ? (sw2[0].swPartNumber + sw2[0].swPartVersion) : '',
                    swPartType: sw1[0].swPartType || sw1[1].swPartType
                })
                ecu_obj[params] = val.ecuName;
            })
            this.ecu_arr = lodash.cloneDeep(ecuArr)
            this.ecu_swk_obj = lodash.cloneDeep(obj)
            this.tableData = lodash.cloneDeep(arr)
            this.ecuForm = lodash.cloneDeep(ecu_obj)
        },
        clearSwk (idx) {
            this.tableData[idx].swk1 = ''
            this.tableData[idx].swk2 = ''
        },
        handleFilter (val) {
            const arr = [];
            this.tableData.map((item) => {
                if (this.ecuForm[item.params] != val) {
                    this.$refs[item.params].blur();
                    arr.push(this.ecuForm[item.params]);
                }
            });
            this.ecu_arr.map((item) => {
                if (arr.includes(item.ecuName)) {
                    item.perms = 1;
                } else {
                    item.perms = '';
                }
            });
            this.ecu_arr = lodash.cloneDeep(this.ecu_arr);
        },
        handleSupplier () {
            const arr = [];
            this.ecu_arr.map((item) => (item.perms = '')); // 删除时候触发
            this.tableData.map((item) => {
                arr.push(this.ecuForm[item.params]);
            });
            setTimeout(() => {
                this.ecu_arr.map((item) => {
                    if (arr.includes(item.ecuName)) {
                        item.perms = 1;
                    } else {
                        item.perms = '';
                    }
                });
                this.ecu_arr = lodash.cloneDeep(this.ecu_arr);
            }, 0);
        },
        addRow (row) {
            this.perms += 1;
            const param = row.params + this.perms + 'A';
            this.tableData.push({
                ecuName: '',
                swk1: '',
                swk2: '',
                swPartType: '',
                params: param,
                type: 'reduce'
            });
            this.ecuForm[param] = '';
            this.ecuForm = lodash.cloneDeep(this.ecuForm);
        },
        deleteRow (index) {
            this.tableData.splice(index, 1);
            this.ecuForm = lodash.cloneDeep(this.ecuForm);
            this.handleSupplier(); // 删除时候触发事件
        },
        setEcu (idx) {
            this.tableData[idx].swk1 = ''
            this.tableData[idx].swk2 = ''
        }
    }
}

相关文章

  • fsLayui联动表格使用(二)

    复杂联动表格使用 点击主表格,加载副表格数据,支持主、副表格的 增删改查 操作。演示地址:http://fslay...

  • react-table滚动到指定行位置

    使用React-table进行表格数据和地图的联动展示,其中用户提出需要根据当前选中的要素表格中也要自动滚动到属性...

  • fsLayui联动表格使用(一)

    简单联动表格使用 点击主表格,加载副表格数据,演示地址:http://fslayui.itcto.cn 联动表格配...

  • JimuReport积木报表—表格联动图表专题

    联动是指在一个报表中点击表格某行或者图表某区域,根据点击数据重新渲染联动的图表。积木报表联动分为表格联动图表和图表...

  • Echarts表格联动

    Echarts表格联动设置最主要要设置connect,并且联动表格数据长度要相同。 html js 效果图

  • 常见网页特效

    1.下拉框联动 下拉框联动效果用于在两个或多个内容相关联的下拉框中选取数据,比如在招聘网站中选择求职意向时,需要先...

  • 自动表格布局和固定表格布局

    表格的应用场景 统计数据 电子邮件 展示大量的元数据 难点 表格默认是 自动布局算法(table-layout: ...

  • 页面控件 - 自制单选下拉列表

    1.需求 有的时候,下拉数据集,单选下拉树,以及联动的多个下拉数据集都无法满足复杂的单选要求。如下图所示,希望点击...

  • 原生js实现地址选择组件(三级联动)

    1.实现效果 2.实现步骤 首先引入地址json数据,省市区,三级联动,该demo展示省市两级联动,三级联动同理。...

  • antd tree + 可编辑的表格

    业务场景:    树和表格联动,当选中树的某个节点时,动态添加表格展示. 难点:    1. 树的层级不固定,当我...

网友评论

      本文标题:table表格默认展示所有联动下拉,支持增删改,第1列数据联动后

      本文链接:https://www.haomeiwen.com/subject/qnrwddtx.html