123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <template>
- <el-dialog
- title="选择元素表"
- :visible.sync="dialogVisible"
- width="800px"
- append-to-body
- :close-on-click-modal="false"
- >
- <div class="flex mg-b-10">
- <el-input
- v-model="formulaInput"
- placeholder="请输入名称"
- size="samll" clearable
- ></el-input>
- <el-button type="primary" class="mg-l-10" @click="searchFormulaName">搜索</el-button>
- </div>
- <el-table
- :data="editEleListFilter"
- border
- style="width: 100%"
- height="400px"
- >
- <el-table-column align="center" prop="eName" label="字段信息">
- </el-table-column>
- <el-table-column align="center" label="操作" width="200">
- <template slot-scope="scope">
- <el-link v-if="!scope.row.select" @click="selectElement(scope.row,scope.$index)"
- type="primary"
- >选择</el-link
- >
- <el-link
- @click="canlSelect(scope.row,scope.$index)"
- v-else
- type="danger"
- >取消选择</el-link
- >
-
- </template>
- </el-table-column>
- </el-table>
- <span slot="footer" class="dialog-footer">
- <el-button @click="dialogVisible = false">取消</el-button>
- <el-button type="primary" @click="confirmSelection">确定</el-button>
- </span>
- </el-dialog>
- </template>
- <script>
- import {getTableElments} from "@/api/manager/wbstree";
- import { log } from "@antv/g2plot/lib/utils";
- export default {
- data() {
- return {
- dialogVisible: false,
- formulaInput:'',
- editEleListFilter:[],
- editEleListAll:[],
- selectedDataValue:[]
-
-
- };
- },
- methods: {
- show(id,selectedData) {
- this.dialogVisible = true;
- this.selectedDataValue = selectedData;
- console.log(this.selectedDataValue,'this.selectedDataValue');
-
- getTableElments(id).then((res) => {
- this.editEleListFilter = res.data.data;
- this.editEleListAll = [].concat(this.editEleListFilter);
- this.updateSelectStatus();
- })
-
- },
- updateSelectStatus() {
- const selectedIds = new Set(this.selectedDataValue.map(item => item.id));
- this.editEleListFilter.forEach(item => {
- if (selectedIds.has(item.id)) {
- // item.select = true;
- this.$set(item, 'select', true)
- }
- });
- },
- //搜索 筛选
- searchFormulaName(){
- this.editEleListFilter = this.editEleListAll.filter((ele)=>{
- return ele.eName.indexOf(this.formulaInput) > -1;
- })
- },
- selectElement(row,index){
- // row.select =true
- this.$set(row, "select", true)
- console.log(row,'row');
-
- },
- canlSelect(row,index){
- this.$set(row, "select", false)
-
- },
- /**
- * 确认用户选择的操作,并将选中的数据传递给父组件
- */
- confirmSelection() {
- // 过滤出 select 为 true 的数据
- const selectedData = this.editEleListFilter.filter(item => item.select === true);
- const combinedData = [...this.selectedDataValue, ...selectedData];
- // 使用 Map 来过滤掉重复的 id
- const uniqueData = Array.from(new Map(combinedData.map(item => [item.id, item])).values());
- // 触发事件将选中的数据传递给父组件
- this.$emit('confirm-selection', uniqueData);
- this.dialogVisible = false;
-
- }
- }
- }
- </script>
|