每个科室负责人都是根据各自的科室选取的,那么就不适合用一个数组去保存科室负责人,这个时候我们使用二维数组。
<el-table-column label="科室负责人" width="200" align="center">
<template slot-scope="scope">
<el-input :disabled="disabled" v-if="!scope.row.start" v-model="scope.row.departUserName" @focus="getReal(scope.row, scope.$index)"></el-input>
<el-select v-else :disabled="disabled" v-model="scope.row.departUser" filterable>
<el-option :label="item.realName" :value="item.userId" :key="item.userId" v-for="item in departUserList[scope.$index]"></el-option>
</el-select>
</template>
</el-table-column>
当选择了3条数据过来的时候,先给每个数组遍历添加一个start字段: this.selectedEqus.forEach(item=>{item.start=false} ;
给这个input框加一个@foucs事件,当他点击的时候将row.start=true,这就展示下拉了是吧。
根据前面选择的科室选择各自的负责人,然后用this.$set(数组, 下标,下拉数组)变成一个新的。
当查看或者编辑之前,先遍历,把start还要设置成false,这样先展示departUserName(这里注意后端一定要既返回一个depratUserId,也要加一个departUserName)